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


Groups > linux.kernel > #1552023 > unrolled thread

Re: x86: warning in unwind_get_return_address

Started byJosh Poimboeuf <jpoimboe@redhat.com>
First post2017-01-05 15:50 +0100
Last post2017-01-05 21:40 +0100
Articles 6 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: x86: warning in unwind_get_return_address Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-05 15:50 +0100
    Re: x86: warning in unwind_get_return_address Dmitry Vyukov <dvyukov@google.com> - 2017-01-05 16:20 +0100
      Re: x86: warning in unwind_get_return_address Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-05 16:20 +0100
        Re: x86: warning in unwind_get_return_address Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-05 18:10 +0100
          Re: x86: warning in unwind_get_return_address Dmitry Vyukov <dvyukov@google.com> - 2017-01-05 21:30 +0100
            Re: x86: warning in unwind_get_return_address Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-05 21:40 +0100

#1552023 — Re: x86: warning in unwind_get_return_address

FromJosh Poimboeuf <jpoimboe@redhat.com>
Date2017-01-05 15:50 +0100
SubjectRe: x86: warning in unwind_get_return_address
Message-ID<sWhwB-4ll-5@gated-at.bofh.it>
On Tue, Dec 27, 2016 at 05:38:59PM +0100, Dmitry Vyukov wrote:
> On Thu, Dec 22, 2016 at 6:17 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> > On Wed, Dec 21, 2016 at 01:46:36PM +0100, Andrey Konovalov wrote:
> >> On Wed, Dec 21, 2016 at 12:36 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> >> >
> >> > Thanks.  Looking at the stack trace, my guess is that an interrupt hit
> >> > while running in generated BPF code, and the unwinder got confused
> >> > because regs->ip points to the generated code.  I may need to disable
> >> > that warning until we figure out a better solution.
> >> >
> >> > Can you share your .config file?
> >>
> >> Sure, attached.
> >
> > Ok, I was able to recreate with your config.  The culprit was generated
> > code, as I suspected, though it wasn't BPF, it was a kprobe (created by
> > dccpprobe_init()).
> >
> > I'll make a patch to disable the warning.
> 
> Hi,
> 
> I am also seeing the following warnings:
> 
> [  281.889259] WARNING: kernel stack regs at ffff8801c29a7ea8 in
> syz-executor8:1302 has bad 'bp' value ffff8801c29a7f28
> [  833.994878] WARNING: kernel stack regs at ffff8801c4e77ea8 in
> syz-executor1:13094 has bad 'bp' value ffff8801c4e77f28
> 
> Can it also be caused by bpf/kprobe?

This is a different warning.  I suspect it's due to unwinding the stack
of another CPU while it's running, which is still possible in a few
places.  I'm going to have to disable all these warnings for now.

-- 
Josh

[toc] | [next] | [standalone]


#1552049

FromDmitry Vyukov <dvyukov@google.com>
Date2017-01-05 16:20 +0100
Message-ID<sWhZE-4MO-15@gated-at.bofh.it>
In reply to#1552023
On Thu, Jan 5, 2017 at 3:49 PM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> On Tue, Dec 27, 2016 at 05:38:59PM +0100, Dmitry Vyukov wrote:
>> On Thu, Dec 22, 2016 at 6:17 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
>> > On Wed, Dec 21, 2016 at 01:46:36PM +0100, Andrey Konovalov wrote:
>> >> On Wed, Dec 21, 2016 at 12:36 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
>> >> >
>> >> > Thanks.  Looking at the stack trace, my guess is that an interrupt hit
>> >> > while running in generated BPF code, and the unwinder got confused
>> >> > because regs->ip points to the generated code.  I may need to disable
>> >> > that warning until we figure out a better solution.
>> >> >
>> >> > Can you share your .config file?
>> >>
>> >> Sure, attached.
>> >
>> > Ok, I was able to recreate with your config.  The culprit was generated
>> > code, as I suspected, though it wasn't BPF, it was a kprobe (created by
>> > dccpprobe_init()).
>> >
>> > I'll make a patch to disable the warning.
>>
>> Hi,
>>
>> I am also seeing the following warnings:
>>
>> [  281.889259] WARNING: kernel stack regs at ffff8801c29a7ea8 in
>> syz-executor8:1302 has bad 'bp' value ffff8801c29a7f28
>> [  833.994878] WARNING: kernel stack regs at ffff8801c4e77ea8 in
>> syz-executor1:13094 has bad 'bp' value ffff8801c4e77f28
>>
>> Can it also be caused by bpf/kprobe?
>
> This is a different warning.  I suspect it's due to unwinding the stack
> of another CPU while it's running, which is still possible in a few
> places.  I'm going to have to disable all these warnings for now.


I also have the following diff locally. These loads trigger episodic
KASAN warnings about stack-of-bounds reads on rcu stall warnings when
it does backtrace of all cpus.
If it looks correct to you, can you please also incorporate it into your patch?


diff --git a/arch/x86/include/asm/stacktrace.h
b/arch/x86/include/asm/stacktrace.h
index a3269c897ec5..d8d4fc66ffec 100644
--- a/arch/x86/include/asm/stacktrace.h
+++ b/arch/x86/include/asm/stacktrace.h
@@ -58,7 +58,7 @@ get_frame_pointer(struct task_struct *task, struct
pt_regs *regs)
        if (task == current)
                return __builtin_frame_address(0);

-       return (unsigned long *)((struct inactive_task_frame
*)task->thread.sp)->bp;
+       return (unsigned long *)READ_ONCE_NOCHECK(((struct
inactive_task_frame *)task->thread.sp)->bp);
 }
 #else
 static inline unsigned long *
diff --git a/arch/x86/kernel/unwind_frame.c b/arch/x86/kernel/unwind_frame.c
index 4443e499f279..f3a225ffa231 100644
--- a/arch/x86/kernel/unwind_frame.c
+++ b/arch/x86/kernel/unwind_frame.c
@@ -162,7 +162,7 @@ bool unwind_next_frame(struct unwind_state *state)
        if (state->regs)
                next_bp = (unsigned long *)state->regs->bp;
        else
-               next_bp = (unsigned long *)*state->bp;
+               next_bp = (unsigned long *)READ_ONCE_NOCHECK(*state->bp);

        /* is the next frame pointer an encoded pointer to pt_regs? */
        regs = decode_frame_pointer(next_bp);

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


#1552052

FromJosh Poimboeuf <jpoimboe@redhat.com>
Date2017-01-05 16:20 +0100
Message-ID<sWhZE-4MO-43@gated-at.bofh.it>
In reply to#1552049
On Thu, Jan 05, 2017 at 03:59:52PM +0100, Dmitry Vyukov wrote:
> On Thu, Jan 5, 2017 at 3:49 PM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> > On Tue, Dec 27, 2016 at 05:38:59PM +0100, Dmitry Vyukov wrote:
> >> On Thu, Dec 22, 2016 at 6:17 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> >> > On Wed, Dec 21, 2016 at 01:46:36PM +0100, Andrey Konovalov wrote:
> >> >> On Wed, Dec 21, 2016 at 12:36 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> >> >> >
> >> >> > Thanks.  Looking at the stack trace, my guess is that an interrupt hit
> >> >> > while running in generated BPF code, and the unwinder got confused
> >> >> > because regs->ip points to the generated code.  I may need to disable
> >> >> > that warning until we figure out a better solution.
> >> >> >
> >> >> > Can you share your .config file?
> >> >>
> >> >> Sure, attached.
> >> >
> >> > Ok, I was able to recreate with your config.  The culprit was generated
> >> > code, as I suspected, though it wasn't BPF, it was a kprobe (created by
> >> > dccpprobe_init()).
> >> >
> >> > I'll make a patch to disable the warning.
> >>
> >> Hi,
> >>
> >> I am also seeing the following warnings:
> >>
> >> [  281.889259] WARNING: kernel stack regs at ffff8801c29a7ea8 in
> >> syz-executor8:1302 has bad 'bp' value ffff8801c29a7f28
> >> [  833.994878] WARNING: kernel stack regs at ffff8801c4e77ea8 in
> >> syz-executor1:13094 has bad 'bp' value ffff8801c4e77f28
> >>
> >> Can it also be caused by bpf/kprobe?
> >
> > This is a different warning.  I suspect it's due to unwinding the stack
> > of another CPU while it's running, which is still possible in a few
> > places.  I'm going to have to disable all these warnings for now.
> 
> 
> I also have the following diff locally. These loads trigger episodic
> KASAN warnings about stack-of-bounds reads on rcu stall warnings when
> it does backtrace of all cpus.
> If it looks correct to you, can you please also incorporate it into your patch?

Ok, will do.

BTW, I think there's an issue with your mail client.  Your last two
replies to me didn't have me on To/Cc.

-- 
Josh

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


#1552114

FromJosh Poimboeuf <jpoimboe@redhat.com>
Date2017-01-05 18:10 +0100
Message-ID<sWjI5-5Ut-5@gated-at.bofh.it>
In reply to#1552052
On Thu, Jan 05, 2017 at 09:17:00AM -0600, Josh Poimboeuf wrote:
> On Thu, Jan 05, 2017 at 03:59:52PM +0100, Dmitry Vyukov wrote:
> > On Thu, Jan 5, 2017 at 3:49 PM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> > > On Tue, Dec 27, 2016 at 05:38:59PM +0100, Dmitry Vyukov wrote:
> > >> On Thu, Dec 22, 2016 at 6:17 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> > >> > On Wed, Dec 21, 2016 at 01:46:36PM +0100, Andrey Konovalov wrote:
> > >> >> On Wed, Dec 21, 2016 at 12:36 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> > >> >> >
> > >> >> > Thanks.  Looking at the stack trace, my guess is that an interrupt hit
> > >> >> > while running in generated BPF code, and the unwinder got confused
> > >> >> > because regs->ip points to the generated code.  I may need to disable
> > >> >> > that warning until we figure out a better solution.
> > >> >> >
> > >> >> > Can you share your .config file?
> > >> >>
> > >> >> Sure, attached.
> > >> >
> > >> > Ok, I was able to recreate with your config.  The culprit was generated
> > >> > code, as I suspected, though it wasn't BPF, it was a kprobe (created by
> > >> > dccpprobe_init()).
> > >> >
> > >> > I'll make a patch to disable the warning.
> > >>
> > >> Hi,
> > >>
> > >> I am also seeing the following warnings:
> > >>
> > >> [  281.889259] WARNING: kernel stack regs at ffff8801c29a7ea8 in
> > >> syz-executor8:1302 has bad 'bp' value ffff8801c29a7f28
> > >> [  833.994878] WARNING: kernel stack regs at ffff8801c4e77ea8 in
> > >> syz-executor1:13094 has bad 'bp' value ffff8801c4e77f28
> > >>
> > >> Can it also be caused by bpf/kprobe?
> > >
> > > This is a different warning.  I suspect it's due to unwinding the stack
> > > of another CPU while it's running, which is still possible in a few
> > > places.  I'm going to have to disable all these warnings for now.
> > 
> > 
> > I also have the following diff locally. These loads trigger episodic
> > KASAN warnings about stack-of-bounds reads on rcu stall warnings when
> > it does backtrace of all cpus.
> > If it looks correct to you, can you please also incorporate it into your patch?
> 
> Ok, will do.
> 
> BTW, I think there's an issue with your mail client.  Your last two
> replies to me didn't have me on To/Cc.

Would you mind testing if the following patch fixes it?  It's based on
the latest linus/master.


diff --git a/arch/x86/kernel/unwind_frame.c b/arch/x86/kernel/unwind_frame.c
index 4443e49..05adf9a 100644
--- a/arch/x86/kernel/unwind_frame.c
+++ b/arch/x86/kernel/unwind_frame.c
@@ -6,6 +6,21 @@
 
 #define FRAME_HEADER_SIZE (sizeof(long) * 2)
 
+/*
+ * This disables KASAN checking when reading a value from another task's stack,
+ * since the other task could be running on another CPU and could have poisoned
+ * the stack in the meantime.
+ */
+#define UNWIND_READ_ONCE(state, x)			\
+({							\
+	unsigned long val;				\
+	if (state->task == current)			\
+		val = READ_ONCE(x);			\
+	else						\
+		val = READ_ONCE_NOCHECK(x);		\
+	val;						\
+})
+
 static void unwind_dump(struct unwind_state *state, unsigned long *sp)
 {
 	static bool dumped_before = false;
@@ -48,7 +63,8 @@ unsigned long unwind_get_return_address(struct unwind_state *state)
 	if (state->regs && user_mode(state->regs))
 		return 0;
 
-	addr = ftrace_graph_ret_addr(state->task, &state->graph_idx, *addr_p,
+	addr = UNWIND_READ_ONCE(state, *addr_p);
+	addr = ftrace_graph_ret_addr(state->task, &state->graph_idx, addr,
 				     addr_p);
 
 	return __kernel_text_address(addr) ? addr : 0;
@@ -162,7 +178,7 @@ bool unwind_next_frame(struct unwind_state *state)
 	if (state->regs)
 		next_bp = (unsigned long *)state->regs->bp;
 	else
-		next_bp = (unsigned long *)*state->bp;
+		next_bp = (unsigned long *)UNWIND_READ_ONCE(state, *state->bp);
 
 	/* is the next frame pointer an encoded pointer to pt_regs? */
 	regs = decode_frame_pointer(next_bp);
@@ -207,6 +223,16 @@ bool unwind_next_frame(struct unwind_state *state)
 	return true;
 
 bad_address:
+	/*
+	 * When dumping a task other than current, the task might actually be
+	 * running on another CPU, in which case it could be modifying its
+	 * stack while we're reading it.  This is generally not a problem and
+	 * can be ignored as long as the caller understands that unwinding
+	 * another task will not always succeed.
+	 */
+	if (state->task != current)
+		goto the_end;
+
 	if (state->regs) {
 		printk_deferred_once(KERN_WARNING
 			"WARNING: kernel stack regs at %p in %s:%d has bad 'bp' value %p\n",

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


#1552308

FromDmitry Vyukov <dvyukov@google.com>
Date2017-01-05 21:30 +0100
Message-ID<sWmPD-7Tp-29@gated-at.bofh.it>
In reply to#1552114
On Thu, Jan 5, 2017 at 6:03 PM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> On Thu, Jan 05, 2017 at 09:17:00AM -0600, Josh Poimboeuf wrote:
>> On Thu, Jan 05, 2017 at 03:59:52PM +0100, Dmitry Vyukov wrote:
>> > On Thu, Jan 5, 2017 at 3:49 PM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
>> > > On Tue, Dec 27, 2016 at 05:38:59PM +0100, Dmitry Vyukov wrote:
>> > >> On Thu, Dec 22, 2016 at 6:17 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
>> > >> > On Wed, Dec 21, 2016 at 01:46:36PM +0100, Andrey Konovalov wrote:
>> > >> >> On Wed, Dec 21, 2016 at 12:36 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
>> > >> >> >
>> > >> >> > Thanks.  Looking at the stack trace, my guess is that an interrupt hit
>> > >> >> > while running in generated BPF code, and the unwinder got confused
>> > >> >> > because regs->ip points to the generated code.  I may need to disable
>> > >> >> > that warning until we figure out a better solution.
>> > >> >> >
>> > >> >> > Can you share your .config file?
>> > >> >>
>> > >> >> Sure, attached.
>> > >> >
>> > >> > Ok, I was able to recreate with your config.  The culprit was generated
>> > >> > code, as I suspected, though it wasn't BPF, it was a kprobe (created by
>> > >> > dccpprobe_init()).
>> > >> >
>> > >> > I'll make a patch to disable the warning.
>> > >>
>> > >> Hi,
>> > >>
>> > >> I am also seeing the following warnings:
>> > >>
>> > >> [  281.889259] WARNING: kernel stack regs at ffff8801c29a7ea8 in
>> > >> syz-executor8:1302 has bad 'bp' value ffff8801c29a7f28
>> > >> [  833.994878] WARNING: kernel stack regs at ffff8801c4e77ea8 in
>> > >> syz-executor1:13094 has bad 'bp' value ffff8801c4e77f28
>> > >>
>> > >> Can it also be caused by bpf/kprobe?
>> > >
>> > > This is a different warning.  I suspect it's due to unwinding the stack
>> > > of another CPU while it's running, which is still possible in a few
>> > > places.  I'm going to have to disable all these warnings for now.
>> >
>> >
>> > I also have the following diff locally. These loads trigger episodic
>> > KASAN warnings about stack-of-bounds reads on rcu stall warnings when
>> > it does backtrace of all cpus.
>> > If it looks correct to you, can you please also incorporate it into your patch?
>>
>> Ok, will do.
>>
>> BTW, I think there's an issue with your mail client.  Your last two
>> replies to me didn't have me on To/Cc.
>
> Would you mind testing if the following patch fixes it?  It's based on
> the latest linus/master.
>
>
> diff --git a/arch/x86/kernel/unwind_frame.c b/arch/x86/kernel/unwind_frame.c
> index 4443e49..05adf9a 100644
> --- a/arch/x86/kernel/unwind_frame.c
> +++ b/arch/x86/kernel/unwind_frame.c
> @@ -6,6 +6,21 @@
>
>  #define FRAME_HEADER_SIZE (sizeof(long) * 2)
>
> +/*
> + * This disables KASAN checking when reading a value from another task's stack,
> + * since the other task could be running on another CPU and could have poisoned
> + * the stack in the meantime.
> + */
> +#define UNWIND_READ_ONCE(state, x)                     \
> +({                                                     \
> +       unsigned long val;                              \
> +       if (state->task == current)                     \
> +               val = READ_ONCE(x);                     \
> +       else                                            \
> +               val = READ_ONCE_NOCHECK(x);             \
> +       val;                                            \
> +})
> +
>  static void unwind_dump(struct unwind_state *state, unsigned long *sp)
>  {
>         static bool dumped_before = false;
> @@ -48,7 +63,8 @@ unsigned long unwind_get_return_address(struct unwind_state *state)
>         if (state->regs && user_mode(state->regs))
>                 return 0;
>
> -       addr = ftrace_graph_ret_addr(state->task, &state->graph_idx, *addr_p,
> +       addr = UNWIND_READ_ONCE(state, *addr_p);
> +       addr = ftrace_graph_ret_addr(state->task, &state->graph_idx, addr,
>                                      addr_p);
>
>         return __kernel_text_address(addr) ? addr : 0;
> @@ -162,7 +178,7 @@ bool unwind_next_frame(struct unwind_state *state)
>         if (state->regs)
>                 next_bp = (unsigned long *)state->regs->bp;
>         else
> -               next_bp = (unsigned long *)*state->bp;
> +               next_bp = (unsigned long *)UNWIND_READ_ONCE(state, *state->bp);
>
>         /* is the next frame pointer an encoded pointer to pt_regs? */
>         regs = decode_frame_pointer(next_bp);
> @@ -207,6 +223,16 @@ bool unwind_next_frame(struct unwind_state *state)
>         return true;
>
>  bad_address:
> +       /*
> +        * When dumping a task other than current, the task might actually be
> +        * running on another CPU, in which case it could be modifying its
> +        * stack while we're reading it.  This is generally not a problem and
> +        * can be ignored as long as the caller understands that unwinding
> +        * another task will not always succeed.
> +        */
> +       if (state->task != current)
> +               goto the_end;
> +
>         if (state->regs) {
>                 printk_deferred_once(KERN_WARNING
>                         "WARNING: kernel stack regs at %p in %s:%d has bad 'bp' value %p\n",


Applied locally for testing.


What about this part?

diff --git a/arch/x86/include/asm/stacktrace.h
b/arch/x86/include/asm/stacktrace.h
index a3269c897ec5..d8d4fc66ffec 100644
--- a/arch/x86/include/asm/stacktrace.h
+++ b/arch/x86/include/asm/stacktrace.h
@@ -58,7 +58,7 @@ get_frame_pointer(struct task_struct *task, struct
pt_regs *regs)
        if (task == current)
                return __builtin_frame_address(0);

-       return (unsigned long *)((struct
inactive_task_frame*)task->thread.sp)->bp;
+       return (unsigned long *)READ_ONCE_NOCHECK(((struct
inactive_task_frame *)task->thread.sp)->bp);
 }
 #else
 static inline unsigned long *


I am hitting it as welL:

[<     inline     >] kasan_report_error mm/kasan/report.c:213
[<        none        >] kasan_report+0x42d/0x460 mm/kasan/report.c:307
[<        none        >] __asan_report_load8_noabort+0x14/0x20
mm/kasan/report.c:333
[<     inline     >] get_frame_pointer ./arch/x86/include/asm/stacktrace.h:61
[<        none        >] __unwind_start+0x38d/0x3a0
arch/x86/kernel/unwind_frame.c:247
[<     inline     >] unwind_start ./arch/x86/include/asm/unwind.h:40
[<        none        >] show_trace_log_lvl+0x1ed/0x2c0
arch/x86/kernel/dumpstack.c:61
[<        none        >] show_stack+0x2f/0x40 arch/x86/kernel/dumpstack.c:174
[<        none        >] sched_show_task+0x3e4/0x540 kernel/sched/core.c:5217

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


#1552314

FromJosh Poimboeuf <jpoimboe@redhat.com>
Date2017-01-05 21:40 +0100
Message-ID<sWmZk-7WS-31@gated-at.bofh.it>
In reply to#1552308
On Thu, Jan 05, 2017 at 09:23:14PM +0100, Dmitry Vyukov wrote:
> On Thu, Jan 5, 2017 at 6:03 PM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> > On Thu, Jan 05, 2017 at 09:17:00AM -0600, Josh Poimboeuf wrote:
> >> On Thu, Jan 05, 2017 at 03:59:52PM +0100, Dmitry Vyukov wrote:
> >> > On Thu, Jan 5, 2017 at 3:49 PM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> >> > > On Tue, Dec 27, 2016 at 05:38:59PM +0100, Dmitry Vyukov wrote:
> >> > >> On Thu, Dec 22, 2016 at 6:17 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> >> > >> > On Wed, Dec 21, 2016 at 01:46:36PM +0100, Andrey Konovalov wrote:
> >> > >> >> On Wed, Dec 21, 2016 at 12:36 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> >> > >> >> >
> >> > >> >> > Thanks.  Looking at the stack trace, my guess is that an interrupt hit
> >> > >> >> > while running in generated BPF code, and the unwinder got confused
> >> > >> >> > because regs->ip points to the generated code.  I may need to disable
> >> > >> >> > that warning until we figure out a better solution.
> >> > >> >> >
> >> > >> >> > Can you share your .config file?
> >> > >> >>
> >> > >> >> Sure, attached.
> >> > >> >
> >> > >> > Ok, I was able to recreate with your config.  The culprit was generated
> >> > >> > code, as I suspected, though it wasn't BPF, it was a kprobe (created by
> >> > >> > dccpprobe_init()).
> >> > >> >
> >> > >> > I'll make a patch to disable the warning.
> >> > >>
> >> > >> Hi,
> >> > >>
> >> > >> I am also seeing the following warnings:
> >> > >>
> >> > >> [  281.889259] WARNING: kernel stack regs at ffff8801c29a7ea8 in
> >> > >> syz-executor8:1302 has bad 'bp' value ffff8801c29a7f28
> >> > >> [  833.994878] WARNING: kernel stack regs at ffff8801c4e77ea8 in
> >> > >> syz-executor1:13094 has bad 'bp' value ffff8801c4e77f28
> >> > >>
> >> > >> Can it also be caused by bpf/kprobe?
> >> > >
> >> > > This is a different warning.  I suspect it's due to unwinding the stack
> >> > > of another CPU while it's running, which is still possible in a few
> >> > > places.  I'm going to have to disable all these warnings for now.
> >> >
> >> >
> >> > I also have the following diff locally. These loads trigger episodic
> >> > KASAN warnings about stack-of-bounds reads on rcu stall warnings when
> >> > it does backtrace of all cpus.
> >> > If it looks correct to you, can you please also incorporate it into your patch?
> >>
> >> Ok, will do.
> >>
> >> BTW, I think there's an issue with your mail client.  Your last two
> >> replies to me didn't have me on To/Cc.
> >
> > Would you mind testing if the following patch fixes it?  It's based on
> > the latest linus/master.
> >
> >
> > diff --git a/arch/x86/kernel/unwind_frame.c b/arch/x86/kernel/unwind_frame.c
> > index 4443e49..05adf9a 100644
> > --- a/arch/x86/kernel/unwind_frame.c
> > +++ b/arch/x86/kernel/unwind_frame.c
> > @@ -6,6 +6,21 @@
> >
> >  #define FRAME_HEADER_SIZE (sizeof(long) * 2)
> >
> > +/*
> > + * This disables KASAN checking when reading a value from another task's stack,
> > + * since the other task could be running on another CPU and could have poisoned
> > + * the stack in the meantime.
> > + */
> > +#define UNWIND_READ_ONCE(state, x)                     \
> > +({                                                     \
> > +       unsigned long val;                              \
> > +       if (state->task == current)                     \
> > +               val = READ_ONCE(x);                     \
> > +       else                                            \
> > +               val = READ_ONCE_NOCHECK(x);             \
> > +       val;                                            \
> > +})
> > +
> >  static void unwind_dump(struct unwind_state *state, unsigned long *sp)
> >  {
> >         static bool dumped_before = false;
> > @@ -48,7 +63,8 @@ unsigned long unwind_get_return_address(struct unwind_state *state)
> >         if (state->regs && user_mode(state->regs))
> >                 return 0;
> >
> > -       addr = ftrace_graph_ret_addr(state->task, &state->graph_idx, *addr_p,
> > +       addr = UNWIND_READ_ONCE(state, *addr_p);
> > +       addr = ftrace_graph_ret_addr(state->task, &state->graph_idx, addr,
> >                                      addr_p);
> >
> >         return __kernel_text_address(addr) ? addr : 0;
> > @@ -162,7 +178,7 @@ bool unwind_next_frame(struct unwind_state *state)
> >         if (state->regs)
> >                 next_bp = (unsigned long *)state->regs->bp;
> >         else
> > -               next_bp = (unsigned long *)*state->bp;
> > +               next_bp = (unsigned long *)UNWIND_READ_ONCE(state, *state->bp);
> >
> >         /* is the next frame pointer an encoded pointer to pt_regs? */
> >         regs = decode_frame_pointer(next_bp);
> > @@ -207,6 +223,16 @@ bool unwind_next_frame(struct unwind_state *state)
> >         return true;
> >
> >  bad_address:
> > +       /*
> > +        * When dumping a task other than current, the task might actually be
> > +        * running on another CPU, in which case it could be modifying its
> > +        * stack while we're reading it.  This is generally not a problem and
> > +        * can be ignored as long as the caller understands that unwinding
> > +        * another task will not always succeed.
> > +        */
> > +       if (state->task != current)
> > +               goto the_end;
> > +
> >         if (state->regs) {
> >                 printk_deferred_once(KERN_WARNING
> >                         "WARNING: kernel stack regs at %p in %s:%d has bad 'bp' value %p\n",
> 
> 
> Applied locally for testing.
> 
> 
> What about this part?
> 
> diff --git a/arch/x86/include/asm/stacktrace.h
> b/arch/x86/include/asm/stacktrace.h
> index a3269c897ec5..d8d4fc66ffec 100644
> --- a/arch/x86/include/asm/stacktrace.h
> +++ b/arch/x86/include/asm/stacktrace.h
> @@ -58,7 +58,7 @@ get_frame_pointer(struct task_struct *task, struct
> pt_regs *regs)
>         if (task == current)
>                 return __builtin_frame_address(0);
> 
> -       return (unsigned long *)((struct
> inactive_task_frame*)task->thread.sp)->bp;
> +       return (unsigned long *)READ_ONCE_NOCHECK(((struct
> inactive_task_frame *)task->thread.sp)->bp);
>  }
>  #else
>  static inline unsigned long *

Oops, I missed that part.  That's needed too.

BTW, I'm still not on your email To: list.

-- 
Josh

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web