Skip to content

Commit d417302

Browse files
committed
Merge branch 'siginfo-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace
Pull siginfo cleanups from Eric Biederman: "Long ago when 2.4 was just a testing release copy_siginfo_to_user was made to copy individual fields to userspace, possibly for efficiency and to ensure initialized values were not copied to userspace. Unfortunately the design was complex, it's assumptions unstated, and humans are fallible and so while it worked much of the time that design failed to ensure unitialized memory is not copied to userspace. This set of changes is part of a new design to clean up siginfo and simplify things, and hopefully make the siginfo handling robust enough that a simple inspection of the code can be made to ensure we don't copy any unitializied fields to userspace. The design is to unify struct siginfo and struct compat_siginfo into a single definition that is shared between all architectures so that anyone adding to the set of information shared with struct siginfo can see the whole picture. Hopefully ensuring all future si_code assignments are arch independent. The design is to unify copy_siginfo_to_user32 and copy_siginfo_from_user32 so that those function are complete and cope with all of the different cases documented in signinfo_layout. I don't think there was a single implementation of either of those functions that was complete and correct before my changes unified them. The design is to introduce a series of helpers including force_siginfo_fault that take the values that are needed in struct siginfo and build the siginfo structure for their callers. Ensuring struct siginfo is built correctly. The remaining work for 4.17 (unless someone thinks it is post -rc1 material) is to push usage of those helpers down into the architectures so that architecture specific code will not need to deal with the fiddly work of intializing struct siginfo, and then when struct siginfo is guaranteed to be fully initialized change copy siginfo_to_user into a simple wrapper around copy_to_user. Further there is work in progress on the issues that have been documented requires arch specific knowledge to sort out. The changes below fix or at least document all of the issues that have been found with siginfo generation. Then proceed to unify struct siginfo the 32 bit helpers that copy siginfo to and from userspace, and generally clean up anything that is not arch specific with regards to siginfo generation. It is a lot but with the unification you can of siginfo you can already see the code reduction in the kernel" * 'siginfo-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: (45 commits) signal/memory-failure: Use force_sig_mceerr and send_sig_mceerr mm/memory_failure: Remove unused trapno from memory_failure signal/ptrace: Add force_sig_ptrace_errno_trap and use it where needed signal/powerpc: Remove unnecessary signal_code parameter of do_send_trap signal: Helpers for faults with specialized siginfo layouts signal: Add send_sig_fault and force_sig_fault signal: Replace memset(info,...) with clear_siginfo for clarity signal: Don't use structure initializers for struct siginfo signal/arm64: Better isolate the COMPAT_TASK portion of ptrace_hbptriggered ptrace: Use copy_siginfo in setsiginfo and getsiginfo signal: Unify and correct copy_siginfo_to_user32 signal: Remove the code to clear siginfo before calling copy_siginfo_from_user32 signal: Unify and correct copy_siginfo_from_user32 signal/blackfin: Remove pointless UID16_SIGINFO_COMPAT_NEEDED signal/blackfin: Move the blackfin specific si_codes to asm-generic/siginfo.h signal/tile: Move the tile specific si_codes to asm-generic/siginfo.h signal/frv: Move the frv specific si_codes to asm-generic/siginfo.h signal/ia64: Move the ia64 specific si_codes to asm-generic/siginfo.h signal/powerpc: Remove redefinition of NSIGTRAP on powerpc signal: Move addr_lsb into the _sigfault union for clarity ...
2 parents 0aebc6a + c0f4555 commit d417302

76 files changed

Lines changed: 855 additions & 1808 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎arch/arc/kernel/traps.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ unhandled_exception(const char *str, struct pt_regs *regs, siginfo_t *info)
6565
#define DO_ERROR_INFO(signr, str, name, sicode) \
6666
int name(unsigned long address, struct pt_regs *regs) \
6767
{ \
68-
siginfo_t info = { \
69-
.si_signo = signr, \
70-
.si_errno = 0, \
71-
.si_code = sicode, \
72-
.si_addr = (void __user *)address, \
73-
}; \
68+
siginfo_t info; \
69+
\
70+
clear_siginfo(&info); \
71+
info.si_signo = signr; \
72+
info.si_errno = 0; \
73+
info.si_code = sicode; \
74+
info.si_addr = (void __user *)address; \
75+
\
7476
return unhandled_exception(str, regs, &info);\
7577
}
7678

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef __ASM_SIGINFO_H
2+
#define __ASM_SIGINFO_H
3+
4+
#include <asm-generic/siginfo.h>
5+
6+
/*
7+
* SIGFPE si_codes
8+
*/
9+
#ifdef __KERNEL__
10+
#define FPE_FIXME 0 /* Broken dup of SI_USER */
11+
#endif /* __KERNEL__ */
12+
13+
#endif

‎arch/arm/kernel/ptrace.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,20 +390,14 @@ static void ptrace_hbptriggered(struct perf_event *bp,
390390
struct arch_hw_breakpoint *bkpt = counter_arch_bp(bp);
391391
long num;
392392
int i;
393-
siginfo_t info;
394393

395394
for (i = 0; i < ARM_MAX_HBP_SLOTS; ++i)
396395
if (current->thread.debug.hbp[i] == bp)
397396
break;
398397

399398
num = (i == ARM_MAX_HBP_SLOTS) ? 0 : ptrace_hbp_idx_to_num(i);
400399

401-
info.si_signo = SIGTRAP;
402-
info.si_errno = (int)num;
403-
info.si_code = TRAP_HWBKPT;
404-
info.si_addr = (void __user *)(bkpt->trigger);
405-
406-
force_sig_info(SIGTRAP, &info, current);
400+
force_sig_ptrace_errno_trap((int)num, (void __user *)(bkpt->trigger));
407401
}
408402

409403
/*

‎arch/arm/vfp/vfpmodule.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static void vfp_raise_exceptions(u32 exceptions, u32 inst, u32 fpscr, struct pt_
257257

258258
if (exceptions == VFP_EXCEPTION_ERROR) {
259259
vfp_panic("unhandled bounce", inst);
260-
vfp_raise_sigfpe(0, regs);
260+
vfp_raise_sigfpe(FPE_FIXME, regs);
261261
return;
262262
}
263263

‎arch/arm64/include/asm/compat.h‎

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -150,70 +150,6 @@ typedef u32 compat_old_sigset_t;
150150

151151
typedef u32 compat_sigset_word;
152152

153-
typedef union compat_sigval {
154-
compat_int_t sival_int;
155-
compat_uptr_t sival_ptr;
156-
} compat_sigval_t;
157-
158-
typedef struct compat_siginfo {
159-
int si_signo;
160-
int si_errno;
161-
int si_code;
162-
163-
union {
164-
int _pad[128/sizeof(int) - 3];
165-
166-
/* kill() */
167-
struct {
168-
compat_pid_t _pid; /* sender's pid */
169-
__compat_uid32_t _uid; /* sender's uid */
170-
} _kill;
171-
172-
/* POSIX.1b timers */
173-
struct {
174-
compat_timer_t _tid; /* timer id */
175-
int _overrun; /* overrun count */
176-
compat_sigval_t _sigval; /* same as below */
177-
int _sys_private; /* not to be passed to user */
178-
} _timer;
179-
180-
/* POSIX.1b signals */
181-
struct {
182-
compat_pid_t _pid; /* sender's pid */
183-
__compat_uid32_t _uid; /* sender's uid */
184-
compat_sigval_t _sigval;
185-
} _rt;
186-
187-
/* SIGCHLD */
188-
struct {
189-
compat_pid_t _pid; /* which child */
190-
__compat_uid32_t _uid; /* sender's uid */
191-
int _status; /* exit code */
192-
compat_clock_t _utime;
193-
compat_clock_t _stime;
194-
} _sigchld;
195-
196-
/* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
197-
struct {
198-
compat_uptr_t _addr; /* faulting insn/memory ref. */
199-
short _addr_lsb; /* LSB of the reported address */
200-
} _sigfault;
201-
202-
/* SIGPOLL */
203-
struct {
204-
compat_long_t _band; /* POLL_IN, POLL_OUT, POLL_MSG */
205-
int _fd;
206-
} _sigpoll;
207-
208-
/* SIGSYS */
209-
struct {
210-
compat_uptr_t _call_addr; /* calling user insn */
211-
int _syscall; /* triggering system call number */
212-
compat_uint_t _arch; /* AUDIT_ARCH_* of syscall */
213-
} _sigsys;
214-
} _sifields;
215-
} compat_siginfo_t;
216-
217153
#define COMPAT_OFF_T_MAX 0x7fffffff
218154

219155
/*

‎arch/arm64/include/uapi/asm/siginfo.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,25 @@
2121

2222
#include <asm-generic/siginfo.h>
2323

24+
/*
25+
* SIGFPE si_codes
26+
*/
27+
#ifdef __KERNEL__
28+
#define FPE_FIXME 0 /* Broken dup of SI_USER */
29+
#endif /* __KERNEL__ */
30+
31+
/*
32+
* SIGBUS si_codes
33+
*/
34+
#ifdef __KERNEL__
35+
#define BUS_FIXME 0 /* Broken dup of SI_USER */
36+
#endif /* __KERNEL__ */
37+
38+
/*
39+
* SIGTRAP si_codes
40+
*/
41+
#ifdef __KERNEL__
42+
#define TRAP_FIXME 0 /* Broken dup of SI_USER */
43+
#endif /* __KERNEL__ */
44+
2445
#endif

‎arch/arm64/kernel/debug-monitors.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,13 @@ NOKPROBE_SYMBOL(call_step_hook);
209209
static void send_user_sigtrap(int si_code)
210210
{
211211
struct pt_regs *regs = current_pt_regs();
212-
siginfo_t info = {
213-
.si_signo = SIGTRAP,
214-
.si_errno = 0,
215-
.si_code = si_code,
216-
.si_addr = (void __user *)instruction_pointer(regs),
217-
};
212+
siginfo_t info;
213+
214+
clear_siginfo(&info);
215+
info.si_signo = SIGTRAP;
216+
info.si_errno = 0;
217+
info.si_code = si_code;
218+
info.si_addr = (void __user *)instruction_pointer(regs);
218219

219220
if (WARN_ON(!user_mode(regs)))
220221
return;

‎arch/arm64/kernel/fpsimd.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ asmlinkage void do_fpsimd_acc(unsigned int esr, struct pt_regs *regs)
867867
asmlinkage void do_fpsimd_exc(unsigned int esr, struct pt_regs *regs)
868868
{
869869
siginfo_t info;
870-
unsigned int si_code = 0;
870+
unsigned int si_code = FPE_FIXME;
871871

872872
if (esr & FPEXC_IOF)
873873
si_code = FPE_FLTINV;

‎arch/arm64/kernel/ptrace.c‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -180,34 +180,34 @@ static void ptrace_hbptriggered(struct perf_event *bp,
180180
struct pt_regs *regs)
181181
{
182182
struct arch_hw_breakpoint *bkpt = counter_arch_bp(bp);
183-
siginfo_t info = {
184-
.si_signo = SIGTRAP,
185-
.si_errno = 0,
186-
.si_code = TRAP_HWBKPT,
187-
.si_addr = (void __user *)(bkpt->trigger),
188-
};
183+
siginfo_t info;
189184

190-
#ifdef CONFIG_COMPAT
191-
int i;
185+
clear_siginfo(&info);
186+
info.si_signo = SIGTRAP;
187+
info.si_errno = 0;
188+
info.si_code = TRAP_HWBKPT;
189+
info.si_addr = (void __user *)(bkpt->trigger);
192190

193-
if (!is_compat_task())
194-
goto send_sig;
191+
#ifdef CONFIG_COMPAT
192+
if (is_compat_task()) {
193+
int si_errno = 0;
194+
int i;
195195

196-
for (i = 0; i < ARM_MAX_BRP; ++i) {
197-
if (current->thread.debug.hbp_break[i] == bp) {
198-
info.si_errno = (i << 1) + 1;
199-
break;
196+
for (i = 0; i < ARM_MAX_BRP; ++i) {
197+
if (current->thread.debug.hbp_break[i] == bp) {
198+
si_errno = (i << 1) + 1;
199+
break;
200+
}
200201
}
201-
}
202202

203-
for (i = 0; i < ARM_MAX_WRP; ++i) {
204-
if (current->thread.debug.hbp_watch[i] == bp) {
205-
info.si_errno = -((i << 1) + 1);
206-
break;
203+
for (i = 0; i < ARM_MAX_WRP; ++i) {
204+
if (current->thread.debug.hbp_watch[i] == bp) {
205+
si_errno = -((i << 1) + 1);
206+
break;
207+
}
207208
}
209+
force_sig_ptrace_errno_trap(si_errno, (void __user *)bkpt->trigger);
208210
}
209-
210-
send_sig:
211211
#endif
212212
force_sig_info(SIGTRAP, &info, current);
213213
}

‎arch/arm64/kernel/signal32.c‎

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -125,86 +125,6 @@ static inline int get_sigset_t(sigset_t *set,
125125
return 0;
126126
}
127127

128-
int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
129-
{
130-
int err;
131-
132-
if (!access_ok(VERIFY_WRITE, to, sizeof(*to)))
133-
return -EFAULT;
134-
135-
/* If you change siginfo_t structure, please be sure
136-
* this code is fixed accordingly.
137-
* It should never copy any pad contained in the structure
138-
* to avoid security leaks, but must copy the generic
139-
* 3 ints plus the relevant union member.
140-
* This routine must convert siginfo from 64bit to 32bit as well
141-
* at the same time.
142-
*/
143-
err = __put_user(from->si_signo, &to->si_signo);
144-
err |= __put_user(from->si_errno, &to->si_errno);
145-
err |= __put_user(from->si_code, &to->si_code);
146-
if (from->si_code < 0)
147-
err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad,
148-
SI_PAD_SIZE);
149-
else switch (siginfo_layout(from->si_signo, from->si_code)) {
150-
case SIL_KILL:
151-
err |= __put_user(from->si_pid, &to->si_pid);
152-
err |= __put_user(from->si_uid, &to->si_uid);
153-
break;
154-
case SIL_TIMER:
155-
err |= __put_user(from->si_tid, &to->si_tid);
156-
err |= __put_user(from->si_overrun, &to->si_overrun);
157-
err |= __put_user(from->si_int, &to->si_int);
158-
break;
159-
case SIL_POLL:
160-
err |= __put_user(from->si_band, &to->si_band);
161-
err |= __put_user(from->si_fd, &to->si_fd);
162-
break;
163-
case SIL_FAULT:
164-
err |= __put_user((compat_uptr_t)(unsigned long)from->si_addr,
165-
&to->si_addr);
166-
#ifdef BUS_MCEERR_AO
167-
/*
168-
* Other callers might not initialize the si_lsb field,
169-
* so check explicitly for the right codes here.
170-
*/
171-
if (from->si_signo == SIGBUS &&
172-
(from->si_code == BUS_MCEERR_AR || from->si_code == BUS_MCEERR_AO))
173-
err |= __put_user(from->si_addr_lsb, &to->si_addr_lsb);
174-
#endif
175-
break;
176-
case SIL_CHLD:
177-
err |= __put_user(from->si_pid, &to->si_pid);
178-
err |= __put_user(from->si_uid, &to->si_uid);
179-
err |= __put_user(from->si_status, &to->si_status);
180-
err |= __put_user(from->si_utime, &to->si_utime);
181-
err |= __put_user(from->si_stime, &to->si_stime);
182-
break;
183-
case SIL_RT:
184-
err |= __put_user(from->si_pid, &to->si_pid);
185-
err |= __put_user(from->si_uid, &to->si_uid);
186-
err |= __put_user(from->si_int, &to->si_int);
187-
break;
188-
case SIL_SYS:
189-
err |= __put_user((compat_uptr_t)(unsigned long)
190-
from->si_call_addr, &to->si_call_addr);
191-
err |= __put_user(from->si_syscall, &to->si_syscall);
192-
err |= __put_user(from->si_arch, &to->si_arch);
193-
break;
194-
}
195-
return err;
196-
}
197-
198-
int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
199-
{
200-
if (copy_from_user(to, from, __ARCH_SI_PREAMBLE_SIZE) ||
201-
copy_from_user(to->_sifields._pad,
202-
from->_sifields._pad, SI_PAD_SIZE))
203-
return -EFAULT;
204-
205-
return 0;
206-
}
207-
208128
/*
209129
* VFP save/restore code.
210130
*

0 commit comments

Comments
 (0)