All of lore.kernel.org
 help / color / mirror / Atom feed
* [BUGFIX PATCH] kprobes: Fix to check probe enabled before disarm_kprobe_ftrace()
@ 2020-08-31 15:12 Masami Hiramatsu
  2020-08-31 15:47 ` [External] " Muchun Song
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Masami Hiramatsu @ 2020-08-31 15:12 UTC (permalink / raw)
  To: Ingo Molnar, Steven Rostedt
  Cc: mhiramat, linux-kernel, Naveen N . Rao, Anil S Keshavamurthy,
	David Miller, Muchun Song, Chengming Zhou

Commit 0cb2f1372baa ("kprobes: Fix NULL pointer dereference at
kprobe_ftrace_handler") fixed one bug but not completely fixed yet.
If we run a kprobe_module.tc of ftracetest, kernel showed a warning
as below.


# ./ftracetest test.d/kprobe/kprobe_module.tc
=== Ftrace unit tests ===
[1] Kprobe dynamic event - probing module
...
[   22.400215] ------------[ cut here ]------------
[   22.400962] Failed to disarm kprobe-ftrace at trace_printk_irq_work+0x0/0x7e [trace_printk] (-2)
[   22.402139] WARNING: CPU: 7 PID: 200 at kernel/kprobes.c:1091 __disarm_kprobe_ftrace.isra.0+0x7e/0xa0
[   22.403358] Modules linked in: trace_printk(-)
[   22.404028] CPU: 7 PID: 200 Comm: rmmod Not tainted 5.9.0-rc2+ #66
[   22.404870] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1 04/01/2014
[   22.406139] RIP: 0010:__disarm_kprobe_ftrace.isra.0+0x7e/0xa0
[   22.406947] Code: 30 8b 03 eb c9 80 3d e5 09 1f 01 00 75 dc 49 8b 34 24 89 c2 48 c7 c7 a0 c2 05 82 89 45 e4 c6 05 cc 09 1f 01 01 e8 a9 c7 f0 ff <0f> 0b 8b 45 e4 eb b9 89 c6 48 c7 c7 70 c2 05 82 89 45 e4 e8 91 c7
[   22.409544] RSP: 0018:ffffc90000237df0 EFLAGS: 00010286
[   22.410385] RAX: 0000000000000000 RBX: ffffffff83066024 RCX: 0000000000000000
[   22.411434] RDX: 0000000000000001 RSI: ffffffff810de8d3 RDI: ffffffff810de8d3
[   22.412687] RBP: ffffc90000237e10 R08: 0000000000000001 R09: 0000000000000001
[   22.413762] R10: 0000000000000000 R11: 0000000000000001 R12: ffff88807c478640
[   22.414852] R13: ffffffff8235ebc0 R14: ffffffffa00060c0 R15: 0000000000000000
[   22.415941] FS:  00000000019d48c0(0000) GS:ffff88807d7c0000(0000) knlGS:0000000000000000
[   22.417264] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   22.418176] CR2: 00000000005bb7e3 CR3: 0000000078f7a000 CR4: 00000000000006a0
[   22.419309] Call Trace:
[   22.419990]  kill_kprobe+0x94/0x160
[   22.420652]  kprobes_module_callback+0x64/0x230
[   22.421470]  notifier_call_chain+0x4f/0x70
[   22.422184]  blocking_notifier_call_chain+0x49/0x70
[   22.422979]  __x64_sys_delete_module+0x1ac/0x240
[   22.423733]  do_syscall_64+0x38/0x50
[   22.424366]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[   22.425176] RIP: 0033:0x4bb81d
[   22.425741] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e0 ff ff ff f7 d8 64 89 01 48
[   22.428726] RSP: 002b:00007ffc70fef008 EFLAGS: 00000246 ORIG_RAX: 00000000000000b0
[   22.430169] RAX: ffffffffffffffda RBX: 00000000019d48a0 RCX: 00000000004bb81d
[   22.431375] RDX: 0000000000000000 RSI: 0000000000000880 RDI: 00007ffc70fef028
[   22.432543] RBP: 0000000000000880 R08: 00000000ffffffff R09: 00007ffc70fef320
[   22.433692] R10: 0000000000656300 R11: 0000000000000246 R12: 00007ffc70fef028
[   22.434635] R13: 0000000000000000 R14: 0000000000000002 R15: 0000000000000000
[   22.435682] irq event stamp: 1169
[   22.436240] hardirqs last  enabled at (1179): [<ffffffff810df542>] console_unlock+0x422/0x580
[   22.437466] hardirqs last disabled at (1188): [<ffffffff810df19b>] console_unlock+0x7b/0x580
[   22.438608] softirqs last  enabled at (866): [<ffffffff81c0038e>] __do_softirq+0x38e/0x490
[   22.439637] softirqs last disabled at (859): [<ffffffff81a00f42>] asm_call_on_stack+0x12/0x20
[   22.440690] ---[ end trace 1e7ce7e1e4567276 ]---
[   22.472832] trace_kprobe: This probe might be able to register after target module is loaded. Continue.


This is because the kill_kprobe() calls disarm_kprobe_ftrace() even
if the given probe is not enabled. In that case, ftrace_set_filter_ip()
fails because the given probe point is not registered to ftrace.

Fix to check the given (going) probe is enabled before invoking
disarm_kprobe_ftrace().

Fixes: 0cb2f1372baa ("kprobes: Fix NULL pointer dereference at kprobe_ftrace_handler")
Cc: stable@vger.kernel.org
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/kprobes.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 287b263c9cb9..d43b48ecdb4f 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2159,9 +2159,10 @@ static void kill_kprobe(struct kprobe *p)
 
 	/*
 	 * The module is going away. We should disarm the kprobe which
-	 * is using ftrace.
+	 * is using ftrace, because ftrace framework is still available at
+	 * MODULE_STATE_GOING notification.
 	 */
-	if (kprobe_ftrace(p))
+	if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed)
 		disarm_kprobe_ftrace(p);
 }
 


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [External] [BUGFIX PATCH] kprobes: Fix to check probe enabled before disarm_kprobe_ftrace()
  2020-08-31 15:12 [BUGFIX PATCH] kprobes: Fix to check probe enabled before disarm_kprobe_ftrace() Masami Hiramatsu
@ 2020-08-31 15:47 ` Muchun Song
  2020-08-31 22:24   ` Masami Hiramatsu
  2020-09-12  2:27 ` Masami Hiramatsu
  2020-09-14 17:16 ` [tip: perf/kprobes] " tip-bot2 for Masami Hiramatsu
  2 siblings, 1 reply; 6+ messages in thread
From: Muchun Song @ 2020-08-31 15:47 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Ingo Molnar, Steven Rostedt, LKML, Naveen N . Rao,
	Anil S Keshavamurthy, David Miller, Chengming Zhou

On Mon, Aug 31, 2020 at 11:12 PM Masami Hiramatsu <mhiramat@kernel.org> wrote:
>
> Commit 0cb2f1372baa ("kprobes: Fix NULL pointer dereference at
> kprobe_ftrace_handler") fixed one bug but not completely fixed yet.
> If we run a kprobe_module.tc of ftracetest, kernel showed a warning
> as below.
>
>
> # ./ftracetest test.d/kprobe/kprobe_module.tc
> === Ftrace unit tests ===
> [1] Kprobe dynamic event - probing module
> ...
> [   22.400215] ------------[ cut here ]------------
> [   22.400962] Failed to disarm kprobe-ftrace at trace_printk_irq_work+0x0/0x7e [trace_printk] (-2)
> [   22.402139] WARNING: CPU: 7 PID: 200 at kernel/kprobes.c:1091 __disarm_kprobe_ftrace.isra.0+0x7e/0xa0
> [   22.403358] Modules linked in: trace_printk(-)
> [   22.404028] CPU: 7 PID: 200 Comm: rmmod Not tainted 5.9.0-rc2+ #66
> [   22.404870] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1 04/01/2014
> [   22.406139] RIP: 0010:__disarm_kprobe_ftrace.isra.0+0x7e/0xa0
> [   22.406947] Code: 30 8b 03 eb c9 80 3d e5 09 1f 01 00 75 dc 49 8b 34 24 89 c2 48 c7 c7 a0 c2 05 82 89 45 e4 c6 05 cc 09 1f 01 01 e8 a9 c7 f0 ff <0f> 0b 8b 45 e4 eb b9 89 c6 48 c7 c7 70 c2 05 82 89 45 e4 e8 91 c7
> [   22.409544] RSP: 0018:ffffc90000237df0 EFLAGS: 00010286
> [   22.410385] RAX: 0000000000000000 RBX: ffffffff83066024 RCX: 0000000000000000
> [   22.411434] RDX: 0000000000000001 RSI: ffffffff810de8d3 RDI: ffffffff810de8d3
> [   22.412687] RBP: ffffc90000237e10 R08: 0000000000000001 R09: 0000000000000001
> [   22.413762] R10: 0000000000000000 R11: 0000000000000001 R12: ffff88807c478640
> [   22.414852] R13: ffffffff8235ebc0 R14: ffffffffa00060c0 R15: 0000000000000000
> [   22.415941] FS:  00000000019d48c0(0000) GS:ffff88807d7c0000(0000) knlGS:0000000000000000
> [   22.417264] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> [   22.418176] CR2: 00000000005bb7e3 CR3: 0000000078f7a000 CR4: 00000000000006a0
> [   22.419309] Call Trace:
> [   22.419990]  kill_kprobe+0x94/0x160
> [   22.420652]  kprobes_module_callback+0x64/0x230
> [   22.421470]  notifier_call_chain+0x4f/0x70
> [   22.422184]  blocking_notifier_call_chain+0x49/0x70
> [   22.422979]  __x64_sys_delete_module+0x1ac/0x240
> [   22.423733]  do_syscall_64+0x38/0x50
> [   22.424366]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
> [   22.425176] RIP: 0033:0x4bb81d
> [   22.425741] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e0 ff ff ff f7 d8 64 89 01 48
> [   22.428726] RSP: 002b:00007ffc70fef008 EFLAGS: 00000246 ORIG_RAX: 00000000000000b0
> [   22.430169] RAX: ffffffffffffffda RBX: 00000000019d48a0 RCX: 00000000004bb81d
> [   22.431375] RDX: 0000000000000000 RSI: 0000000000000880 RDI: 00007ffc70fef028
> [   22.432543] RBP: 0000000000000880 R08: 00000000ffffffff R09: 00007ffc70fef320
> [   22.433692] R10: 0000000000656300 R11: 0000000000000246 R12: 00007ffc70fef028
> [   22.434635] R13: 0000000000000000 R14: 0000000000000002 R15: 0000000000000000
> [   22.435682] irq event stamp: 1169
> [   22.436240] hardirqs last  enabled at (1179): [<ffffffff810df542>] console_unlock+0x422/0x580
> [   22.437466] hardirqs last disabled at (1188): [<ffffffff810df19b>] console_unlock+0x7b/0x580
> [   22.438608] softirqs last  enabled at (866): [<ffffffff81c0038e>] __do_softirq+0x38e/0x490
> [   22.439637] softirqs last disabled at (859): [<ffffffff81a00f42>] asm_call_on_stack+0x12/0x20
> [   22.440690] ---[ end trace 1e7ce7e1e4567276 ]---
> [   22.472832] trace_kprobe: This probe might be able to register after target module is loaded. Continue.
>
>
> This is because the kill_kprobe() calls disarm_kprobe_ftrace() even
> if the given probe is not enabled. In that case, ftrace_set_filter_ip()
> fails because the given probe point is not registered to ftrace.

Does the following patch solve this issue?  Thanks.

  kprobes: Fix kill kprobe which has been marked as gone
  https://lkml.org/lkml/2020/8/19/1496

>
> Fix to check the given (going) probe is enabled before invoking
> disarm_kprobe_ftrace().
>
> Fixes: 0cb2f1372baa ("kprobes: Fix NULL pointer dereference at kprobe_ftrace_handler")
> Cc: stable@vger.kernel.org
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
>  kernel/kprobes.c |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 287b263c9cb9..d43b48ecdb4f 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -2159,9 +2159,10 @@ static void kill_kprobe(struct kprobe *p)
>
>         /*
>          * The module is going away. We should disarm the kprobe which
> -        * is using ftrace.
> +        * is using ftrace, because ftrace framework is still available at
> +        * MODULE_STATE_GOING notification.
>          */
> -       if (kprobe_ftrace(p))
> +       if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed)
>                 disarm_kprobe_ftrace(p);
>  }
>
>


-- 
Yours,
Muchun

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [External] [BUGFIX PATCH] kprobes: Fix to check probe enabled before disarm_kprobe_ftrace()
  2020-08-31 15:47 ` [External] " Muchun Song
@ 2020-08-31 22:24   ` Masami Hiramatsu
  0 siblings, 0 replies; 6+ messages in thread
From: Masami Hiramatsu @ 2020-08-31 22:24 UTC (permalink / raw)
  To: Muchun Song
  Cc: Ingo Molnar, Steven Rostedt, LKML, Naveen N . Rao,
	Anil S Keshavamurthy, David Miller, Chengming Zhou

Hi Muchun,

On Mon, 31 Aug 2020 23:47:14 +0800
Muchun Song <songmuchun@bytedance.com> wrote:

> On Mon, Aug 31, 2020 at 11:12 PM Masami Hiramatsu <mhiramat@kernel.org> wrote:
> >
> > Commit 0cb2f1372baa ("kprobes: Fix NULL pointer dereference at
> > kprobe_ftrace_handler") fixed one bug but not completely fixed yet.
> > If we run a kprobe_module.tc of ftracetest, kernel showed a warning
> > as below.
> >
> >
> > # ./ftracetest test.d/kprobe/kprobe_module.tc
> > === Ftrace unit tests ===
> > [1] Kprobe dynamic event - probing module
> > ...
> > [   22.400215] ------------[ cut here ]------------
> > [   22.400962] Failed to disarm kprobe-ftrace at trace_printk_irq_work+0x0/0x7e [trace_printk] (-2)
> > [   22.402139] WARNING: CPU: 7 PID: 200 at kernel/kprobes.c:1091 __disarm_kprobe_ftrace.isra.0+0x7e/0xa0
> > [   22.403358] Modules linked in: trace_printk(-)
> > [   22.404028] CPU: 7 PID: 200 Comm: rmmod Not tainted 5.9.0-rc2+ #66
> > [   22.404870] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1 04/01/2014
> > [   22.406139] RIP: 0010:__disarm_kprobe_ftrace.isra.0+0x7e/0xa0
> > [   22.406947] Code: 30 8b 03 eb c9 80 3d e5 09 1f 01 00 75 dc 49 8b 34 24 89 c2 48 c7 c7 a0 c2 05 82 89 45 e4 c6 05 cc 09 1f 01 01 e8 a9 c7 f0 ff <0f> 0b 8b 45 e4 eb b9 89 c6 48 c7 c7 70 c2 05 82 89 45 e4 e8 91 c7
> > [   22.409544] RSP: 0018:ffffc90000237df0 EFLAGS: 00010286
> > [   22.410385] RAX: 0000000000000000 RBX: ffffffff83066024 RCX: 0000000000000000
> > [   22.411434] RDX: 0000000000000001 RSI: ffffffff810de8d3 RDI: ffffffff810de8d3
> > [   22.412687] RBP: ffffc90000237e10 R08: 0000000000000001 R09: 0000000000000001
> > [   22.413762] R10: 0000000000000000 R11: 0000000000000001 R12: ffff88807c478640
> > [   22.414852] R13: ffffffff8235ebc0 R14: ffffffffa00060c0 R15: 0000000000000000
> > [   22.415941] FS:  00000000019d48c0(0000) GS:ffff88807d7c0000(0000) knlGS:0000000000000000
> > [   22.417264] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> > [   22.418176] CR2: 00000000005bb7e3 CR3: 0000000078f7a000 CR4: 00000000000006a0
> > [   22.419309] Call Trace:
> > [   22.419990]  kill_kprobe+0x94/0x160
> > [   22.420652]  kprobes_module_callback+0x64/0x230
> > [   22.421470]  notifier_call_chain+0x4f/0x70
> > [   22.422184]  blocking_notifier_call_chain+0x49/0x70
> > [   22.422979]  __x64_sys_delete_module+0x1ac/0x240
> > [   22.423733]  do_syscall_64+0x38/0x50
> > [   22.424366]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
> > [   22.425176] RIP: 0033:0x4bb81d
> > [   22.425741] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e0 ff ff ff f7 d8 64 89 01 48
> > [   22.428726] RSP: 002b:00007ffc70fef008 EFLAGS: 00000246 ORIG_RAX: 00000000000000b0
> > [   22.430169] RAX: ffffffffffffffda RBX: 00000000019d48a0 RCX: 00000000004bb81d
> > [   22.431375] RDX: 0000000000000000 RSI: 0000000000000880 RDI: 00007ffc70fef028
> > [   22.432543] RBP: 0000000000000880 R08: 00000000ffffffff R09: 00007ffc70fef320
> > [   22.433692] R10: 0000000000656300 R11: 0000000000000246 R12: 00007ffc70fef028
> > [   22.434635] R13: 0000000000000000 R14: 0000000000000002 R15: 0000000000000000
> > [   22.435682] irq event stamp: 1169
> > [   22.436240] hardirqs last  enabled at (1179): [<ffffffff810df542>] console_unlock+0x422/0x580
> > [   22.437466] hardirqs last disabled at (1188): [<ffffffff810df19b>] console_unlock+0x7b/0x580
> > [   22.438608] softirqs last  enabled at (866): [<ffffffff81c0038e>] __do_softirq+0x38e/0x490
> > [   22.439637] softirqs last disabled at (859): [<ffffffff81a00f42>] asm_call_on_stack+0x12/0x20
> > [   22.440690] ---[ end trace 1e7ce7e1e4567276 ]---
> > [   22.472832] trace_kprobe: This probe might be able to register after target module is loaded. Continue.
> >
> >
> > This is because the kill_kprobe() calls disarm_kprobe_ftrace() even
> > if the given probe is not enabled. In that case, ftrace_set_filter_ip()
> > fails because the given probe point is not registered to ftrace.
> 
> Does the following patch solve this issue?  Thanks.
> 
>   kprobes: Fix kill kprobe which has been marked as gone
>   https://lkml.org/lkml/2020/8/19/1496

No, your patch skips all gone probes, but this one disabled ftrace
probes (not gone yet).

Thank you,

-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [BUGFIX PATCH] kprobes: Fix to check probe enabled before disarm_kprobe_ftrace()
  2020-08-31 15:12 [BUGFIX PATCH] kprobes: Fix to check probe enabled before disarm_kprobe_ftrace() Masami Hiramatsu
  2020-08-31 15:47 ` [External] " Muchun Song
@ 2020-09-12  2:27 ` Masami Hiramatsu
  2020-09-18 15:52   ` Steven Rostedt
  2020-09-14 17:16 ` [tip: perf/kprobes] " tip-bot2 for Masami Hiramatsu
  2 siblings, 1 reply; 6+ messages in thread
From: Masami Hiramatsu @ 2020-09-12  2:27 UTC (permalink / raw)
  To: Masami Hiramatsu, Ingo Molnar
  Cc: Ingo Molnar, Steven Rostedt, linux-kernel, Naveen N . Rao,
	Anil S Keshavamurthy, David Miller, Muchun Song, Chengming Zhou,
	Peter Zijlstra, x86

Hi Ingo,

Could you also pick this fix to fix the reproducible warning?

Thank you,

On Tue,  1 Sep 2020 00:12:07 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> Commit 0cb2f1372baa ("kprobes: Fix NULL pointer dereference at
> kprobe_ftrace_handler") fixed one bug but not completely fixed yet.
> If we run a kprobe_module.tc of ftracetest, kernel showed a warning
> as below.
> 
> 
> # ./ftracetest test.d/kprobe/kprobe_module.tc
> === Ftrace unit tests ===
> [1] Kprobe dynamic event - probing module
> ...
> [   22.400215] ------------[ cut here ]------------
> [   22.400962] Failed to disarm kprobe-ftrace at trace_printk_irq_work+0x0/0x7e [trace_printk] (-2)
> [   22.402139] WARNING: CPU: 7 PID: 200 at kernel/kprobes.c:1091 __disarm_kprobe_ftrace.isra.0+0x7e/0xa0
> [   22.403358] Modules linked in: trace_printk(-)
> [   22.404028] CPU: 7 PID: 200 Comm: rmmod Not tainted 5.9.0-rc2+ #66
> [   22.404870] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1 04/01/2014
> [   22.406139] RIP: 0010:__disarm_kprobe_ftrace.isra.0+0x7e/0xa0
> [   22.406947] Code: 30 8b 03 eb c9 80 3d e5 09 1f 01 00 75 dc 49 8b 34 24 89 c2 48 c7 c7 a0 c2 05 82 89 45 e4 c6 05 cc 09 1f 01 01 e8 a9 c7 f0 ff <0f> 0b 8b 45 e4 eb b9 89 c6 48 c7 c7 70 c2 05 82 89 45 e4 e8 91 c7
> [   22.409544] RSP: 0018:ffffc90000237df0 EFLAGS: 00010286
> [   22.410385] RAX: 0000000000000000 RBX: ffffffff83066024 RCX: 0000000000000000
> [   22.411434] RDX: 0000000000000001 RSI: ffffffff810de8d3 RDI: ffffffff810de8d3
> [   22.412687] RBP: ffffc90000237e10 R08: 0000000000000001 R09: 0000000000000001
> [   22.413762] R10: 0000000000000000 R11: 0000000000000001 R12: ffff88807c478640
> [   22.414852] R13: ffffffff8235ebc0 R14: ffffffffa00060c0 R15: 0000000000000000
> [   22.415941] FS:  00000000019d48c0(0000) GS:ffff88807d7c0000(0000) knlGS:0000000000000000
> [   22.417264] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> [   22.418176] CR2: 00000000005bb7e3 CR3: 0000000078f7a000 CR4: 00000000000006a0
> [   22.419309] Call Trace:
> [   22.419990]  kill_kprobe+0x94/0x160
> [   22.420652]  kprobes_module_callback+0x64/0x230
> [   22.421470]  notifier_call_chain+0x4f/0x70
> [   22.422184]  blocking_notifier_call_chain+0x49/0x70
> [   22.422979]  __x64_sys_delete_module+0x1ac/0x240
> [   22.423733]  do_syscall_64+0x38/0x50
> [   22.424366]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
> [   22.425176] RIP: 0033:0x4bb81d
> [   22.425741] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e0 ff ff ff f7 d8 64 89 01 48
> [   22.428726] RSP: 002b:00007ffc70fef008 EFLAGS: 00000246 ORIG_RAX: 00000000000000b0
> [   22.430169] RAX: ffffffffffffffda RBX: 00000000019d48a0 RCX: 00000000004bb81d
> [   22.431375] RDX: 0000000000000000 RSI: 0000000000000880 RDI: 00007ffc70fef028
> [   22.432543] RBP: 0000000000000880 R08: 00000000ffffffff R09: 00007ffc70fef320
> [   22.433692] R10: 0000000000656300 R11: 0000000000000246 R12: 00007ffc70fef028
> [   22.434635] R13: 0000000000000000 R14: 0000000000000002 R15: 0000000000000000
> [   22.435682] irq event stamp: 1169
> [   22.436240] hardirqs last  enabled at (1179): [<ffffffff810df542>] console_unlock+0x422/0x580
> [   22.437466] hardirqs last disabled at (1188): [<ffffffff810df19b>] console_unlock+0x7b/0x580
> [   22.438608] softirqs last  enabled at (866): [<ffffffff81c0038e>] __do_softirq+0x38e/0x490
> [   22.439637] softirqs last disabled at (859): [<ffffffff81a00f42>] asm_call_on_stack+0x12/0x20
> [   22.440690] ---[ end trace 1e7ce7e1e4567276 ]---
> [   22.472832] trace_kprobe: This probe might be able to register after target module is loaded. Continue.
> 
> 
> This is because the kill_kprobe() calls disarm_kprobe_ftrace() even
> if the given probe is not enabled. In that case, ftrace_set_filter_ip()
> fails because the given probe point is not registered to ftrace.
> 
> Fix to check the given (going) probe is enabled before invoking
> disarm_kprobe_ftrace().
> 
> Fixes: 0cb2f1372baa ("kprobes: Fix NULL pointer dereference at kprobe_ftrace_handler")
> Cc: stable@vger.kernel.org
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
>  kernel/kprobes.c |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 287b263c9cb9..d43b48ecdb4f 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -2159,9 +2159,10 @@ static void kill_kprobe(struct kprobe *p)
>  
>  	/*
>  	 * The module is going away. We should disarm the kprobe which
> -	 * is using ftrace.
> +	 * is using ftrace, because ftrace framework is still available at
> +	 * MODULE_STATE_GOING notification.
>  	 */
> -	if (kprobe_ftrace(p))
> +	if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed)
>  		disarm_kprobe_ftrace(p);
>  }
>  
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [tip: perf/kprobes] kprobes: Fix to check probe enabled before disarm_kprobe_ftrace()
  2020-08-31 15:12 [BUGFIX PATCH] kprobes: Fix to check probe enabled before disarm_kprobe_ftrace() Masami Hiramatsu
  2020-08-31 15:47 ` [External] " Muchun Song
  2020-09-12  2:27 ` Masami Hiramatsu
@ 2020-09-14 17:16 ` tip-bot2 for Masami Hiramatsu
  2 siblings, 0 replies; 6+ messages in thread
From: tip-bot2 for Masami Hiramatsu @ 2020-09-14 17:16 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Masami Hiramatsu, Ingo Molnar, stable, x86, LKML

The following commit has been merged into the perf/kprobes branch of tip:

Commit-ID:     bcb53209be5cb32d485507452edda19b78f31d84
Gitweb:        https://git.kernel.org/tip/bcb53209be5cb32d485507452edda19b78f31d84
Author:        Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate:    Tue, 01 Sep 2020 00:12:07 +09:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Mon, 14 Sep 2020 11:20:03 +02:00

kprobes: Fix to check probe enabled before disarm_kprobe_ftrace()

Commit:

  0cb2f1372baa ("kprobes: Fix NULL pointer dereference at kprobe_ftrace_handler")

fixed one bug but the underlying bugs are not completely fixed yet.

If we run a kprobe_module.tc of ftracetest, a warning triggers:

  # ./ftracetest test.d/kprobe/kprobe_module.tc
  === Ftrace unit tests ===
  [1] Kprobe dynamic event - probing module
  ...
   ------------[ cut here ]------------
   Failed to disarm kprobe-ftrace at trace_printk_irq_work+0x0/0x7e [trace_printk] (-2)
   WARNING: CPU: 7 PID: 200 at kernel/kprobes.c:1091 __disarm_kprobe_ftrace.isra.0+0x7e/0xa0

This is because the kill_kprobe() calls disarm_kprobe_ftrace() even
if the given probe is not enabled. In that case, ftrace_set_filter_ip()
fails because the given probe point is not registered to ftrace.

Fix to check the given (going) probe is enabled before invoking
disarm_kprobe_ftrace().

Fixes: 0cb2f1372baa ("kprobes: Fix NULL pointer dereference at kprobe_ftrace_handler")
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/159888672694.1411785.5987998076694782591.stgit@devnote2
---
 kernel/kprobes.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 732a701..3b61ae8 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2235,9 +2235,10 @@ static void kill_kprobe(struct kprobe *p)
 
 	/*
 	 * The module is going away. We should disarm the kprobe which
-	 * is using ftrace.
+	 * is using ftrace, because ftrace framework is still available at
+	 * MODULE_STATE_GOING notification.
 	 */
-	if (kprobe_ftrace(p))
+	if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed)
 		disarm_kprobe_ftrace(p);
 }
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [BUGFIX PATCH] kprobes: Fix to check probe enabled before disarm_kprobe_ftrace()
  2020-09-12  2:27 ` Masami Hiramatsu
@ 2020-09-18 15:52   ` Steven Rostedt
  0 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2020-09-18 15:52 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Ingo Molnar, Ingo Molnar, linux-kernel, Naveen N . Rao,
	Anil S Keshavamurthy, David Miller, Muchun Song, Chengming Zhou,
	Peter Zijlstra, x86

On Sat, 12 Sep 2020 11:27:49 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> Hi Ingo,
> 
> Could you also pick this fix to fix the reproducible warning?
> 
>

If Ingo hasn't done this already, I'll pick it up now and start putting it
through my tests.

Thanks Masami!

-- Steve

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-09-18 15:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-31 15:12 [BUGFIX PATCH] kprobes: Fix to check probe enabled before disarm_kprobe_ftrace() Masami Hiramatsu
2020-08-31 15:47 ` [External] " Muchun Song
2020-08-31 22:24   ` Masami Hiramatsu
2020-09-12  2:27 ` Masami Hiramatsu
2020-09-18 15:52   ` Steven Rostedt
2020-09-14 17:16 ` [tip: perf/kprobes] " tip-bot2 for Masami Hiramatsu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.