arm64: kprobes: Update blacklist checking on arm64
v3 cover arm64: kprobes: Update blacklist checking on arm64
Hello,
Here is the v3 series of update of the kprobe blacklist checking on arm64.
I found that some blacklist checking code were mis-placed in arch_prepare_kprobe() and arch_within_kprobe_blacklist(). Since the blacklist just filters by symbol, smaller than the symbol, like extable must be checked in arch_prepare_kprobe(). Also, all function (symbol) level check must be done by blacklist.
For arm64, it checks the extable entry address in blacklist and exception/irqentry function in arch_prepare_kprobe(). And, RODATA check is unneeded since kernel/kprobes.c already ensures the probe address is in kernel-text area.
In v3, I rebased on the latest arm64 kernel which includes James' KVM/HYP fixes for kprobes, and fix a reported bugs in [4/4].
Changes in v3:
- [4/4] Fixes to remove redundant blacklist of kprobe_text and add blacklist on exception_text.
Thank you,
---
Masami Hiramatsu (4):
arm64: kprobes: Move extable address check into arch_prepare_kprobe()
arm64: kprobes: Remove unneeded RODATA check
arm64: kprobes: Move exception_text check in blacklist
arm64: kprobes: Use arch_populate_kprobe_blacklist()
arch/arm64/kernel/probes/kprobes.c | 52 +++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 25 deletions(-)
--
Masami Hiramatsu (Linaro) <[email protected]>
PATCH v3 1/4 arm64: kprobes: Move extable address check into arch_prepare_kprobe()
Move extable address check into arch_prepare_kprobe() from arch_within_kprobe_blacklist().
The blacklist is exposed via debugfs as a list of symbols. The extable entries are smaller, so must be filtered out by arch_prepare_kprobe().
---
Update in v2:
- Update commit message.
- Add Reviewed-by from James.
--- arch/arm64/kernel/probes/kprobes.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/arm64/kernel/probes/kprobes.c +5 -2
@@ -102,6 +102,10 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)if (in_exception_text (probe_addr))return -EINVAL ; + +if (search_exception_tables (probe_addr)) +return -EINVAL ; +if (probe_addr >= (unsigned long ) __start_rodata && probe_addr <= (unsigned long ) __end_rodata)return -EINVAL ;
@@ -479,8 +483,7 @@ bool arch_within_kprobe_blacklist(unsigned long addr) (addr >= (unsigned long )__idmap_text_start && addr < (unsigned long )__idmap_text_end) || (addr >= (unsigned long )__hyp_text_start && - addr < (unsigned long )__hyp_text_end) || - !!search_exception_tables(addr)) + addr < (unsigned long)__hyp_text_end)) return true;if (!is_kernel_in_hyp_mode ()) {
PATCH v3 2/4 arm64: kprobes: Remove unneeded RODATA check
In reply to Masami HiramatsuRemove unneeded RODATA check from arch_prepare_kprobe().
Since check_kprobe_address_safe() already ensured that the probe address is in kernel text, we don't need to check whether the address in RODATA or not. That must be always false.
--- arch/arm64/kernel/probes/kprobes.c | 6 ------ 1 file changed, 6 deletions(-)
arch/arm64/kernel/probes/kprobes.c +0 -6
@@ -91,8 +91,6 @@ static void __kprobes arch_simulate_insn(struct kprobe *p, struct pt_regs *regs)int __kprobes arch_prepare_kprobe (struct kprobe *p) {unsigned long probe_addr = (unsigned long )p->addr; -extern char __start_rodata[]; -extern char __end_rodata[];if (probe_addr &0x3 )return -EINVAL ;
@@ -106,10 +104,6 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)if (search_exception_tables (probe_addr))return -EINVAL ; -if (probe_addr >= (unsigned long ) __start_rodata && - probe_addr <= (unsigned long ) __end_rodata) -return -EINVAL ; -/* decode instruction */ switch (arm_kprobe_decode_insn (p->addr, &p->ainsn)) {case INSN_REJECTED :/* insn not supported */
PATCH v3 3/4 arm64: kprobes: Move exception_text check in blacklist
In reply to Masami HiramatsuMove exception/irqentry text address check in blacklist, since those are symbol based rejection.
If we prohibit probing on the symbols in exception_text, those should be blacklisted.
--- arch/arm64/kernel/probes/kprobes.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
arch/arm64/kernel/probes/kprobes.c +2 -4
@@ -98,9 +98,6 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)/* copy instruction */ p->opcode =le32_to_cpu (*p->addr); -if (in_exception_text (probe_addr)) -return -EINVAL ; -if (search_exception_tables (probe_addr))return -EINVAL ;
@@ -477,7 +474,8 @@ bool arch_within_kprobe_blacklist(unsigned long addr) (addr >= (unsigned long )__idmap_text_start && addr < (unsigned long )__idmap_text_end) || (addr >= (unsigned long )__hyp_text_start && - addr < (unsigned long)__hyp_text_end)) + addr < (unsigned long )__hyp_text_end) || + in_exception_text(addr)) return true;if (!is_kernel_in_hyp_mode ()) {
PATCH v3 4/4 arm64: kprobes: Use arch_populate_kprobe_blacklist()
In reply to Masami HiramatsuUse arch_populate_kprobe_blacklist() instead of arch_within_kprobe_blacklist() so that we can see the full blacklisted symbols under the debugfs.
---
Changes in v3
- Do not populate blacklist in __kprobe_text in arch_populate_kprobe_blacklist(), since it is already populated in populate_kprobe_blacklist().
- Add exception entry text blacklist since those are rejected by in_exception_text().
--- arch/arm64/kernel/probes/kprobes.c | 45 +++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 19 deletions(-)
arch/arm64/kernel/probes/kprobes.c +26 -19
@@ -465,26 +465,33 @@ kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr)return DBG_HOOK_HANDLED ; } -bool arch_within_kprobe_blacklist (unsigned long addr) +int __init arch_populate_kprobe_blacklist (void ) { -if ((addr >= (unsigned long )__kprobes_text_start && - addr < (unsigned long )__kprobes_text_end) || - (addr >= (unsigned long )__entry_text_start && - addr < (unsigned long )__entry_text_end) || - (addr >= (unsigned long )__idmap_text_start && - addr < (unsigned long )__idmap_text_end) || - (addr >= (unsigned long )__hyp_text_start && - addr < (unsigned long )__hyp_text_end) || -in_exception_text (addr)) -return true; - -if (!is_kernel_in_hyp_mode ()) { -if ((addr >= (unsigned long )__hyp_idmap_text_start && - addr < (unsigned long )__hyp_idmap_text_end)) -return true; - } - -return false; +int ret; + + ret =kprobe_add_area_blacklist ((unsigned long )__entry_text_start, + (unsigned long )__entry_text_end); +if (ret) +return ret; + ret =kprobe_add_area_blacklist ((unsigned long )__irqentry_text_start, + (unsigned long )__irqentry_text_end); +if (ret) +return ret; + ret =kprobe_add_area_blacklist ((unsigned long )__exception_text_start, + (unsigned long )__exception_text_end); +if (ret) +return ret; + ret =kprobe_add_area_blacklist ((unsigned long )__idmap_text_start, + (unsigned long )__idmap_text_end); +if (ret) +return ret; + ret =kprobe_add_area_blacklist ((unsigned long )__hyp_text_start, + (unsigned long )__hyp_text_end); +if (ret ||is_kernel_in_hyp_mode ()) +return ret; + ret =kprobe_add_area_blacklist ((unsigned long )__hyp_idmap_text_start, + (unsigned long )__hyp_idmap_text_end); +return ret; }void __kprobes __used *trampoline_probe_handler (struct pt_regs *regs)
Re: [PATCH v3 4/4] arm64: kprobes: Use arch_populate_kprobe_blacklist()
Hi Masami,
Quoted 21 lines · Masami Hiramatsu
Use
arch_populate_kprobe_blacklist()instead ofarch_within_kprobe_blacklist()so that we can see the full blacklisted symbols under the debugfs.Signed-off-by Masami Hiramatsu <[email protected]>---
Changes in v3
- Do not populate blacklist in__kprobe_textinarch_populate_kprobe_blacklist(), since it is already populated inpopulate_kprobe_blacklist().
- Add exception entry text blacklist since those are rejected byin_exception_text().--- arch/arm64/kernel/probes/kprobes.c | 45 +++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 19 deletions(-)arch/arm64/kernel/probes/kprobes.c +0
-0
arch/arm64/kernel/probes/kprobes.c kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr) · line 468
Quoted 4 lines
arch/arm64/kernel/probes/kprobes.c +0
-1@@ -465,26 +465,33 @@ kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr)return DBG_HOOK_HANDLED ; } -bool arch_within_kprobe_blacklist (unsigned long addr)
I think it would be useful to add a comment here so that we remember why this code is the way it is:
/*
* Provide a blacklist of symbols identifying ranges which cannot be kprobed.
* This blacklist is exposed to userspace via debugfs (kprobes/blacklist). */
With that, you can have my ack for the series:
Catalin -- can you pick these up with that comment added, please?
Cheers,
Will
Re: [PATCH v3 4/4] arm64: kprobes: Use arch_populate_kprobe_blacklist()
Quoted 32 lines · On Thu, 14 Feb 2019 15:55:22 +0000 Will Deacon <[email protected]> wrote:
Hi Masami,
Quoted 21 lines · Masami Hiramatsu
Use
arch_populate_kprobe_blacklist()instead ofarch_within_kprobe_blacklist()so that we can see the full blacklisted symbols under the debugfs.Signed-off-by Masami Hiramatsu <[email protected]>---
Changes in v3
- Do not populate blacklist in__kprobe_textinarch_populate_kprobe_blacklist(), since it is already populated inpopulate_kprobe_blacklist().
- Add exception entry text blacklist since those are rejected byin_exception_text().--- arch/arm64/kernel/probes/kprobes.c | 45 +++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 19 deletions(-)arch/arm64/kernel/probes/kprobes.c +0
-0arch/arm64/kernel/probes/kprobes.c kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr) · line 468
Quoted 4 lines
arch/arm64/kernel/probes/kprobes.c +0
-1@@ -465,26 +465,33 @@ kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr)return DBG_HOOK_HANDLED ; } -bool arch_within_kprobe_blacklist (unsigned long addr)I think it would be useful to add a comment here so that we remember why this code is the way it is:
Quoted 4 lines
/*
* Provide a blacklist of symbols identifying ranges which cannot be kprobed.
* This blacklist is exposed to userspace via debugfs (kprobes/blacklist). */
Agreed. This looks good to me too.
Quoted 4 lines
With that, you can have my ack for the series:
Acked-by Will Deacon <[email protected]>
Thank you!
Quoted 6 lines
Catalin -- can you pick these up with that comment added, please?
Cheers,
Will
Signature · 1 line
Masami Hiramatsu <[email protected]>
Catalin Marinas
maintainerHi Masami,
Quoted 3 lines · Masami Hiramatsu
In v3, I rebased on the latest arm64 kernel which includes James' KVM/HYP fixes for kprobes, and fix a reported bugs in [4/4].
I will queue this patches at 5.1-rc1 since the arm64 for-next/core branch is currently based on -rc3 and does not include James' fix. Even if I rebased your patches on top of -rc3, we'd still get a conflict when pushing into mainline, so I'd rather send them after -rc1.
Thanks.
Signature · 1 line
Catalin