X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd%2Fsd-bus%2Fbus-kernel.c;h=27899c1989140d0ce193cdf14565739da9933596;hb=1a2409e262da65a4b0ca8ab18fcf5eabd2d404ca;hp=0c39e22ed78706dc066f85e77d5f6ef732e0eb88;hpb=2c652b6bfe816296a5664dae1125e6bb665b9d5e;p=elogind.git diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c index 0c39e22ed..27899c198 100644 --- a/src/libsystemd/sd-bus/bus-kernel.c +++ b/src/libsystemd/sd-bus/bus-kernel.c @@ -332,6 +332,18 @@ fail: return r; } +static void unset_memfds(struct sd_bus_message *m) { + struct bus_body_part *part; + unsigned i; + + assert(m); + + /* Make sure the memfds are not freed twice */ + MESSAGE_FOREACH_PART(part, i, m) + if (part->memfd >= 0) + part->memfd = -1; +} + static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) { sd_bus_message *m = NULL; struct kdbus_item *d; @@ -627,17 +639,8 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) { return 1; fail: - if (m) { - struct bus_body_part *part; - unsigned i; - - /* Make sure the memfds are not freed twice */ - MESSAGE_FOREACH_PART(part, i, m) - if (part->memfd >= 0) - part->memfd = -1; - - sd_bus_message_unref(m); - } + unset_memfds(m); + sd_bus_message_unref(m); return r; } @@ -796,14 +799,14 @@ int bus_kernel_connect(sd_bus *b) { } static void close_kdbus_msg(sd_bus *bus, struct kdbus_msg *k) { - uint64_t off _alignas_(8); + struct kdbus_cmd_free cmd; struct kdbus_item *d; assert(bus); assert(k); - off = (uint8_t *)k - (uint8_t *)bus->kdbus_buffer; - ioctl(bus->input_fd, KDBUS_CMD_FREE, &off); + cmd.flags = 0; + cmd.offset = (uint8_t *)k - (uint8_t *)bus->kdbus_buffer; KDBUS_ITEM_FOREACH(d, k, items) { @@ -812,6 +815,8 @@ static void close_kdbus_msg(sd_bus *bus, struct kdbus_msg *k) { else if (d->type == KDBUS_ITEM_PAYLOAD_MEMFD) safe_close(d->memfd.fd); } + + (void) ioctl(bus->input_fd, KDBUS_CMD_FREE, &cmd); } int bus_kernel_write_message(sd_bus *bus, sd_bus_message *m, bool hint_sync_call) { @@ -1302,9 +1307,9 @@ int bus_kernel_create_bus(const char *name, bool world, char **s) { return -errno; } - /* The higher 32bit of the flags field are considered - * 'incompatible flags'. Refuse them all for now. */ - if (make->flags > 0xFFFFFFFFULL) { + /* The features field are considered 'incompatible flags'. + * Refuse them all for now. */ + if (make->features) { safe_close(fd); return -ENOTSUP; } @@ -1434,14 +1439,14 @@ int bus_kernel_create_endpoint(const char *bus_name, const char *ep_name, char * n->size = offsetof(struct kdbus_item, str) + strlen(ep_name) + 1; strcpy(n->str, ep_name); - if (ioctl(fd, KDBUS_CMD_EP_MAKE, make) < 0) { + if (ioctl(fd, KDBUS_CMD_ENDPOINT_MAKE, make) < 0) { safe_close(fd); return -errno; } - /* The higher 32bit of the flags field are considered - * 'incompatible flags'. Refuse them all for now. */ - if (make->flags > 0xFFFFFFFFULL) { + /* The features field are considered 'incompatible flags'. + * Refuse them all for now. */ + if (make->features) { safe_close(fd); return -ENOTSUP; } @@ -1498,7 +1503,7 @@ int bus_kernel_set_endpoint_policy(int fd, uid_t uid, BusEndpoint *ep) { n = KDBUS_ITEM_NEXT(n); } - r = ioctl(fd, KDBUS_CMD_EP_UPDATE, update); + r = ioctl(fd, KDBUS_CMD_ENDPOINT_UPDATE, update); if (r < 0) return -errno; @@ -1561,6 +1566,7 @@ int bus_kernel_make_starter( hello->size = size; hello->conn_flags = + KDBUS_HELLO_ACCEPT_MEMFD | (activating ? KDBUS_HELLO_ACTIVATOR : KDBUS_HELLO_POLICY_HOLDER) | (accept_fd ? KDBUS_HELLO_ACCEPT_FD : 0); hello->pool_size = KDBUS_POOL_SIZE; @@ -1571,7 +1577,8 @@ int bus_kernel_make_starter( /* The higher 32bit of both flags fields are considered * 'incompatible flags'. Refuse them all for now. */ - if (hello->bus_flags > 0xFFFFFFFFULL || + if (hello->features || + hello->bus_flags > 0xFFFFFFFFULL || hello->conn_flags > 0xFFFFFFFFULL) return -ENOTSUP;