Skip to content

Commit 014940b

Browse files
committed
uprobes/x86: Send SIGILL if arch_uprobe_post_xol() fails
Currently the error from arch_uprobe_post_xol() is silently ignored. This doesn't look good and this can lead to the hard-to-debug problems. 1. Change handle_singlestep() to loudly complain and send SIGILL. Note: this only affects x86, ppc/arm can't fail. 2. Change arch_uprobe_post_xol() to call arch_uprobe_abort_xol() and avoid TF games if it is going to return an error. This can help to to analyze the problem, if nothing else we should not report ->ip = xol_slot in the core-file. Note: this means that handle_riprel_post_xol() can be called twice, but this is fine because it is idempotent. Signed-off-by: Oleg Nesterov <[email protected]> Reviewed-by: Masami Hiramatsu <[email protected]> Reviewed-by: Jim Keniston <[email protected]>
1 parent e55848a commit 014940b

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

arch/x86/kernel/uprobes.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,15 @@ int arch_uprobe_post_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
594594
struct uprobe_task *utask = current->utask;
595595

596596
WARN_ON_ONCE(current->thread.trap_nr != UPROBE_TRAP_NR);
597+
598+
if (auprobe->ops->post_xol) {
599+
int err = auprobe->ops->post_xol(auprobe, regs);
600+
if (err) {
601+
arch_uprobe_abort_xol(auprobe, regs);
602+
return err;
603+
}
604+
}
605+
597606
current->thread.trap_nr = utask->autask.saved_trap_nr;
598607
/*
599608
* arch_uprobe_pre_xol() doesn't save the state of TIF_BLOCKSTEP
@@ -605,8 +614,6 @@ int arch_uprobe_post_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
605614
else if (!(auprobe->fixups & UPROBE_FIX_SETF))
606615
regs->flags &= ~X86_EFLAGS_TF;
607616

608-
if (auprobe->ops->post_xol)
609-
return auprobe->ops->post_xol(auprobe, regs);
610617
return 0;
611618
}
612619

@@ -641,8 +648,9 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
641648

642649
/*
643650
* This function gets called when XOL instruction either gets trapped or
644-
* the thread has a fatal signal, so reset the instruction pointer to its
645-
* probed address.
651+
* the thread has a fatal signal, or if arch_uprobe_post_xol() failed.
652+
* Reset the instruction pointer to its probed address for the potential
653+
* restart or for post mortem analysis.
646654
*/
647655
void arch_uprobe_abort_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
648656
{

kernel/events/uprobes.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1867,10 +1867,11 @@ static void handle_swbp(struct pt_regs *regs)
18671867
static void handle_singlestep(struct uprobe_task *utask, struct pt_regs *regs)
18681868
{
18691869
struct uprobe *uprobe;
1870+
int err = 0;
18701871

18711872
uprobe = utask->active_uprobe;
18721873
if (utask->state == UTASK_SSTEP_ACK)
1873-
arch_uprobe_post_xol(&uprobe->arch, regs);
1874+
err = arch_uprobe_post_xol(&uprobe->arch, regs);
18741875
else if (utask->state == UTASK_SSTEP_TRAPPED)
18751876
arch_uprobe_abort_xol(&uprobe->arch, regs);
18761877
else
@@ -1884,6 +1885,11 @@ static void handle_singlestep(struct uprobe_task *utask, struct pt_regs *regs)
18841885
spin_lock_irq(&current->sighand->siglock);
18851886
recalc_sigpending(); /* see uprobe_deny_signal() */
18861887
spin_unlock_irq(&current->sighand->siglock);
1888+
1889+
if (unlikely(err)) {
1890+
uprobe_warn(current, "execute the probed insn, sending SIGILL.");
1891+
force_sig_info(SIGILL, SEND_SIG_FORCED, current);
1892+
}
18871893
}
18881894

18891895
/*

0 commit comments

Comments
 (0)