kprobes: Rollback kprobe flags on failed arm_kprobe
Subsystems (2)
PATCH v2 1/1 kprobes: Rollback kprobe flags on failed arm_kprobe
From: Chuang Wang <[email protected]>
In aggrprobe scenes, if arm_kprobe() returns an error(e.g. livepatch and kprobe are using the same function X), kprobe flags, while has been modified to ~KPROBE_FLAG_DISABLED, is not rollled back.
Then, __disable_kprobe() will be failed in __unregister_kprobe_top(), the kprobe list will be not removed from aggrprobe, memory leaks or illegal pointers will be caused.
WARN disarm_kprobe:
Failed to disarm kprobe-ftrace at 00000000c729fdbc (-2)
RIP: 0010:disarm_kprobe+0xcc/0x110 Call Trace: __disable_kprobe+0x78/0x90 __unregister_kprobe_top+0x13/0x1b0 ? _cond_resched+0x15/0x30 unregister_kprobes+0x32/0x80 unregister_kprobe+0x1a/0x20
Illegal Pointers:
BUG: unable to handle kernel paging request at 0000000000656369 RIP: 0010:__get_valid_kprobe+0x69/0x90 Call Trace: register_kprobe+0x30/0x60 __register_trace_kprobe.part.7+0x8b/0xc0 create_local_trace_kprobe+0xd2/0x130 perf_kprobe_init+0x83/0xd0
---v1->v2:
- Supplement commit information: fixline, Cc stable
kernel/kprobes.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/kprobes.c +4 -1
@@ -2422,8 +2422,11 @@ int enable_kprobe(struct kprobe *kp)if (!kprobes_all_disarmed &&kprobe_disabled (p)) { p->flags &= ~KPROBE_FLAG_DISABLED ; ret =arm_kprobe (p); -if (ret) +if (ret) { p->flags |=KPROBE_FLAG_DISABLED ; +if (p != kp) + kp->flags |=KPROBE_FLAG_DISABLED ; + } } out:mutex_unlock (&kprobe_mutex);
Signature · 1 line
2.34.1
Quoted 20 lines · On Fri, 10 Jun 2022 23:09:33 +0800 Chuang <[email protected]> wrote:
From: Chuang Wang <[email protected]>
In aggrprobe scenes, if
arm_kprobe()returns an error(e.g. livepatch and kprobe are using the same function X), kprobe flags, while has been modified to ~KPROBE_FLAG_DISABLED, is not rollled back.Then,
__disable_kprobe()will be failed in__unregister_kprobe_top(), the kprobe list will be not removed from aggrprobe, memory leaks or illegal pointers will be caused.WARN
disarm_kprobe:
Failed to disarm kprobe-ftrace at00000000c729fdbc(-2)RIP: 0010:disarm_kprobe+0xcc/0x110 Call Trace: __disable_kprobe+0x78/0x90 __unregister_kprobe_top+0x13/0x1b0 ? _cond_resched+0x15/0x30 unregister_kprobes+0x32/0x80 unregister_kprobe+0x1a/0x20
Quoted 9 lines
Illegal Pointers:
BUG: unable to handle kernel paging request at 0000000000656369 RIP: 0010:__get_valid_kprobe+0x69/0x90 Call Trace: register_kprobe+0x30/0x60 __register_trace_kprobe.part.7+0x8b/0xc0 create_local_trace_kprobe+0xd2/0x130 perf_kprobe_init+0x83/0xd0
This looks good to me.
Thanks for update!
Quoted 31 lines
Fixes 12310e343755 ("kprobes: Propagate error from arm_kprobe_ftrace()")Signed-off-by Chuang Wang <[email protected]>Cc <[email protected]>Signed-off-by Jingren Zhou <[email protected]>---
v1->v2:
- Supplement commit information: fixline, Cc stablekernel/kprobes.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)kernel/kprobes.c +4
-1@@ -2422,8 +2422,11 @@ int enable_kprobe(struct kprobe *kp)if (!kprobes_all_disarmed &&kprobe_disabled (p)) { p->flags &= ~KPROBE_FLAG_DISABLED ; ret =arm_kprobe (p); -if (ret) +if (ret) { p->flags |=KPROBE_FLAG_DISABLED ; +if (p != kp) + kp->flags |=KPROBE_FLAG_DISABLED ; + } } out:mutex_unlock (&kprobe_mutex);Signature · 1 line
2.34.1
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>