Skip to content

Commit add0b32

Browse files
committed
siginfo: Move si_trapno inside the union inside _si_fault
It turns out that linux uses si_trapno very sparingly, and as such it can be considered extra information for a very narrow selection of signals, rather than information that is present with every fault reported in siginfo. As such move si_trapno inside the union inside of _si_fault. This results in no change in placement, and makes it eaiser to extend _si_fault in the future as this reduces the number of special cases. In particular with si_trapno included in the union it is no longer a concern that the union must be pointer aligned on most architectures because the union follows immediately after si_addr which is a pointer. This change results in a difference in siginfo field placement on sparc and alpha for the fields si_addr_lsb, si_lower, si_upper, si_pkey, and si_perf. These architectures do not implement the signals that would use si_addr_lsb, si_lower, si_upper, si_pkey, and si_perf. Further these architecture have not yet implemented the userspace that would use si_perf. The point of this change is in fact to correct these placement issues before sparc or alpha grow userspace that cares. This change was discussed[1] and the agreement is that this change is currently safe. [1]: https://lkml.kernel.org/r/CAK8P3a0+uKYwL1NhY6Hvtieghba2hKYGD6hcKx5n8=4Gtt+pHA@mail.gmail.com Acked-by: Marco Elver <elver@google.com> v1: https://lkml.kernel.org/r/m1tunns7yf.fsf_-_@fess.ebiederm.org v2: https://lkml.kernel.org/r/20210505141101.11519-5-ebiederm@xmission.com Link: https://lkml.kernel.org/r/20210517195748.8880-1-ebiederm@xmission.com Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent 42dec9a commit add0b32

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

arch/x86/kernel/signal_compat.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ static inline void signal_compat_build_tests(void)
127127
BUILD_BUG_ON(offsetof(siginfo_t, si_addr) != 0x10);
128128
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_addr) != 0x0C);
129129

130+
BUILD_BUG_ON(offsetof(siginfo_t, si_trapno) != 0x18);
131+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_trapno) != 0x10);
132+
130133
BUILD_BUG_ON(offsetof(siginfo_t, si_addr_lsb) != 0x18);
131134
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_addr_lsb) != 0x10);
132135

include/linux/compat.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,11 @@ typedef struct compat_siginfo {
214214
/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */
215215
struct {
216216
compat_uptr_t _addr; /* faulting insn/memory ref. */
217-
#ifdef __ARCH_SI_TRAPNO
218-
int _trapno; /* TRAP # which caused the signal */
219-
#endif
220217
#define __COMPAT_ADDR_BND_PKEY_PAD (__alignof__(compat_uptr_t) < sizeof(short) ? \
221218
sizeof(short) : __alignof__(compat_uptr_t))
222219
union {
220+
/* used on alpha and sparc */
221+
int _trapno; /* TRAP # which caused the signal */
223222
/*
224223
* used when si_code=BUS_MCEERR_AR or
225224
* used when si_code=BUS_MCEERR_AO

include/uapi/asm-generic/siginfo.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ union __sifields {
6363
/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */
6464
struct {
6565
void __user *_addr; /* faulting insn/memory ref. */
66-
#ifdef __ARCH_SI_TRAPNO
67-
int _trapno; /* TRAP # which caused the signal */
68-
#endif
6966
#ifdef __ia64__
7067
int _imm; /* immediate value for "break" */
7168
unsigned int _flags; /* see ia64 si_flags */
@@ -75,6 +72,8 @@ union __sifields {
7572
#define __ADDR_BND_PKEY_PAD (__alignof__(void *) < sizeof(short) ? \
7673
sizeof(short) : __alignof__(void *))
7774
union {
75+
/* used on alpha and sparc */
76+
int _trapno; /* TRAP # which caused the signal */
7877
/*
7978
* used when si_code=BUS_MCEERR_AR or
8079
* used when si_code=BUS_MCEERR_AO
@@ -150,9 +149,7 @@ typedef struct siginfo {
150149
#define si_int _sifields._rt._sigval.sival_int
151150
#define si_ptr _sifields._rt._sigval.sival_ptr
152151
#define si_addr _sifields._sigfault._addr
153-
#ifdef __ARCH_SI_TRAPNO
154152
#define si_trapno _sifields._sigfault._trapno
155-
#endif
156153
#define si_addr_lsb _sifields._sigfault._addr_lsb
157154
#define si_lower _sifields._sigfault._addr_bnd._lower
158155
#define si_upper _sifields._sigfault._addr_bnd._upper

kernel/signal.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4607,6 +4607,7 @@ static inline void siginfo_buildtime_checks(void)
46074607

46084608
/* sigfault */
46094609
CHECK_OFFSET(si_addr);
4610+
CHECK_OFFSET(si_trapno);
46104611
CHECK_OFFSET(si_addr_lsb);
46114612
CHECK_OFFSET(si_lower);
46124613
CHECK_OFFSET(si_upper);

0 commit comments

Comments
 (0)