uprobes: return probe implementation
Subsystems (3)
v3 cover uprobes: return probe implementation
Hello,
RFC v3 uretprobes implementation. I'd be grateful for review.
These patches extending uprobes by enabling tools, such as perf(trace_event),
set a breakpoint on probed function's return address.
v3 changes:
- removed uretprobe_bypass logic, it will be better to send it as independent patch
- unified xol_get_trampoline_slot() and xol_get_insn_slot()
- protected uprobe with refcounter in prepare_uretprobe()
- uprobe_register() routine fails now, if neither consumer is set
- enclosed implementation into 1/6, 6/6 patches -ENOSYS bits
v2 changes:
- introduced rp_handler(), get rid of return_consumers
- get rid of uretprobe_[un]register()
- introduced arch_uretprobe_get_sp()
- removed uprobe_task->doomed, kill task immediately
- fix arch_uretprobe_hijack_return_addr()'s returns
- address the v1 minor issues
integrated patchset:
http://github.com/arapov/linux-aa/commits/uretprobes_v3
previous implementations:
RFCv2: https://lkml.org/lkml/2013/1/9/157
RFCv1: https://lkml.org/lkml/2012/12/21/133
thanks,
Anton
Anton Arapov (6):
uretprobes: preparation patch uretprobes/x86: hijack return address
uretprobes: generalize xol_get_insn_slot()
uretprobes: return probe entry, prepare uretprobe
uretprobes: invoke return probe handlers
uretprobes: implemented, thus remove -ENOSYS
arch/x86/include/asm/uprobes.h | 6 +++ arch/x86/kernel/uprobes.c | 29 +++++++++++ include/linux/uprobes.h | 6 +++ kernel/events/uprobes.c | 112 ++++++++++++++++++++++++++++++++++++++--- 4 files changed, 146 insertions(+), 7 deletions(-)
Signature · 1 line
1.8.1.2
RFC PATCH v3 1/6 uretprobes: preparation patch
1/6 and 6/6 patches are here to enclose return probes implementation as well
as prohibit uprobe_register() routine with no consumer set.
v3 changes: (the patch is introduced in v3)
- check whether at least one of the consumer's handlers were set
- a 'TODO' cap that will be removed once return probes be implemented
--- include/linux/uprobes.h | 1 + kernel/events/uprobes.c | 8 ++++++++ 2 files changed, 9 insertions(+)
include/linux/uprobes.h +1 -0
@@ -46,6 +46,7 @@ enum uprobe_filter_ctx {struct uprobe_consumer {int (*handler)(struct uprobe_consumer *self,struct pt_regs *regs); +int (*rp_handler)(struct uprobe_consumer *self,struct pt_regs *regs);bool (*filter)(struct uprobe_consumer *self,enum uprobe_filter_ctx ctx,struct mm_struct *mm);
kernel/events/uprobes.c +8 -0
@@ -828,6 +828,14 @@ int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *struct uprobe *uprobe;int ret; +/* Uprobe must have at least one set consumer */ +if (!uc->handler && !uc->rp_handler) +return -EINVAL ; + +/* TODO: Implement return probes */ +if (uc->rp_handler) +return -ENOSYS ; +/* Racy, just to catch the obvious mistakes */ if (offset >i_size_read (inode))return -EINVAL ;
Signature · 1 line
1.8.1.2
RFC PATCH v3 2/6 uretprobes/x86: hijack return address
In reply to Anton Arapovhijack the return address and replace it with a "trampoline"
v2:
- remove ->doomed flag, kill task immediately
--- arch/x86/include/asm/uprobes.h | 1 + arch/x86/kernel/uprobes.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
arch/x86/include/asm/uprobes.h +1 -0
@@ -55,4 +55,5 @@ extern int arch_uprobe_post_xol(struct arch_uprobe *aup, struct pt_regs *regs);extern bool arch_uprobe_xol_was_trapped (struct task_struct *tsk);extern int arch_uprobe_exception_notify (struct notifier_block *self,unsigned long val,void *data);extern void arch_uprobe_abort_xol (struct arch_uprobe *aup,struct pt_regs *regs); +extern unsigned long arch_uretprobe_hijack_return_addr (unsigned long rp_trampoline_vaddr,struct pt_regs *regs);#endif /* _ASM_UPROBES_H */
arch/x86/kernel/uprobes.c +29 -0
@@ -697,3 +697,32 @@ bool arch_uprobe_skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs)send_sig (SIGTRAP , current,0 );return ret; } + +extern unsigned long arch_uretprobe_hijack_return_addr (unsigned long + rp_trampoline_vaddr,struct pt_regs *regs) +{ +int rasize, ncopied; +unsigned long orig_ret_vaddr =0 ;/* clear high bits for 32-bit apps */ + + rasize =is_ia32_task () ?4 :8 ; + ncopied =copy_from_user (&orig_ret_vaddr, (void __user *)regs->sp, rasize); +if (unlikely (ncopied)) +return 0 ; + +/* check whether address has been already hijacked */ +if (orig_ret_vaddr == rp_trampoline_vaddr) +return orig_ret_vaddr; + + ncopied =copy_to_user ((void __user *)regs->sp, &rp_trampoline_vaddr, rasize); +if (unlikely (ncopied)) { +if (ncopied != rasize) { +printk (KERN_ERR "uretprobe: return address clobbered: " +"pid=%d, %%sp=%#lx, %%ip=%#lx\n" , + current->pid, regs->sp, regs->ip); +/* kill task immediately */ +send_sig (SIGSEGV , current,0 ); + } + } + +return orig_ret_vaddr; +}
Signature · 1 line
1.8.1.2
Re: [RFC PATCH v3 2/6] uretprobes/x86: hijack return address
Quoted 29 lines · Anton Arapov
hijack the return address and replace it with a "trampoline"
v2:
- remove ->doomed flag, kill task immediatelySigned-off-by Anton Arapov <[email protected]>--- arch/x86/include/asm/uprobes.h | 1 + arch/x86/kernel/uprobes.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)arch/x86/include/asm/uprobes.h +1
-0@@ -55,4 +55,5 @@ extern int arch_uprobe_post_xol(struct arch_uprobe *aup, struct pt_regs *regs);extern bool arch_uprobe_xol_was_trapped (struct task_struct *tsk);extern int arch_uprobe_exception_notify (struct notifier_block *self,unsigned long val,void *data);extern void arch_uprobe_abort_xol (struct arch_uprobe *aup,struct pt_regs *regs); +extern unsigned long arch_uretprobe_hijack_return_addr (unsigned long rp_trampoline_vaddr,struct pt_regs *regs);#endif /* _ASM_UPROBES_H */ arch/x86/kernel/uprobes.c +0
-0@@ -697,3 +697,32 @@ bool arch_uprobe_skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs)send_sig (SIGTRAP , current,0 );return ret; }
arch/x86/kernel/uprobes.c bool arch_uprobe_skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs) · line 709
Quoted 10 lines
arch/x86/kernel/uprobes.c +10
-0+ +extern unsigned long arch_uretprobe_hijack_return_addr (unsigned long + rp_trampoline_vaddr,struct pt_regs *regs) +{ +int rasize, ncopied; +unsigned long orig_ret_vaddr =0 ;/* clear high bits for 32-bit apps */ + + rasize =is_ia32_task () ?4 :8 ; + ncopied =copy_from_user (&orig_ret_vaddr, (void __user *)regs->sp, rasize); +if (unlikely (ncopied))
What if ncopied < rasize? Agreed that the upper order bits can be 0, but should you not validate ncopied == rasize?
Ananth
Re: [RFC PATCH v3 2/6] uretprobes/x86: hijack return address
Quoted 35 lines · Ananth N Mavinakayanahalli
Quoted 34 lines · Anton Arapov
hijack the return address and replace it with a "trampoline"
v2:
- remove ->doomed flag, kill task immediatelySigned-off-by Anton Arapov <[email protected]>--- arch/x86/include/asm/uprobes.h | 1 + arch/x86/kernel/uprobes.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)arch/x86/include/asm/uprobes.h +1
-0@@ -55,4 +55,5 @@ extern int arch_uprobe_post_xol(struct arch_uprobe *aup, struct pt_regs *regs);extern bool arch_uprobe_xol_was_trapped (struct task_struct *tsk);extern int arch_uprobe_exception_notify (struct notifier_block *self,unsigned long val,void *data);extern void arch_uprobe_abort_xol (struct arch_uprobe *aup,struct pt_regs *regs); +extern unsigned long arch_uretprobe_hijack_return_addr (unsigned long rp_trampoline_vaddr,struct pt_regs *regs);#endif /* _ASM_UPROBES_H */ arch/x86/kernel/uprobes.c +5
-0@@ -697,3 +697,32 @@ bool arch_uprobe_skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs)send_sig (SIGTRAP , current,0 );return ret; } + +extern unsigned long arch_uretprobe_hijack_return_addr (unsigned long + rp_trampoline_vaddr,struct pt_regs *regs) +{ +int rasize, ncopied;
Quoted 8 lines
arch/x86/kernel/uprobes.c bool arch_uprobe_skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs) · line 709
Quoted 5 lines
arch/x86/kernel/uprobes.c +5
-0+unsigned long orig_ret_vaddr =0 ;/* clear high bits for 32-bit apps */ + + rasize =is_ia32_task () ?4 :8 ; + ncopied =copy_from_user (&orig_ret_vaddr, (void __user *)regs->sp, rasize); +if (unlikely (ncopied))What if ncopied < rasize? Agreed that the upper order bits can be 0, but should you not validate ncopied == rasize?
Function returns 0 in case copy_from_user() was not able to copy
return address entirely, and "if (ncopied)" makes sure of it. We can't continue if we have no correct return address.
copy_from_user() returns number of bytes that were *not* copied,
thus "ncopied == rasize" means copy_from_user() was not able to copy *all* bytes. I don't see the point of such check here.
Or am I missing anything?
thank you!
Anton.
Re: [RFC PATCH v3 2/6] uretprobes/x86: hijack return address
Quoted 2 lines · Anton Arapov
Quoted 1 line · Ananth N Mavinakayanahalli
On Thu, Feb 28, 2013 at 12:00:11PM +0100, Anton Arapov wrote:
...
Quoted 17 lines
Quoted 4 lines
Quoted 4 lines
arch/x86/kernel/uprobes.c +4
-0+extern unsigned long arch_uretprobe_hijack_return_addr (unsigned long + rp_trampoline_vaddr,struct pt_regs *regs) +{ +int rasize, ncopied;Quoted 8 lines
arch/x86/kernel/uprobes.c bool arch_uprobe_skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs) · line 709
Quoted 5 lines
arch/x86/kernel/uprobes.c +5
-0+unsigned long orig_ret_vaddr =0 ;/* clear high bits for 32-bit apps */ + + rasize =is_ia32_task () ?4 :8 ; + ncopied =copy_from_user (&orig_ret_vaddr, (void __user *)regs->sp, rasize); +if (unlikely (ncopied))What if ncopied < rasize? Agreed that the upper order bits can be 0, but should you not validate ncopied == rasize?
Function returns 0 in case
copy_from_user()was not able to copy
return address entirely, and "if (ncopied)" makes sure of it. We can't continue if we have no correct return address.
Quoted 5 lines
copy_from_user()returns number of bytes that were *not* copied,
thus "ncopied == rasize" meanscopy_from_user()was not able to copy *all* bytes. I don't see the point of such check here.Or am I missing anything?
You are right... my bad.
Ananth
RFC PATCH v3 3/6 uretprobes: generalize xol_get_insn_slot()
In reply to Anton Arapov Generalize xol_take_insn_slot() to enable more consumers of the
function, e.g. trampoline implementation for return probes.
The first time a uprobe with return consumer is hit for a process, a
trampoline slot is obtained in the xol_area and initialized with a breakpoint instruction. This slot is subsequently used by all uretprobes.
v3:
- unified xol_get_insn_slot(), thus get rid of xol_get_trampoline_slot()
--- kernel/events/uprobes.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/events/uprobes.c +3 -3
@@ -1221,7 +1221,7 @@ static unsigned long xol_take_insn_slot(struct xol_area *area)* xol_get_insn_slot - allocate a slot for xol. * Returns the allocated slot address or 0. */ -static unsigned long xol_get_insn_slot (struct uprobe *uprobe) +static unsigned long xol_get_insn_slot (unsigned char *insn) {struct xol_area *area;unsigned long offset;
@@ -1239,7 +1239,7 @@ static unsigned long xol_get_insn_slot(struct uprobe *uprobe)/* Initialize the slot */ offset = xol_vaddr & ~PAGE_MASK ; vaddr =kmap_atomic (area->page); -memcpy (vaddr + offset, uprobe->arch.insn,MAX_UINSN_BYTES ); +memcpy (vaddr + offset, insn,MAX_UINSN_BYTES );kunmap_atomic (vaddr);/* * We probably need flush_icache_user_range() but it needs vma.
@@ -1353,7 +1353,7 @@ pre_ssout(struct uprobe *uprobe, struct pt_regs *regs, unsigned long bp_vaddr)if (!utask)return -ENOMEM ; - xol_vaddr =xol_get_insn_slot (uprobe); + xol_vaddr =xol_get_insn_slot (uprobe->arch.insn);if (!xol_vaddr)return -ENOMEM ;
Signature · 1 line
1.8.1.2
Oleg Nesterov
maintainerRe: [RFC PATCH v3 3/6] uretprobes: generalize xol_get_insn_slot()
Anton, I'll try to read this series asap. Just one note,
Quoted 3 lines · Anton Arapov
Generalize
xol_take_insn_slot()to enable more consumers of the
function, e.g. trampoline implementation for return probes.
Yes, this is can work too.
But I guess you misunderstood me, or I missed something...
Why do you need xol_area->rp_trampoline_vaddr at all? From the very beginning I am trying to suggest to use the first slot for trampoline:
Or. Perhaps even better, do not add this helper at all. xol_alloc_area() could reserve the first slot/bit for trampoline. And note that in this case we do not need xol_area->rp_trampoline_vaddr, it is always equal to xol_area->vaddr.
Doesn't this look simpler?
Oleg.
RFC PATCH v3 4/6 uretprobes: return probe entry, prepare uretprobe
In reply to Anton Arapov When a uprobe with return consumer is hit, prepare_uretprobe function is
invoked. It creates return_instance, hijacks return address and replaces it with the trampoline.
N.B. it might be a good idea to introduce get_uprobe() to reflectput_uprobe() later, but it is not a subject of this patchset.
v3:
- protected uprobe with refcounter. See atomic_inc in prepare_uretprobe()
and put_uprobe() in a following patch in handle_uretprobe() v2:
- get rid of ->return_consumers member from struct uprobe, introducerp_handler() in consumer
--- include/linux/uprobes.h | 5 +++++ kernel/events/uprobes.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-)
include/linux/uprobes.h +5 -0
@@ -69,6 +69,10 @@ struct uprobe_task {enum uprobe_task_state state;struct arch_uprobe_task autask; +/* +* list for tracking uprobes with return consumers +*/ +struct hlist_head return_uprobes;struct uprobe *active_uprobe;unsigned long xol_vaddr;
@@ -92,6 +96,7 @@ struct xol_area {* the vma go away, and we must handle that reasonably gracefully. */ unsigned long vaddr;/* Page(s) of instruction slots */ +unsigned long rp_trampoline_vaddr;/* trampoline address */ };struct uprobes_state {
kernel/events/uprobes.c +50 -2
79 lines not on this page · raw message
Signature · 1 line
1.8.1.2
Oleg Nesterov
maintainerRe: [RFC PATCH v3 4/6] uretprobes: return probe entry, prepare uretprobe
Quoted 8 lines · Anton Arapov
kernel/events/uprobes.c +7
-0+static void prepare_uretprobe (struct uprobe *uprobe,struct pt_regs *regs) +{ +struct return_uprobe_i *ri; +struct uprobe_task *utask; +struct xol_area *area; +unsigned long rp_trampoline_vaddr =0 ; +uprobe_opcode_t insn =UPROBE_SWBP_INSN ;
kernel/events/uprobes.c void uprobe_copy_process(struct task_struct *t) · line 1369
Quoted 10 lines
kernel/events/uprobes.c +10
-0+ + area =get_xol_area (); +if (area) + rp_trampoline_vaddr = area->rp_trampoline_vaddr; +if (!rp_trampoline_vaddr) { + rp_trampoline_vaddr =xol_get_insn_slot (&insn); +if (!rp_trampoline_vaddr) +return ; + } + area->rp_trampoline_vaddr = rp_trampoline_vaddr;
This is called under down_read(), so 2 threads can race with each other and use the different rp_trampoline_vaddr's if ->rp_trampoline_vaddr was NULL.
And again, I think ->rp_trampoline_vaddr is simply unneeded, see my reply to 3/6.
Quoted 4 lines
static void
handler_chain(struct uprobe *uprobe, struct pt_regs *regs){kernel/events/uprobes.c +1
-0+int rc =0 ;struct uprobe_consumer *uc;
kernel/events/uprobes.c static struct uprobe *find_active_uprobe(unsigned long bp_vaddr, int *is_swbp) · line 1550
Quoted 10 lines
kernel/events/uprobes.c +5
-1int remove =UPROBE_HANDLER_REMOVE ;down_read (&uprobe->register_rwsem);for (uc = uprobe->consumers; uc; uc = uc->next) { -int rc = uc->handler (uc, regs); +if (uc->handler) + rc = uc->handler (uc, regs); + +if (uc->rp_handler) +prepare_uretprobe (uprobe, regs);/* put bp at return */
Hmm. I didn't read this series yet. But at first glance I am not sure prepare_uretprobe() should be called every time we see ->rp_handler != NULL, there could be multiple consumers...
Oleg.
Re: [RFC PATCH v3 4/6] uretprobes: return probe entry, prepare uretprobe
Quoted 17 lines · Oleg Nesterov
Quoted 16 lines · Anton Arapov
kernel/events/uprobes.c +15
-0+static void prepare_uretprobe (struct uprobe *uprobe,struct pt_regs *regs) +{ +struct return_uprobe_i *ri; +struct uprobe_task *utask; +struct xol_area *area; +unsigned long rp_trampoline_vaddr =0 ; +uprobe_opcode_t insn =UPROBE_SWBP_INSN ; + + area =get_xol_area (); +if (area) + rp_trampoline_vaddr = area->rp_trampoline_vaddr; +if (!rp_trampoline_vaddr) { + rp_trampoline_vaddr =xol_get_insn_slot (&insn); +if (!rp_trampoline_vaddr) +return ;
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ } + area->rp_trampoline_vaddr = rp_trampoline_vaddr;This is called under
down_read(), so 2 threads can race with each other and use the different rp_trampoline_vaddr's if ->rp_trampoline_vaddr was NULL.
And again, I think ->rp_trampoline_vaddr is simply unneeded, see my reply to 3/6.
Yes, 'fixed' this, I will send quirky v4 in a few, to maintain your attention. :)
Quoted 7 lines
Quoted 7 lines
static void
handler_chain(struct uprobe *uprobe, struct pt_regs *regs){kernel/events/uprobes.c +1
-0+int rc =0 ;struct uprobe_consumer *uc;int remove =UPROBE_HANDLER_REMOVE ;
Quoted 12 lines
kernel/events/uprobes.c static struct uprobe *find_active_uprobe(unsigned long bp_vaddr, int *is_swbp) · line 1550
Quoted 8 lines
kernel/events/uprobes.c +5
-1down_read (&uprobe->register_rwsem);for (uc = uprobe->consumers; uc; uc = uc->next) { -int rc = uc->handler (uc, regs); +if (uc->handler) + rc = uc->handler (uc, regs); + +if (uc->rp_handler) +prepare_uretprobe (uprobe, regs);/* put bp at return */ Hmm. I didn't read this series yet. But at first glance I am not sure
prepare_uretprobe()should be called every time we see ->rp_handler != NULL, there could be multiple consumers...
I can not come up with a better idea yet, that would narrow down the
number of prepare_uretprobe() calls.
Anton.
Oleg Nesterov
maintainerRe: [RFC PATCH v3 4/6] uretprobes: return probe entry, prepare uretprobe
In reply to Anton ArapovQuoted 18 lines · Anton Arapov
kernel/events/uprobes.c +17
-0+static void prepare_uretprobe (struct uprobe *uprobe,struct pt_regs *regs) +{ +struct return_uprobe_i *ri; +struct uprobe_task *utask; +struct xol_area *area; +unsigned long rp_trampoline_vaddr =0 ; +uprobe_opcode_t insn =UPROBE_SWBP_INSN ; + + area =get_xol_area (); +if (area) + rp_trampoline_vaddr = area->rp_trampoline_vaddr; +if (!rp_trampoline_vaddr) { + rp_trampoline_vaddr =xol_get_insn_slot (&insn); +if (!rp_trampoline_vaddr) +return ; + } + area->rp_trampoline_vaddr = rp_trampoline_vaddr;
kernel/events/uprobes.c void uprobe_copy_process(struct task_struct *t) · line 1379
Quoted 10 lines
kernel/events/uprobes.c +10
-0+ + ri =kzalloc (sizeof (struct return_uprobe_i ),GFP_KERNEL ); +if (!ri) +return ; + + utask =get_utask (); + ri->orig_ret_vaddr =arch_uretprobe_hijack_return_addr (rp_trampoline_vaddr, regs); +if (likely (ri->orig_ret_vaddr)) { +/* TODO: uretprobe bypass logic */ +atomic_inc (&uprobe->ref);
OK, but even this is not enough.
Once we inserted "int3" we must ensure that handle_swbp() will be called even if this uprobe goes away. We have the reference but it only protects uprobe itself, it can't protect agains delete_uprobe().
IOW, we must ensure that uprobe_pre_sstep_notifier() can't return 0.
So this patch needs the additional change in find_active_uprobe(),
- if (!uprobe && test_and_clear_bit(MMF_RECALC_UPROBES, &mm->flags)) + if (!uprobe && hlist_empty(->return_uprobes) && + test_and_clear_bit(MMF_RECALC_UPROBES, &mm->flags))
Oleg.
Oleg Nesterov
maintainerRe: [RFC PATCH v3 4/6] uretprobes: return probe entry, prepare uretprobe
In reply to Anton Arapovinclude/linux/uprobes.h struct uprobe_task { · line 75
Quoted 9 lines · Anton Arapov
include/linux/uprobes.h +4
-0@@ -69,6 +69,10 @@ struct uprobe_task {enum uprobe_task_state state;struct arch_uprobe_task autask; +/* +* list for tracking uprobes with return consumers +*/ +struct hlist_head return_uprobes;
Forgot to mention, at least you should also change uprobe_free_utask() to cleanup this list, the task can exit from inside the ret-probe'd function(s).
Oleg.
Re: [RFC PATCH v3 4/6] uretprobes: return probe entry, prepare uretprobe
Quoted 6 lines · Oleg Nesterov
Quoted 5 lines · Anton Arapov
include/linux/uprobes.h +0
-0@@ -69,6 +69,10 @@ struct uprobe_task {enum uprobe_task_state state;struct arch_uprobe_task autask;
Quoted 8 lines
include/linux/uprobes.h struct uprobe_task { · line 75
Quoted 4 lines
include/linux/uprobes.h +4
-0+/* +* list for tracking uprobes with return consumers +*/ +struct hlist_head return_uprobes;Forgot to mention, at least you should also change
uprobe_free_utask()to cleanup this list, the task can exit from inside the ret-probe'd function(s).
Yes, right. Thanks for the other mails as well. I will fix it for the next RFC v4.
Anton.
Quoted 2 lines
Oleg.
RFC PATCH v3 5/6 uretprobes: invoke return probe handlers
In reply to Anton Arapov Uretprobe handlers are invoked when the trampoline is hit, on completion the
trampoline is replaced with the saved return address and the uretprobe instance deleted.
v3:
- protected uprobe with refcounter. See put_uprobe() in handle_uretprobe()
that reflects increment in prepare_uretprobe()
v2:
- get rid of ->return_consumers member from struct uprobe, introducerp_handler() in consumer instead
--- arch/x86/include/asm/uprobes.h | 5 +++++ kernel/events/uprobes.c | 50 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-)
arch/x86/include/asm/uprobes.h +5 -0
@@ -56,4 +56,9 @@ extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk);extern int arch_uprobe_exception_notify (struct notifier_block *self,unsigned long val,void *data);extern void arch_uprobe_abort_xol (struct arch_uprobe *aup,struct pt_regs *regs);extern unsigned long arch_uretprobe_hijack_return_addr (unsigned long rp_trampoline_vaddr,struct pt_regs *regs); + +static inline unsigned long arch_uretprobe_get_sp (struct pt_regs *regs) +{ +return (unsigned long )regs->sp; +}#endif /* _ASM_UPROBES_H */
kernel/events/uprobes.c +48 -2
62 lines not on this page · raw message
Signature · 1 line
1.8.1.2
Oleg Nesterov
maintainerRe: [RFC PATCH v3 5/6] uretprobes: invoke return probe handlers
kernel/events/uprobes.c static void handle_swbp(struct pt_regs *regs) · line 1626
Quoted 9 lines · Anton Arapov
kernel/events/uprobes.c +2
-2@@ -1576,8 +1622,8 @@ static void handle_swbp(struct pt_regs *regs)if (!uprobe) {if (is_swbp >0 ) { -/* No matching uprobe; signal SIGTRAP. */ -send_sig (SIGTRAP , current,0 ); +/* No matching uprobe; Try with uretprobe */ +handle_uretprobe (regs);
Hmm. at least this looks certainly wrong.
You shifted send_sig(SIGSEGV) into handle_uretprobe(), but if nothing else printk(KERN_ERR "uprobe: no instance found!") doesn't look nice if we hit the regular breakoint.
In fact everything handle_uretprobe() does in this case looks wrong. Including the fact that get_xol_area/get_utask can fail. And unwinding looks bogus...
I think you need
if (bp_vaddr == rp_trampoline_vaddr) handle_uretprobe()
like the previous version did.
Oleg.
RFC PATCH v3 6/6 uretprobes: implemented, thus remove -ENOSYS
In reply to Anton Arapov 1/6 and 6/6 patches are here to enclose return probes implementation
as well as prohibit uprobe_register() routine with no consumer set.
v3 changes: (the patch is introduced in v3)
- remove 'TODO' as return probes implemented now
--- kernel/events/uprobes.c | 4 ---- 1 file changed, 4 deletions(-)
kernel/events/uprobes.c +0 -4
@@ -838,10 +838,6 @@ int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *if (!uc->handler && !uc->rp_handler)return -EINVAL ; -/* TODO: Implement return probes */ -if (uc->rp_handler) -return -ENOSYS ; -/* Racy, just to catch the obvious mistakes */ if (offset >i_size_read (inode))return -EINVAL ;
Signature · 1 line
1.8.1.2