policy: move credential checks from policy.c to endpooint.c
authorDaniel Mack <daniel@zonque.org>
Wed, 1 Oct 2014 17:34:49 +0000 (19:34 +0200)
committerDaniel Mack <daniel@zonque.org>
Wed, 1 Oct 2014 17:34:49 +0000 (19:34 +0200)
When checking the policy on custom endpoints, we cannot white-list
privileged users. Even when the bus owner and the bus client are
using the same uid, we still have to look at the policy entries,

For connections on the default endpoint, however, things are different,
so move the checks from policy.c into endpoint.c and conduct them
after checking the custom endpoint's policy db, but before the default
endpoint's is looked at.

Signed-off-by: Daniel Mack <daniel@zonque.org>
endpoint.c
policy.c

index bebb56d4ac9d36aa2f75d8661f1771d387de8167..214e3e045fdf997de30d68d764058c0efccf3584 100644 (file)
@@ -425,6 +425,11 @@ int kdbus_ep_policy_check_talk_access(struct kdbus_ep *ep,
                        return ret;
        }
 
+       if (kdbus_bus_cred_is_privileged(conn_src->bus, conn_src->cred))
+               return 0;
+       if (uid_eq(conn_src->cred->fsuid, conn_dst->cred->uid))
+               return 0;
+
        ret = kdbus_policy_check_talk_access(&ep->bus->policy_db,
                                             conn_src, conn_dst);
        if (ret < 0)
@@ -457,6 +462,9 @@ int kdbus_ep_policy_check_own_access(struct kdbus_ep *ep,
                        return ret;
        }
 
+       if (kdbus_bus_cred_is_privileged(conn->bus, conn->cred))
+               return 0;
+
        ret = kdbus_policy_check_own_access(&ep->bus->policy_db, conn, name);
        if (ret < 0)
                return ret;
index c245356a6af1b5140a7ff5d666b703f9475ec476..968814f18bec9e5b5dba3f0da1dea025d0d1bb8c 100644 (file)
--- a/policy.c
+++ b/policy.c
@@ -265,11 +265,6 @@ int kdbus_policy_check_talk_access(struct kdbus_policy_db *db,
        const void *owner;
        int ret;
 
-       if (kdbus_bus_cred_is_privileged(conn_src->bus, conn_src->cred))
-               return 0;
-       if (uid_eq(conn_src->cred->fsuid, conn_dst->cred->uid))
-               return 0;
-
        /*
         * If there was a positive match for these two connections before,
         * there's an entry in the hash table for them.
@@ -345,9 +340,6 @@ int kdbus_policy_check_see_access_unlocked(struct kdbus_policy_db *db,
 {
        const struct kdbus_policy_db_entry *e;
 
-       if (kdbus_bus_cred_is_privileged(conn->bus, conn->cred))
-               return 0;
-
        e = kdbus_policy_lookup(db, name, kdbus_str_hash(name), true);
        return kdbus_policy_check_access(e, conn->cred, KDBUS_POLICY_SEE);
 }