]> git.proxmox.com Git - mirror_ubuntu-kernels.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>
Fri, 23 Jul 2021 18:15:31 +0000 (13:15 -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>
v1: https://lkml.kernel.org/r/20210505141101.11519-4-ebiederm@xmission.co
Link: https://lkml.kernel.org/r/875yxaxmyl.fsf_-_@disp2133
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 7ef453e8a96ff1e245d21f689def9850811d8caa..f3800c0f428b75b8a42579b632f5c0fa8483ebb7 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 4413b6a4e32a3efed5ab7e9aab0830d442221ac3..d3721e01441b09406c6ef4a9162193d2d5535770 100644 (file)
@@ -1011,6 +1011,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 ab177521671253ed1336303b57778f24fc9b64b3..d3be01c46becc54240713beb4c60d3f22c7bd9e4 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 65fd26ae9d25f77b63c5a9f75ba2ebfc1ce1b860..4276b9e003ca5c265a60cea20568d5280552fb99 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 a58e0cc45d24a4475455949435d453518e181425..cea23cf95600673da588c5f32e61c71aba618978 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 06743ec054d2a99026050456094c7917b5fa7c86..b52407c56000e11c6a97a1d0b414e535cbc6b5dd 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 5a3c221f4c9d3837692a390fc2da301afadb04df..3ba180f550d7cfc9cf78e4c7133047070625b11b 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 {