systemd/0355-bus-align-kdbus-ioctl-parameters-to-8byte.patch
Zbigniew Jędrzejewski-Szmek 62fe9450da Update to latest git
2014-10-07 15:51:56 -04:00

173 lines
7.0 KiB
Diff

From 7f3d3ba1a61f28a951ca5fbe59ed15c7ce55219c Mon Sep 17 00:00:00 2001
From: David Herrmann <dh.herrmann@gmail.com>
Date: Mon, 22 Sep 2014 12:49:47 +0200
Subject: [PATCH] bus: align kdbus ioctl parameters to 8byte
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 | 14 +++++++-------
src/libsystemd/sd-bus/bus-kernel.c | 26 ++++++++++++++------------
src/libsystemd/sd-bus/bus-message.c | 2 +-
3 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index ad372f6772..5ac48c081f 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -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;
diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c
index b3cc996b1e..c30491e687 100644
--- a/src/libsystemd/sd-bus/bus-kernel.c
+++ b/src/libsystemd/sd-bus/bus-kernel.c
@@ -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);
diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
index 1fa3ad2611..400ba307bc 100644
--- a/src/libsystemd/sd-bus/bus-message.c
+++ b/src/libsystemd/sd-bus/bus-message.c
@@ -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);