uprobes: Change handle_swbp() to expose bp_vaddr to handler_chain()
Subsystems (4)
Oleg Nesterov
maintainercover uprobes: Change handle_swbp() to expose bp_vaddr to handler_chain()
Hello.
Inspired by the recent uretrpobe RFC's. I think it simply makes no sense to call handler/skip/arch_uprobe_pre_xol with regs->ip pointing to the "random" address after the task hits bp.
Ananth, could you please confirm 2/2 can't break powerpc? It "obviously" shouldn't because uprobe_get_swbp_addr() is a "nop" on ppc, but still your ack is welcomed.
Oleg.
Oleg Nesterov
maintainerPATCH 1/2 uprobes/x86: Change __skip_sstep() to actually skip the whole insn
__skip_sstep() doesn't update regs->ip. Currently this is correct but only "by accident" and it doesn't skip the whole insn. Change it to advance ->ip by the length of the detected 0x66*0x90 sequence.
--- arch/x86/kernel/uprobes.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
arch/x86/kernel/uprobes.c +4 -1
@@ -680,8 +680,11 @@ static bool __skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs)if (auprobe->insn[i] ==0x66 )continue ; -if (auprobe->insn[i] ==0x90 ) +if (auprobe->insn[i] ==0x90 ) { + regs->ip =uprobe_get_swbp_addr (regs); + regs->ip += i +1 ;return true; + }break ; }
Signature · 1 line
1.5.5.1
Oleg Nesterov
maintainerPATCH 2/2 uprobes: Change handle_swbp() to expose bp_vaddr to handler_chain()
In reply to Oleg NesterovChange handle_swbp() to set regs->ip = bp_vaddr in advance, this is what consumer->handler() needs but uprobe_get_swbp_addr() is not exported.
This also simplifies the code and makes it more consistent across the supported architectures. handle_swbp() becomes the only caller of uprobe_get_swbp_addr().
--- arch/x86/kernel/uprobes.c | 1 - kernel/events/uprobes.c | 15 +++++++-------- kernel/trace/trace_uprobe.c | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-)
arch/x86/kernel/uprobes.c +0 -1
@@ -681,7 +681,6 @@ static bool __skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs)continue ;if (auprobe->insn[i] ==0x90 ) { - regs->ip =uprobe_get_swbp_addr (regs); regs->ip += i +1 ;return true; }
kernel/events/uprobes.c +7 -8
@@ -1504,6 +1504,10 @@ static void handle_swbp(struct pt_regs *regs) }return ; } + +/* change it in advance for ->handler() and restart */ +instruction_pointer_set (regs, bp_vaddr); +/* * TODO: move copy_insn/etc into _register and remove this hack. * After we hit the bp, _unregister + _register can install the
@@ -1511,14 +1515,14 @@ static void handle_swbp(struct pt_regs *regs)*/ smp_rmb ();/* pairs with wmb() in install_breakpoint() */ if (unlikely (!test_bit (UPROBE_COPY_INSN , &uprobe->flags))) - goto restart; + goto out; utask = current->utask;if (!utask) { utask =add_utask ();/* Cannot allocate; re-execute the instruction. */ if (!utask) - goto restart; + goto out; }handler_chain (uprobe, regs);
@@ -1531,12 +1535,7 @@ static void handle_swbp(struct pt_regs *regs)return ; } -restart: -/* -* cannot singlestep; cannot skip instruction; -* re-execute the instruction. -*/ -instruction_pointer_set (regs, bp_vaddr); +/* can_skip_sstep() succeeded, or restart if can't singlestep */ out:put_uprobe (uprobe); }
kernel/trace/trace_uprobe.c +2 -2
@@ -488,7 +488,7 @@ static void uprobe_trace_func(struct trace_uprobe *tu, struct pt_regs *regs)return ; entry =ring_buffer_event_data (event); - entry->ip =uprobe_get_swbp_addr (task_pt_regs (current)); + entry->ip =instruction_pointer (task_pt_regs (current)); data = (u8 *)&entry[1 ];for (i =0 ; i < tu->nr_args; i++)call_fetch (&tu->args[i].fetch, regs, data + tu->args[i].offset);
@@ -663,7 +663,7 @@ static void uprobe_perf_func(struct trace_uprobe *tu, struct pt_regs *regs)if (!entry) goto out; - entry->ip =uprobe_get_swbp_addr (task_pt_regs (current)); + entry->ip =instruction_pointer (task_pt_regs (current)); data = (u8 *)&entry[1 ];for (i =0 ; i < tu->nr_args; i++)call_fetch (&tu->args[i].fetch, regs, data + tu->args[i].offset);
Signature · 1 line
1.5.5.1
Quoted 7 lines · Oleg Nesterov
Change
handle_swbp()to setregs->ip=bp_vaddrin advance, this is whatconsumer->handler()needs butuprobe_get_swbp_addr()is not exported.This also simplifies the code and makes it more consistent across the supported architectures.
handle_swbp()becomes the only caller ofuprobe_get_swbp_addr().
The arch agnostic bits look fine to me.
Quoted 1 line
Signed-off-by Oleg Nesterov <[email protected]>
Re: [PATCH 1/2] uprobes/x86: Change __skip_sstep() to actually skip the whole insn
In reply to Oleg NesterovQuoted 14 lines · Oleg Nesterov
__skip_sstep()doesn't updateregs->ip. Currently this is correct but only "by accident" and it doesn't skip the whole insn. Change it to advance ->ip by the length of the detected 0x66*0x90 sequence.Signed-off-by Oleg Nesterov <[email protected]>--- arch/x86/kernel/uprobes.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)arch/x86/kernel/uprobes.c +0
-0
arch/x86/kernel/uprobes.c static bool __skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs) · line 687
Quoted 9 lines
arch/x86/kernel/uprobes.c +4
-1@@ -680,8 +680,11 @@ static bool __skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs)if (auprobe->insn[i] ==0x66 )continue ; -if (auprobe->insn[i] ==0x90 ) +if (auprobe->insn[i] ==0x90 ) { + regs->ip =uprobe_get_swbp_addr (regs); + regs->ip += i +1 ;return true; + }
This change/routine is not obvious without the patch description, I
would appreciate some comment in the code. :) I believe it could help some random developer in future.
/ I leave it to your judgement though /
Anton.
Re: [PATCH 1/2] uprobes/x86: Change __skip_sstep() to actually skip the whole insn
In reply to Oleg NesterovQuoted 5 lines · Oleg Nesterov
__skip_sstep()doesn't updateregs->ip. Currently this is correct but only "by accident" and it doesn't skip the whole insn. Change it to advance ->ip by the length of the detected 0x66*0x90 sequence.Signed-off-by Oleg Nesterov <[email protected]>
Quoted 24 lines
--- arch/x86/kernel/uprobes.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)arch/x86/kernel/uprobes.c +4
-1@@ -680,8 +680,11 @@ static bool __skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs)if (auprobe->insn[i] ==0x66 )continue ; -if (auprobe->insn[i] ==0x90 ) +if (auprobe->insn[i] ==0x90 ) { + regs->ip =uprobe_get_swbp_addr (regs); + regs->ip += i +1 ;return true; + }break ; }Signature · 1 line
1.5.5.1
Re: [PATCH 1/2] uprobes/x86: Change __skip_sstep() to actually skip the whole insn
In reply to Oleg NesterovQuoted 5 lines · Oleg Nesterov
__skip_sstep()doesn't updateregs->ip. Currently this is correct but only "by accident" and it doesn't skip the whole insn. Change it to advance ->ip by the length of the detected 0x66*0x90 sequence.Signed-off-by Oleg Nesterov <[email protected]>
Quoted 24 lines
--- arch/x86/kernel/uprobes.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)arch/x86/kernel/uprobes.c +4
-1@@ -680,8 +680,11 @@ static bool __skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs)if (auprobe->insn[i] ==0x66 )continue ; -if (auprobe->insn[i] ==0x90 ) +if (auprobe->insn[i] ==0x90 ) { + regs->ip =uprobe_get_swbp_addr (regs); + regs->ip += i +1 ;return true; + }break ; }Signature · 1 line
1.5.5.1
Quoted 9 lines · Oleg Nesterov
Change
handle_swbp()to setregs->ip=bp_vaddrin advance, this is whatconsumer->handler()needs butuprobe_get_swbp_addr()is not exported.This also simplifies the code and makes it more consistent across the supported architectures.
handle_swbp()becomes the only caller ofuprobe_get_swbp_addr().Signed-off-by Oleg Nesterov <[email protected]>
Quoted 89 lines
--- arch/x86/kernel/uprobes.c | 1 - kernel/events/uprobes.c | 15 +++++++-------- kernel/trace/trace_uprobe.c | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-)arch/x86/kernel/uprobes.c +0
-1@@ -681,7 +681,6 @@ static bool __skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs)continue ;if (auprobe->insn[i] ==0x90 ) { - regs->ip =uprobe_get_swbp_addr (regs); regs->ip += i +1 ;return true; }kernel/events/uprobes.c +7
-8@@ -1504,6 +1504,10 @@ static void handle_swbp(struct pt_regs *regs) }return ; } + +/* change it in advance for ->handler() and restart */ +instruction_pointer_set (regs, bp_vaddr); +/* * TODO: move copy_insn/etc into _register and remove this hack. * After we hit the bp, _unregister + _register can install the @@ -1511,14 +1515,14 @@ static void handle_swbp(struct pt_regs *regs)*/ smp_rmb ();/* pairs with wmb() in install_breakpoint() */ if (unlikely (!test_bit (UPROBE_COPY_INSN , &uprobe->flags))) - goto restart; + goto out; utask = current->utask;if (!utask) { utask =add_utask ();/* Cannot allocate; re-execute the instruction. */ if (!utask) - goto restart; + goto out; }handler_chain (uprobe, regs);@@ -1531,12 +1535,7 @@ static void handle_swbp(struct pt_regs *regs)return ; } -restart: -/* -* cannot singlestep; cannot skip instruction; -* re-execute the instruction. -*/ -instruction_pointer_set (regs, bp_vaddr); +/* can_skip_sstep() succeeded, or restart if can't singlestep */ out:put_uprobe (uprobe); }kernel/trace/trace_uprobe.c +2
-2@@ -488,7 +488,7 @@ static void uprobe_trace_func(struct trace_uprobe *tu, struct pt_regs *regs)return ; entry =ring_buffer_event_data (event); - entry->ip =uprobe_get_swbp_addr (task_pt_regs (current)); + entry->ip =instruction_pointer (task_pt_regs (current)); data = (u8 *)&entry[1 ];for (i =0 ; i < tu->nr_args; i++)call_fetch (&tu->args[i].fetch, regs, data + tu->args[i].offset);@@ -663,7 +663,7 @@ static void uprobe_perf_func(struct trace_uprobe *tu, struct pt_regs *regs)if (!entry) goto out; - entry->ip =uprobe_get_swbp_addr (task_pt_regs (current)); + entry->ip =instruction_pointer (task_pt_regs (current)); data = (u8 *)&entry[1 ];for (i =0 ; i < tu->nr_args; i++)call_fetch (&tu->args[i].fetch, regs, data + tu->args[i].offset);Signature · 1 line
1.5.5.1