signal/arm: siginfo cleanups
cover signal/arm: siginfo cleanups
This is the latest and hopefully round of siginfo cleanups for arm. This replaces the use of siginal sending functions that take siginfo with siginfo sending functions that take the values that go in siginfo and this is harder to get wrong, and frequently results in cleaner code.
I don't think I have made made any mistakes in this coversion but if people can look the code over and see if they can spot anything I would appreciate it.
Eric W. Biederman (4):
signal/arm: Push siginfo generation into arm_notify_die signal/arm: Use force_sig_fault where appropriate signal/arm: Use send_sig_fault where appropriate signal/arm/kvm: Use send_sig_mceerr
arch/arm/include/asm/bug.h | 4 +-- arch/arm/kernel/ptrace.c | 11 ++------ arch/arm/kernel/swp_emulate.c | 16 +++++------ arch/arm/kernel/traps.c | 63 ++++++++++++------------------------------- arch/arm/mm/alignment.c | 10 +------ arch/arm/mm/fault.c | 28 ++++--------------- arch/arm/vfp/vfpmodule.c | 11 +++----- virt/kvm/arm/mmu.c | 14 +++------- 8 files changed, 41 insertions(+), 116 deletions(-)
Eric
PATCH 1/4 signal/arm: Push siginfo generation into arm_notify_die
In arm_notify_die call force_sig_fault to let the generic code handle siginfo generation.
This removes some boiler plate making the code easier to maintain in the long run.
--- arch/arm/include/asm/bug.h | 4 +-- arch/arm/kernel/swp_emulate.c | 16 ++++----- arch/arm/kernel/traps.c | 63 ++++++++++------------------------- arch/arm/mm/fault.c | 18 +++------- 4 files changed, 30 insertions(+), 71 deletions(-)
arch/arm/include/asm/bug.h +2 -2
@@ -62,8 +62,8 @@ do { \struct pt_regs ;void die (const char *msg,struct pt_regs *regs,int err); -struct siginfo ; -void arm_notify_die (const char *str,struct pt_regs *regs,struct siginfo *info, +void arm_notify_die (const char *str,struct pt_regs *regs, +int signo,int si_code,void __user *addr,unsigned long err,unsigned long trap);#ifdef CONFIG_ARM_LPAE
arch/arm/kernel/swp_emulate.c +7 -9
@@ -98,22 +98,20 @@ static int proc_status_show(struct seq_file *m, void *v)*/ static void set_segfault (struct pt_regs *regs,unsigned long addr) { -siginfo_t info; +int si_code; -clear_siginfo (&info);down_read (¤t->mm->mmap_sem);if (find_vma (current->mm, addr) ==NULL ) - info.si_code =SEGV_MAPERR ; + si_code =SEGV_MAPERR ;else - info.si_code =SEGV_ACCERR ; + si_code =SEGV_ACCERR ;up_read (¤t->mm->mmap_sem); - info.si_signo =SIGSEGV ; - info.si_errno =0 ; - info.si_addr = (void *)instruction_pointer (regs); -pr_debug ("SWP{B} emulation: access caused memory abort!\n" ); -arm_notify_die ("Illegal memory access" , regs, &info,0 ,0 ); +arm_notify_die ("Illegal memory access" , regs, +SIGSEGV , si_code, + (void __user *)instruction_pointer (regs), +0 ,0 ); abtcounter++; }
arch/arm/kernel/traps.c +17 -46
129 lines not on this page · raw message
arch/arm/mm/fault.c +4 -14
@@ -554,7 +554,6 @@ asmlinkage void do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs) { const struct fsr_info *inf = fsr_info + fsr_fs(fsr); -struct siginfo info;if (!inf->fn (addr, fsr & ~FSR_LNX_PF , regs))return ;
@@ -563,12 +562,8 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs) inf->name, fsr, addr);show_pte (current->mm, addr); -clear_siginfo (&info); - info.si_signo = inf->sig; - info.si_errno =0 ; - info.si_code = inf->code; - info.si_addr = (void __user *)addr; -arm_notify_die ("" , regs, &info, fsr,0 ); +arm_notify_die ("" , regs, inf->sig, inf->code, (void __user *)addr, + fsr,0 ); }void __init
@@ -588,7 +583,6 @@ asmlinkage void do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs) { const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr); -struct siginfo info;if (!inf->fn (addr, ifsr |FSR_LNX_PF , regs))return ;
@@ -596,12 +590,8 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)pr_alert ("Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n" , inf->name, ifsr, addr); -clear_siginfo (&info); - info.si_signo = inf->sig; - info.si_errno =0 ; - info.si_code = inf->code; - info.si_addr = (void __user *)addr; -arm_notify_die ("" , regs, &info, ifsr,0 ); +arm_notify_die ("" , regs, inf->sig, inf->code, (void __user *)addr, + ifsr,0 ); }/*
Signature · 1 line
2.17.1
PATCH 2/4 signal/arm: Use force_sig_fault where appropriate
In reply to Eric W. Biederman--- arch/arm/kernel/ptrace.c | 11 ++--------- arch/arm/mm/alignment.c | 10 +--------- arch/arm/mm/fault.c | 10 +--------- 3 files changed, 4 insertions(+), 27 deletions(-)
arch/arm/kernel/ptrace.c +2 -9
@@ -203,15 +203,8 @@ void ptrace_disable(struct task_struct *child)*/ void ptrace_break (struct task_struct *tsk,struct pt_regs *regs) { -siginfo_t info; - -clear_siginfo (&info); - info.si_signo =SIGTRAP ; - info.si_errno =0 ; - info.si_code =TRAP_BRKPT ; - info.si_addr = (void __user *)instruction_pointer (regs); - -force_sig_info (SIGTRAP , &info, tsk); +force_sig_fault (SIGTRAP ,TRAP_BRKPT , + (void __user *)instruction_pointer (regs), tsk); }static int break_trap (struct pt_regs *regs,unsigned int instr)
arch/arm/mm/alignment.c +1 -9
@@ -948,15 +948,7 @@ do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs) goto fixup;if (ai_usermode &UM_SIGNAL ) { -siginfo_t si; - -clear_siginfo (&si); - si.si_signo =SIGBUS ; - si.si_errno =0 ; - si.si_code =BUS_ADRALN ; - si.si_addr = (void __user *)addr; - -force_sig_info (si.si_signo, &si, current); +force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *)addr, current); }else {/* * We're about to disable the alignment trap and return to
arch/arm/mm/fault.c +1 -9
@@ -161,13 +161,9 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr, unsigned int fsr, unsigned int sig, int code, struct pt_regs *regs) { - struct siginfo si; - if (addr > TASK_SIZE) harden_branch_predictor(); -clear_siginfo (&si); - #ifdef CONFIG_DEBUG_USER if (((user_debug & UDBG_SEGV) && (sig == SIGSEGV)) || ((user_debug & UDBG_BUS) && (sig == SIGBUS))) {
@@ -181,11 +177,7 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr, tsk->thread.address = addr; tsk->thread.error_code = fsr; tsk->thread.trap_no =14 ; - si.si_signo = sig; - si.si_errno =0 ; - si.si_code = code; - si.si_addr = (void __user *)addr; -force_sig_info (sig, &si, tsk); +force_sig_fault (sig, code, (void __user *)addr, tsk); }void do_bad_area (unsigned long addr,unsigned int fsr,struct pt_regs *regs)
Signature · 1 line
2.17.1
PATCH 3/4 signal/arm: Use send_sig_fault where appropriate
In reply to Eric W. Biederman--- arch/arm/vfp/vfpmodule.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
arch/arm/vfp/vfpmodule.c +3 -8
@@ -216,13 +216,6 @@ static struct notifier_block vfp_notifier_block = {*/ static void vfp_raise_sigfpe (unsigned int sicode,struct pt_regs *regs) { -siginfo_t info; - -clear_siginfo (&info); - info.si_signo =SIGFPE ; - info.si_code = sicode; - info.si_addr = (void __user *)(instruction_pointer (regs) -4 ); -/* * This is the same as NWFPE, because it's not clear what * this is used for
@@ -230,7 +223,9 @@ static void vfp_raise_sigfpe(unsigned int sicode, struct pt_regs *regs) current->thread.error_code =0 ; current->thread.trap_no =6 ; -send_sig_info (SIGFPE , &info, current); +send_sig_fault (SIGFPE , sicode, + (void __user *)(instruction_pointer (regs) -4 ), + current); }static void vfp_panic (char *reason,u32 inst)
Signature · 1 line
2.17.1
PATCH 4/4 signal/arm/kvm: Use send_sig_mceerr
In reply to Eric W. BiedermanThis simplifies the code making it clearer what is going on, and making the siginfo generation easier to maintain.
--- virt/kvm/arm/mmu.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
virt/kvm/arm/mmu.c +4 -10
@@ -1450,20 +1450,14 @@ static void invalidate_icache_guest_page(kvm_pfn_t pfn, unsigned long size)static void kvm_send_hwpoison_signal (unsigned long address,struct vm_area_struct *vma) { -siginfo_t info; - -clear_siginfo (&info); - info.si_signo =SIGBUS ; - info.si_errno =0 ; - info.si_code =BUS_MCEERR_AR ; - info.si_addr = (void __user *)address; +short lsb;if (is_vm_hugetlb_page (vma)) - info.si_addr_lsb =huge_page_shift (hstate_vma (vma)); + lsb =huge_page_shift (hstate_vma (vma));else - info.si_addr_lsb =PAGE_SHIFT ; + lsb =PAGE_SHIFT ; -send_sig_info (SIGBUS , &info, current); +send_sig_mceerr (BUS_MCEERR_AR , (void __user *)address, lsb, current); } static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
Signature · 1 line
2.17.1
PATCH 1/3 signal/ia64: Use the generic force_sigsegv in setup_frame
In reply to Eric W. BiedermanThe ia64 handling of failure to setup a signal frame has been trying to set overlapping fields in struct siginfo since 2.3.43. The si_pid and si_uid fields are stomped when the si_addr field is set. The si_code of SI_KERNEL indicates that si_pid and si_uid should be valid, and that si_addr does not exist.
Being at odds with the definition of SI_KERNEL and with nothing to indicate that this was a signal frame setup failure there is no way for userspace to know that si_addr was filled out instead.
In practice failure to setup a signal frame is rare, and si_pid and si_uid are always set to 0 when si_code is SI_KERNEL so I expect no one has looked closely enough before to see this weirdness. Further the only difference between force_sigsegv_info and the generic force_sigsegv other than the return code is that force_sigsegv_info stomps the si_uid and si_pid fields.
Remove the bug and simplify the code by using force_sigsegv in this case just like other architectures.
--- arch/ia64/kernel/signal.c | 50 ++++++++++----------------------------- 1 file changed, 12 insertions(+), 38 deletions(-)
arch/ia64/kernel/signal.c +12 -38
@@ -231,37 +231,6 @@ rbs_on_sig_stack (unsigned long bsp)return (bsp - current->sas_ss_sp < current->sas_ss_size); } -static long -force_sigsegv_info (int sig,void __user *addr) -{ -unsigned long flags; -struct siginfo si; - -clear_siginfo (&si); -if (sig ==SIGSEGV ) { -/* -* Acquiring siglock around the sa_handler-update is almost -* certainly overkill, but this isn't a -* performance-critical path and I'd rather play it safe -* here than having to debug a nasty race if and when -* something changes in kernel/signal.c that would make it -* no longer safe to modify sa_handler without holding the -* lock. -*/ -spin_lock_irqsave (¤t->sighand->siglock, flags); - current->sighand->action[sig -1 ].sa.sa_handler =SIG_DFL ; -spin_unlock_irqrestore (¤t->sighand->siglock, flags); - } - si.si_signo =SIGSEGV ; - si.si_errno =0 ; - si.si_code =SI_KERNEL ; - si.si_pid =task_pid_vnr (current); - si.si_uid =from_kuid_munged (current_user_ns (),current_uid ()); - si.si_addr = addr; -force_sig_info (SIGSEGV , &si, current); -return 1 ; -} -static long setup_frame (struct ksignal *ksig,sigset_t *set,struct sigscratch *scr) {
@@ -295,15 +264,18 @@ setup_frame(struct ksignal *ksig, sigset_t *set, struct sigscratch *scr)* instead so we will die with SIGSEGV. */ check_sp = (new_sp -sizeof (*frame)) & -STACK_ALIGN ; -if (!likely (on_sig_stack (check_sp))) -return force_sigsegv_info (ksig->sig, (void __user *) - check_sp); +if (!likely (on_sig_stack (check_sp))) { +force_sigsegv (ksig->sig, current); +return 1 ; + } } } frame = (void __user *) ((new_sp -sizeof (*frame)) & -STACK_ALIGN ); -if (!access_ok (VERIFY_WRITE , frame,sizeof (*frame))) -return force_sigsegv_info (ksig->sig, frame); +if (!access_ok (VERIFY_WRITE , frame,sizeof (*frame))) { +force_sigsegv (ksig->sig, current); +return 1 ; + } err =__put_user (ksig->sig, &frame->arg0); err |=__put_user (&frame->info, &frame->arg1);
@@ -317,8 +289,10 @@ setup_frame(struct ksignal *ksig, sigset_t *set, struct sigscratch *scr) err |=__save_altstack (&frame->sc.sc_stack, scr->pt.r12); err |=setup_sigcontext (&frame->sc, set, scr); -if (unlikely (err)) -return force_sigsegv_info (ksig->sig, frame); +if (unlikely (err)) { +force_sigsegv (ksig->sig, current); +return 1 ; + } scr->pt.r12 = (unsigned long ) frame -16 ;/* new stack pointer */ scr->pt.ar_fpsr =FPSR_DEFAULT ;/* reset fpsr for signal handler */
Signature · 1 line
2.17.1
PATCH 2/3 signal/ia64: Use the force_sig(SIGSEGV,...) in ia64_rt_sigreturn
In reply to Eric W. BiedermanThe ia64 handling of failure to return from a signal frame has been trying to set overlapping fields in struct siginfo since 2.3.43. The si_code corresponds to the fields that were stomped (not the field that is actually written), so I can not imagine a piece of userspace code making sense of the signal frame if it looks closely.
In practice failure to return from a signal frame is a rare event that almost never happens. Someone using an alternate signal stack to recover and looking in detail is even more rare. So I presume no one has ever noticed and reported this ia64 nonsense.
Sort this out by causing ia64 to use force_sig(SIGSEGV) like other architectures.
--- arch/ia64/kernel/signal.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
arch/ia64/kernel/signal.c +1 -9
@@ -110,7 +110,6 @@ ia64_rt_sigreturn (struct sigscratch *scr) {extern char ia64_strace_leave_kernel, ia64_leave_kernel;struct sigcontext __user *sc; -struct siginfo si;sigset_t set;long retval;
@@ -153,14 +152,7 @@ ia64_rt_sigreturn (struct sigscratch *scr)return retval; give_sigsegv: -clear_siginfo (&si); - si.si_signo =SIGSEGV ; - si.si_errno =0 ; - si.si_code =SI_KERNEL ; - si.si_pid =task_pid_vnr (current); - si.si_uid =from_kuid_munged (current_user_ns (),current_uid ()); - si.si_addr = sc; -force_sig_info (SIGSEGV , &si, current); +force_sig (SIGSEGV , current);return retval; }
Signature · 1 line
2.17.1
PATCH 3/3 signal/ia64: Use force_sig_fault where appropriate
In reply to Eric W. Biederman--- arch/ia64/kernel/brl_emu.c | 31 ++------ arch/ia64/kernel/traps.c | 144 ++++++++++------------------------- arch/ia64/kernel/unaligned.c | 12 +-- arch/ia64/mm/fault.c | 12 +-- 4 files changed, 49 insertions(+), 150 deletions(-)
arch/ia64/kernel/brl_emu.c +6 -25
@@ -58,11 +58,9 @@ ia64_emulate_brl (struct pt_regs *regs, unsigned long ar_ec)unsigned long bundle[2 ];unsigned long opcode, btype, qp, offset, cpl;unsigned long next_ip; -struct siginfo siginfo;struct illegal_op_return rv;long tmp_taken, unimplemented_address; -clear_siginfo (&siginfo); rv.fkt = (unsigned long )-1 ;/*
@@ -198,39 +196,22 @@ ia64_emulate_brl (struct pt_regs *regs, unsigned long ar_ec)* The target address contains unimplemented bits. */ printk (KERN_DEBUG "Woah! Unimplemented Instruction Address Trap!\n" ); - siginfo.si_signo =SIGILL ; - siginfo.si_errno =0 ; - siginfo.si_flags =0 ; - siginfo.si_isr =0 ; - siginfo.si_imm =0 ; - siginfo.si_code =ILL_BADIADDR ; -force_sig_info (SIGILL , &siginfo, current); +force_sig_fault (SIGILL ,ILL_BADIADDR , (void __user *)NULL , +0 ,0 ,0 , current); }else if (ia64_psr (regs)->tb) {/* * Branch Tracing is enabled. * Force a taken branch signal. */ - siginfo.si_signo =SIGTRAP ; - siginfo.si_errno =0 ; - siginfo.si_code =TRAP_BRANCH ; - siginfo.si_flags =0 ; - siginfo.si_isr =0 ; - siginfo.si_addr =0 ; - siginfo.si_imm =0 ; -force_sig_info (SIGTRAP , &siginfo, current); +force_sig_fault (SIGTRAP ,TRAP_BRANCH , (void __user *)NULL , +0 ,0 ,0 , current); }else if (ia64_psr (regs)->ss) {/* * Single Step is enabled. * Force a trace signal. */ - siginfo.si_signo =SIGTRAP ; - siginfo.si_errno =0 ; - siginfo.si_code =TRAP_TRACE ; - siginfo.si_flags =0 ; - siginfo.si_isr =0 ; - siginfo.si_addr =0 ; - siginfo.si_imm =0 ; -force_sig_info (SIGTRAP , &siginfo, current); +force_sig_fault (SIGTRAP ,TRAP_TRACE , (void __user *)NULL , +0 ,0 ,0 , current); }return rv; }
arch/ia64/kernel/traps.c +39 -105
254 lines not on this page · raw message
arch/ia64/kernel/unaligned.c +2 -10
@@ -1298,7 +1298,6 @@ ia64_handle_unaligned (unsigned long ifa, struct pt_regs *regs)mm_segment_t old_fs =get_fs ();unsigned long bundle[2 ];unsigned long opcode; -struct siginfo si;const struct exception_table_entry *eh =NULL ;union {unsigned long l;
@@ -1537,14 +1536,7 @@ ia64_handle_unaligned (unsigned long ifa, struct pt_regs *regs)/* NOT_REACHED */ } force_sigbus: -clear_siginfo (&si); - si.si_signo =SIGBUS ; - si.si_errno =0 ; - si.si_code =BUS_ADRALN ; - si.si_addr = (void __user *) ifa; - si.si_flags =0 ; - si.si_isr =0 ; - si.si_imm =0 ; -force_sig_info (SIGBUS , &si, current); +force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) ifa, +0 ,0 ,0 , current); goto done; }
arch/ia64/mm/fault.c +2 -10
@@ -248,16 +248,8 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *rereturn ; }if (user_mode (regs)) { -struct siginfo si; - -clear_siginfo (&si); - si.si_signo = signal; - si.si_errno =0 ; - si.si_code = code; - si.si_addr = (void __user *) address; - si.si_isr = isr; - si.si_flags = __ISR_VALID; -force_sig_info (signal, &si, current); +force_sig_fault (signal, code, (void __user *) address, +0 , __ISR_VALID, isr, current);return ; }
Signature · 1 line
2.17.1