connection: kdbus_ep_policy_check_see_access* -> kdbus_conn_policy_see_name()
authorDavid Herrmann <dh.herrmann@gmail.com>
Fri, 19 Dec 2014 11:50:36 +0000 (12:50 +0100)
committerDavid Herrmann <dh.herrmann@gmail.com>
Fri, 19 Dec 2014 11:50:36 +0000 (12:50 +0100)
Same as the other policy helpers, move SEE verification to connection.c
and drop the endpoint argument. It's always implicitly given via the
connection.

Also follow the easier naming style that does not clash with policy.c.

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

index fb1b4330eaacc3d225928c3ea17f45763c5529fd..fc7797f9975f0413959050e55ccc6db03e8f536d 100644 (file)
@@ -1314,8 +1314,7 @@ int kdbus_cmd_conn_info(struct kdbus_conn *conn,
                if (!kdbus_name_is_valid(name, false))
                        return -EINVAL;
 
-               /* check if 'conn' is allowed to see 'name' */
-               ret = kdbus_ep_policy_check_see_access(conn->ep, conn, name);
+               ret = kdbus_conn_policy_see_name(conn, name);
                if (ret < 0)
                        return ret;
 
@@ -1956,3 +1955,55 @@ int kdbus_conn_policy_talk(struct kdbus_conn *conn, struct kdbus_conn *to)
        return kdbus_policy_check_talk_access(&conn->ep->bus->policy_db,
                                              conn, to);
 }
+
+/**
+ * kdbus_conn_policy_see_name_unlocked() - verify a connection can see a given
+ *                                        name
+ * @conn:              Connection
+ * @name:              Name
+ *
+ * This verifies that @conn is allowed to see the well-known name @name. Caller
+ * must hold policy-lock.
+ *
+ * Return: 0 if allowed, negative error code if not.
+ */
+int kdbus_conn_policy_see_name_unlocked(struct kdbus_conn *conn,
+                                       const char *name)
+{
+       int ret;
+
+       /*
+        * By default, all names are visible on a bus. SEE policies can only be
+        * installed on custom endpoints, where by default no name is visible.
+        */
+       if (!conn->ep->has_policy)
+               return 0;
+
+       ret = kdbus_policy_check_see_access_unlocked(&conn->ep->policy_db,
+                                                    conn->cred, name);
+
+       /* don't leak hints whether a name exists on a custom endpoint. */
+       return (ret == -EPERM) ? -ENOENT : ret;
+}
+
+/**
+ * kdbus_conn_policy_see_name() - verify a connection can see a given name
+ * @conn:              Connection
+ * @name:              Name
+ *
+ * This verifies that @conn is allowed to see the well-known name @name.
+ *
+ * Return: 0 if allowed, negative error code if not.
+ */
+int kdbus_conn_policy_see_name(struct kdbus_conn *conn, const char *name)
+{
+       int ret;
+
+       down_read(&conn->ep->policy_db.entries_rwlock);
+       mutex_lock(&conn->lock);
+       ret = kdbus_conn_policy_see_name_unlocked(conn, name);
+       mutex_unlock(&conn->lock);
+       up_read(&conn->ep->policy_db.entries_rwlock);
+
+       return ret;
+}
index b5fb36595bdcee946940b25f88505d5f242a8722..ce2278437849daf6a50a32483f7de4afebcf6d90 100644 (file)
@@ -138,6 +138,9 @@ bool kdbus_conn_has_name(struct kdbus_conn *conn, const char *name);
 
 int kdbus_conn_policy_own_name(struct kdbus_conn *conn, const char *name);
 int kdbus_conn_policy_talk(struct kdbus_conn *conn, struct kdbus_conn *to);
+int kdbus_conn_policy_see_name_unlocked(struct kdbus_conn *conn,
+                                       const char *name);
+int kdbus_conn_policy_see_name(struct kdbus_conn *conn, const char *name);
 
 /* command dispatcher */
 int kdbus_cmd_msg_send(struct kdbus_conn *conn_src,
index 84b1bc692a961af87c6e4b3b04cdd970f3b6d575..dd215a0620172a710d1ac436109b4a1f7814b1cd 100644 (file)
@@ -231,78 +231,6 @@ int kdbus_ep_policy_set(struct kdbus_ep *ep,
        return kdbus_policy_set(&ep->policy_db, items, items_size, 0, true, ep);
 }
 
-/**
- * kdbus_ep_policy_check_see_access_unlocked() - verify a connection can see
- *                                              the passed name
- * @ep:                        Endpoint to operate on
- * @conn:              Connection that lists names
- * @name:              Name that is tried to be listed
- *
- * This verifies that @conn is allowed to see the well-known name @name via the
- * endpoint @ep.
- *
- * Return: 0 if allowed, negative error code if not.
- */
-int kdbus_ep_policy_check_see_access_unlocked(struct kdbus_ep *ep,
-                                             struct kdbus_conn *conn,
-                                             const char *name)
-{
-       int ret;
-
-       /*
-        * Check policy, if the endpoint of the connection has a db.
-        * Note that policy DBs instanciated along with connections
-        * don't have SEE rules, so it's sufficient to check the
-        * endpoint's database.
-        *
-        * The lock for the policy db is held across all calls of
-        * kdbus_name_list_all(), so the entries in both writing
-        * and non-writing runs of kdbus_name_list_write() are the
-        * same.
-        */
-
-       if (!ep->has_policy)
-               return 0;
-
-       ret = kdbus_policy_check_see_access_unlocked(&ep->policy_db,
-                                                    conn->cred, name);
-
-       /* don't leak hints whether a name exists on a custom endpoint. */
-       if (ret == -EPERM)
-               return -ENOENT;
-
-       return ret;
-}
-
-/**
- * kdbus_ep_policy_check_see_access() - verify a connection can see
- *                                     the passed name
- * @ep:                        Endpoint to operate on
- * @conn:              Connection that lists names
- * @name:              Name that is tried to be listed
- *
- * This verifies that @conn is allowed to see the well-known name @name via the
- * endpoint @ep.
- *
- * Return: 0 if allowed, negative error code if not.
- */
-int kdbus_ep_policy_check_see_access(struct kdbus_ep *ep,
-                                    struct kdbus_conn *conn,
-                                    const char *name)
-{
-       int ret;
-
-       down_read(&ep->policy_db.entries_rwlock);
-       mutex_lock(&conn->lock);
-
-       ret = kdbus_ep_policy_check_see_access_unlocked(ep, conn, name);
-
-       mutex_unlock(&conn->lock);
-       up_read(&ep->policy_db.entries_rwlock);
-
-       return ret;
-}
-
 /**
  * kdbus_ep_policy_check_notification() - verify a connection is allowed to see
  *                                       the name in a notification
@@ -346,8 +274,7 @@ int kdbus_ep_policy_check_notification(struct kdbus_ep *ep,
        case KDBUS_ITEM_NAME_ADD:
        case KDBUS_ITEM_NAME_REMOVE:
        case KDBUS_ITEM_NAME_CHANGE:
-               ret = kdbus_ep_policy_check_see_access(ep, conn,
-                                                      kmsg->notify_name);
+               ret = kdbus_conn_policy_see_name(conn, kmsg->notify_name);
                break;
        default:
                break;
@@ -394,8 +321,7 @@ int kdbus_ep_policy_check_src_names(struct kdbus_ep *ep,
         * conn_dst
         */
        list_for_each_entry(e, &conn_src->names_list, conn_entry) {
-               ret = kdbus_ep_policy_check_see_access_unlocked(ep, conn_dst,
-                                                               e->name);
+               ret = kdbus_conn_policy_see_name_unlocked(conn_dst, e->name);
                if (ret == 0)
                        break;
        }
index 527b25aec037533ad95995b692f6837fb806f41c..3661ebb0db78e1954de8ef88ec3a18a467cdd0be 100644 (file)
@@ -64,12 +64,6 @@ int kdbus_ep_policy_set(struct kdbus_ep *ep,
                        const struct kdbus_item *items,
                        size_t items_size);
 
-int kdbus_ep_policy_check_see_access_unlocked(struct kdbus_ep *ep,
-                                             struct kdbus_conn *conn,
-                                             const char *name);
-int kdbus_ep_policy_check_see_access(struct kdbus_ep *ep,
-                                    struct kdbus_conn *conn,
-                                    const char *name);
 int kdbus_ep_policy_check_notification(struct kdbus_ep *ep,
                                       struct kdbus_conn *conn,
                                       const struct kdbus_kmsg *kmsg);
diff --git a/names.c b/names.c
index 11550c9184b56d16c4f5daaff0a178d22a9b5cd4..535d22efe57dbd1af50677b0249f42fcc8436631 100644 (file)
--- a/names.c
+++ b/names.c
@@ -692,7 +692,7 @@ int kdbus_cmd_name_release(struct kdbus_name_registry *reg,
        if (!kdbus_name_is_valid(name, false))
                return -EINVAL;
 
-       ret = kdbus_ep_policy_check_see_access(conn->ep, conn, name);
+       ret = kdbus_conn_policy_see_name(conn, name);
        if (ret < 0)
                return ret;
 
@@ -727,9 +727,8 @@ static int kdbus_name_list_write(struct kdbus_conn *conn,
                u64 flags;
        } h = {};
 
-       if (e && kdbus_ep_policy_check_see_access_unlocked(conn->ep, conn,
-                                                          e->name) < 0)
-                       return 0;
+       if (e && kdbus_conn_policy_see_name_unlocked(conn, e->name) < 0)
+               return 0;
 
        kdbus_kvec_set(&kvec[cnt++], &info, sizeof(info), &info.size);
 
@@ -854,7 +853,6 @@ int kdbus_cmd_name_list(struct kdbus_name_registry *reg,
                        struct kdbus_cmd_name_list *cmd)
 {
        struct kdbus_pool_slice *slice = NULL;
-       struct kdbus_policy_db *policy_db;
        struct kdbus_name_list list = {};
        const struct kdbus_item *item;
        struct kvec kvec;
@@ -869,12 +867,10 @@ int kdbus_cmd_name_list(struct kdbus_name_registry *reg,
                }
        }
 
-       policy_db = &conn->ep->policy_db;
-
        /* lock order: domain -> bus -> ep -> names -> conn */
        down_read(&reg->rwlock);
        down_read(&conn->ep->bus->conn_rwlock);
-       down_read(&policy_db->entries_rwlock);
+       down_read(&conn->ep->policy_db.entries_rwlock);
 
        /* size of header + records */
        pos = sizeof(struct kdbus_name_list);
@@ -905,7 +901,7 @@ int kdbus_cmd_name_list(struct kdbus_name_registry *reg,
 
 exit_unlock:
        kdbus_pool_slice_release(slice);
-       up_read(&policy_db->entries_rwlock);
+       up_read(&conn->ep->policy_db.entries_rwlock);
        up_read(&conn->ep->bus->conn_rwlock);
        up_read(&reg->rwlock);
        return ret;