#include "strv.h"
#include "memfd-util.h"
#include "capability.h"
-#include "cgroup-util.h"
#include "fileio.h"
#include "bus-internal.h"
m->kdbus->dst_id = destination ? unique : KDBUS_DST_ID_BROADCAST;
m->kdbus->payload_type = KDBUS_PAYLOAD_DBUS;
- m->kdbus->cookie = (uint64_t) m->header->serial;
+ m->kdbus->cookie = m->header->dbus2.cookie;
m->kdbus->priority = m->priority;
if (m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)
struct kdbus_item *d;
unsigned n_fds = 0;
_cleanup_free_ int *fds = NULL;
- struct bus_header *h = NULL;
- size_t total, n_bytes = 0, idx = 0;
+ struct bus_header *header = NULL;
+ void *footer = NULL;
+ size_t header_size = 0, footer_size = 0;
+ size_t n_bytes = 0, idx = 0;
const char *destination = NULL, *seclabel = NULL;
+ bool last_was_memfd = false;
int r;
assert(bus);
switch (d->type) {
case KDBUS_ITEM_PAYLOAD_OFF:
- if (!h) {
- h = (struct bus_header *)((uint8_t *)bus->kdbus_buffer + d->vec.offset);
-
- if (!bus_header_is_complete(h, d->vec.size))
- return -EBADMSG;
+ if (!header) {
+ header = (struct bus_header*)((uint8_t*) k + d->vec.offset);
+ header_size = d->vec.size;
}
+ footer = (uint8_t*) k + d->vec.offset;
+ footer_size = d->vec.size;
+
n_bytes += d->vec.size;
+ last_was_memfd = false;
break;
case KDBUS_ITEM_PAYLOAD_MEMFD:
- if (!h)
+ if (!header) /* memfd cannot be first part */
return -EBADMSG;
n_bytes += d->memfd.size;
+ last_was_memfd = true;
break;
case KDBUS_ITEM_FDS: {
}
}
- if (!h)
+ if (last_was_memfd) /* memfd cannot be last part */
return -EBADMSG;
- r = bus_header_message_size(h, &total);
- if (r < 0)
- return r;
+ if (!header)
+ return -EBADMSG;
- if (n_bytes != total)
+ if (header_size < sizeof(struct bus_header))
return -EBADMSG;
/* on kdbus we only speak native endian gvariant, never dbus1
* marshalling or reverse endian */
- if (h->version != 2 ||
- h->endian != BUS_NATIVE_ENDIAN)
+ if (header->version != 2 ||
+ header->endian != BUS_NATIVE_ENDIAN)
return -EPROTOTYPE;
- r = bus_message_from_header(bus, h, sizeof(struct bus_header), fds, n_fds, NULL, seclabel, 0, &m);
+ r = bus_message_from_header(
+ bus,
+ header, header_size,
+ footer, footer_size,
+ n_bytes,
+ fds, n_fds,
+ NULL,
+ seclabel, 0, &m);
if (r < 0)
return r;
if (idx >= begin_body) {
if (!part->is_zero)
- part->data = (uint8_t *)bus->kdbus_buffer + d->vec.offset;
+ part->data = (uint8_t* )k + d->vec.offset;
part->size = d->vec.size;
} else {
if (!part->is_zero)
- part->data = (uint8_t *)bus->kdbus_buffer + d->vec.offset + (begin_body - idx);
+ part->data = (uint8_t*) k + d->vec.offset + (begin_body - idx);
part->size = d->vec.size - (begin_body - idx);
}
case KDBUS_ITEM_PIDS:
/* The PID/TID might be missing, 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. */
+ * is faked by a bus proxy and it lacks that
+ * information about the real client (since
+ * SO_PEERCRED is used for that). Also kernel
+ * namespacing might make some of this data
+ * unavailable when untranslatable. */
if (d->pids.pid > 0) {
m->creds.pid = (pid_t) d->pids.pid;
case KDBUS_ITEM_CREDS:
- /* EUID/SUID/FSUID/EGID/SGID/FSGID might be missing too (see above). */
+ /* EUID/SUID/FSUID/EGID/SGID/FSGID might be
+ * missing too (see above). */
if ((uid_t) d->creds.uid != UID_INVALID) {
m->creds.uid = (uid_t) d->creds.uid;
goto fail;
m->creds.cgroup_root = bus->cgroup_root;
-
break;
case KDBUS_ITEM_AUDIT:
case KDBUS_ITEM_AUXGROUPS:
if (bus->creds_mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS) {
- assert_cc(sizeof(gid_t) == sizeof(uint32_t));
+ size_t i, n;
+ gid_t *g;
+
+ n = (d->size - offsetof(struct kdbus_item, data64)) / sizeof(uint64_t);
+ g = new(gid_t, n);
+ if (!g) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ for (i = 0; i < n; i++)
+ g[i] = d->data64[i];
- m->creds.n_supplementary_gids = (d->size - offsetof(struct kdbus_item, data32)) / sizeof(uint32_t);
- m->creds.supplementary_gids = (gid_t*) d->data32;
+ m->creds.supplementary_gids = g;
+ m->creds.n_supplementary_gids = n;
m->creds.mask |= SD_BUS_CREDS_SUPPLEMENTARY_GIDS;
}
goto fail;
/* Refuse messages if kdbus and dbus1 cookie doesn't match up */
- if ((uint64_t) m->header->serial != k->cookie) {
+ if ((uint64_t) m->header->dbus2.cookie != k->cookie) {
r = -EBADMSG;
goto fail;
}
int bus_kernel_take_fd(sd_bus *b) {
struct kdbus_bloom_parameter *bloom = NULL;
+ struct kdbus_item *items, *item;
struct kdbus_cmd_hello *hello;
- struct kdbus_item_list *items;
- struct kdbus_item *item;
_cleanup_free_ char *g = NULL;
const char *name;
size_t l = 0, m = 0, sz;
/* The higher 32bit of the bus_flags fields are considered
* 'incompatible flags'. Refuse them all for now. */
if (hello->bus_flags > 0xFFFFFFFFULL) {
- r = -ENOTSUP;
+ r = -EOPNOTSUPP;
goto fail;
}
/* extract bloom parameters from items */
items = (void*)((uint8_t*)b->kdbus_buffer + hello->offset);
- KDBUS_ITEM_FOREACH(item, items, items) {
+ KDBUS_FOREACH(item, items, hello->items_size) {
switch (item->type) {
case KDBUS_ITEM_BLOOM_PARAMETER:
bloom = &item->bloom_parameter;
}
if (!bloom || !bloom_validate_parameters((size_t) bloom->size, (unsigned) bloom->n_hash)) {
- r = -ENOTSUP;
+ r = -EOPNOTSUPP;
goto fail;
}
/* Anybody can send us invalid messages, let's just drop them. */
if (r == -EBADMSG || r == -EPROTOTYPE)
- log_debug_errno(r, "Ignoring invalid message: %m");
+ log_debug_errno(r, "Ignoring invalid synchronous reply: %m");
else
return r;
}
}
r = ioctl(bus->input_fd, KDBUS_CMD_RECV, &recv);
+ if (recv.return_flags & KDBUS_RECV_RETURN_DROPPED_MSGS)
+ log_debug("%s: kdbus reports %" PRIu64 " dropped broadcast messages, ignoring.", strna(bus->description), (uint64_t) recv.dropped_msgs);
if (r < 0) {
if (errno == EAGAIN)
return 0;
- if (errno == EOVERFLOW) {
- log_debug("%s: kdbus reports %" PRIu64 " dropped broadcast messages, ignoring.", strna(bus->description), (uint64_t) recv.dropped_msgs);
- return 0;
- }
-
return -errno;
}
assert(allocated);
if (!bus || !bus->is_kernel)
- return -ENOTSUP;
+ return -EOPNOTSUPP;
assert_se(pthread_mutex_lock(&bus->memfd_cache_mutex) >= 0);