[systemd-devel] [PATCH 3/4] connection: use the already cached metadata if KDBUS_HELLO_CACHE_META is set

Djalal Harouni tixxdz at opendz.org
Fri Jun 27 03:32:07 PDT 2014


For connections with the KDBUS_HELLO_CACHE_META flag dup the
metadata/credentials from handle or from the HELLO cmd, and use it to
construct kdbus kmsg object, this improves benchmark by ~50%

The KDBUS_HELLO_CACHE_META flag is only for privileged bus users, others
will fail with -EPERM. Privileged bus users can do what ever they want.

This will also have a valid use case where you have a privileged process
that serves multiple connections and perhaps broadcasting, normal
unprivileged connections should just trust what they receive and should
not be able to cause extra work for the privileged process.

Signed-off-by: Djalal Harouni <tixxdz at opendz.org>
---
 connection.c | 22 +++++++++++++++++++---
 connection.h |  2 +-
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/connection.c b/connection.c
index 85ffa5a..f460ad1 100644
--- a/connection.c
+++ b/connection.c
@@ -1230,7 +1230,16 @@ int kdbus_conn_kmsg_send(struct kdbus_ep *ep,
 
 	/* non-kernel senders append credentials/metadata */
 	if (conn_src) {
-		ret = kdbus_meta_new(&kmsg->meta);
+		/*
+		 * If KDBUS_HELLO_CACHE_META then dup and use the
+		 * cached metadata/credentials from handle or from
+		 * HELLO cmd, otherwise allocate a new one.
+		 */
+		if (conn_src->flags & KDBUS_HELLO_CACHE_META)
+			ret = kdbus_meta_memdup(conn_src->meta, &kmsg->meta);
+		else
+			ret = kdbus_meta_new(&kmsg->meta);
+
 		if (ret < 0)
 			return ret;
 	}
@@ -1888,9 +1897,16 @@ int kdbus_conn_new(struct kdbus_ep *ep,
 	if (is_activator && is_policy_holder)
 		return -EINVAL;
 
-	/* only privileged connections can activate and monitor */
+	/*
+	 * Only privileged connections can be/do :
+	 * 1) Activators
+	 * 2) Policy holders
+	 * 3) Monitors
+	 * 4) Use the cached metadata
+	 */
 	if (!kdbus_bus_uid_is_privileged(bus) &&
-	    (is_activator || is_policy_holder || is_monitor))
+	    (is_activator || is_policy_holder || is_monitor ||
+	     hello->conn_flags & KDBUS_HELLO_CACHE_META))
 		return -EPERM;
 
 	KDBUS_ITEMS_FOREACH(item, hello->items,
diff --git a/connection.h b/connection.h
index 46f7b6e..c8b1e25 100644
--- a/connection.h
+++ b/connection.h
@@ -47,7 +47,7 @@
  * @work:		Delayed work to handle timeouts
  * @match_db:		Subscription filter to broadcast messages
  * @meta:		Active connection creator's metadata/credentials,
- *			either from the handle of from HELLO
+ *			either from the handle or from HELLO
  * @owner_meta:		The connection's metadata/credentials supplied by
  *			HELLO
  * @pool:		The user's buffer to receive messages
-- 
1.9.3



More information about the systemd-devel mailing list