Skip to content

Commit a0e31f3

Browse files
committed
Merge branch 'for-v5.13-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace
Pull siginfo fix from Eric Biederman: "During the merge window an issue with si_perf and the siginfo ABI came up. The alpha and sparc siginfo structure layout had changed with the addition of SIGTRAP TRAP_PERF and the new field si_perf. The reason only alpha and sparc were affected is that they are the only architectures that use si_trapno. Looking deeper it was discovered that si_trapno is used for only a few select signals on alpha and sparc, and that none of the other _sigfault fields past si_addr are used at all. Which means technically no regression on alpha and sparc. While the alignment concerns might be dismissed the abuse of si_errno by SIGTRAP TRAP_PERF does have the potential to cause regressions in existing userspace. While we still have time before userspace starts using and depending on the new definition siginfo for SIGTRAP TRAP_PERF this set of changes cleans up siginfo_t. - The si_trapno field is demoted from magic alpha and sparc status and made an ordinary union member of the _sigfault member of siginfo_t. Without moving it of course. - si_perf is replaced with si_perf_data and si_perf_type ending the abuse of si_errno. - Unnecessary additions to signalfd_siginfo are removed" * 'for-v5.13-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: signalfd: Remove SIL_PERF_EVENT fields from signalfd_siginfo signal: Deliver all of the siginfo perf data in _perf signal: Factor force_sig_perf out of perf_sigtrap signal: Implement SIL_FAULT_TRAPNO siginfo: Move si_trapno inside the union inside _si_fault
2 parents c1f47eb + 922e301 commit a0e31f3

File tree

12 files changed

+79
-73
lines changed

12 files changed

+79
-73
lines changed

arch/m68k/kernel/signal.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,8 @@ static inline void siginfo_build_tests(void)
623623
BUILD_BUG_ON(offsetof(siginfo_t, si_pkey) != 0x12);
624624

625625
/* _sigfault._perf */
626-
BUILD_BUG_ON(offsetof(siginfo_t, si_perf) != 0x10);
626+
BUILD_BUG_ON(offsetof(siginfo_t, si_perf_data) != 0x10);
627+
BUILD_BUG_ON(offsetof(siginfo_t, si_perf_type) != 0x14);
627628

628629
/* _sigpoll */
629630
BUILD_BUG_ON(offsetof(siginfo_t, si_band) != 0x0c);

arch/x86/kernel/signal_compat.c

Lines changed: 7 additions & 2 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

@@ -138,8 +141,10 @@ static inline void signal_compat_build_tests(void)
138141
BUILD_BUG_ON(offsetof(siginfo_t, si_pkey) != 0x20);
139142
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_pkey) != 0x14);
140143

141-
BUILD_BUG_ON(offsetof(siginfo_t, si_perf) != 0x18);
142-
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_perf) != 0x10);
144+
BUILD_BUG_ON(offsetof(siginfo_t, si_perf_data) != 0x18);
145+
BUILD_BUG_ON(offsetof(siginfo_t, si_perf_type) != 0x20);
146+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_perf_data) != 0x10);
147+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_perf_type) != 0x14);
143148

144149
CHECK_CSI_OFFSET(_sigpoll);
145150
CHECK_CSI_SIZE (_sigpoll, 2*sizeof(int));

fs/signalfd.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,29 +114,24 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
114114
break;
115115
case SIL_FAULT_BNDERR:
116116
case SIL_FAULT_PKUERR:
117+
case SIL_PERF_EVENT:
117118
/*
118-
* Fall through to the SIL_FAULT case. Both SIL_FAULT_BNDERR
119-
* and SIL_FAULT_PKUERR are only generated by faults that
120-
* deliver them synchronously to userspace. In case someone
121-
* injects one of these signals and signalfd catches it treat
122-
* it as SIL_FAULT.
119+
* Fall through to the SIL_FAULT case. SIL_FAULT_BNDERR,
120+
* SIL_FAULT_PKUERR, and SIL_PERF_EVENT are only
121+
* generated by faults that deliver them synchronously to
122+
* userspace. In case someone injects one of these signals
123+
* and signalfd catches it treat it as SIL_FAULT.
123124
*/
124125
case SIL_FAULT:
125126
new.ssi_addr = (long) kinfo->si_addr;
126-
#ifdef __ARCH_SI_TRAPNO
127-
new.ssi_trapno = kinfo->si_trapno;
128-
#endif
129127
break;
130-
case SIL_FAULT_MCEERR:
128+
case SIL_FAULT_TRAPNO:
131129
new.ssi_addr = (long) kinfo->si_addr;
132-
#ifdef __ARCH_SI_TRAPNO
133130
new.ssi_trapno = kinfo->si_trapno;
134-
#endif
135-
new.ssi_addr_lsb = (short) kinfo->si_addr_lsb;
136131
break;
137-
case SIL_PERF_EVENT:
132+
case SIL_FAULT_MCEERR:
138133
new.ssi_addr = (long) kinfo->si_addr;
139-
new.ssi_perf = kinfo->si_perf;
134+
new.ssi_addr_lsb = (short) kinfo->si_addr_lsb;
140135
break;
141136
case SIL_CHLD:
142137
new.ssi_pid = kinfo->si_pid;

include/linux/compat.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,11 @@ typedef struct compat_siginfo {
213213
/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */
214214
struct {
215215
compat_uptr_t _addr; /* faulting insn/memory ref. */
216-
#ifdef __ARCH_SI_TRAPNO
217-
int _trapno; /* TRAP # which caused the signal */
218-
#endif
219216
#define __COMPAT_ADDR_BND_PKEY_PAD (__alignof__(compat_uptr_t) < sizeof(short) ? \
220217
sizeof(short) : __alignof__(compat_uptr_t))
221218
union {
219+
/* used on alpha and sparc */
220+
int _trapno; /* TRAP # which caused the signal */
222221
/*
223222
* used when si_code=BUS_MCEERR_AR or
224223
* used when si_code=BUS_MCEERR_AO
@@ -236,7 +235,10 @@ typedef struct compat_siginfo {
236235
u32 _pkey;
237236
} _addr_pkey;
238237
/* used when si_code=TRAP_PERF */
239-
compat_ulong_t _perf;
238+
struct {
239+
compat_ulong_t _data;
240+
u32 _type;
241+
} _perf;
240242
};
241243
} _sigfault;
242244

include/linux/sched/signal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ int send_sig_mceerr(int code, void __user *, short, struct task_struct *);
326326

327327
int force_sig_bnderr(void __user *addr, void __user *lower, void __user *upper);
328328
int force_sig_pkuerr(void __user *addr, u32 pkey);
329+
int force_sig_perf(void __user *addr, u32 type, u64 sig_data);
329330

330331
int force_sig_ptrace_errno_trap(int errno, void __user *addr);
331332

include/linux/signal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ enum siginfo_layout {
4040
SIL_TIMER,
4141
SIL_POLL,
4242
SIL_FAULT,
43+
SIL_FAULT_TRAPNO,
4344
SIL_FAULT_MCEERR,
4445
SIL_FAULT_BNDERR,
4546
SIL_FAULT_PKUERR,

include/uapi/asm-generic/siginfo.h

Lines changed: 8 additions & 7 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
@@ -92,7 +91,10 @@ union __sifields {
9291
__u32 _pkey;
9392
} _addr_pkey;
9493
/* used when si_code=TRAP_PERF */
95-
unsigned long _perf;
94+
struct {
95+
unsigned long _data;
96+
__u32 _type;
97+
} _perf;
9698
};
9799
} _sigfault;
98100

@@ -150,14 +152,13 @@ typedef struct siginfo {
150152
#define si_int _sifields._rt._sigval.sival_int
151153
#define si_ptr _sifields._rt._sigval.sival_ptr
152154
#define si_addr _sifields._sigfault._addr
153-
#ifdef __ARCH_SI_TRAPNO
154155
#define si_trapno _sifields._sigfault._trapno
155-
#endif
156156
#define si_addr_lsb _sifields._sigfault._addr_lsb
157157
#define si_lower _sifields._sigfault._addr_bnd._lower
158158
#define si_upper _sifields._sigfault._addr_bnd._upper
159159
#define si_pkey _sifields._sigfault._addr_pkey._pkey
160-
#define si_perf _sifields._sigfault._perf
160+
#define si_perf_data _sifields._sigfault._perf._data
161+
#define si_perf_type _sifields._sigfault._perf._type
161162
#define si_band _sifields._sigpoll._band
162163
#define si_fd _sifields._sigpoll._fd
163164
#define si_call_addr _sifields._sigsys._call_addr

include/uapi/linux/perf_event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ struct perf_event_attr {
464464

465465
/*
466466
* User provided data if sigtrap=1, passed back to user via
467-
* siginfo_t::si_perf, e.g. to permit user to identify the event.
467+
* siginfo_t::si_perf_data, e.g. to permit user to identify the event.
468468
*/
469469
__u64 sig_data;
470470
};

include/uapi/linux/signalfd.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ struct signalfd_siginfo {
3939
__s32 ssi_syscall;
4040
__u64 ssi_call_addr;
4141
__u32 ssi_arch;
42-
__u32 __pad3;
43-
__u64 ssi_perf;
4442

4543
/*
4644
* Pad strcture to 128 bytes. Remember to update the
@@ -51,7 +49,7 @@ struct signalfd_siginfo {
5149
* comes out of a read(2) and we really don't want to have
5250
* a compat on read(2).
5351
*/
54-
__u8 __pad[16];
52+
__u8 __pad[28];
5553
};
5654

5755

kernel/events/core.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6389,8 +6389,6 @@ void perf_event_wakeup(struct perf_event *event)
63896389

63906390
static void perf_sigtrap(struct perf_event *event)
63916391
{
6392-
struct kernel_siginfo info;
6393-
63946392
/*
63956393
* We'd expect this to only occur if the irq_work is delayed and either
63966394
* ctx->task or current has changed in the meantime. This can be the
@@ -6405,13 +6403,8 @@ static void perf_sigtrap(struct perf_event *event)
64056403
if (current->flags & PF_EXITING)
64066404
return;
64076405

6408-
clear_siginfo(&info);
6409-
info.si_signo = SIGTRAP;
6410-
info.si_code = TRAP_PERF;
6411-
info.si_errno = event->attr.type;
6412-
info.si_perf = event->attr.sig_data;
6413-
info.si_addr = (void __user *)event->pending_addr;
6414-
force_sig_info(&info);
6406+
force_sig_perf((void __user *)event->pending_addr,
6407+
event->attr.type, event->attr.sig_data);
64156408
}
64166409

64176410
static void perf_pending_event_disable(struct perf_event *event)

0 commit comments

Comments
 (0)