chiark / gitweb /
tree-wide: use {pid,uid,gid}_is_valid() where appropriate
authorLennart Poettering <lennart@poettering.net>
Sat, 30 Dec 2017 14:15:03 +0000 (15:15 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:49:53 +0000 (07:49 +0200)
Also, drop UID/GID validity checks from getpeercred() as the kernel will
never pass us invalid UID/GID on userns, but the overflow UID/GID
instead. Add a comment about this.

src/basic/socket-util.c
src/libelogind/sd-bus/bus-control.c

index ea46477767cd1e9ce3a3de81dd6ecc3086d45fbe..860c8fbfcca4681277276568c9436032346852a2 100644 (file)
@@ -975,15 +975,13 @@ int getpeercred(int fd, struct ucred *ucred) {
         if (n != sizeof(struct ucred))
                 return -EIO;
 
-        /* Check if the data is actually useful and not suppressed due
-         * to namespacing issues */
-        if (u.pid <= 0)
-                return -ENODATA;
-        if (u.uid == UID_INVALID)
-                return -ENODATA;
-        if (u.gid == GID_INVALID)
+        /* Check if the data is actually useful and not suppressed due to namespacing issues */
+        if (!pid_is_valid(u.pid))
                 return -ENODATA;
 
+        /* Note that we don't check UID/GID here, as namespace translation works differently there: instead of
+         * receiving in "invalid" user/group we get the overflow UID/GID. */
+
         *ucred = u;
         return 0;
 }
index 12478e7cc68a68b20576ce302ee7173a3c78b43a..ffe0af2ce77fa757c6bd1d54fcbaed1b3e2e88b5 100644 (file)
@@ -571,17 +571,17 @@ static int bus_get_owner_creds_dbus1(sd_bus *bus, uint64_t mask, sd_bus_creds **
                 return -ENOMEM;
 
         if (bus->ucred_valid) {
-                if (bus->ucred.pid > 0) {
+                if (pid_is_valid(bus->ucred.pid)) {
                         pid = c->pid = bus->ucred.pid;
                         c->mask |= SD_BUS_CREDS_PID & mask;
                 }
 
-                if (bus->ucred.uid != UID_INVALID) {
+                if (uid_is_valid(bus->ucred.uid)) {
                         c->euid = bus->ucred.uid;
                         c->mask |= SD_BUS_CREDS_EUID & mask;
                 }
 
-                if (bus->ucred.gid != GID_INVALID) {
+                if (gid_is_valid(bus->ucred.gid)) {
                         c->egid = bus->ucred.gid;
                         c->mask |= SD_BUS_CREDS_EGID & mask;
                 }