diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-12-24 16:20:47 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-12-24 16:20:47 +0100 |
commit | 2dc9970bed3cee69e6746b110a649a9285dd6369 (patch) | |
tree | 848a91dc350b1d077ee5c98b5ea2bc90cd793a2f /src/libsystemd-bus/bus-kernel.c | |
parent | eff05270986a13e7de93ae16311f654d3f7c166f (diff) |
bus: only accept kdbus creds if they are valid
This allows userspace to fake kdbus creds via struct ucred in the proxy,
without making the recieving side choke on the missing fields of the
kdbus struct, more precisel pid_starttime and tid
Diffstat (limited to 'src/libsystemd-bus/bus-kernel.c')
-rw-r--r-- | src/libsystemd-bus/bus-kernel.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c index 05544e1e47..19d97b7e00 100644 --- a/src/libsystemd-bus/bus-kernel.c +++ b/src/libsystemd-bus/bus-kernel.c @@ -793,12 +793,27 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) { } case KDBUS_ITEM_CREDS: - m->creds.pid_starttime = d->creds.starttime / NSEC_PER_USEC; + /* UID/GID/PID are always valid */ m->creds.uid = d->creds.uid; m->creds.gid = d->creds.gid; m->creds.pid = d->creds.pid; - m->creds.tid = d->creds.tid; - m->creds.mask |= (SD_BUS_CREDS_UID|SD_BUS_CREDS_GID|SD_BUS_CREDS_PID|SD_BUS_CREDS_PID_STARTTIME|SD_BUS_CREDS_TID) & bus->creds_mask; + m->creds.mask |= (SD_BUS_CREDS_UID|SD_BUS_CREDS_GID|SD_BUS_CREDS_PID) & bus->creds_mask; + + /* The PID starttime/TID might be missing + * however, when the data is faked by some + * data bus proxy and it lacks that + * information about the real client since + * SO_PEERCRED is used for that */ + + if (d->creds.starttime > 0) { + m->creds.pid_starttime = d->creds.starttime / NSEC_PER_USEC; + m->creds.mask |= SD_BUS_CREDS_PID_STARTTIME & bus->creds_mask; + } + + if (d->creds.tid > 0) { + m->creds.tid = d->creds.tid; + m->creds.mask |= SD_BUS_CREDS_TID & bus->creds_mask; + } break; case KDBUS_ITEM_TIMESTAMP: |