Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1453621 > unrolled thread

[PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to NOKPROBE_SYMBOL

Started byPratyush Anand <panand@redhat.com>
First post2016-08-02 09:00 +0200
Last post2016-08-03 06:20 +0200
Articles 7 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to NOKPROBE_SYMBOL Pratyush Anand <panand@redhat.com> - 2016-08-02 09:00 +0200
    Re: [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to  NOKPROBE_SYMBOL Masami Hiramatsu <mhiramat@kernel.org> - 2016-08-02 18:00 +0200
      Re: [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to  NOKPROBE_SYMBOL Pratyush Anand <panand@redhat.com> - 2016-08-03 06:30 +0200
        Re: [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to NOKPROBE_SYMBOL Pratyush Anand <panand@redhat.com> - 2016-08-03 12:50 +0200
          Re: [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to  NOKPROBE_SYMBOL Masami Hiramatsu <mhiramat@kernel.org> - 2016-08-03 16:50 +0200
    Re: [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to  NOKPROBE_SYMBOL Oleg Nesterov <oleg@redhat.com> - 2016-08-02 22:50 +0200
      Re: [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to  NOKPROBE_SYMBOL Pratyush Anand <panand@redhat.com> - 2016-08-03 06:20 +0200

#1453621 — [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to NOKPROBE_SYMBOL

FromPratyush Anand <panand@redhat.com>
Date2016-08-02 09:00 +0200
Subject[PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to NOKPROBE_SYMBOL
Message-ID<s1BQd-TD-3@gated-at.bofh.it>
uprobe_pre_sstep_notifier and uprobe_post_sstep_notifier are called from
debug exception handler, so blacklist them for kprobing.

Signed-off-by: Pratyush Anand <panand@redhat.com>
---
 kernel/events/uprobes.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index b7a525ab2083..206e594cb65e 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -37,6 +37,7 @@
 #include <linux/percpu-rwsem.h>
 #include <linux/task_work.h>
 #include <linux/shmem_fs.h>
+#include <linux/kprobes.h>
 
 #include <linux/uprobes.h>
 
@@ -1997,6 +1998,7 @@ int uprobe_pre_sstep_notifier(struct pt_regs *regs)
 	set_thread_flag(TIF_UPROBE);
 	return 1;
 }
+NOKPROBE_SYMBOL(uprobe_pre_sstep_notifier);
 
 /*
  * uprobe_post_sstep_notifier gets called in interrupt context as part of notifier
@@ -2014,6 +2016,7 @@ int uprobe_post_sstep_notifier(struct pt_regs *regs)
 	set_thread_flag(TIF_UPROBE);
 	return 1;
 }
+NOKPROBE_SYMBOL(uprobe_post_sstep_notifier);
 
 static struct notifier_block uprobe_exception_nb = {
 	.notifier_call		= arch_uprobe_exception_notify,
-- 
2.5.5

[toc] | [next] | [standalone]


#1454858 — Re: [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to NOKPROBE_SYMBOL

FromMasami Hiramatsu <mhiramat@kernel.org>
Date2016-08-02 18:00 +0200
SubjectRe: [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to NOKPROBE_SYMBOL
Message-ID<s1KgO-6sT-59@gated-at.bofh.it>
In reply to#1453621
On Tue,  2 Aug 2016 12:14:06 +0530
Pratyush Anand <panand@redhat.com> wrote:

> uprobe_pre_sstep_notifier and uprobe_post_sstep_notifier are called from
> debug exception handler, so blacklist them for kprobing.

Actually, these exception notifers are kicked only if the debug exception
is not related to kprobes (at least on x86). In that case, we don't have
to take care about that. Or, would you hit any problem on it?

IOW, where do we have to prohibit kprobes are, the code path from where 
right after the breakpoint (debug) exception is occurred, to where right
before the kprobe is handled. After that, it should be safe.

Thank you,


> 
> Signed-off-by: Pratyush Anand <panand@redhat.com>
> ---
>  kernel/events/uprobes.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index b7a525ab2083..206e594cb65e 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -37,6 +37,7 @@
>  #include <linux/percpu-rwsem.h>
>  #include <linux/task_work.h>
>  #include <linux/shmem_fs.h>
> +#include <linux/kprobes.h>
>  
>  #include <linux/uprobes.h>
>  
> @@ -1997,6 +1998,7 @@ int uprobe_pre_sstep_notifier(struct pt_regs *regs)
>  	set_thread_flag(TIF_UPROBE);
>  	return 1;
>  }
> +NOKPROBE_SYMBOL(uprobe_pre_sstep_notifier);
>  
>  /*
>   * uprobe_post_sstep_notifier gets called in interrupt context as part of notifier
> @@ -2014,6 +2016,7 @@ int uprobe_post_sstep_notifier(struct pt_regs *regs)
>  	set_thread_flag(TIF_UPROBE);
>  	return 1;
>  }
> +NOKPROBE_SYMBOL(uprobe_post_sstep_notifier);
>  
>  static struct notifier_block uprobe_exception_nb = {
>  	.notifier_call		= arch_uprobe_exception_notify,
> -- 
> 2.5.5
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

[toc] | [prev] | [next] | [standalone]


#1455625 — Re: [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to NOKPROBE_SYMBOL

FromPratyush Anand <panand@redhat.com>
Date2016-08-03 06:30 +0200
SubjectRe: [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to NOKPROBE_SYMBOL
Message-ID<s1VYB-5Um-5@gated-at.bofh.it>
In reply to#1454858
Hi Masami,

On 03/08/2016:12:45:24 AM, Masami Hiramatsu wrote:
> On Tue,  2 Aug 2016 12:14:06 +0530
> Pratyush Anand <panand@redhat.com> wrote:
> 
> > uprobe_pre_sstep_notifier and uprobe_post_sstep_notifier are called from
> > debug exception handler, so blacklist them for kprobing.
> 
> Actually, these exception notifers are kicked only if the debug exception
> is not related to kprobes (at least on x86). In that case, we don't have
> to take care about that. Or, would you hit any problem on it?

Well, I have faced issue on ARM64. So, if I have a kprobe instrumented at these
functions and then if I hit a uprobe then kernel goes into an infinite loop of
"Unexpected kernel single-step exception at EL1".

On x86 I have not tested, but I see that all functions except
arch_uprobe_exception_notify() in the call stack of
uprobe_pre/post_sstep_notifier() are blacklisted for kprobe. So, I am unable to
understand that why arch_uprobe_exception_notify() and
uprobe_pre/post_sstep_notifier() are not blacklisted.

> 
> IOW, where do we have to prohibit kprobes are, the code path from where 
> right after the breakpoint (debug) exception is occurred, to where right
> before the kprobe is handled. After that, it should be safe.

Hummmm...My understanding was that if a function a() is not good to be kprobed
then we can not kprobe any function called by a() as well. Thanks for the
clarification. So, if I go with your definition then, something is still wrong on
ARM64 which is causing issue when I kprobe uprobe_pre/post_sstep_notifier().

~Pratyush

> 
> Thank you,
> 
> 
> > 
> > Signed-off-by: Pratyush Anand <panand@redhat.com>
> > ---
> >  kernel/events/uprobes.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> > index b7a525ab2083..206e594cb65e 100644
> > --- a/kernel/events/uprobes.c
> > +++ b/kernel/events/uprobes.c
> > @@ -37,6 +37,7 @@
> >  #include <linux/percpu-rwsem.h>
> >  #include <linux/task_work.h>
> >  #include <linux/shmem_fs.h>
> > +#include <linux/kprobes.h>
> >  
> >  #include <linux/uprobes.h>
> >  
> > @@ -1997,6 +1998,7 @@ int uprobe_pre_sstep_notifier(struct pt_regs *regs)
> >  	set_thread_flag(TIF_UPROBE);
> >  	return 1;
> >  }
> > +NOKPROBE_SYMBOL(uprobe_pre_sstep_notifier);
> >  
> >  /*
> >   * uprobe_post_sstep_notifier gets called in interrupt context as part of notifier
> > @@ -2014,6 +2016,7 @@ int uprobe_post_sstep_notifier(struct pt_regs *regs)
> >  	set_thread_flag(TIF_UPROBE);
> >  	return 1;
> >  }
> > +NOKPROBE_SYMBOL(uprobe_post_sstep_notifier);
> >  
> >  static struct notifier_block uprobe_exception_nb = {
> >  	.notifier_call		= arch_uprobe_exception_notify,
> > -- 
> > 2.5.5
> > 
> 
> 
> -- 
> Masami Hiramatsu <mhiramat@kernel.org>

[toc] | [prev] | [next] | [standalone]


#1455741

FromPratyush Anand <panand@redhat.com>
Date2016-08-03 12:50 +0200
Message-ID<s21Ul-1q9-15@gated-at.bofh.it>
In reply to#1455625
On Wed, Aug 3, 2016 at 9:54 AM, Pratyush Anand <panand@redhat.com> wrote:
> Hi Masami,
>
> On 03/08/2016:12:45:24 AM, Masami Hiramatsu wrote:
>> On Tue,  2 Aug 2016 12:14:06 +0530
>> Pratyush Anand <panand@redhat.com> wrote:
>>
>> > uprobe_pre_sstep_notifier and uprobe_post_sstep_notifier are called from
>> > debug exception handler, so blacklist them for kprobing.
>>
>> Actually, these exception notifers are kicked only if the debug exception
>> is not related to kprobes (at least on x86). In that case, we don't have
>> to take care about that. Or, would you hit any problem on it?
>
> Well, I have faced issue on ARM64. So, if I have a kprobe instrumented at these
> functions and then if I hit a uprobe then kernel goes into an infinite loop of
> "Unexpected kernel single-step exception at EL1".
>
> On x86 I have not tested, but I see that all functions except
> arch_uprobe_exception_notify() in the call stack of
> uprobe_pre/post_sstep_notifier() are blacklisted for kprobe. So, I am unable to
> understand that why arch_uprobe_exception_notify() and
> uprobe_pre/post_sstep_notifier() are not blacklisted.
>
>>
>> IOW, where do we have to prohibit kprobes are, the code path from where
>> right after the breakpoint (debug) exception is occurred, to where right
>> before the kprobe is handled. After that, it should be safe.
>
> Hummmm...My understanding was that if a function a() is not good to be kprobed
> then we can not kprobe any function called by a() as well. Thanks for the
> clarification. So, if I go with your definition then, something is still wrong on
> ARM64 which is causing issue when I kprobe uprobe_pre/post_sstep_notifier().

I found that one modification in ARM64 kprobe code allows me to kprobe
uprobe_pre/post_sstep_notifier(). So, taking back this patch. Will
discuss ARM64 modification on arm mailing list.

Thanks Masami for your input.

~Pratyush

[toc] | [prev] | [next] | [standalone]


#1455831 — Re: [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to NOKPROBE_SYMBOL

FromMasami Hiramatsu <mhiramat@kernel.org>
Date2016-08-03 16:50 +0200
SubjectRe: [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to NOKPROBE_SYMBOL
Message-ID<s25EB-3Lb-3@gated-at.bofh.it>
In reply to#1455741
On Wed, 3 Aug 2016 16:05:34 +0530
Pratyush Anand <panand@redhat.com> wrote:

> On Wed, Aug 3, 2016 at 9:54 AM, Pratyush Anand <panand@redhat.com> wrote:
> > Hi Masami,
> >
> > On 03/08/2016:12:45:24 AM, Masami Hiramatsu wrote:
> >> On Tue,  2 Aug 2016 12:14:06 +0530
> >> Pratyush Anand <panand@redhat.com> wrote:
> >>
> >> > uprobe_pre_sstep_notifier and uprobe_post_sstep_notifier are called from
> >> > debug exception handler, so blacklist them for kprobing.
> >>
> >> Actually, these exception notifers are kicked only if the debug exception
> >> is not related to kprobes (at least on x86). In that case, we don't have
> >> to take care about that. Or, would you hit any problem on it?
> >
> > Well, I have faced issue on ARM64. So, if I have a kprobe instrumented at these
> > functions and then if I hit a uprobe then kernel goes into an infinite loop of
> > "Unexpected kernel single-step exception at EL1".
> >
> > On x86 I have not tested, but I see that all functions except
> > arch_uprobe_exception_notify() in the call stack of
> > uprobe_pre/post_sstep_notifier() are blacklisted for kprobe. So, I am unable to
> > understand that why arch_uprobe_exception_notify() and
> > uprobe_pre/post_sstep_notifier() are not blacklisted.
> >
> >>
> >> IOW, where do we have to prohibit kprobes are, the code path from where
> >> right after the breakpoint (debug) exception is occurred, to where right
> >> before the kprobe is handled. After that, it should be safe.
> >
> > Hummmm...My understanding was that if a function a() is not good to be kprobed
> > then we can not kprobe any function called by a() as well. Thanks for the
> > clarification. So, if I go with your definition then, something is still wrong on
> > ARM64 which is causing issue when I kprobe uprobe_pre/post_sstep_notifier().
> 
> I found that one modification in ARM64 kprobe code allows me to kprobe
> uprobe_pre/post_sstep_notifier(). So, taking back this patch. Will
> discuss ARM64 modification on arm mailing list.

OK, so that will be ARM64 specific issue. We'd better to trace it.
Thank you for your effort!!


> 
> Thanks Masami for your input.
> 
> ~Pratyush


-- 
Masami Hiramatsu <mhiramat@kernel.org>

[toc] | [prev] | [next] | [standalone]


#1455464 — Re: [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to NOKPROBE_SYMBOL

FromOleg Nesterov <oleg@redhat.com>
Date2016-08-02 22:50 +0200
SubjectRe: [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to NOKPROBE_SYMBOL
Message-ID<s1ONs-19V-15@gated-at.bofh.it>
In reply to#1453621
On 08/02, Pratyush Anand wrote:
>
> uprobe_pre_sstep_notifier and uprobe_post_sstep_notifier are called from
> debug exception handler, so blacklist them for kprobing.

Let me add kprobes maintainers, I am a bit confused...

> @@ -1997,6 +1998,7 @@ int uprobe_pre_sstep_notifier(struct pt_regs *regs)
>  	set_thread_flag(TIF_UPROBE);
>  	return 1;
>  }
> +NOKPROBE_SYMBOL(uprobe_pre_sstep_notifier);
>
>  /*
>   * uprobe_post_sstep_notifier gets called in interrupt context as part of notifier
> @@ -2014,6 +2016,7 @@ int uprobe_post_sstep_notifier(struct pt_regs *regs)
>  	set_thread_flag(TIF_UPROBE);
>  	return 1;
>  }
> +NOKPROBE_SYMBOL(uprobe_post_sstep_notifier);

but if we need to blacklist uprobe_pre/post_sstep_notifier then we
also need to blacklist their caller, arch_uprobe_exception_notify() ?

and every .notifier_call used in register_die_notifier() ?

Oleg.

[toc] | [prev] | [next] | [standalone]


#1455623 — Re: [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to NOKPROBE_SYMBOL

FromPratyush Anand <panand@redhat.com>
Date2016-08-03 06:20 +0200
SubjectRe: [PATCH] uprobe: Add uprobe_pre/post_sstep_notifier to NOKPROBE_SYMBOL
Message-ID<s1VOV-5NQ-9@gated-at.bofh.it>
In reply to#1455464
Hi Oleg,

On 02/08/2016:10:30:35 PM, Oleg Nesterov wrote:
> On 08/02, Pratyush Anand wrote:
> >
> > uprobe_pre_sstep_notifier and uprobe_post_sstep_notifier are called from
> > debug exception handler, so blacklist them for kprobing.
> 
> Let me add kprobes maintainers, I am a bit confused...
> 
> > @@ -1997,6 +1998,7 @@ int uprobe_pre_sstep_notifier(struct pt_regs *regs)
> >  	set_thread_flag(TIF_UPROBE);
> >  	return 1;
> >  }
> > +NOKPROBE_SYMBOL(uprobe_pre_sstep_notifier);
> >
> >  /*
> >   * uprobe_post_sstep_notifier gets called in interrupt context as part of notifier
> > @@ -2014,6 +2016,7 @@ int uprobe_post_sstep_notifier(struct pt_regs *regs)
> >  	set_thread_flag(TIF_UPROBE);
> >  	return 1;
> >  }
> > +NOKPROBE_SYMBOL(uprobe_post_sstep_notifier);
> 
> but if we need to blacklist uprobe_pre/post_sstep_notifier then we
> also need to blacklist their caller, arch_uprobe_exception_notify() ?

I think yes, in ARM64 I have done that. However, arm64 does not use notifier
method, so arch_uprobe_exception_notify() is just a dummy function for it.

> 
> and every .notifier_call used in register_die_notifier() ?

I tried to look into x86 notify path related to uprobe_pre/post_sstep_notifier().
I see that calling sequence is like do_int3()-> notify_die() ->
atomic_notifier_call_chain() -> __atomic_notifier_call_chain() ->
notifier_call_chain() -> arch_uprobe_exception_notify().

In this sequence, every function is blacklisted for kprobe except
arch_uprobe_exception_notify(). So, I am unable to understand, if
notifier_call_chain() is not safe for kprobe then how can it be safe for a
function it calls.

~Pratyush

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web