diff options
author | Oleg Nesterov <oleg@redhat.com> | 2014-05-12 12:24:45 -0400 |
---|---|---|
committer | Oleg Nesterov <oleg@redhat.com> | 2014-05-14 07:57:28 -0400 |
commit | b02ef20a9fba08948e643d3eec0efadf1da01a44 (patch) | |
tree | d0db097668940dce698fec8b00d228cd29c1dee0 /kernel | |
parent | 0eb14833d5b1ea1accfeffb71be5de5929f85da9 (diff) |
uprobes/x86: Fix the wrong ->si_addr when xol triggers a trap
If the probed insn triggers a trap, ->si_addr = regs->ip is technically
correct, but this is not what the signal handler wants; we need to pass
the address of the probed insn, not the address of xol slot.
Add the new arch-agnostic helper, uprobe_get_trap_addr(), and change
fill_trap_info() and math_error() to use it. !CONFIG_UPROBES case in
uprobes.h uses a macro to avoid include hell and ensure that it can be
compiled even if an architecture doesn't define instruction_pointer().
Test-case:
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
extern void probe_div(void);
void sigh(int sig, siginfo_t *info, void *c)
{
int passed = (info->si_addr == probe_div);
printf(passed ? "PASS\n" : "FAIL\n");
_exit(!passed);
}
int main(void)
{
struct sigaction sa = {
.sa_sigaction = sigh,
.sa_flags = SA_SIGINFO,
};
sigaction(SIGFPE, &sa, NULL);
asm (
"xor %ecx,%ecx\n"
".globl probe_div; probe_div:\n"
"idiv %ecx\n"
);
return 0;
}
it fails if probe_div() is probed.
Note: show_unhandled_signals users should probably use this helper too,
but we need to cleanup them first.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/events/uprobes.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index a13251e8bfa4..3b02c72938a8 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c | |||
@@ -1351,6 +1351,16 @@ unsigned long __weak uprobe_get_swbp_addr(struct pt_regs *regs) | |||
1351 | return instruction_pointer(regs) - UPROBE_SWBP_INSN_SIZE; | 1351 | return instruction_pointer(regs) - UPROBE_SWBP_INSN_SIZE; |
1352 | } | 1352 | } |
1353 | 1353 | ||
1354 | unsigned long uprobe_get_trap_addr(struct pt_regs *regs) | ||
1355 | { | ||
1356 | struct uprobe_task *utask = current->utask; | ||
1357 | |||
1358 | if (unlikely(utask && utask->active_uprobe)) | ||
1359 | return utask->vaddr; | ||
1360 | |||
1361 | return instruction_pointer(regs); | ||
1362 | } | ||
1363 | |||
1354 | /* | 1364 | /* |
1355 | * Called with no locks held. | 1365 | * Called with no locks held. |
1356 | * Called in context of a exiting or a exec-ing thread. | 1366 | * Called in context of a exiting or a exec-ing thread. |