]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
signal: Verify the alignment and size of siginfo_t
authorEric W. Biederman <ebiederm@xmission.com>
Tue, 4 May 2021 16:25:22 +0000 (11:25 -0500)
committerEric W. Biederman <ebiederm@xmission.com>
Wed, 5 May 2021 17:49:06 +0000 (12:49 -0500)
Update the static assertions about siginfo_t to also describe
it's alignment and size.

While investigating if it was possible to add a 64bit field into
siginfo_t[1] it became apparent that the alignment of siginfo_t
is as much a part of the ABI as the size of the structure.

If the alignment changes siginfo_t when embedded in another structure
can move to a different offset.  Which is not acceptable from an ABI
structure.

So document that fact and add static assertions to notify developers
if they change change the alignment by accident.

[1] https://lkml.kernel.org/r/YJEZdhe6JGFNYlum@elver.google.com
Acked-by: Marco Elver <elver@google.com>
Link: https://lkml.kernel.org/r/20210505141101.11519-4-ebiederm@xmission.co
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
arch/arm/kernel/signal.c
arch/arm64/kernel/signal.c
arch/arm64/kernel/signal32.c
arch/sparc/kernel/signal32.c
arch/sparc/kernel/signal_64.c
arch/x86/kernel/signal_compat.c
include/uapi/asm-generic/siginfo.h

index 2dac5d2c5cf6665496bef50cbf706caa24bf5a86..643bcb0f091b823c03e1e5ea9ed35b579ad6d9af 100644 (file)
@@ -737,6 +737,8 @@ static_assert(NSIGBUS       == 5);
 static_assert(NSIGTRAP == 6);
 static_assert(NSIGCHLD == 6);
 static_assert(NSIGSYS  == 2);
+static_assert(sizeof(siginfo_t) == 128);
+static_assert(__alignof__(siginfo_t) == 4);
 static_assert(offsetof(siginfo_t, si_signo)    == 0x00);
 static_assert(offsetof(siginfo_t, si_errno)    == 0x04);
 static_assert(offsetof(siginfo_t, si_code)     == 0x08);
index af8bd2af12986e6296549972858520cd6c12c56f..ad4bd27fc044343554eb31709443fd81b3669c16 100644 (file)
@@ -985,6 +985,8 @@ static_assert(NSIGBUS       == 5);
 static_assert(NSIGTRAP == 6);
 static_assert(NSIGCHLD == 6);
 static_assert(NSIGSYS  == 2);
+static_assert(sizeof(siginfo_t) == 128);
+static_assert(__alignof__(siginfo_t) == 8);
 static_assert(offsetof(siginfo_t, si_signo)    == 0x00);
 static_assert(offsetof(siginfo_t, si_errno)    == 0x04);
 static_assert(offsetof(siginfo_t, si_code)     == 0x08);
index b6afb646515faad91bfbce24bbea89e2b83a5aa9..ee6c7484e130949266de2070ced1238fdd4a21ef 100644 (file)
@@ -469,6 +469,8 @@ static_assert(NSIGBUS       == 5);
 static_assert(NSIGTRAP == 6);
 static_assert(NSIGCHLD == 6);
 static_assert(NSIGSYS  == 2);
+static_assert(sizeof(compat_siginfo_t) == 128);
+static_assert(__alignof__(compat_siginfo_t) == 4);
 static_assert(offsetof(compat_siginfo_t, si_signo)     == 0x00);
 static_assert(offsetof(compat_siginfo_t, si_errno)     == 0x04);
 static_assert(offsetof(compat_siginfo_t, si_code)      == 0x08);
index 778ed5c26d4a276b699ecf433512a39125f94cdb..32b977f253e3276e74bf57fe127a4aa91d596eea 100644 (file)
@@ -757,6 +757,8 @@ static_assert(NSIGBUS       == 5);
 static_assert(NSIGTRAP == 6);
 static_assert(NSIGCHLD == 6);
 static_assert(NSIGSYS  == 2);
+static_assert(sizeof(compat_siginfo_t) == 128);
+static_assert(__alignof__(compat_siginfo_t) == 4);
 static_assert(offsetof(compat_siginfo_t, si_signo)     == 0x00);
 static_assert(offsetof(compat_siginfo_t, si_errno)     == 0x04);
 static_assert(offsetof(compat_siginfo_t, si_code)      == 0x08);
index c9bbf5f290784ff6eb1bab8e9584cc8dc28fbb2b..e9dda9db156c4305333df1a972ef6a33ea72aa58 100644 (file)
@@ -567,6 +567,8 @@ static_assert(NSIGBUS       == 5);
 static_assert(NSIGTRAP == 6);
 static_assert(NSIGCHLD == 6);
 static_assert(NSIGSYS  == 2);
+static_assert(sizeof(siginfo_t) == 128);
+static_assert(__alignof__(siginfo_t) == 8);
 static_assert(offsetof(siginfo_t, si_signo)    == 0x00);
 static_assert(offsetof(siginfo_t, si_errno)    == 0x04);
 static_assert(offsetof(siginfo_t, si_code)     == 0x08);
index 0e5d0a7e203b36f5b6171cde4b4207ee67cbb32c..e735bc1293312a561d349124d2fe7c39aa8612a6 100644 (file)
@@ -34,7 +34,13 @@ static inline void signal_compat_build_tests(void)
        BUILD_BUG_ON(NSIGSYS  != 2);
 
        /* This is part of the ABI and can never change in size: */
+       BUILD_BUG_ON(sizeof(siginfo_t) != 128);
        BUILD_BUG_ON(sizeof(compat_siginfo_t) != 128);
+
+       /* This is a part of the ABI and can never change in alignment */
+       BUILD_BUG_ON(__alignof__(siginfo_t) != 8);
+       BUILD_BUG_ON(__alignof__(compat_siginfo_t) != 4);
+
        /*
         * The offsets of all the (unioned) si_fields are fixed
         * in the ABI, of course.  Make sure none of them ever
index 03d6f6d2c1fe8298ec164513a7358a541d101c24..91c80d0c10c56d68c6d44f33f797394d3cf0de1b 100644 (file)
@@ -29,6 +29,11 @@ typedef union sigval {
 #define __ARCH_SI_ATTRIBUTES
 #endif
 
+/*
+ * Be careful when extending this union.  On 32bit siginfo_t is 32bit
+ * aligned.  Which means that a 64bit field or any other field that
+ * would increase the alignment of siginfo_t will break the ABI.
+ */
 union __sifields {
        /* kill() */
        struct {