[systemd-devel] [PATCH] libsystemd-bus: make sure buf transfered into kenrel is 8 aligned

Yin Kangkai kangkai.yin at linux.intel.com
Mon Dec 16 00:21:10 PST 2013


From: Yin Kangkai <kangkai.yin at intel.com>

Otherwise, for example hello arg passed to KDBUS_CMD_HELLO might not be 8 bytes
aligned and kernel returns -EFAULT.

319     int bus_kernel_take_fd(sd_bus *b) {
320             struct kdbus_cmd_hello hello;

(gdb) p &hello
$8 = (struct kdbus_cmd_hello *) 0xbffff354
---
 src/libsystemd-bus/bus-control.c | 4 ++--
 src/libsystemd-bus/bus-kernel.c  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
index 0072c37..6b2790d 100644
--- a/src/libsystemd-bus/bus-control.c
+++ b/src/libsystemd-bus/bus-control.c
@@ -207,7 +207,7 @@ _public_ int sd_bus_release_name(sd_bus *bus, const char *name) {
 }
 
 static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
-        struct kdbus_cmd_name_list cmd = {};
+        struct kdbus_cmd_name_list __attribute__ ((__aligned__(8))) cmd = {};
         struct kdbus_name_list *name_list;
         struct kdbus_cmd_name *name;
         uint64_t previous_id = 0;
@@ -1088,7 +1088,7 @@ static int bus_remove_match_internal_kernel(
                 const char *match,
                 uint64_t cookie) {
 
-        struct kdbus_cmd_match m;
+        struct kdbus_cmd_match __attribute__ ((__aligned__(8))) m;
         int r;
 
         assert(bus);
diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index 0e47308..4947d39 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -317,7 +317,7 @@ fail:
 }
 
 int bus_kernel_take_fd(sd_bus *b) {
-        struct kdbus_cmd_hello hello;
+        struct kdbus_cmd_hello __attribute__ ((__aligned__(8))) hello;
         int r;
 
         assert(b);
-- 
1.8.2.1



More information about the systemd-devel mailing list