names: skip policy-check on NAME_RELEASE
authorDavid Herrmann <dh.herrmann@gmail.com>
Fri, 19 Dec 2014 16:36:02 +0000 (17:36 +0100)
committerDavid Herrmann <dh.herrmann@gmail.com>
Fri, 19 Dec 2014 16:36:02 +0000 (17:36 +0100)
If user-space requests to release a name, we *must* grant that. Otherwise,
a policy-change after the name was acquired might prevent the user from
releasing it.

Furthermore, there really is no reason to check policy to release
_acquire_ resources. So drop that.

However, make sure to return ESRCH regardless whether the name is un-owned
or owned by someone else. We must not leak information about a name in
case the caller cannot see it. Furthermore, it's really not our business
to return information on a name when someone tries to release it. The
information that they don't own this resource should be more than enough.
I'd be even inclined to return "0" in those cases...

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
names.c

diff --git a/names.c b/names.c
index e5713f5c44adb0aefe2afd300688bdc33be631f6..79549e66b158d7346e45eb9c7113c585abbce428 100644 (file)
--- a/names.c
+++ b/names.c
@@ -247,8 +247,8 @@ static int kdbus_name_release(struct kdbus_name_registry *reg,
 {
        struct kdbus_name_queue_item *q_tmp, *q;
        struct kdbus_name_entry *e = NULL;
+       int ret = -ESRCH;
        u32 hash;
-       int ret = 0;
 
        hash = kdbus_str_hash(name);
 
@@ -257,10 +257,8 @@ static int kdbus_name_release(struct kdbus_name_registry *reg,
        down_write(&reg->rwlock);
 
        e = kdbus_name_lookup(reg, hash, name);
-       if (!e) {
-               ret = -ESRCH;
+       if (!e)
                goto exit_unlock;
-       }
 
        /* Is the connection already the real owner of the name? */
        if (e->conn == conn) {
@@ -271,9 +269,6 @@ static int kdbus_name_release(struct kdbus_name_registry *reg,
                 * for items for connection.
                 */
 
-               /* In case the name belongs to somebody else */
-               ret = -EADDRINUSE;
-
                list_for_each_entry_safe(q, q_tmp,
                                         &e->queue_list,
                                         entry_entry) {
@@ -684,10 +679,6 @@ int kdbus_cmd_name_release(struct kdbus_name_registry *reg,
        if (!kdbus_name_is_valid(name, false))
                return -EINVAL;
 
-       ret = kdbus_conn_policy_see_name(conn, name);
-       if (ret < 0)
-               return ret;
-
        ret = kdbus_name_release(reg, conn, name);
 
        kdbus_notify_flush(conn->ep->bus);