chiark / gitweb /
bus: align kdbus ioctl parameters to 8byte
authorDavid Herrmann <dh.herrmann@gmail.com>
Mon, 22 Sep 2014 10:49:47 +0000 (12:49 +0200)
committerDavid Herrmann <dh.herrmann@gmail.com>
Mon, 22 Sep 2014 12:27:02 +0000 (14:27 +0200)
All kdbus ioctl arguments must be 8byte aligned. Make sure we use
alloca_align() and _alignas_(8) in all situations where gcc doesn't
guarantee 8-byte alignment.

Note that objects on the stack are always 8byte aligned as we put
_alignas_(8) into the structure definition in kdbus.h.

src/libsystemd/sd-bus/bus-control.c
src/libsystemd/sd-bus/bus-kernel.c
src/libsystemd/sd-bus/bus-message.c

index ad372f6772c5b8a3b795f5636ad4ac1c96eac30c..5ac48c081f9bac5297dfe44bd325e4094ec052ff 100644 (file)
@@ -60,7 +60,7 @@ static int bus_request_name_kernel(sd_bus *bus, const char *name, uint64_t flags
 
         l = strlen(name);
         size = offsetof(struct kdbus_cmd_name, name) + l + 1;
-        n = alloca0(size);
+        n = alloca0_align(size, 8);
         n->size = size;
         kdbus_translate_request_name_flags(flags, (uint64_t *) &n->flags);
         memcpy(n->name, name, l+1);
@@ -151,7 +151,7 @@ static int bus_release_name_kernel(sd_bus *bus, const char *name) {
         assert(name);
 
         l = strlen(name);
-        n = alloca0(offsetof(struct kdbus_cmd_name, name) + l + 1);
+        n = alloca0_align(offsetof(struct kdbus_cmd_name, name) + l + 1, 8);
         n->size = offsetof(struct kdbus_cmd_name, name) + l + 1;
         memcpy(n->name, name, l+1);
 
@@ -376,11 +376,11 @@ static int bus_get_owner_kdbus(
                 return r;
         if (r > 0) {
                 size = offsetof(struct kdbus_cmd_conn_info, name);
-                cmd = alloca0(size);
+                cmd = alloca0_align(size, 8);
                 cmd->id = id;
         } else {
                 size = offsetof(struct kdbus_cmd_conn_info, name) + strlen(name) + 1;
-                cmd = alloca0(size);
+                cmd = alloca0_align(size, 8);
                 strcpy(cmd->name, name);
         }
 
@@ -827,7 +827,7 @@ static int add_name_change_match(sd_bus *bus,
                             offsetof(struct kdbus_notify_name_change, name) +
                             l);
 
-                m = alloca0(sz);
+                m = alloca0_align(sz, 8);
                 m->size = sz;
                 m->cookie = cookie;
 
@@ -887,7 +887,7 @@ static int add_name_change_match(sd_bus *bus,
                             offsetof(struct kdbus_item, id_change) +
                             sizeof(struct kdbus_notify_id_change));
 
-                m = alloca0(sz);
+                m = alloca0_align(sz, 8);
                 m->size = sz;
                 m->cookie = cookie;
 
@@ -1057,7 +1057,7 @@ int bus_add_match_internal_kernel(
         if (using_bloom)
                 sz += ALIGN8(offsetof(struct kdbus_item, data64) + bus->bloom_size);
 
-        m = alloca0(sz);
+        m = alloca0_align(sz, 8);
         m->size = sz;
         m->cookie = cookie;
 
index b3cc996b1e869fe391d3cf7da0ef759532244afb..c30491e687d93df414c4b0c5e98d3d1674b30289 100644 (file)
@@ -709,7 +709,7 @@ int bus_kernel_take_fd(sd_bus *b) {
                 sz += ALIGN8(offsetof(struct kdbus_item, str) + l + 1);
         }
 
-        hello = alloca0(sz);
+        hello = alloca0_align(sz, 8);
         hello->size = sz;
         hello->conn_flags = b->hello_flags;
         hello->attach_flags = b->attach_flags;
@@ -796,7 +796,7 @@ int bus_kernel_connect(sd_bus *b) {
 }
 
 static void close_kdbus_msg(sd_bus *bus, struct kdbus_msg *k) {
-        uint64_t off;
+        uint64_t off _alignas_(8);
         struct kdbus_item *d;
 
         assert(bus);
@@ -1268,10 +1268,11 @@ int bus_kernel_create_bus(const char *name, bool world, char **s) {
         if (fd < 0)
                 return -errno;
 
-        make = alloca0(ALIGN8(offsetof(struct kdbus_cmd_make, items) +
-                              offsetof(struct kdbus_item, data64) + sizeof(uint64_t) +
-                              offsetof(struct kdbus_item, str) +
-                              DECIMAL_STR_MAX(uid_t) + 1 + strlen(name) + 1));
+        make = alloca0_align(ALIGN8(offsetof(struct kdbus_cmd_make, items) +
+                                    offsetof(struct kdbus_item, data64) + sizeof(uint64_t) +
+                                    offsetof(struct kdbus_item, str) +
+                                    DECIMAL_STR_MAX(uid_t) + 1 + strlen(name) + 1),
+                             8);
 
         make->size = offsetof(struct kdbus_cmd_make, items);
 
@@ -1423,7 +1424,7 @@ int bus_kernel_create_endpoint(const char *bus_name, const char *ep_name, char *
         size = ALIGN8(offsetof(struct kdbus_cmd_make, items));
         size += ALIGN8(offsetof(struct kdbus_item, str) + strlen(ep_name) + 1);
 
-        make = alloca0(size);
+        make = alloca0_align(size, 8);
         make->size = size;
         make->flags = KDBUS_MAKE_ACCESS_WORLD;
 
@@ -1472,7 +1473,7 @@ int bus_kernel_set_endpoint_policy(int fd, uid_t uid, BusEndpoint *ep) {
                 size += ALIGN8(offsetof(struct kdbus_item, policy_access) + sizeof(struct kdbus_policy_access));
         }
 
-        update = alloca0(size);
+        update = alloca0_align(size, 8);
         update->size = size;
 
         n = update->items;
@@ -1528,7 +1529,7 @@ int bus_kernel_make_starter(
                ALIGN8(offsetof(struct kdbus_item, str) + strlen(name) + 1) +
                policy_cnt * ALIGN8(offsetof(struct kdbus_item, policy_access) + sizeof(struct kdbus_policy_access));
 
-        hello = alloca0(size);
+        hello = alloca0_align(size, 8);
 
         n = hello->items;
         strcpy(n->str, name);
@@ -1588,9 +1589,10 @@ int bus_kernel_create_domain(const char *name, char **s) {
         if (fd < 0)
                 return -errno;
 
-        make = alloca0(ALIGN8(offsetof(struct kdbus_cmd_make, items) +
-                              offsetof(struct kdbus_item, str) +
-                              strlen(name) + 1));
+        make = alloca0_align(ALIGN8(offsetof(struct kdbus_cmd_make, items) +
+                                    offsetof(struct kdbus_item, str) +
+                                    strlen(name) + 1),
+                             8);
 
         n = make->items;
         strcpy(n->str, name);
index 1fa3ad2611f2171e10b1f0319aca0ec9310b8b42..400ba307bc9bc05113386dce4afafde915b294fc 100644 (file)
@@ -128,7 +128,7 @@ static void message_free(sd_bus_message *m) {
         message_reset_parts(m);
 
         if (m->release_kdbus) {
-                uint64_t off;
+                uint64_t off _alignas_(8);
 
                 off = (uint8_t *)m->kdbus - (uint8_t *)m->bus->kdbus_buffer;
                 ioctl(m->bus->input_fd, KDBUS_CMD_FREE, &off);