signal/arm64: siginfo cleanups
Subsystems (3)
cover signal/arm64: siginfo cleanups
This is the continuation of my work to sort out signaling of exceptions with siginfo. The old signal sending functions by taking a siginfo argument resulted in their callers having to deal with the fiddly nature of siginfo directly. In small numbers of callers this is not a problem but in the number of callers in the kernel this resulted in cases where fields were not initialized or improperly initialized before being passed to userspace.
To avoid having to worry about those issues I have added new signal sending functions that each deal wit a different siginfo case. When using these functions there is no room for the fiddly nature of siginfo to cause mistakes.
This is my set of changes to update arm64 to use those functions. Along with some refactoring so those functions can be cleanly used.
Folks please review and double check me. I think I have kept these changes simple and obviously correct but I am human and mess up sometimes.
After these patches have had a chance to be reviewed I plan to merge them by my siginfo tree. If you would rather take them in the arm64
tree let me know. All of the prerequisites should have been merged
through Linus's tree several releases ago.
Eric W. Biederman (15):
signal/arm64: Push siginfo generation into arm64_notify_die signal/arm64: Remove unneeded tsk parameter from arm64_force_sig_info signal/arm64: Factor out arm64_show_signal from arm64_force_sig_info signal/arm64: Factor set_thread_esr out of __do_user_fault signal/arm64: Consolidate the two hwpoison cases in do_page_fault signal/arm64: For clarity separate the 3 signal sending cases in do_page_fault signal/arm64: Expand __do_user_fault and remove it
signal/arm64: Only perform one esr_to_fault_info call in do_page_fault signal/arm64: Only call set_thread_esr once in do_page_fault signal/arm64: Add and use arm64_force_sig_fault where appropriate signal/arm64: Add and use arm64_force_sig_mceerr as appropriate signal/arm64: Remove arm64_force_sig_info
signal/arm64: In ptrace_hbptriggered name the signal description string signal/arm64: Add and use arm64_force_sig_ptrace_errno_trap signal/arm64: Use send_sig_fault where appropriate
arch/arm64/include/asm/system_misc.h | 3 +- arch/arm64/include/asm/traps.h | 5 +- arch/arm64/kernel/debug-monitors.c | 11 ++--- arch/arm64/kernel/fpsimd.c | 10 ++-- arch/arm64/kernel/ptrace.c | 16 +++--- arch/arm64/kernel/sys_compat.c | 13 ++--- arch/arm64/kernel/traps.c | 67 ++++++++++++------------- arch/arm64/mm/fault.c | 94 +++++++++++++----------------------- 8 files changed, 90 insertions(+), 129 deletions(-)
PATCH 1/15 signal/arm64: Push siginfo generation into arm64_notify_die
Instead of generating a struct siginfo before calling arm64_notify_die pass the signal number, tne sicode and the fault address into arm64_notify_die and have it call force_sig_fault instead of force_sig_info to let the generic code generate the struct siginfo.
This keeps code passing just the needed information into siginfo generating code, making it easier to see what is happening and harder to get wrong. Further by letting the generic code handle the generation of struct siginfo it reduces the number of sites generating struct siginfo making it possible to review them and verify that all of the fiddly details for a structure passed to userspace are handled properly.
--- arch/arm64/include/asm/system_misc.h | 3 +- arch/arm64/kernel/sys_compat.c | 13 ++++----- arch/arm64/kernel/traps.c | 24 ++++++++-------- arch/arm64/mm/fault.c | 41 +++++++--------------------- 4 files changed, 30 insertions(+), 51 deletions(-)
arch/arm64/include/asm/system_misc.h +2 -1
@@ -33,7 +33,8 @@ void die(const char *msg, struct pt_regs *regs, int err);struct siginfo ;void arm64_notify_die (const char *str,struct pt_regs *regs, -struct siginfo *info,int err); +int signo,int sicode,void __user *addr, +int err); void hook_debug_fault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *),
arch/arm64/kernel/sys_compat.c +5 -8
@@ -68,8 +68,8 @@ do_compat_cache_op(unsigned long start, unsigned long end, int flags)*/ long compat_arm_syscall (struct pt_regs *regs) { -siginfo_t info;unsigned int no = regs->regs[7 ]; +void __user *addr;switch (no) {/*
@@ -112,13 +112,10 @@ long compat_arm_syscall(struct pt_regs *regs)break ; } -clear_siginfo (&info); - info.si_signo =SIGILL ; - info.si_errno =0 ; - info.si_code =ILL_ILLTRP ; - info.si_addr = (void __user *)instruction_pointer (regs) - - (compat_thumb_mode (regs) ?2 :4 ); + addr = (void __user *)instruction_pointer (regs) - + (compat_thumb_mode (regs) ?2 :4 ); -arm64_notify_die ("Oops - bad compat syscall(2)" , regs, &info, no); +arm64_notify_die ("Oops - bad compat syscall(2)" , regs, +SIGILL ,ILL_ILLTRP , addr, no);return 0 ; }
arch/arm64/kernel/traps.c +13 -11
@@ -257,13 +257,23 @@ void arm64_force_sig_info(struct siginfo *info, const char *str, }void arm64_notify_die (const char *str,struct pt_regs *regs, -struct siginfo *info,int err) +int signo,int sicode,void __user *addr, +int err) {if (user_mode (regs)) { +struct siginfo info; +WARN_ON (regs !=current_pt_regs ()); current->thread.fault_address =0 ; current->thread.fault_code = err; -arm64_force_sig_info (info, str, current); + +clear_siginfo (&info); + info.si_signo = signo; + info.si_errno =0 ; + info.si_code = sicode; + info.si_addr = addr; + +arm64_force_sig_info (&info, str, current); }else {die (str, regs, err); }
@@ -348,12 +358,9 @@ static int call_undef_hook(struct pt_regs *regs)void force_signal_inject (int signal,int code,unsigned long address) { -siginfo_t info;const char *desc;struct pt_regs *regs =current_pt_regs (); -clear_siginfo (&info); -switch (signal) {case SIGILL : desc ="undefined instruction" ;
@@ -372,12 +379,7 @@ void force_signal_inject(int signal, int code, unsigned long address) signal =SIGKILL ; } - info.si_signo = signal; - info.si_errno =0 ; - info.si_code = code; - info.si_addr = (void __user *)address; - -arm64_notify_die (desc, regs, &info,0 ); +arm64_notify_die (desc, regs, signal, code, (void __user *)address,0 ); }/*
arch/arm64/mm/fault.c +10 -31
86 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 2/15 signal/arm64: Remove unneeded tsk parameter from arm64_force_sig_info
In reply to Eric W. BiedermanEvery caller passes in current for tsk so there is no need to pass tsk. Instead make tsk a local variable initialized to current.
--- arch/arm64/include/asm/traps.h | 3 +-- arch/arm64/kernel/debug-monitors.c | 2 +- arch/arm64/kernel/ptrace.c | 2 +- arch/arm64/kernel/traps.c | 8 ++++---- arch/arm64/mm/fault.c | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-)
arch/arm64/include/asm/traps.h +1 -2
@@ -37,8 +37,7 @@ void register_undef_hook(struct undef_hook *hook);void unregister_undef_hook (struct undef_hook *hook);void force_signal_inject (int signal,int code,unsigned long address);void arm64_notify_segfault (unsigned long addr); -void arm64_force_sig_info (struct siginfo *info,const char *str, -struct task_struct *tsk); +void arm64_force_sig_info (struct siginfo *info,const char *str);/* * Move regs->pc to next instruction and do necessary setup before it
arch/arm64/kernel/debug-monitors.c +1 -1
@@ -224,7 +224,7 @@ static void send_user_sigtrap(int si_code)if (interrupts_enabled (regs))local_irq_enable (); -arm64_force_sig_info (&info,"User debug trap" , current); +arm64_force_sig_info (&info,"User debug trap" ); } static int single_step_handler(unsigned long addr, unsigned int esr,
arch/arm64/kernel/ptrace.c +1 -1
@@ -211,7 +211,7 @@ static void ptrace_hbptriggered(struct perf_event *bp, force_sig_ptrace_errno_trap(si_errno, (void __user *)bkpt->trigger); }#endif -arm64_force_sig_info (&info,"Hardware breakpoint trap (ptrace)" , current); +arm64_force_sig_info (&info,"Hardware breakpoint trap (ptrace)" ); }/*
arch/arm64/kernel/traps.c +4 -4
@@ -231,9 +231,9 @@ static bool show_unhandled_signals_ratelimited(void)return show_unhandled_signals &&__ratelimit (&rs); } -void arm64_force_sig_info (struct siginfo *info,const char *str, -struct task_struct *tsk) +void arm64_force_sig_info (struct siginfo *info,const char *str) { +struct task_struct *tsk = current;unsigned int esr = tsk->thread.fault_code;struct pt_regs *regs =task_pt_regs (tsk);
@@ -273,7 +273,7 @@ void arm64_notify_die(const char *str, struct pt_regs *regs, info.si_code = sicode; info.si_addr = addr; -arm64_force_sig_info (&info, str, current); +arm64_force_sig_info (&info, str); }else {die (str, regs, err); }
@@ -630,7 +630,7 @@ asmlinkage void bad_el0_sync(struct pt_regs *regs, int reason, unsigned int esr) current->thread.fault_address =0 ; current->thread.fault_code = esr; -arm64_force_sig_info (&info,"Bad EL0 synchronous exception" , current); +arm64_force_sig_info (&info,"Bad EL0 synchronous exception" ); }#ifdef CONFIG_VMAP_STACK
arch/arm64/mm/fault.c +1 -1
@@ -352,7 +352,7 @@ static void __do_user_fault(struct siginfo *info, unsigned int esr) } current->thread.fault_code = esr; -arm64_force_sig_info (info,esr_to_fault_info (esr)->name, current); +arm64_force_sig_info (info,esr_to_fault_info (esr)->name); }static void do_bad_area (unsigned long addr,unsigned int esr,struct pt_regs *regs)
Signature · 1 line
2.17.1
PATCH 3/15 signal/arm64: Factor out arm64_show_signal from arm64_force_sig_info
In reply to Eric W. BiedermanFilling in siginfo is error prone and so it is wise to use more specialized helpers to do that work. Factor out the arm specific unhandled signal reporting from the work of delivering a signal so the code can be modified to use functions that take the information to fill out siginfo as parameters.
--- arch/arm64/kernel/traps.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
arch/arm64/kernel/traps.c +11 -13
@@ -224,24 +224,19 @@ void die(const char *str, struct pt_regs *regs, int err)do_exit (SIGSEGV ); } -static bool show_unhandled_signals_ratelimited (void ) +static void arm64_show_signal (int signo,const char *str) { static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST); -return show_unhandled_signals &&__ratelimit (&rs); -} - -void arm64_force_sig_info (struct siginfo *info,const char *str) -{struct task_struct *tsk = current;unsigned int esr = tsk->thread.fault_code;struct pt_regs *regs =task_pt_regs (tsk); -if (!unhandled_signal (tsk, info->si_signo)) - goto send_sig; - -if (!show_unhandled_signals_ratelimited ()) - goto send_sig; +/* Leave if the signal won't be shown */ +if (!show_unhandled_signals || + !unhandled_signal (tsk, signo) || + !__ratelimit (&rs)) +return ;pr_info ("%s[%d]: unhandled exception: " , tsk->comm,task_pid_nr (tsk));if (esr)
@@ -251,9 +246,12 @@ void arm64_force_sig_info(struct siginfo *info, const char *str)print_vma_addr (KERN_CONT " in " , regs->pc);pr_cont ("\n" );__show_regs (regs); +} -send_sig: -force_sig_info (info->si_signo, info, tsk); +void arm64_force_sig_info (struct siginfo *info,const char *str) +{ +arm64_show_signal (info->si_signo, str); +force_sig_info (info->si_signo, info, current); } void arm64_notify_die(const char *str, struct pt_regs *regs,
Signature · 1 line
2.17.1
PATCH 4/15 signal/arm64: Factor set_thread_esr out of __do_user_fault
In reply to Eric W. BiedermanThis pepares for sending signals with something other than arm64_force_sig_info.
--- arch/arm64/mm/fault.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
arch/arm64/mm/fault.c +7 -2
@@ -297,9 +297,9 @@ static void __do_kernel_fault(unsigned long addr, unsigned int esr,die_kernel_fault (msg, addr, esr, regs); } -static void __do_user_fault (struct siginfo *info,unsigned int esr) +static void set_thread_esr (unsigned long address,unsigned int esr) { - current->thread.fault_address = (unsigned long )info->si_addr; + current->thread.fault_address = address;/* * If the faulting address is in the kernel, we must sanitize the ESR.
@@ -352,6 +352,11 @@ static void __do_user_fault(struct siginfo *info, unsigned int esr) } current->thread.fault_code = esr; +} + +static void __do_user_fault (struct siginfo *info,unsigned int esr) +{ +set_thread_esr ((unsigned long )info->si_addr, esr);arm64_force_sig_info (info,esr_to_fault_info (esr)->name); }
Signature · 1 line
2.17.1
PATCH 5/15 signal/arm64: Consolidate the two hwpoison cases in do_page_fault
In reply to Eric W. BiedermanThese two cases are practically the same and use siginfo differently from the other signals sent from do_page_fault. So consolidate them to make future changes easier.
--- arch/arm64/mm/fault.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
arch/arm64/mm/fault.c +7 -7
@@ -577,16 +577,16 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,*/ si.si_signo =SIGBUS ; si.si_code =BUS_ADRERR ; - }else if (fault &VM_FAULT_HWPOISON_LARGE ) { -unsigned int hindex =VM_FAULT_GET_HINDEX (fault); + }else if (fault & (VM_FAULT_HWPOISON_LARGE |VM_FAULT_HWPOISON )) { +unsigned int lsb; + + lsb =PAGE_SHIFT ; +if (fault &VM_FAULT_HWPOISON_LARGE ) + lsb =hstate_index_to_shift (VM_FAULT_GET_HINDEX (fault)); si.si_signo =SIGBUS ; si.si_code =BUS_MCEERR_AR ; - si.si_addr_lsb =hstate_index_to_shift (hindex); - }else if (fault &VM_FAULT_HWPOISON ) { - si.si_signo =SIGBUS ; - si.si_code =BUS_MCEERR_AR ; - si.si_addr_lsb =PAGE_SHIFT ; + si.si_addr_lsb = lsb; }else {/* * Something tried to access memory that isn't in our memory
Signature · 1 line
2.17.1
PATCH 6/15 signal/arm64: For clarity separate the 3 signal sending cases in do_page_fault
In reply to Eric W. BiedermanIt gets easy to confuse what is going on when some code is shared and some not so stop sharing the trivial bits of signal generation to make future updates easier to understand.
--- arch/arm64/mm/fault.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
arch/arm64/mm/fault.c +9 -4
@@ -567,16 +567,16 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,return 0 ; } -clear_siginfo (&si); - si.si_addr = (void __user *)addr; -if (fault &VM_FAULT_SIGBUS ) {/* * We had some memory, but were unable to successfully fix up * this page fault. */ +clear_siginfo (&si); si.si_signo =SIGBUS ; si.si_code =BUS_ADRERR ; + si.si_addr = (void __user *)addr; +__do_user_fault (&si, esr); }else if (fault & (VM_FAULT_HWPOISON_LARGE |VM_FAULT_HWPOISON )) {unsigned int lsb;
@@ -584,20 +584,25 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,if (fault &VM_FAULT_HWPOISON_LARGE ) lsb =hstate_index_to_shift (VM_FAULT_GET_HINDEX (fault)); +clear_siginfo (&si); si.si_signo =SIGBUS ; si.si_code =BUS_MCEERR_AR ; + si.si_addr = (void __user *)addr; si.si_addr_lsb = lsb; +__do_user_fault (&si, esr); }else {/* * Something tried to access memory that isn't in our memory * map. */ +clear_siginfo (&si); si.si_signo =SIGSEGV ; si.si_code = fault ==VM_FAULT_BADACCESS ?SEGV_ACCERR :SEGV_MAPERR ; + si.si_addr = (void __user *)addr; +__do_user_fault (&si, esr); } -__do_user_fault (&si, esr);return 0 ; no_context:
Signature · 1 line
2.17.1
PATCH 7/15 signal/arm64: Expand __do_user_fault and remove it
In reply to Eric W. BiedermanNot all of the signals passed to __do_user_fault can be handled the same way so expand the now tiny __do_user_fault in it's callers and remove it.
--- arch/arm64/mm/fault.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
arch/arm64/mm/fault.c +8 -10
@@ -354,12 +354,6 @@ static void set_thread_esr(unsigned long address, unsigned int esr) current->thread.fault_code = esr; } -static void __do_user_fault (struct siginfo *info,unsigned int esr) -{ -set_thread_esr ((unsigned long )info->si_addr, esr); -arm64_force_sig_info (info,esr_to_fault_info (esr)->name); -} -static void do_bad_area (unsigned long addr,unsigned int esr,struct pt_regs *regs) {/*
@@ -375,7 +369,8 @@ static void do_bad_area(unsigned long addr, unsigned int esr, struct pt_regs *re si.si_code = inf->code; si.si_addr = (void __user *)addr; -__do_user_fault (&si, esr); +set_thread_esr (addr, esr); +arm64_force_sig_info (&si, inf->name); }else {__do_kernel_fault (addr, esr, regs); }
@@ -576,7 +571,8 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, si.si_signo =SIGBUS ; si.si_code =BUS_ADRERR ; si.si_addr = (void __user *)addr; -__do_user_fault (&si, esr); +set_thread_esr (addr, esr); +arm64_force_sig_info (&si,esr_to_fault_info (esr)->name); }else if (fault & (VM_FAULT_HWPOISON_LARGE |VM_FAULT_HWPOISON )) {unsigned int lsb;
@@ -589,7 +585,8 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, si.si_code =BUS_MCEERR_AR ; si.si_addr = (void __user *)addr; si.si_addr_lsb = lsb; -__do_user_fault (&si, esr); +set_thread_esr (addr, esr); +arm64_force_sig_info (&si,esr_to_fault_info (esr)->name); }else {/* * Something tried to access memory that isn't in our memory
@@ -600,7 +597,8 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, si.si_code = fault ==VM_FAULT_BADACCESS ?SEGV_ACCERR :SEGV_MAPERR ; si.si_addr = (void __user *)addr; -__do_user_fault (&si, esr); +set_thread_esr (addr, esr); +arm64_force_sig_info (&si,esr_to_fault_info (esr)->name); }return 0 ;
Signature · 1 line
2.17.1
PATCH 8/15 signal/arm64: Only perform one esr_to_fault_info call in do_page_fault
In reply to Eric W. BiedermanAs this work is truly common between all of the signal sending cases there is no need to repeat it between the different cases.
--- arch/arm64/mm/fault.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
arch/arm64/mm/fault.c +5 -3
@@ -424,6 +424,7 @@ static bool is_el0_instruction_abort(unsigned int esr)static int __kprobes do_page_fault (unsigned long addr,unsigned int esr,struct pt_regs *regs) { +const struct fault_info *inf;struct task_struct *tsk;struct mm_struct *mm;struct siginfo si;
@@ -562,6 +563,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,return 0 ; } + inf =esr_to_fault_info (esr);if (fault &VM_FAULT_SIGBUS ) {/* * We had some memory, but were unable to successfully fix up
@@ -572,7 +574,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, si.si_code =BUS_ADRERR ; si.si_addr = (void __user *)addr;set_thread_esr (addr, esr); -arm64_force_sig_info (&si,esr_to_fault_info (esr)->name); +arm64_force_sig_info (&si, inf->name); }else if (fault & (VM_FAULT_HWPOISON_LARGE |VM_FAULT_HWPOISON )) {unsigned int lsb;
@@ -586,7 +588,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, si.si_addr = (void __user *)addr; si.si_addr_lsb = lsb;set_thread_esr (addr, esr); -arm64_force_sig_info (&si,esr_to_fault_info (esr)->name); +arm64_force_sig_info (&si, inf->name); }else {/* * Something tried to access memory that isn't in our memory
@@ -598,7 +600,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, SEGV_ACCERR :SEGV_MAPERR ; si.si_addr = (void __user *)addr;set_thread_esr (addr, esr); -arm64_force_sig_info (&si,esr_to_fault_info (esr)->name); +arm64_force_sig_info (&si, inf->name); }return 0 ;
Signature · 1 line
2.17.1
PATCH 9/15 signal/arm64: Only call set_thread_esr once in do_page_fault
In reply to Eric W. BiedermanThis code is truly common between the signal sending cases so share it.
--- arch/arm64/mm/fault.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
arch/arm64/mm/fault.c +1 -3
@@ -564,6 +564,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, } inf =esr_to_fault_info (esr); +set_thread_esr (addr, esr);if (fault &VM_FAULT_SIGBUS ) {/* * We had some memory, but were unable to successfully fix up
@@ -573,7 +574,6 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, si.si_signo =SIGBUS ; si.si_code =BUS_ADRERR ; si.si_addr = (void __user *)addr; -set_thread_esr (addr, esr);arm64_force_sig_info (&si, inf->name); }else if (fault & (VM_FAULT_HWPOISON_LARGE |VM_FAULT_HWPOISON )) {unsigned int lsb;
@@ -587,7 +587,6 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, si.si_code =BUS_MCEERR_AR ; si.si_addr = (void __user *)addr; si.si_addr_lsb = lsb; -set_thread_esr (addr, esr);arm64_force_sig_info (&si, inf->name); }else {/*
@@ -599,7 +598,6 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, si.si_code = fault ==VM_FAULT_BADACCESS ?SEGV_ACCERR :SEGV_MAPERR ; si.si_addr = (void __user *)addr; -set_thread_esr (addr, esr);arm64_force_sig_info (&si, inf->name); }
Signature · 1 line
2.17.1
PATCH 10/15 signal/arm64: Add and use arm64_force_sig_fault where appropriate
In reply to Eric W. BiedermanWrap force_sig_fault with a helper that calls arm64_show_signal and call arm64_force_sig_fault where appropraite.
--- arch/arm64/include/asm/traps.h | 1 + arch/arm64/kernel/debug-monitors.c | 11 +++-------- arch/arm64/kernel/ptrace.c | 11 +++-------- arch/arm64/kernel/traps.c | 27 ++++++++++----------------- arch/arm64/mm/fault.c | 26 ++++++++------------------ 5 files changed, 25 insertions(+), 51 deletions(-)
arch/arm64/include/asm/traps.h +1 -0
@@ -37,6 +37,7 @@ void register_undef_hook(struct undef_hook *hook);void unregister_undef_hook (struct undef_hook *hook);void force_signal_inject (int signal,int code,unsigned long address);void arm64_notify_segfault (unsigned long addr); +void arm64_force_sig_fault (int signo,int code,void __user *addr,const char *str);void arm64_force_sig_info (struct siginfo *info,const char *str);/*
arch/arm64/kernel/debug-monitors.c +3 -8
@@ -210,13 +210,6 @@ NOKPROBE_SYMBOL(call_step_hook);static void send_user_sigtrap (int si_code) {struct pt_regs *regs =current_pt_regs (); -siginfo_t info; - -clear_siginfo (&info); - info.si_signo =SIGTRAP ; - info.si_errno =0 ; - info.si_code = si_code; - info.si_addr = (void __user *)instruction_pointer (regs);if (WARN_ON (!user_mode (regs)))return ;
@@ -224,7 +217,9 @@ static void send_user_sigtrap(int si_code)if (interrupts_enabled (regs))local_irq_enable (); -arm64_force_sig_info (&info,"User debug trap" ); +arm64_force_sig_fault (SIGTRAP , si_code, + (void __user *)instruction_pointer (regs), +"User debug trap" ); } static int single_step_handler(unsigned long addr, unsigned int esr,
arch/arm64/kernel/ptrace.c +3 -8
@@ -182,13 +182,6 @@ static void ptrace_hbptriggered(struct perf_event *bp, struct pt_regs *regs) {struct arch_hw_breakpoint *bkpt =counter_arch_bp (bp); -siginfo_t info; - -clear_siginfo (&info); - info.si_signo =SIGTRAP ; - info.si_errno =0 ; - info.si_code =TRAP_HWBKPT ; - info.si_addr = (void __user *)(bkpt->trigger);#ifdef CONFIG_COMPAT if (is_compat_task ()) {
@@ -211,7 +204,9 @@ static void ptrace_hbptriggered(struct perf_event *bp, force_sig_ptrace_errno_trap(si_errno, (void __user *)bkpt->trigger); }#endif -arm64_force_sig_info (&info,"Hardware breakpoint trap (ptrace)" ); +arm64_force_sig_fault (SIGTRAP ,TRAP_HWBKPT , + (void __user *)(bkpt->trigger), +"Hardware breakpoint trap (ptrace)" ); }/*
arch/arm64/kernel/traps.c +10 -17
@@ -248,6 +248,13 @@ static void arm64_show_signal(int signo, const char *str)__show_regs (regs); } +void arm64_force_sig_fault (int signo,int code,void __user *addr, +const char *str) +{ +arm64_show_signal (signo, str); +force_sig_fault (signo, code, addr, current); +} +void arm64_force_sig_info (struct siginfo *info,const char *str) {arm64_show_signal (info->si_signo, str);
@@ -259,19 +266,11 @@ void arm64_notify_die(const char *str, struct pt_regs *regs, int err) {if (user_mode (regs)) { -struct siginfo info; -WARN_ON (regs !=current_pt_regs ()); current->thread.fault_address =0 ; current->thread.fault_code = err; -clear_siginfo (&info); - info.si_signo = signo; - info.si_errno =0 ; - info.si_code = sicode; - info.si_addr = addr; - -arm64_force_sig_info (&info, str); +arm64_force_sig_fault (signo, sicode, addr, str); }else {die (str, regs, err); }
@@ -616,19 +615,13 @@ asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr)*/ asmlinkage void bad_el0_sync(struct pt_regs *regs, int reason, unsigned int esr) { -siginfo_t info;void __user *pc = (void __user *)instruction_pointer (regs); -clear_siginfo (&info); - info.si_signo =SIGILL ; - info.si_errno =0 ; - info.si_code =ILL_ILLOPC ; - info.si_addr = pc; - current->thread.fault_address =0 ; current->thread.fault_code = esr; -arm64_force_sig_info (&info,"Bad EL0 synchronous exception" ); +arm64_force_sig_fault (SIGILL ,ILL_ILLOPC , pc, +"Bad EL0 synchronous exception" ); }#ifdef CONFIG_VMAP_STACK
arch/arm64/mm/fault.c +8 -18
@@ -362,15 +362,10 @@ static void do_bad_area(unsigned long addr, unsigned int esr, struct pt_regs *re*/ if (user_mode (regs)) {const struct fault_info *inf =esr_to_fault_info (esr); -struct siginfo si; - -clear_siginfo (&si); - si.si_signo = inf->sig; - si.si_code = inf->code; - si.si_addr = (void __user *)addr;set_thread_esr (addr, esr); -arm64_force_sig_info (&si, inf->name); +arm64_force_sig_fault (inf->sig, inf->code, (void __user *)addr, + inf->name); }else {__do_kernel_fault (addr, esr, regs); }
@@ -570,11 +565,8 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,* We had some memory, but were unable to successfully fix up * this page fault. */ -clear_siginfo (&si); - si.si_signo =SIGBUS ; - si.si_code =BUS_ADRERR ; - si.si_addr = (void __user *)addr; -arm64_force_sig_info (&si, inf->name); +arm64_force_sig_fault (SIGBUS ,BUS_ADRERR , (void __user *)addr, + inf->name); }else if (fault & (VM_FAULT_HWPOISON_LARGE |VM_FAULT_HWPOISON )) {unsigned int lsb;
@@ -593,12 +585,10 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,* Something tried to access memory that isn't in our memory * map. */ -clear_siginfo (&si); - si.si_signo =SIGSEGV ; - si.si_code = fault ==VM_FAULT_BADACCESS ? -SEGV_ACCERR :SEGV_MAPERR ; - si.si_addr = (void __user *)addr; -arm64_force_sig_info (&si, inf->name); +arm64_force_sig_fault (SIGSEGV , + fault ==VM_FAULT_BADACCESS ?SEGV_ACCERR :SEGV_MAPERR , + (void __user *)addr, + inf->name); }return 0 ;
Signature · 1 line
2.17.1
PATCH 11/15 signal/arm64: Add and use arm64_force_sig_mceerr as appropriate
In reply to Eric W. BiedermanAdd arm64_force_sig_mceerr for consistency with arm64_force_sig_fault, and use it in the one location that can take advantage of it.
This removes the fiddly filling out of siginfo before sending a signal reporting an memory error to userspace.
--- arch/arm64/include/asm/traps.h | 1 + arch/arm64/kernel/traps.c | 7 +++++++ arch/arm64/mm/fault.c | 9 ++------- 3 files changed, 10 insertions(+), 7 deletions(-)
arch/arm64/include/asm/traps.h +1 -0
@@ -38,6 +38,7 @@ void unregister_undef_hook(struct undef_hook *hook);void force_signal_inject (int signal,int code,unsigned long address);void arm64_notify_segfault (unsigned long addr);void arm64_force_sig_fault (int signo,int code,void __user *addr,const char *str); +void arm64_force_sig_mceerr (int code,void __user *addr,short lsb,const char *str);void arm64_force_sig_info (struct siginfo *info,const char *str);/*
arch/arm64/kernel/traps.c +7 -0
@@ -255,6 +255,13 @@ void arm64_force_sig_fault(int signo, int code, void __user *addr,force_sig_fault (signo, code, addr, current); } +void arm64_force_sig_mceerr (int code,void __user *addr,short lsb, +const char *str) +{ +arm64_show_signal (SIGBUS , str); +force_sig_mceerr (code, addr, lsb, current); +} +void arm64_force_sig_info (struct siginfo *info,const char *str) {arm64_show_signal (info->si_signo, str);
arch/arm64/mm/fault.c +2 -7
@@ -422,7 +422,6 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,const struct fault_info *inf;struct task_struct *tsk;struct mm_struct *mm; -struct siginfo si;vm_fault_t fault, major =0 ;unsigned long vm_flags =VM_READ |VM_WRITE ;unsigned int mm_flags =FAULT_FLAG_ALLOW_RETRY |FAULT_FLAG_KILLABLE ;
@@ -574,12 +573,8 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,if (fault &VM_FAULT_HWPOISON_LARGE ) lsb =hstate_index_to_shift (VM_FAULT_GET_HINDEX (fault)); -clear_siginfo (&si); - si.si_signo =SIGBUS ; - si.si_code =BUS_MCEERR_AR ; - si.si_addr = (void __user *)addr; - si.si_addr_lsb = lsb; -arm64_force_sig_info (&si, inf->name); +arm64_force_sig_mceerr (BUS_MCEERR_AR , (void __user *)addr, lsb, + inf->name); }else {/* * Something tried to access memory that isn't in our memory
Signature · 1 line
2.17.1
PATCH 12/15 signal/arm64: Remove arm64_force_sig_info
In reply to Eric W. BiedermanThe function has no more callers so remove it.
--- arch/arm64/include/asm/traps.h | 1 - arch/arm64/kernel/traps.c | 6 ------ 2 files changed, 7 deletions(-)
arch/arm64/include/asm/traps.h +0 -1
@@ -39,7 +39,6 @@ void force_signal_inject(int signal, int code, unsigned long address);void arm64_notify_segfault (unsigned long addr);void arm64_force_sig_fault (int signo,int code,void __user *addr,const char *str);void arm64_force_sig_mceerr (int code,void __user *addr,short lsb,const char *str); -void arm64_force_sig_info (struct siginfo *info,const char *str);/* * Move regs->pc to next instruction and do necessary setup before it
arch/arm64/kernel/traps.c +0 -6
@@ -262,12 +262,6 @@ void arm64_force_sig_mceerr(int code, void __user *addr, short lsb,force_sig_mceerr (code, addr, lsb, current); } -void arm64_force_sig_info (struct siginfo *info,const char *str) -{ -arm64_show_signal (info->si_signo, str); -force_sig_info (info->si_signo, info, current); -} -void arm64_notify_die (const char *str,struct pt_regs *regs,int signo,int sicode,void __user *addr,int err)
Signature · 1 line
2.17.1
PATCH 13/15 signal/arm64: In ptrace_hbptriggered name the signal description string
In reply to Eric W. BiedermanThis will let the description be reused shortly.
--- arch/arm64/kernel/ptrace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kernel/ptrace.c +2 -1
@@ -182,6 +182,7 @@ static void ptrace_hbptriggered(struct perf_event *bp, struct pt_regs *regs) {struct arch_hw_breakpoint *bkpt =counter_arch_bp (bp); +const char *desc ="Hardware breakpoint trap (ptrace)" ;#ifdef CONFIG_COMPAT if (is_compat_task ()) {
@@ -206,7 +207,7 @@ static void ptrace_hbptriggered(struct perf_event *bp,#endif arm64_force_sig_fault (SIGTRAP ,TRAP_HWBKPT , (void __user *)(bkpt->trigger), -"Hardware breakpoint trap (ptrace)" ); + desc); }/*
Signature · 1 line
2.17.1
PATCH 14/15 signal/arm64: Add and use arm64_force_sig_ptrace_errno_trap
In reply to Eric W. BiedermanAdd arm64_force_sig_ptrace_errno_trap for consistency with arm64_force_sig_fault and use it where appropriate.
This adds the show_signal logic to the force_sig_errno_trap case, where it was apparently overlooked earlier.
--- arch/arm64/include/asm/traps.h | 1 + arch/arm64/kernel/ptrace.c | 4 +++- arch/arm64/kernel/traps.c | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-)
arch/arm64/include/asm/traps.h +1 -0
@@ -39,6 +39,7 @@ void force_signal_inject(int signal, int code, unsigned long address);void arm64_notify_segfault (unsigned long addr);void arm64_force_sig_fault (int signo,int code,void __user *addr,const char *str);void arm64_force_sig_mceerr (int code,void __user *addr,short lsb,const char *str); +void arm64_force_sig_ptrace_errno_trap (int errno,void __user *addr,const char *str);/* * Move regs->pc to next instruction and do necessary setup before it
arch/arm64/kernel/ptrace.c +3 -1
@@ -202,7 +202,9 @@ static void ptrace_hbptriggered(struct perf_event *bp, break; } } -force_sig_ptrace_errno_trap (si_errno, (void __user *)bkpt->trigger); +arm64_force_sig_ptrace_errno_trap (si_errno, + (void __user *)bkpt->trigger, + desc); }#endif arm64_force_sig_fault(SIGTRAP, TRAP_HWBKPT,
arch/arm64/kernel/traps.c +7 -0
@@ -262,6 +262,13 @@ void arm64_force_sig_mceerr(int code, void __user *addr, short lsb,force_sig_mceerr (code, addr, lsb, current); } +void arm64_force_sig_ptrace_errno_trap (int errno,void __user *addr, +const char *str) +{ +arm64_show_signal (SIGTRAP , str); +force_sig_ptrace_errno_trap (errno, addr); +} +void arm64_notify_die (const char *str,struct pt_regs *regs,int signo,int sicode,void __user *addr,int err)
Signature · 1 line
2.17.1
PATCH 15/15 signal/arm64: Use send_sig_fault where appropriate
In reply to Eric W. Biederman--- arch/arm64/kernel/fpsimd.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
arch/arm64/kernel/fpsimd.c +3 -7
@@ -842,7 +842,6 @@ asmlinkage void do_fpsimd_acc(unsigned int esr, struct pt_regs *regs)*/ asmlinkage void do_fpsimd_exc(unsigned int esr, struct pt_regs *regs) { -siginfo_t info;unsigned int si_code =FPE_FLTUNK ;if (esr & ESR_ELx_FP_EXC_TFV) {
@@ -858,12 +857,9 @@ asmlinkage void do_fpsimd_exc(unsigned int esr, struct pt_regs *regs) si_code =FPE_FLTRES ; } -clear_siginfo (&info); - info.si_signo =SIGFPE ; - info.si_code = si_code; - info.si_addr = (void __user *)instruction_pointer (regs); - -send_sig_info (SIGFPE , &info, current); +send_sig_fault (SIGFPE , si_code, + (void __user *)instruction_pointer (regs), + current); }void fpsimd_thread_switch (struct task_struct *next)
Signature · 1 line
2.17.1
Catalin Marinas
maintainerHi Eric,
Quoted 13 lines · Eric W. Biederman
This is the continuation of my work to sort out signaling of exceptions with siginfo. The old signal sending functions by taking a siginfo argument resulted in their callers having to deal with the fiddly nature of siginfo directly. In small numbers of callers this is not a problem but in the number of callers in the kernel this resulted in cases where fields were not initialized or improperly initialized before being passed to userspace.
To avoid having to worry about those issues I have added new signal sending functions that each deal wit a different siginfo case. When using these functions there is no room for the fiddly nature of siginfo to cause mistakes.
Quoted 6 lines
This is my set of changes to update arm64 to use those functions. Along with some refactoring so those functions can be cleanly used.
Folks please review and double check me. I think I have kept these changes simple and obviously correct but I am human and mess up sometimes.
Nice clean-up, thanks. I started reviewing the patches, I should finish by tomorrow (I also applied them locally to give some testing).
Quoted 4 lines
After these patches have had a chance to be reviewed I plan to merge them by my siginfo tree. If you would rather take them in the arm64
tree let me know. All of the prerequisites should have been merged
through Linus's tree several releases ago.
Either way works for me. There is a trivial conflict in force_signal_inject() with the arm64 for-next/core tree so I could as well put them on top of this branch and send them during the 4.20 merging window.
Signature · 1 line
Catalin
Quoted 31 lines · Catalin Marinas
Hi Eric,
Quoted 13 lines · Eric W. Biederman
This is the continuation of my work to sort out signaling of exceptions with siginfo. The old signal sending functions by taking a siginfo argument resulted in their callers having to deal with the fiddly nature of siginfo directly. In small numbers of callers this is not a problem but in the number of callers in the kernel this resulted in cases where fields were not initialized or improperly initialized before being passed to userspace.
To avoid having to worry about those issues I have added new signal sending functions that each deal wit a different siginfo case. When using these functions there is no room for the fiddly nature of siginfo to cause mistakes.
Quoted 6 lines
This is my set of changes to update arm64 to use those functions. Along with some refactoring so those functions can be cleanly used.
Folks please review and double check me. I think I have kept these changes simple and obviously correct but I am human and mess up sometimes.
Nice clean-up, thanks. I started reviewing the patches, I should finish by tomorrow (I also applied them locally to give some testing).
Quoted 4 lines
After these patches have had a chance to be reviewed I plan to merge them by my siginfo tree. If you would rather take them in the arm64
tree let me know. All of the prerequisites should have been merged
through Linus's tree several releases ago.
Quoted 4 lines
Either way works for me. There is a trivial conflict in
force_signal_inject()with the arm64 for-next/core tree so I could as well put them on top of this branch and send them during the 4.20 merging window.
As long as there is a trivial conflict I would like to keep everything in one tree.
There is a following patchset that manages to reduce the size of struct
siginfo in the kernel that I have also posted for review. With
everything in one tree I can make that change now, and just cross it off my list of things to worry about.
Eric
Quoted 12 lines · Eric W. Biederman
Quoted 10 lines · Catalin Marinas
Quoted 4 lines · Eric W. Biederman
After these patches have had a chance to be reviewed I plan to merge them by my siginfo tree. If you would rather take them in the arm64
tree let me know. All of the prerequisites should have been merged
through Linus's tree several releases ago.Either way works for me. There is a trivial conflict in
force_signal_inject()with the arm64 for-next/core tree so I could as well put them on top of this branch and send them during the 4.20 merging window.
Quoted 7 lines
As long as there is a trivial conflict I would like to keep everything in one tree.
There is a following patchset that manages to reduce the size of struct
siginfo in the kernel that I have also posted for review. With
everything in one tree I can make that change now, and just cross it off my list of things to worry about.
Fine by me:
The conflict will appear in -next but the resolution is simple:
arch/arm64/kernel/traps.c +0 -0
@@@ -353,12 -366,6 +368,9 @@@ void force_signal_inject(int signal, inconst char *desc;struct pt_regs *regs =current_pt_regs (); + if (WARN_ON(!user_mode(regs))) + return; + -clear_siginfo (&info); - switch (signal) {case SIGILL : desc ="undefined instruction" ;
Signature · 1 line
Catalin