From 25b47758b748dbc0afaaa96d5bfd72e3c4cc7c67 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Tue, 26 Jun 2018 12:01:44 +0200 Subject: [PATCH] linux: new slots for non-existent capabilities only Prevent allocation of new cap-space slots each time a capability is received by checking if the received capability already exists. Fixes #2885 --- repos/base-linux/src/lib/base/ipc.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/repos/base-linux/src/lib/base/ipc.cc b/repos/base-linux/src/lib/base/ipc.cc index 0ababee1e..2ab0d75b0 100644 --- a/repos/base-linux/src/lib/base/ipc.cc +++ b/repos/base-linux/src/lib/base/ipc.cc @@ -301,8 +301,20 @@ static void extract_sds_from_message(unsigned start_index, int const associated_sd = Genode::ep_sd_registry()->try_associate(sd, id); - buf.insert(Capability_space::import(Rpc_destination(associated_sd), - Rpc_obj_key(badge))); + Native_capability arg_cap = Capability_space::lookup(Rpc_obj_key(badge)); + + if (arg_cap.valid()) { + + /* + * Discard the received selector and keep using the already + * present one. + */ + + buf.insert(arg_cap); + } else { + buf.insert(Capability_space::import(Rpc_destination(associated_sd), + Rpc_obj_key(badge))); + } if ((associated_sd >= 0) && (associated_sd != sd)) {