Commit 2c9120f3 authored by Will Deacon's avatar Will Deacon

arm64: signal: Make force_signal_inject more robust

force_signal_inject is a little flakey:

  * It only knows about SIGILL and SIGSEGV, so can potentially deliver
    other signals based on a partially initialised siginfo_t

  * It sets si_addr to point at the PC for SIGSEGV

  * It always operates on current, so doesn't need the regs argument

This patch fixes these issues by always assigning the si_addr field to
the address parameter of the function and updates the callers (including
those that indirectly call via arm64_notify_segfault) accordingly.
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
parent e0f6429d
...@@ -35,10 +35,8 @@ struct undef_hook { ...@@ -35,10 +35,8 @@ struct undef_hook {
void register_undef_hook(struct undef_hook *hook); void register_undef_hook(struct undef_hook *hook);
void unregister_undef_hook(struct undef_hook *hook); void unregister_undef_hook(struct undef_hook *hook);
void force_signal_inject(int signal, int code, struct pt_regs *regs, void force_signal_inject(int signal, int code, unsigned long address);
unsigned long address); void arm64_notify_segfault(unsigned long addr);
void arm64_notify_segfault(struct pt_regs *regs, unsigned long addr);
/* /*
* Move regs->pc to next instruction and do necessary setup before it * Move regs->pc to next instruction and do necessary setup before it
......
...@@ -429,7 +429,7 @@ static int swp_handler(struct pt_regs *regs, u32 instr) ...@@ -429,7 +429,7 @@ static int swp_handler(struct pt_regs *regs, u32 instr)
fault: fault:
pr_debug("SWP{B} emulation: access caused memory abort!\n"); pr_debug("SWP{B} emulation: access caused memory abort!\n");
arm64_notify_segfault(regs, address); arm64_notify_segfault(address);
return 0; return 0;
} }
......
...@@ -285,8 +285,7 @@ static void task_fpsimd_save(void) ...@@ -285,8 +285,7 @@ static void task_fpsimd_save(void)
* re-enter user with corrupt state. * re-enter user with corrupt state.
* There's no way to recover, so kill it: * There's no way to recover, so kill it:
*/ */
force_signal_inject( force_signal_inject(SIGKILL, 0, 0);
SIGKILL, 0, current_pt_regs(), 0);
return; return;
} }
...@@ -831,7 +830,7 @@ asmlinkage void do_sve_acc(unsigned int esr, struct pt_regs *regs) ...@@ -831,7 +830,7 @@ asmlinkage void do_sve_acc(unsigned int esr, struct pt_regs *regs)
{ {
/* Even if we chose not to use SVE, the hardware could still trap: */ /* Even if we chose not to use SVE, the hardware could still trap: */
if (unlikely(!system_supports_sve()) || WARN_ON(is_compat_task())) { if (unlikely(!system_supports_sve()) || WARN_ON(is_compat_task())) {
force_signal_inject(SIGILL, ILL_ILLOPC, regs, 0); force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc);
return; return;
} }
......
...@@ -311,12 +311,13 @@ static int call_undef_hook(struct pt_regs *regs) ...@@ -311,12 +311,13 @@ static int call_undef_hook(struct pt_regs *regs)
return fn ? fn(regs, instr) : 1; return fn ? fn(regs, instr) : 1;
} }
void force_signal_inject(int signal, int code, struct pt_regs *regs, void force_signal_inject(int signal, int code, unsigned long address)
unsigned long address)
{ {
siginfo_t info; siginfo_t info;
void __user *pc = (void __user *)instruction_pointer(regs);
const char *desc; const char *desc;
struct pt_regs *regs = current_pt_regs();
clear_siginfo(&info);
switch (signal) { switch (signal) {
case SIGILL: case SIGILL:
...@@ -332,15 +333,15 @@ void force_signal_inject(int signal, int code, struct pt_regs *regs, ...@@ -332,15 +333,15 @@ void force_signal_inject(int signal, int code, struct pt_regs *regs,
if (unhandled_signal(current, signal) && if (unhandled_signal(current, signal) &&
show_unhandled_signals_ratelimited()) { show_unhandled_signals_ratelimited()) {
pr_info("%s[%d]: %s: pc=%p\n", pr_info("%s[%d]: %s: pc=%08llx\n",
current->comm, task_pid_nr(current), desc, pc); current->comm, task_pid_nr(current), desc, regs->pc);
dump_instr(KERN_INFO, regs); dump_instr(KERN_INFO, regs);
} }
info.si_signo = signal; info.si_signo = signal;
info.si_errno = 0; info.si_errno = 0;
info.si_code = code; info.si_code = code;
info.si_addr = pc; info.si_addr = (void __user *)address;
arm64_notify_die(desc, regs, &info, 0); arm64_notify_die(desc, regs, &info, 0);
} }
...@@ -348,7 +349,7 @@ void force_signal_inject(int signal, int code, struct pt_regs *regs, ...@@ -348,7 +349,7 @@ void force_signal_inject(int signal, int code, struct pt_regs *regs,
/* /*
* Set up process info to signal segmentation fault - called on access error. * Set up process info to signal segmentation fault - called on access error.
*/ */
void arm64_notify_segfault(struct pt_regs *regs, unsigned long addr) void arm64_notify_segfault(unsigned long addr)
{ {
int code; int code;
...@@ -359,7 +360,7 @@ void arm64_notify_segfault(struct pt_regs *regs, unsigned long addr) ...@@ -359,7 +360,7 @@ void arm64_notify_segfault(struct pt_regs *regs, unsigned long addr)
code = SEGV_ACCERR; code = SEGV_ACCERR;
up_read(&current->mm->mmap_sem); up_read(&current->mm->mmap_sem);
force_signal_inject(SIGSEGV, code, regs, addr); force_signal_inject(SIGSEGV, code, addr);
} }
asmlinkage void __exception do_undefinstr(struct pt_regs *regs) asmlinkage void __exception do_undefinstr(struct pt_regs *regs)
...@@ -371,7 +372,7 @@ asmlinkage void __exception do_undefinstr(struct pt_regs *regs) ...@@ -371,7 +372,7 @@ asmlinkage void __exception do_undefinstr(struct pt_regs *regs)
if (call_undef_hook(regs) == 0) if (call_undef_hook(regs) == 0)
return; return;
force_signal_inject(SIGILL, ILL_ILLOPC, regs, 0); force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc);
} }
int cpu_enable_cache_maint_trap(void *__unused) int cpu_enable_cache_maint_trap(void *__unused)
...@@ -426,12 +427,12 @@ static void user_cache_maint_handler(unsigned int esr, struct pt_regs *regs) ...@@ -426,12 +427,12 @@ static void user_cache_maint_handler(unsigned int esr, struct pt_regs *regs)
__user_cache_maint("ic ivau", address, ret); __user_cache_maint("ic ivau", address, ret);
break; break;
default: default:
force_signal_inject(SIGILL, ILL_ILLOPC, regs, 0); force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc);
return; return;
} }
if (ret) if (ret)
arm64_notify_segfault(regs, address); arm64_notify_segfault(address);
else else
arm64_skip_faulting_instruction(regs, AARCH64_INSN_SIZE); arm64_skip_faulting_instruction(regs, AARCH64_INSN_SIZE);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment