arm64: kprobes: Fix bugs in kprobes for arm64
v2 cover arm64: kprobes: Fix bugs in kprobes for arm64
Hi,
Here is the 2nd version of the kprobe bugfixes on arm64. The previous series is here;
https://lore.kernel.org/all/166990553243.253128.13594802750635478633.stgit@devnote3/T/#u
The first one is a critical issue, which will cause a kernel crach easily with lockdep[1/3]. Others are minor issues and rare cases. The [2/3] let do_page_fault() fixup the page fault in kprobes user handler, and [3/3] is more like code cleanup and returns DBG_HOOK_ERROR if it can not handle kprobe's BRK (but that should not happen.)
In this version I update to use noinstr and __always_inline [1/3] and update comments[3/3]. Also add Mark's Ack (Thanks!)
Thank you,
---
Masami Hiramatsu (Google) (3):
arm64: Prohibit instrumentation on arch_stack_walk()
arm64: kprobes: Let arch do_page_fault() fix up page fault in user handler
arm64: kprobes: Return DBG_HOOK_ERROR if kprobes can not handle a BRK
arch/arm64/kernel/probes/kprobes.c | 86 +++++++++++++++--------------------- arch/arm64/kernel/stacktrace.c | 10 ++-- 2 files changed, 41 insertions(+), 55 deletions(-)
--
Masami Hiramatsu (Google) <[email protected]>
PATCH v2 1/3 arm64: Prohibit instrumentation on arch_stack_walk()
From: Masami Hiramatsu (Google) <[email protected]>
Mark arch_stack_walk() as noinstr instead of notrace and inline functions called from arch_stack_walk() as __always_inline so that user does not put any instrumentations on it, because this function can be used from return_address() which is used by lockdep.
Without this, if the kernel built with CONFIG_LOCKDEP=y, just probing arch_stack_walk() via <tracefs>/kprobe_events will crash the kernel on arm64.
# echo p arch_stack_walk >> ${TRACEFS}/kprobe_events
# echo 1 > ${TRACEFS}/events/kprobes/enable
kprobes: Failed to recover from reentered kprobes.
kprobes: Dump kprobe:
.symbol_name = arch_stack_walk, .offset = 0, .addr = arch_stack_walk+0x0/0x1c0
------------[ cut here ]------------
kernel BUG at arch/arm64/kernel/probes/kprobes.c:241!
kprobes: Failed to recover from reentered kprobes.
kprobes: Dump kprobe:
.symbol_name = arch_stack_walk, .offset = 0, .addr = arch_stack_walk+0x0/0x1c0
------------[ cut here ]------------
kernel BUG at arch/arm64/kernel/probes/kprobes.c:241!
PREEMPT SMP
Modules linked in:
CPU: 0 PID: 17 Comm: migration/0 Tainted: G N 6.1.0-rc5+ #6
Hardware name: linux,dummy-virt (DT)
Stopper: 0x0 <- 0x0
pstate: 600003c5 (nZCv DAIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : kprobe_breakpoint_handler+0x178/0x17c
lr : kprobe_breakpoint_handler+0x178/0x17c
sp : ffff8000080d3090
x29: ffff8000080d3090 x28: ffff0df5845798c0 x27: ffffc4f59057a774
x26: ffff0df5ffbba770 x25: ffff0df58f420f18 x24: ffff49006f641000
x23: ffffc4f590579768 x22: ffff0df58f420f18 x21: ffff8000080d31c0
x20: ffffc4f590579768 x19: ffffc4f590579770 x18: 0000000000000006
x17: 5f6b636174735f68 x16: 637261203d207264 x15: 64612e202c30203d
x14: 2074657366666f2e x13: 30633178302f3078 x12: 302b6b6c61775f6b
x11: 636174735f686372 x10: ffffc4f590dc5bd8 x9 : ffffc4f58eb31958
x8 : 00000000ffffefff x7 : ffffc4f590dc5bd8 x6 : 80000000fffff000
x5 : 000000000000bff4 x4 : 0000000000000000 x3 : 0000000000000000
x2 : 0000000000000000 x1 : ffff0df5845798c0 x0 : 0000000000000064
Call trace:
kprobes: Failed to recover from reentered kprobes.
kprobes: Dump kprobe:
.symbol_name = arch_stack_walk, .offset = 0, .addr = arch_stack_walk+0x0/0x1c0
------------[ cut here ]------------
kernel BUG at arch/arm64/kernel/probes/kprobes.c:241!---
Changes in v2:
- Use noinstr instead of NOKPROBE_SYMBOL()
- Use __always_inline because nokprobe_inline will be changed if CONFIG_KPROBES=n.
- Fix indentation.
--- arch/arm64/kernel/stacktrace.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/arm64/kernel/stacktrace.c +5 -5
@@ -23,8 +23,8 @@* * The regs must be on a stack currently owned by the calling task. */ -static inline void unwind_init_from_regs (struct unwind_state *state, -struct pt_regs *regs) +static __always_inline void unwind_init_from_regs(struct unwind_state *state, +struct pt_regs *regs) {unwind_init_common (state, current);
@@ -58,8 +58,8 @@ static __always_inline void unwind_init_from_caller(struct unwind_state *state)* duration of the unwind, or the unwind will be bogus. It is never valid to * call this for the current task. */ -static inline void unwind_init_from_task (struct unwind_state *state, -struct task_struct *task) +static __always_inline void unwind_init_from_task(struct unwind_state *state, +struct task_struct *task) {unwind_init_common (state, task);
@@ -186,7 +186,7 @@ void show_stack(struct task_struct *tsk, unsigned long *sp, const char *loglvl) : stackinfo_get_unknown(); \ }) -noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, +noinline noinstr void arch_stack_walk(stack_trace_consume_fn consume_entry,void *cookie,struct task_struct *task,struct pt_regs *regs) {
Re: [PATCH v2 1/3] arm64: Prohibit instrumentation on arch_stack_walk()
Quoted 6 lines · Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) <[email protected]>
Mark
arch_stack_walk()as noinstr instead of notrace and inline functions called fromarch_stack_walk()as__always_inlineso that user does not put any instrumentations on it, because this function can be used fromreturn_address()which is used by lockdep.
Hmmm... since arch_stack_walk is marked as notrace, that will be prohibited by default unless the kernel was built with CONFIG_KPROBE_EVENTS_ON_NOTRACE=y, and the commit message for that says:
│ This option disables such protection and allows you to put kprobe │ │ events on ftrace functions for debugging ftrace by itself. │ │ Note that this might let you shoot yourself in the foot.
... and IIUC we generally don't expect people to set that, and that might be worth calling out in the commit message.
Quoted 6 lines
Without this, if the kernel built with
CONFIG_LOCKDEP=y, just probingarch_stack_walk()via <tracefs>/kprobe_events will crash the kernel on arm64.# echo p arch_stack_walk >> ${TRACEFS}/kprobe_events # echo 1 > ${TRACEFS}/events/kprobes/enable
I had a go at testing this patch, and it fixes the crash with the reproducer above, but there are plenty of other instances in stacktrace.c that lead to the same sort of crash, e.g.
# echo p stackinfo_get_task >> ${TRACEFS}/kprobe_events
# echo 1 > ${TRACEFS}/events/kprobes/enable... so I think there's more that we need to do to fix this generally.
Note: I found interesting functions to try tracing by looking at the output of:
aarch64-linux-objdump -t arch/arm64/kernel/stacktrace.o | grep -w '.text'
That all said, I think this patch is nice-to-have, and that we can address the other cases as a follow-up, so for this patch as-is (with or without some wording regarding CONFIG_KPROBE_EVENTS_ON_NOTRACE):
Mark.
Quoted 85 lines
kprobes: Failed to recover from reentered kprobes.
kprobes: Dump kprobe:
.symbol_name =arch_stack_walk, .offset = 0, .addr =arch_stack_walk+0x0/0x1c0------------[ cut here ]------------ kernel BUG at arch/arm64/kernel/probes/kprobes.c:241! kprobes: Failed to recover from reentered kprobes. kprobes: Dump kprobe: .symbol_name = arch_stack_walk, .offset = 0, .addr = arch_stack_walk+0x0/0x1c0 ------------[ cut here ]------------ kernel BUG at arch/arm64/kernel/probes/kprobes.c:241! PREEMPT SMP Modules linked in: CPU: 0 PID: 17 Comm: migration/0 Tainted: G N 6.1.0-rc5+ #6 Hardware name: linux,dummy-virt (DT) Stopper: 0x0 <- 0x0 pstate: 600003c5 (nZCv DAIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : kprobe_breakpoint_handler+0x178/0x17c lr : kprobe_breakpoint_handler+0x178/0x17c sp : ffff8000080d3090 x29: ffff8000080d3090 x28: ffff0df5845798c0 x27: ffffc4f59057a774 x26: ffff0df5ffbba770 x25: ffff0df58f420f18 x24: ffff49006f641000 x23: ffffc4f590579768 x22: ffff0df58f420f18 x21: ffff8000080d31c0 x20: ffffc4f590579768 x19: ffffc4f590579770 x18: 0000000000000006 x17: 5f6b636174735f68 x16: 637261203d207264 x15: 64612e202c30203d x14: 2074657366666f2e x13: 30633178302f3078 x12: 302b6b6c61775f6b x11: 636174735f686372 x10: ffffc4f590dc5bd8 x9 : ffffc4f58eb31958 x8 : 00000000ffffefff x7 : ffffc4f590dc5bd8 x6 : 80000000fffff000 x5 : 000000000000bff4 x4 : 0000000000000000 x3 : 0000000000000000 x2 : 0000000000000000 x1 : ffff0df5845798c0 x0 : 0000000000000064 Call trace: kprobes: Failed to recover from reentered kprobes. kprobes: Dump kprobe: .symbol_name = arch_stack_walk, .offset = 0, .addr = arch_stack_walk+0x0/0x1c0 ------------[ cut here ]------------ kernel BUG at arch/arm64/kernel/probes/kprobes.c:241!Fixes 39ef362d2d45 ("arm64: Make return_address() use arch_stack_walk()")Signed-off-by Masami Hiramatsu (Google) <[email protected]>---
Changes in v2:
- Use noinstr instead ofNOKPROBE_SYMBOL()
- Use__always_inlinebecausenokprobe_inlinewill be changed ifCONFIG_KPROBES=n.
- Fix indentation.--- arch/arm64/kernel/stacktrace.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)arch/arm64/kernel/stacktrace.c +5
-5@@ -23,8 +23,8 @@* * The regs must be on a stack currently owned by the calling task. */ -static inline void unwind_init_from_regs (struct unwind_state *state, -struct pt_regs *regs) +static __always_inline void unwind_init_from_regs(struct unwind_state *state, +struct pt_regs *regs) {unwind_init_common (state, current);@@ -58,8 +58,8 @@ static __always_inline void unwind_init_from_caller(struct unwind_state *state)* duration of the unwind, or the unwind will be bogus. It is never valid to * call this for the current task. */ -static inline void unwind_init_from_task (struct unwind_state *state, -struct task_struct *task) +static __always_inline void unwind_init_from_task(struct unwind_state *state, +struct task_struct *task) {unwind_init_common (state, task);@@ -186,7 +186,7 @@ void show_stack(struct task_struct *tsk, unsigned long *sp, const char *loglvl) : stackinfo_get_unknown(); \ }) -noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, +noinline noinstr void arch_stack_walk(stack_trace_consume_fn consume_entry,void *cookie,struct task_struct *task,struct pt_regs *regs) {
Re: [PATCH v2 1/3] arm64: Prohibit instrumentation on arch_stack_walk()
Quoted 12 lines · On Fri, 2 Dec 2022 13:17:30 +0000 Mark Rutland <[email protected]> wrote:
Quoted 6 lines · Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) <[email protected]>
Mark
arch_stack_walk()as noinstr instead of notrace and inline functions called fromarch_stack_walk()as__always_inlineso that user does not put any instrumentations on it, because this function can be used fromreturn_address()which is used by lockdep.Hmmm... since
arch_stack_walkis marked as notrace, that will be prohibited by default unless the kernel was built withCONFIG_KPROBE_EVENTS_ON_NOTRACE=y, and the commit message for that says:
Quoted 6 lines
│ This option disables such protection and allows you to put kprobe │ │ events on ftrace functions for debugging ftrace by itself. │ │ Note that this might let you shoot yourself in the foot.... and IIUC we generally don't expect people to set that, and that might be worth calling out in the commit message.
Yeah, but that is the feature for kprobe events, and not applied to the kprobes itself. Maybe I should use a test kprobe module to put a probe on it.
Quoted 8 lines
Quoted 7 lines
Without this, if the kernel built with
CONFIG_LOCKDEP=y, just probingarch_stack_walk()via <tracefs>/kprobe_events will crash the kernel on arm64.# echo p arch_stack_walk >> ${TRACEFS}/kprobe_events # echo 1 > ${TRACEFS}/events/kprobes/enable
Quoted 6 lines
I had a go at testing this patch, and it fixes the crash with the reproducer above, but there are plenty of other instances in
stacktrace.cthat lead to the same sort of crash, e.g.# echo p stackinfo_get_task >> ${TRACEFS}/kprobe_events # echo 1 > ${TRACEFS}/events/kprobes/enable
Oops, thanks for pointing! Hmm, I thought stackinfo_get_task() is an inlined function usually. Maybe we should make it nokprobe_inline. But this is just one case. I need to scan all symbols to trace...
Quoted 5 lines
... so I think there's more that we need to do to fix this generally.
Note: I found interesting functions to try tracing by looking at the output of:
Quoted 7 lines
aarch64-linux-objdump -t
arch/arm64/kernel/stacktrace.o| grep -w '.text'That all said, I think this patch is nice-to-have, and that we can address the other cases as a follow-up, so for this patch as-is (with or without some wording regarding
CONFIG_KPROBE_EVENTS_ON_NOTRACE):Acked-by Mark Rutland <[email protected]>
Thanks!
Quoted 88 lines
Mark.
Quoted 85 lines
kprobes: Failed to recover from reentered kprobes.
kprobes: Dump kprobe:
.symbol_name =arch_stack_walk, .offset = 0, .addr =arch_stack_walk+0x0/0x1c0------------[ cut here ]------------ kernel BUG at arch/arm64/kernel/probes/kprobes.c:241! kprobes: Failed to recover from reentered kprobes. kprobes: Dump kprobe: .symbol_name = arch_stack_walk, .offset = 0, .addr = arch_stack_walk+0x0/0x1c0 ------------[ cut here ]------------ kernel BUG at arch/arm64/kernel/probes/kprobes.c:241! PREEMPT SMP Modules linked in: CPU: 0 PID: 17 Comm: migration/0 Tainted: G N 6.1.0-rc5+ #6 Hardware name: linux,dummy-virt (DT) Stopper: 0x0 <- 0x0 pstate: 600003c5 (nZCv DAIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : kprobe_breakpoint_handler+0x178/0x17c lr : kprobe_breakpoint_handler+0x178/0x17c sp : ffff8000080d3090 x29: ffff8000080d3090 x28: ffff0df5845798c0 x27: ffffc4f59057a774 x26: ffff0df5ffbba770 x25: ffff0df58f420f18 x24: ffff49006f641000 x23: ffffc4f590579768 x22: ffff0df58f420f18 x21: ffff8000080d31c0 x20: ffffc4f590579768 x19: ffffc4f590579770 x18: 0000000000000006 x17: 5f6b636174735f68 x16: 637261203d207264 x15: 64612e202c30203d x14: 2074657366666f2e x13: 30633178302f3078 x12: 302b6b6c61775f6b x11: 636174735f686372 x10: ffffc4f590dc5bd8 x9 : ffffc4f58eb31958 x8 : 00000000ffffefff x7 : ffffc4f590dc5bd8 x6 : 80000000fffff000 x5 : 000000000000bff4 x4 : 0000000000000000 x3 : 0000000000000000 x2 : 0000000000000000 x1 : ffff0df5845798c0 x0 : 0000000000000064 Call trace: kprobes: Failed to recover from reentered kprobes. kprobes: Dump kprobe: .symbol_name = arch_stack_walk, .offset = 0, .addr = arch_stack_walk+0x0/0x1c0 ------------[ cut here ]------------ kernel BUG at arch/arm64/kernel/probes/kprobes.c:241!Fixes 39ef362d2d45 ("arm64: Make return_address() use arch_stack_walk()")Signed-off-by Masami Hiramatsu (Google) <[email protected]>---
Changes in v2:
- Use noinstr instead ofNOKPROBE_SYMBOL()
- Use__always_inlinebecausenokprobe_inlinewill be changed ifCONFIG_KPROBES=n.
- Fix indentation.--- arch/arm64/kernel/stacktrace.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)arch/arm64/kernel/stacktrace.c +5
-5@@ -23,8 +23,8 @@* * The regs must be on a stack currently owned by the calling task. */ -static inline void unwind_init_from_regs (struct unwind_state *state, -struct pt_regs *regs) +static __always_inline void unwind_init_from_regs(struct unwind_state *state, +struct pt_regs *regs) {unwind_init_common (state, current);@@ -58,8 +58,8 @@ static __always_inline void unwind_init_from_caller(struct unwind_state *state)* duration of the unwind, or the unwind will be bogus. It is never valid to * call this for the current task. */ -static inline void unwind_init_from_task (struct unwind_state *state, -struct task_struct *task) +static __always_inline void unwind_init_from_task(struct unwind_state *state, +struct task_struct *task) {unwind_init_common (state, task);@@ -186,7 +186,7 @@ void show_stack(struct task_struct *tsk, unsigned long *sp, const char *loglvl) : stackinfo_get_unknown(); \ }) -noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, +noinline noinstr void arch_stack_walk(stack_trace_consume_fn consume_entry,void *cookie,struct task_struct *task,struct pt_regs *regs) {
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Mark Rutland
reviewerRe: [PATCH v2 1/3] arm64: Prohibit instrumentation on arch_stack_walk()
Quoted 6 lines · Masami Hiramatsu
Quoted 4 lines · On Fri, 2 Dec 2022 13:17:30 +0000 Mark Rutland <[email protected]> wrote:
I had a go at testing this patch, and it fixes the crash with the reproducer above, but there are plenty of other instances in
stacktrace.cthat lead to the same sort of crash, e.g.
Quoted 6 lines
Quoted 2 lines
# echo p stackinfo_get_task >> ${TRACEFS}/kprobe_events # echo 1 > ${TRACEFS}/events/kprobes/enableOops, thanks for pointing! Hmm, I thought
stackinfo_get_task()is an inlined function usually. Maybe we should make itnokprobe_inline. But this is just one case. I need to scan all symbols to trace...
FWIW, due to other instrumentation issues I've started doing a larger noinstr cleanup on arm64 which should address this, as fixing this properly involves also modifying a bunch of underlying helpers (e.g. preempt_count()).
I can Cc you when sending that out, if you'd like? That'll probably be in the new year.
Thanks,
Mark.
Re: [PATCH v2 1/3] arm64: Prohibit instrumentation on arch_stack_walk()
Quoted 14 lines · On Fri, 9 Dec 2022 11:16:34 +0000 Mark Rutland <[email protected]> wrote:
Quoted 6 lines · Masami Hiramatsu
Quoted 4 lines · On Fri, 2 Dec 2022 13:17:30 +0000 Mark Rutland <[email protected]> wrote:
I had a go at testing this patch, and it fixes the crash with the reproducer above, but there are plenty of other instances in
stacktrace.cthat lead to the same sort of crash, e.g.Quoted 6 lines
Quoted 2 lines
# echo p stackinfo_get_task >> ${TRACEFS}/kprobe_events # echo 1 > ${TRACEFS}/events/kprobes/enableOops, thanks for pointing! Hmm, I thought
stackinfo_get_task()is an inlined function usually. Maybe we should make itnokprobe_inline. But this is just one case. I need to scan all symbols to trace...
Quoted 6 lines
FWIW, due to other instrumentation issues I've started doing a larger noinstr cleanup on arm64 which should address this, as fixing this properly involves also modifying a bunch of underlying helpers (e.g.
preempt_count()).I can Cc you when sending that out, if you'd like? That'll probably be in the new year.
Thanks Mark, yes, I'm interested in that work.
Until that, I'll finish making a script for testing kprobes widely on kernel symbols.
Thank you,
Quoted 3 lines
Thanks,
Mark.
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
PATCH v2 2/3 arm64: kprobes: Let arch do_page_fault() fix up page fault in user handler
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
Since arm64's do_page_fault() can handle the page fault correctly than kprobe_fault_handler() according to the context, let it handle the page fault instead of simply call fixup_exception() in the kprobe_fault_handler().
--- arch/arm64/kernel/probes/kprobes.c | 8 -------- 1 file changed, 8 deletions(-)
arch/arm64/kernel/probes/kprobes.c +0 -8
@@ -294,14 +294,6 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr) }break ; -case KPROBE_HIT_ACTIVE : -case KPROBE_HIT_SSDONE : -/* -* In case the user-specified fault handler returned -* zero, try to fix up. -*/ -if (fixup_exception (regs)) -return 1 ; }return 0 ; }
PATCH v2 3/3 arm64: kprobes: Return DBG_HOOK_ERROR if kprobes can not handle a BRK
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
Return DBG_HOOK_ERROR if kprobes can not handle a BRK because it fails to find a kprobe corresponding to the address.
Since arm64 kprobes uses stop_machine based text patching for removing BRK, it ensures all running kprobe_break_handler() is done at that point. And after removing the BRK, it removes the kprobe from its hash list. Thus, if the kprobe_break_handler() fails to find kprobe from hash list, there is a bug.
---
Changes in v2:
- Update comments in the code.
--- arch/arm64/kernel/probes/kprobes.c | 78 +++++++++++++++++------------------- 1 file changed, 36 insertions(+), 42 deletions(-)
arch/arm64/kernel/probes/kprobes.c +36 -42
@@ -298,7 +298,8 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr)return 0 ; } -static void __kprobes kprobe_handler (struct pt_regs *regs) +static int __kprobes +kprobe_breakpoint_handler (struct pt_regs *regs,unsigned long esr) {struct kprobe *p, *cur_kprobe;struct kprobe_ctlblk *kcb;
@@ -308,39 +309,44 @@ static void __kprobes kprobe_handler(struct pt_regs *regs) cur_kprobe =kprobe_running (); p =get_kprobe ((kprobe_opcode_t *) addr); +if (WARN_ON_ONCE (!p)) { +/* +* Something went wrong. This BRK used an immediate reserved +* for kprobes, but we couldn't find any corresponding probe. +*/ +return DBG_HOOK_ERROR ; + } -if (p) { -if (cur_kprobe) { -if (reenter_kprobe (p, regs, kcb)) -return ; - }else { -/* Probe hit */ -set_current_kprobe (p); - kcb->kprobe_status =KPROBE_HIT_ACTIVE ; - -/* -* If we have no pre-handler or it returned 0, we -* continue with normal processing. If we have a -* pre-handler and it returned non-zero, it will -* modify the execution path and no need to single -* stepping. Let's just reset current kprobe and exit. -*/ -if (!p->pre_handler || !p->pre_handler (p, regs)) { -setup_singlestep (p, regs, kcb,0 ); - }else -reset_current_kprobe (); - } +if (cur_kprobe) { +/* Hit a kprobe inside another kprobe */ +if (!reenter_kprobe (p, regs, kcb)) +return DBG_HOOK_ERROR ; + }else { +/* Probe hit */ +set_current_kprobe (p); + kcb->kprobe_status =KPROBE_HIT_ACTIVE ; + +/* +* If we have no pre-handler or it returned 0, we +* continue with normal processing. If we have a +* pre-handler and it returned non-zero, it will +* modify the execution path and not need to single-step +* Let's just reset current kprobe and exit. +*/ +if (!p->pre_handler || !p->pre_handler (p, regs)) +setup_singlestep (p, regs, kcb,0 ); +else +reset_current_kprobe (); } -/* -* The breakpoint instruction was removed right -* after we hit it. Another cpu has removed -* either a probepoint or a debugger breakpoint -* at this address. In either case, no further -* handling of this interrupt is appropriate. -* Return back to original instruction, and continue. -*/ + +return DBG_HOOK_HANDLED ; } +static struct break_hook kprobes_break_hook = { + .imm =KPROBES_BRK_IMM , + .fn = kprobe_breakpoint_handler, +}; +static int __kprobes kprobe_breakpoint_ss_handler (struct pt_regs *regs,unsigned long esr) {
@@ -365,18 +371,6 @@ static struct break_hook kprobes_break_ss_hook = { .fn = kprobe_breakpoint_ss_handler, }; -static int __kprobes -kprobe_breakpoint_handler (struct pt_regs *regs,unsigned long esr) -{ -kprobe_handler (regs); -return DBG_HOOK_HANDLED ; -} - -static struct break_hook kprobes_break_hook = { - .imm =KPROBES_BRK_IMM , - .fn = kprobe_breakpoint_handler, -}; -/* * Provide a blacklist of symbols identifying ranges which cannot be kprobed. * This blacklist is exposed to userspace via debugfs (kprobes/blacklist).
Quoted 5 lines · Masami Hiramatsu (Google)
Here is the 2nd version of the kprobe bugfixes on arm64. The previous series is here;
https://lore.kernel.org/all/166990553243.253128.13594802750635478633.stgit@devnote3/T/#u
Quoted 8 lines
The first one is a critical issue, which will cause a kernel crach easily with lockdep[1/3]. Others are minor issues and rare cases. The [2/3] let
do_page_fault()fixup the page fault in kprobes user handler, and [3/3] is more like code cleanup and returnsDBG_HOOK_ERRORif it can not handle kprobe's BRK (but that should not happen.)[...]
Applied to arm64 (for-next/kprobes), thanks!
[1/3] arm64: Prohibit instrumentation on arch_stack_walk()
https://git.kernel.org/arm64/c/0fbcd8abf337 [2/3] arm64: kprobes: Let arch do_page_fault() fix up page fault in user handler https://git.kernel.org/arm64/c/30a421552373 [3/3] arm64: kprobes: Return DBG_HOOK_ERROR if kprobes can not handle a BRK https://git.kernel.org/arm64/c/3b84efc066f8
Cheers,
Signature · 5 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev