[PATCHv2 perf/core 2/4] uprobe: Do not emulate/sstep original instruction when ip is changed

Jiri Olsa posted 4 patches 3 months, 1 week ago
There is a newer version of this series
[PATCHv2 perf/core 2/4] uprobe: Do not emulate/sstep original instruction when ip is changed
Posted by Jiri Olsa 3 months, 1 week ago
If uprobe handler changes instruction pointer we still execute single
step) or emulate the original instruction and increment the (new) ip
with its length.

This makes the new instruction pointer bogus and application will
likely crash on illegal instruction execution.

If user decided to take execution elsewhere, it makes little sense
to execute the original instruction, so let's skip it.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 kernel/events/uprobes.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 996a81080d56..4f46018e507e 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -2768,6 +2768,13 @@ static void handle_swbp(struct pt_regs *regs)
 	/* Try to optimize after first hit. */
 	arch_uprobe_optimize(&uprobe->arch, bp_vaddr);
 
+	/*
+	 * If user decided to take execution elsewhere, it makes little sense
+	 * to execute the original instruction, so let's skip it.
+	 */
+	if (instruction_pointer(regs) != bp_vaddr)
+		goto out;
+
 	if (arch_uprobe_skip_sstep(&uprobe->arch, regs))
 		goto out;
 
-- 
2.51.0
Re: [PATCHv2 perf/core 2/4] uprobe: Do not emulate/sstep original instruction when ip is changed
Posted by Oleg Nesterov 3 months, 1 week ago
On 09/08, Jiri Olsa wrote:
>
> If user decided to take execution elsewhere, it makes little sense
> to execute the original instruction, so let's skip it.

...

> @@ -2768,6 +2768,13 @@ static void handle_swbp(struct pt_regs *regs)
>  	/* Try to optimize after first hit. */
>  	arch_uprobe_optimize(&uprobe->arch, bp_vaddr);
>
> +	/*
> +	 * If user decided to take execution elsewhere, it makes little sense
> +	 * to execute the original instruction, so let's skip it.
> +	 */
> +	if (instruction_pointer(regs) != bp_vaddr)
> +		goto out;
> +

Acked-by: Oleg Nesterov <oleg@redhat.com>