From 549afd6bcbf9b8ba09ec1c496f73db11ff57e220 Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Tue, 14 Oct 2014 19:53:23 +0200 Subject: [PATCH] kdbus.h: add KDBUS_HELLO_ACCEPT_MEMFD (ABI break) Add another flags to the connection's flags to denote whether it want to receive memfds. Reject messages with -ECOMM if it contains a memfd if the receiver can't cope with it. Signed-off-by: Daniel Mack --- connection.c | 10 ++++++---- kdbus.h | 9 ++++++--- test/kdbus-util.c | 3 ++- test/test-connection.c | 10 ++++------ tools/kdbus-monitor.c | 3 ++- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/connection.c b/connection.c index ac26a03..daa3340 100644 --- a/connection.c +++ b/connection.c @@ -506,7 +506,8 @@ static int kdbus_conn_entry_insert(struct kdbus_conn *conn, goto exit_unlock; } - if (kmsg->fds && !(conn->flags & KDBUS_HELLO_ACCEPT_FD)) { + if ((kmsg->fds && !(conn->flags & KDBUS_HELLO_ACCEPT_FD)) || + (kmsg->memfds_count && !(conn->flags & KDBUS_HELLO_ACCEPT_FD))) { ret = -ECOMM; goto exit_unlock; } @@ -1414,9 +1415,10 @@ int kdbus_conn_new(struct kdbus_ep *ep, BUG_ON(*c); /* Reject unknown flags */ - if (hello->conn_flags & ~(KDBUS_HELLO_ACCEPT_FD | - KDBUS_HELLO_ACTIVATOR | - KDBUS_HELLO_POLICY_HOLDER | + if (hello->conn_flags & ~(KDBUS_HELLO_ACCEPT_FD | + KDBUS_HELLO_ACCEPT_MEMFD | + KDBUS_HELLO_ACTIVATOR | + KDBUS_HELLO_POLICY_HOLDER | KDBUS_HELLO_MONITOR)) return -EOPNOTSUPP; diff --git a/kdbus.h b/kdbus.h index 79a17f3..1ea4329 100644 --- a/kdbus.h +++ b/kdbus.h @@ -500,6 +500,8 @@ enum kdbus_policy_type { * enum kdbus_hello_flags - flags for struct kdbus_cmd_hello * @KDBUS_HELLO_ACCEPT_FD: The connection allows the reception of * any passed file descriptors + * @KDBUS_HELLO_ACCEPT_MEMFD: The connection allows the reception of + * any passed memfd file descriptors * @KDBUS_HELLO_ACTIVATOR: Special-purpose connection which registers * a well-know name for a process to be started * when traffic arrives @@ -514,9 +516,10 @@ enum kdbus_policy_type { */ enum kdbus_hello_flags { KDBUS_HELLO_ACCEPT_FD = 1ULL << 0, - KDBUS_HELLO_ACTIVATOR = 1ULL << 1, - KDBUS_HELLO_POLICY_HOLDER = 1ULL << 2, - KDBUS_HELLO_MONITOR = 1ULL << 3, + KDBUS_HELLO_ACCEPT_MEMFD = 1ULL << 1, + KDBUS_HELLO_ACTIVATOR = 1ULL << 2, + KDBUS_HELLO_POLICY_HOLDER = 1ULL << 3, + KDBUS_HELLO_MONITOR = 1ULL << 4, }; /** diff --git a/test/kdbus-util.c b/test/kdbus-util.c index a34fc98..2993b56 100644 --- a/test/kdbus-util.c +++ b/test/kdbus-util.c @@ -137,7 +137,8 @@ kdbus_hello(const char *path, uint64_t flags, return NULL; } - h.hello.conn_flags = flags | KDBUS_HELLO_ACCEPT_FD; + h.hello.conn_flags = flags | KDBUS_HELLO_ACCEPT_FD | + KDBUS_HELLO_ACCEPT_MEMFD; h.hello.attach_flags = _KDBUS_ATTACH_ALL; h.conn_name.type = KDBUS_ITEM_CONN_NAME; strcpy(h.conn_name.str, "this-is-my-name"); diff --git a/test/test-connection.c b/test/test-connection.c index bc397d9..7d51b4d 100644 --- a/test/test-connection.c +++ b/test/test-connection.c @@ -104,7 +104,7 @@ int kdbus_test_hello(struct kdbus_test_env *env) if (fd < 0) return TEST_ERR; - hello.conn_flags = KDBUS_HELLO_ACCEPT_FD; + hello.conn_flags = KDBUS_HELLO_ACCEPT_FD | KDBUS_HELLO_ACCEPT_MEMFD; hello.attach_flags = _KDBUS_ATTACH_ALL; hello.size = sizeof(struct kdbus_cmd_hello); hello.pool_size = POOL_SIZE; @@ -125,8 +125,6 @@ int kdbus_test_hello(struct kdbus_test_env *env) ret = ioctl(fd, KDBUS_CMD_HELLO, &hello); ASSERT_RETURN(ret == -1 && errno == EOPNOTSUPP); - hello.conn_flags = KDBUS_HELLO_ACCEPT_FD; - /* check for faulty pool sizes */ hello.pool_size = 0; ret = ioctl(fd, KDBUS_CMD_HELLO, &hello); @@ -136,9 +134,9 @@ int kdbus_test_hello(struct kdbus_test_env *env) ret = ioctl(fd, KDBUS_CMD_HELLO, &hello); ASSERT_RETURN(ret == -1 && errno == EFAULT); - hello.pool_size = POOL_SIZE; - /* success test */ + hello.pool_size = POOL_SIZE; + hello.conn_flags = KDBUS_HELLO_ACCEPT_FD | KDBUS_HELLO_ACCEPT_MEMFD; ret = ioctl(fd, KDBUS_CMD_HELLO, &hello); ASSERT_RETURN(ret == 0); @@ -304,7 +302,7 @@ int kdbus_test_writable_pool(struct kdbus_test_env *env) ASSERT_RETURN(fd >= 0); memset(&hello, 0, sizeof(hello)); - hello.conn_flags = KDBUS_HELLO_ACCEPT_FD; + hello.conn_flags = KDBUS_HELLO_ACCEPT_FD | KDBUS_HELLO_ACCEPT_MEMFD; hello.attach_flags = _KDBUS_ATTACH_ALL; hello.size = sizeof(struct kdbus_cmd_hello); hello.pool_size = POOL_SIZE; diff --git a/tools/kdbus-monitor.c b/tools/kdbus-monitor.c index 4bb61b7..ef7381e 100644 --- a/tools/kdbus-monitor.c +++ b/tools/kdbus-monitor.c @@ -81,7 +81,8 @@ static struct conn *kdbus_hello(const char *path, uint64_t flags) return NULL; } - h.hello.conn_flags = flags | KDBUS_HELLO_ACCEPT_FD; + h.hello.conn_flags = flags | KDBUS_HELLO_ACCEPT_FD | + KDBUS_HELLO_ACCEPT_MEMFD; h.hello.attach_flags = _KDBUS_ATTACH_ALL; h.type = KDBUS_ITEM_CONN_NAME; strncpy(h.comm, "monitor", sizeof(h.comm) - 1); -- 2.34.1