Skip to content

Commit 3eb0f51

Browse files
committed
signal: Ensure every siginfo we send has all bits initialized
Call clear_siginfo to ensure every stack allocated siginfo is properly initialized before being passed to the signal sending functions. Note: It is not safe to depend on C initializers to initialize struct siginfo on the stack because C is allowed to skip holes when initializing a structure. The initialization of struct siginfo in tracehook_report_syscall_exit was moved from the helper user_single_step_siginfo into tracehook_report_syscall_exit itself, to make it clear that the local variable siginfo gets fully initialized. In a few cases the scope of struct siginfo has been reduced to make it clear that siginfo siginfo is not used on other paths in the function in which it is declared. Instances of using memset to initialize siginfo have been replaced with calls clear_siginfo for clarity. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent f6ed1ec commit 3eb0f51

68 files changed

Lines changed: 158 additions & 24 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/alpha/kernel/osf_sys.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ SYSCALL_DEFINE5(osf_setsysinfo, unsigned long, op, void __user *, buffer,
881881
if (fex & IEEE_TRAP_ENABLE_DZE) si_code = FPE_FLTDIV;
882882
if (fex & IEEE_TRAP_ENABLE_INV) si_code = FPE_FLTINV;
883883

884+
clear_siginfo(&info);
884885
info.si_signo = SIGFPE;
885886
info.si_errno = 0;
886887
info.si_code = si_code;

‎arch/alpha/kernel/signal.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ do_sigreturn(struct sigcontext __user *sc)
221221
if (ptrace_cancel_bpt (current)) {
222222
siginfo_t info;
223223

224+
clear_siginfo(&info);
224225
info.si_signo = SIGTRAP;
225226
info.si_errno = 0;
226227
info.si_code = TRAP_BRKPT;
@@ -255,6 +256,7 @@ do_rt_sigreturn(struct rt_sigframe __user *frame)
255256
if (ptrace_cancel_bpt (current)) {
256257
siginfo_t info;
257258

259+
clear_siginfo(&info);
258260
info.si_signo = SIGTRAP;
259261
info.si_errno = 0;
260262
info.si_code = TRAP_BRKPT;

‎arch/alpha/kernel/traps.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ do_entArith(unsigned long summary, unsigned long write_mask,
228228
}
229229
die_if_kernel("Arithmetic fault", regs, 0, NULL);
230230

231+
clear_siginfo(&info);
231232
info.si_signo = SIGFPE;
232233
info.si_errno = 0;
233234
info.si_code = si_code;
@@ -241,6 +242,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
241242
siginfo_t info;
242243
int signo, code;
243244

245+
clear_siginfo(&info);
244246
if ((regs->ps & ~IPL_MAX) == 0) {
245247
if (type == 1) {
246248
const unsigned int *data
@@ -430,6 +432,7 @@ do_entDbg(struct pt_regs *regs)
430432

431433
die_if_kernel("Instruction fault", regs, 0, NULL);
432434

435+
clear_siginfo(&info);
433436
info.si_signo = SIGILL;
434437
info.si_errno = 0;
435438
info.si_code = ILL_ILLOPC;
@@ -761,6 +764,8 @@ do_entUnaUser(void __user * va, unsigned long opcode,
761764
siginfo_t info;
762765
long error;
763766

767+
clear_siginfo(&info);
768+
764769
/* Check the UAC bits to decide what the user wants us to do
765770
with the unaliged access. */
766771

‎arch/alpha/mm/fault.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
9191
siginfo_t info;
9292
unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
9393

94+
clear_siginfo(&info);
95+
9496
/* As of EV6, a load into $31/$f31 is a prefetch, and never faults
9597
(or is suppressed by the PALcode). Support that for older CPUs
9698
by ignoring such an instruction. */

‎arch/arc/mm/fault.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ void do_page_fault(unsigned long address, struct pt_regs *regs)
7070
int write = regs->ecr_cause & ECR_C_PROTV_STORE; /* ST/EX */
7171
unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
7272

73+
clear_siginfo(&info);
74+
7375
/*
7476
* We fault-in kernel-space virtual memory on-demand. The
7577
* 'reference' page table is init_mm.pgd.

‎arch/arm/kernel/ptrace.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ void ptrace_break(struct task_struct *tsk, struct pt_regs *regs)
205205
{
206206
siginfo_t info;
207207

208+
clear_siginfo(&info);
208209
info.si_signo = SIGTRAP;
209210
info.si_errno = 0;
210211
info.si_code = TRAP_BRKPT;

‎arch/arm/kernel/swp_emulate.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ static void set_segfault(struct pt_regs *regs, unsigned long addr)
112112
{
113113
siginfo_t info;
114114

115+
clear_siginfo(&info);
115116
down_read(&current->mm->mmap_sem);
116117
if (find_vma(current->mm, addr) == NULL)
117118
info.si_code = SEGV_MAPERR;

‎arch/arm/kernel/traps.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ asmlinkage void do_undefinstr(struct pt_regs *regs)
439439
siginfo_t info;
440440
void __user *pc;
441441

442+
clear_siginfo(&info);
442443
pc = (void __user *)instruction_pointer(regs);
443444

444445
if (processor_mode(regs) == SVC_MODE) {
@@ -537,6 +538,7 @@ static int bad_syscall(int n, struct pt_regs *regs)
537538
{
538539
siginfo_t info;
539540

541+
clear_siginfo(&info);
540542
if ((current->personality & PER_MASK) != PER_LINUX) {
541543
send_sig(SIGSEGV, current, 1);
542544
return regs->ARM_r0;
@@ -604,6 +606,7 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
604606
{
605607
siginfo_t info;
606608

609+
clear_siginfo(&info);
607610
if ((no >> 16) != (__ARM_NR_BASE>> 16))
608611
return bad_syscall(no, regs);
609612

@@ -740,6 +743,8 @@ baddataabort(int code, unsigned long instr, struct pt_regs *regs)
740743
unsigned long addr = instruction_pointer(regs);
741744
siginfo_t info;
742745

746+
clear_siginfo(&info);
747+
743748
#ifdef CONFIG_DEBUG_USER
744749
if (user_debug & UDBG_BADABORT) {
745750
pr_err("[%d] %s: bad data abort: code %d instr 0x%08lx\n",

‎arch/arm/mm/alignment.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,7 @@ do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
950950
if (ai_usermode & UM_SIGNAL) {
951951
siginfo_t si;
952952

953+
clear_siginfo(&si);
953954
si.si_signo = SIGBUS;
954955
si.si_errno = 0;
955956
si.si_code = BUS_ADRALN;

‎arch/arm/mm/fault.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
163163
{
164164
struct siginfo si;
165165

166+
clear_siginfo(&si);
167+
166168
#ifdef CONFIG_DEBUG_USER
167169
if (((user_debug & UDBG_SEGV) && (sig == SIGSEGV)) ||
168170
((user_debug & UDBG_BUS) && (sig == SIGBUS))) {
@@ -557,6 +559,7 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
557559
inf->name, fsr, addr);
558560
show_pte(current->mm, addr);
559561

562+
clear_siginfo(&info);
560563
info.si_signo = inf->sig;
561564
info.si_errno = 0;
562565
info.si_code = inf->code;
@@ -589,6 +592,7 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
589592
pr_alert("Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
590593
inf->name, ifsr, addr);
591594

595+
clear_siginfo(&info);
592596
info.si_signo = inf->sig;
593597
info.si_errno = 0;
594598
info.si_code = inf->code;

0 commit comments

Comments
 (0)