siginfo_t ABI break on sparc64 from si_addr_lsb move 3y ago
Subsystems (12)
Re: [PATCH 0/6] Final si_trapno bits
In reply to Eric W. BiedermanQuoted 44 lines · Eric W. Biederman
Quoted 43 lines · Marco Elver
Quoted 32 lines · Eric W. Biederman
As a part of a fix for the ABI of the newly added SIGTRAP
TRAP_PERFasi_trapnowas reduced to an ordinary extention of the_sigfaultcase of struct siginfo.When Linus saw the complete set of changes come in as a fix he requested that the set of changes be trimmed down to just what was necessary to fix the SIGTRAP
TRAP_PERFABI.I had intended to get the rest of the changes into the merge window for v5.14 but I dropped the ball.
I have made the changes to stop using
__ARCH_SI_TRAPNObe per architecture so they are easier to review. In doing so I found one place on alpha where I usedsend_sig_faultinstead of send_sig_fault_trapno(...si_trapno= 0). That would not have changed the userspace behavior but it did make the kernel code less clear.My rule in these patches is everywhere that siginfo layout calls for
SIL_FAULT_TRAPNOthe code uses eitherforce_sig_fault_trapnoorsend_sig_fault_trapno.And of course I have rebased and compile tested Marco's compile time assert patches.
Eric
Eric W. Biederman (3):
signal/sparc:si_trapnois only used with SIGILLILL_ILLTRPsignal/alpha:si_trapnois only used with SIGFPE and SIGTRAPTRAP_UNK
signal: Remove the generic__ARCH_SI_TRAPNOsupportQuoted 4 lines
Marco Elver (3):
sparc64: Add compile-time asserts forsiginfo_toffsets
arm: Add compile-time asserts forsiginfo_toffsets
arm64: Add compile-time asserts forsiginfo_toffsetsNice, thanks for the respin. If I diffed it right, I see this is almost (modulo what you mentioned above) equivalent to:
https://lore.kernel.org/linux-api/[email protected]/
+ what's already in mainline. It's only missing:
Quoted 7 lines
Quoted 5 lines
signal: Verify the alignment and size of
siginfo_t
signal: RenameSIL_PERF_EVENTSIL_FAULT_PERF_EVENTfor consistencyWould this be appropriate for this series, or rather separately, or dropped completely?
Appropriate I just overlooked them.
Full series with the 2 patches just sent looks good to me.
Thanks,
-- Marco
PATCH 7/7 signal: Verify the alignment and size of siginfo_t
In reply to Eric W. BiedermanUpdate 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/[email protected]
v1: https://lkml.kernel.org/r/[email protected]
--- arch/arm/kernel/signal.c | 2 ++ arch/arm64/kernel/signal.c | 2 ++ arch/arm64/kernel/signal32.c | 2 ++ arch/sparc/kernel/signal32.c | 2 ++ arch/sparc/kernel/signal_64.c | 2 ++ arch/x86/kernel/signal_compat.c | 6 ++++++ include/uapi/asm-generic/siginfo.h | 5 +++++ 7 files changed, 21 insertions(+)
arch/arm/kernel/signal.c +2 -0
@@ -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 );
arch/arm64/kernel/signal.c +2 -0
@@ -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 );
arch/arm64/kernel/signal32.c +2 -0
@@ -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 );
arch/sparc/kernel/signal32.c +2 -0
@@ -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 );
arch/sparc/kernel/signal_64.c +2 -0
@@ -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 );
arch/x86/kernel/signal_compat.c +6 -0
@@ -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
include/uapi/asm-generic/siginfo.h +5 -0
@@ -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 {
Signature · 1 line
2.20.1
[PATCH 8/6] signal: Rename SIL_PERF_EVENT SIL_FAULT_PERF_EVENT for consistency
In reply to Eric W. BiedermanIt helps to know which part of the siginfo structure the siginfo_layout value is talking about.
v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
--- fs/signalfd.c | 4 ++-- include/linux/signal.h | 2 +- kernel/signal.c | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-)
fs/signalfd.c +2 -2
@@ -114,10 +114,10 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,break ;case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT :/* * Fall through to the SIL_FAULT case. SIL_FAULT_BNDERR, -* SIL_FAULT_PKUERR, and SIL_PERF_EVENT are only +* SIL_FAULT_PKUERR, and SIL_FAULT_PERF_EVENT are only * generated by faults that deliver them synchronously to * userspace. In case someone injects one of these signals * and signalfd catches it treat it as SIL_FAULT.
include/linux/signal.h +1 -1
@@ -44,7 +44,7 @@ enum siginfo_layout {SIL_FAULT_MCEERR ,SIL_FAULT_BNDERR ,SIL_FAULT_PKUERR , -SIL_PERF_EVENT , +SIL_FAULT_PERF_EVENT ,SIL_CHLD ,SIL_RT , SIL_SYS,
kernel/signal.c +5 -5
@@ -1213,7 +1213,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT :case SIL_SYS : ret = false;break ;
@@ -2580,7 +2580,7 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig)case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : ksig->info.si_addr =arch_untagged_si_addr ( ksig->info.si_addr, ksig->sig, ksig->info.si_code);break ;
@@ -3265,7 +3265,7 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code) layout =SIL_FAULT_PKUERR ;#endif else if ((sig == SIGTRAP) && (si_code == TRAP_PERF)) - layout =SIL_PERF_EVENT ; + layout =SIL_FAULT_PERF_EVENT ; else if (IS_ENABLED(CONFIG_SPARC) && (sig == SIGILL) && (si_code == ILL_ILLTRP)) layout =SIL_FAULT_TRAPNO ;
@@ -3394,7 +3394,7 @@ void copy_siginfo_to_external32(struct compat_siginfo *to, to->si_addr =ptr_to_compat (from->si_addr); to->si_pkey = from->si_pkey;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : to->si_addr =ptr_to_compat (from->si_addr); to->si_perf_data = from->si_perf_data; to->si_perf_type = from->si_perf_type;
@@ -3471,7 +3471,7 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to, to->si_addr =compat_ptr (from->si_addr); to->si_pkey = from->si_pkey;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : to->si_addr =compat_ptr (from->si_addr); to->si_perf_data = from->si_perf_data; to->si_perf_type = from->si_perf_type;
Signature · 1 line
2.20.1
Arnd Bergmann
maintainerQuoted 12 lines · Eric W. Biederman
The code is only safe if the analysis that says we can move
si_trapnoand perhaps the ia64 fields into the union is correct. It looks like ia64 much more actively uses it's signal extension fields including for SIGTRAP, so I am not at all certain the generic definition ofperf_sigtrapis safe on ia64.Quoted 4 lines
I suppose in theory sparc64 or alpha might start using the other fields in the future, and an application might be compiled against mismatched headers, but that is unlikely and is already broken with the current headers.
Quoted 4 lines
If we localize the use of
si_trapnoto just a few special cases on alpha and sparc I think we don't even need to worry about breaking userspace on any architecture. It will complicatesiginfo_layout, but it is a complication that reflects reality.
Ok.
Quoted 5 lines
I don't have a clue how any of this affects ia64. Does perf work on ia64? Does perf work on sparc, and alpha?
If perf works on ia64 we need to take a hard look at what is going on there as well.
ia64 never had perf support. It had oprofile until very recently, and it had a custom thing before that. My feeling is that it's increasingly unlikely to ever gain perf support in the future, given that oprofile (in user space) has required kernel perf support (in kernel) for a long time and nobody cared about that being broken either.
sparc64 has perf support for Sun UltraSPARC 3/3+/3i/4+/T1/T2/T3 and Oracle SPARC T4/T5/M7 but lacks support for most CPUs from Oracle, Fujitsu and the rest, in particular anything from the last ten years.
Alpha has perf support for EV67, EV68, EV7, EV79, and EV69, i.e. anything from 1996 to the end in 2004.
Arnd