* [PATCH v3 1/4] arm64: kprobes: Move extable address check into arch_prepare_kprobe()
2019-02-12 15:42 [PATCH v3 0/4] arm64: kprobes: Update blacklist checking on arm64 Masami Hiramatsu
@ 2019-02-12 15:43 ` Masami Hiramatsu
2019-02-12 15:43 ` [PATCH v3 2/4] arm64: kprobes: Remove unneeded RODATA check Masami Hiramatsu
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2019-02-12 15:43 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon
Cc: Pratyush Anand, linux-kernel, James Morse, Masami Hiramatsu,
linux-arm-kernel, David A . Long
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().
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Reviewed-by: James Morse <james.morse@arm.com>
---
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(-)
diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
index f17afb99890c..9989ec9baa11 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -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()) {
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3 2/4] arm64: kprobes: Remove unneeded RODATA check
2019-02-12 15:42 [PATCH v3 0/4] arm64: kprobes: Update blacklist checking on arm64 Masami Hiramatsu
2019-02-12 15:43 ` [PATCH v3 1/4] arm64: kprobes: Move extable address check into arch_prepare_kprobe() Masami Hiramatsu
@ 2019-02-12 15:43 ` Masami Hiramatsu
2019-02-12 15:44 ` [PATCH v3 3/4] arm64: kprobes: Move exception_text check in blacklist Masami Hiramatsu
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2019-02-12 15:43 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon
Cc: Pratyush Anand, linux-kernel, James Morse, Masami Hiramatsu,
linux-arm-kernel, David A . Long
Remove 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.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
arch/arm64/kernel/probes/kprobes.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
index 9989ec9baa11..bd06b4b13fa9 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -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 */
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3 3/4] arm64: kprobes: Move exception_text check in blacklist
2019-02-12 15:42 [PATCH v3 0/4] arm64: kprobes: Update blacklist checking on arm64 Masami Hiramatsu
2019-02-12 15:43 ` [PATCH v3 1/4] arm64: kprobes: Move extable address check into arch_prepare_kprobe() Masami Hiramatsu
2019-02-12 15:43 ` [PATCH v3 2/4] arm64: kprobes: Remove unneeded RODATA check Masami Hiramatsu
@ 2019-02-12 15:44 ` Masami Hiramatsu
2019-02-12 15:44 ` [PATCH v3 4/4] arm64: kprobes: Use arch_populate_kprobe_blacklist() Masami Hiramatsu
2019-02-15 17:46 ` [PATCH v3 0/4] arm64: kprobes: Update blacklist checking on arm64 Catalin Marinas
4 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2019-02-12 15:44 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon
Cc: Pratyush Anand, linux-kernel, James Morse, Masami Hiramatsu,
linux-arm-kernel, David A . Long
Move 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.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
arch/arm64/kernel/probes/kprobes.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
index bd06b4b13fa9..194262fca5cd 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -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()) {
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3 4/4] arm64: kprobes: Use arch_populate_kprobe_blacklist()
2019-02-12 15:42 [PATCH v3 0/4] arm64: kprobes: Update blacklist checking on arm64 Masami Hiramatsu
` (2 preceding siblings ...)
2019-02-12 15:44 ` [PATCH v3 3/4] arm64: kprobes: Move exception_text check in blacklist Masami Hiramatsu
@ 2019-02-12 15:44 ` Masami Hiramatsu
2019-02-14 15:55 ` Will Deacon
2019-02-15 17:46 ` [PATCH v3 0/4] arm64: kprobes: Update blacklist checking on arm64 Catalin Marinas
4 siblings, 1 reply; 8+ messages in thread
From: Masami Hiramatsu @ 2019-02-12 15:44 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon
Cc: Pratyush Anand, linux-kernel, James Morse, Masami Hiramatsu,
linux-arm-kernel, David A . Long
Use arch_populate_kprobe_blacklist() instead of
arch_within_kprobe_blacklist() so that we can see the full
blacklisted symbols under the debugfs.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
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(-)
diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
index 194262fca5cd..37d913f33a89 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -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)
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v3 4/4] arm64: kprobes: Use arch_populate_kprobe_blacklist()
2019-02-12 15:44 ` [PATCH v3 4/4] arm64: kprobes: Use arch_populate_kprobe_blacklist() Masami Hiramatsu
@ 2019-02-14 15:55 ` Will Deacon
2019-02-15 15:00 ` Masami Hiramatsu
0 siblings, 1 reply; 8+ messages in thread
From: Will Deacon @ 2019-02-14 15:55 UTC (permalink / raw)
To: Masami Hiramatsu
Cc: Pratyush Anand, Catalin Marinas, linux-kernel, James Morse,
David A . Long, linux-arm-kernel
Hi Masami,
On Wed, Feb 13, 2019 at 12:44:48AM +0900, Masami Hiramatsu wrote:
> Use arch_populate_kprobe_blacklist() instead of
> arch_within_kprobe_blacklist() so that we can see the full
> blacklisted symbols under the debugfs.
>
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
> 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(-)
>
> diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
> index 194262fca5cd..37d913f33a89 100644
> --- a/arch/arm64/kernel/probes/kprobes.c
> +++ b/arch/arm64/kernel/probes/kprobes.c
> @@ -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:
Acked-by: Will Deacon <will.deacon@arm.com>
Catalin -- can you pick these up with that comment added, please?
Cheers,
Will
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 4/4] arm64: kprobes: Use arch_populate_kprobe_blacklist()
2019-02-14 15:55 ` Will Deacon
@ 2019-02-15 15:00 ` Masami Hiramatsu
0 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2019-02-15 15:00 UTC (permalink / raw)
To: Will Deacon
Cc: Pratyush Anand, Catalin Marinas, linux-kernel, James Morse,
David A . Long, linux-arm-kernel
On Thu, 14 Feb 2019 15:55:22 +0000
Will Deacon <will.deacon@arm.com> wrote:
> Hi Masami,
>
> On Wed, Feb 13, 2019 at 12:44:48AM +0900, Masami Hiramatsu wrote:
> > Use arch_populate_kprobe_blacklist() instead of
> > arch_within_kprobe_blacklist() so that we can see the full
> > blacklisted symbols under the debugfs.
> >
> > Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> > ---
> > 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(-)
> >
> > diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
> > index 194262fca5cd..37d913f33a89 100644
> > --- a/arch/arm64/kernel/probes/kprobes.c
> > +++ b/arch/arm64/kernel/probes/kprobes.c
> > @@ -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).
> */
Agreed. This looks good to me too.
>
> With that, you can have my ack for the series:
>
> Acked-by: Will Deacon <will.deacon@arm.com>
Thank you!
>
> Catalin -- can you pick these up with that comment added, please?
>
> Cheers,
>
> Will
--
Masami Hiramatsu <mhiramat@kernel.org>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 0/4] arm64: kprobes: Update blacklist checking on arm64
2019-02-12 15:42 [PATCH v3 0/4] arm64: kprobes: Update blacklist checking on arm64 Masami Hiramatsu
` (3 preceding siblings ...)
2019-02-12 15:44 ` [PATCH v3 4/4] arm64: kprobes: Use arch_populate_kprobe_blacklist() Masami Hiramatsu
@ 2019-02-15 17:46 ` Catalin Marinas
4 siblings, 0 replies; 8+ messages in thread
From: Catalin Marinas @ 2019-02-15 17:46 UTC (permalink / raw)
To: Masami Hiramatsu
Cc: Pratyush Anand, Will Deacon, linux-kernel, James Morse,
David A . Long, linux-arm-kernel
Hi Masami,
On Wed, Feb 13, 2019 at 12:42:53AM +0900, Masami Hiramatsu wrote:
> 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.
--
Catalin
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 8+ messages in thread