All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -tip v2] kprobes: Prohibit probing on BUG() and WARN() address
@ 2019-09-03 11:08 Masami Hiramatsu
  2019-09-04  9:13 ` Naveen N. Rao
  2019-09-04 12:29 ` Steven Rostedt
  0 siblings, 2 replies; 3+ messages in thread
From: Masami Hiramatsu @ 2019-09-03 11:08 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Steven Rostedt, Masami Hiramatsu, Naveen N . Rao,
	Anil S Keshavamurthy, David S . Miller, linux-kernel

Since BUG() and WARN() may use a trap (e.g. UD2 on x86) to
get the address where the BUG() has occurred, kprobes can not
do single-step out-of-line that instruction. So prohibit
probing on such address.

Without this fix, if someone put a kprobe on WARN(), the
kernel will crash with invalid opcode error instead of
outputing warning message, because kernel can not find
correct bug address.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
  Changes in v2:
   - Add find_bug() stub function for !CONFIG_GENERIC_BUG
   - Cast the p->addr to unsigned long.
---
 include/linux/bug.h |    5 +++++
 kernel/kprobes.c    |    3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/bug.h b/include/linux/bug.h
index fe5916550da8..f639bd0122f3 100644
--- a/include/linux/bug.h
+++ b/include/linux/bug.h
@@ -47,6 +47,11 @@ void generic_bug_clear_once(void);
 
 #else	/* !CONFIG_GENERIC_BUG */
 
+static inline void *find_bug(unsigned long bugaddr)
+{
+	return NULL;
+}
+
 static inline enum bug_trap_type report_bug(unsigned long bug_addr,
 					    struct pt_regs *regs)
 {
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 452151e79535..5bdf47190f09 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1514,7 +1514,8 @@ static int check_kprobe_address_safe(struct kprobe *p,
 	/* Ensure it is not in reserved area nor out of text */
 	if (!kernel_text_address((unsigned long) p->addr) ||
 	    within_kprobe_blacklist((unsigned long) p->addr) ||
-	    jump_label_text_reserved(p->addr, p->addr)) {
+	    jump_label_text_reserved(p->addr, p->addr) ||
+	    find_bug((unsigned long) p->addr)) {
 		ret = -EINVAL;
 		goto out;
 	}


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

* Re: [PATCH -tip v2] kprobes: Prohibit probing on BUG() and WARN() address
  2019-09-03 11:08 [PATCH -tip v2] kprobes: Prohibit probing on BUG() and WARN() address Masami Hiramatsu
@ 2019-09-04  9:13 ` Naveen N. Rao
  2019-09-04 12:29 ` Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Naveen N. Rao @ 2019-09-04  9:13 UTC (permalink / raw)
  To: Masami Hiramatsu, Ingo Molnar
  Cc: Anil S Keshavamurthy, David S . Miller, linux-kernel, Steven Rostedt

Masami Hiramatsu wrote:
> Since BUG() and WARN() may use a trap (e.g. UD2 on x86) to
> get the address where the BUG() has occurred, kprobes can not
> do single-step out-of-line that instruction. So prohibit
> probing on such address.
> 
> Without this fix, if someone put a kprobe on WARN(), the
> kernel will crash with invalid opcode error instead of
> outputing warning message, because kernel can not find
> correct bug address.
> 
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
>   Changes in v2:
>    - Add find_bug() stub function for !CONFIG_GENERIC_BUG
>    - Cast the p->addr to unsigned long.
> ---
>  include/linux/bug.h |    5 +++++
>  kernel/kprobes.c    |    3 ++-
>  2 files changed, 7 insertions(+), 1 deletion(-)

Acked-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>

- Naveen


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

* Re: [PATCH -tip v2] kprobes: Prohibit probing on BUG() and WARN() address
  2019-09-03 11:08 [PATCH -tip v2] kprobes: Prohibit probing on BUG() and WARN() address Masami Hiramatsu
  2019-09-04  9:13 ` Naveen N. Rao
@ 2019-09-04 12:29 ` Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2019-09-04 12:29 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Ingo Molnar, Naveen N . Rao, Anil S Keshavamurthy,
	David S . Miller, linux-kernel

On Tue,  3 Sep 2019 20:08:21 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> Since BUG() and WARN() may use a trap (e.g. UD2 on x86) to
> get the address where the BUG() has occurred, kprobes can not
> do single-step out-of-line that instruction. So prohibit
> probing on such address.
> 
> Without this fix, if someone put a kprobe on WARN(), the
> kernel will crash with invalid opcode error instead of
> outputing warning message, because kernel can not find
> correct bug address.
> 
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>

Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve

> ---
>   Changes in v2:
>    - Add find_bug() stub function for !CONFIG_GENERIC_BUG
>    - Cast the p->addr to unsigned long.
> ---
>  include/linux/bug.h |    5 +++++
>  kernel/kprobes.c    |    3 ++-
>  2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/bug.h b/include/linux/bug.h
> index fe5916550da8..f639bd0122f3 100644
> --- a/include/linux/bug.h
> +++ b/include/linux/bug.h
> @@ -47,6 +47,11 @@ void generic_bug_clear_once(void);
>  
>  #else	/* !CONFIG_GENERIC_BUG */
>  
> +static inline void *find_bug(unsigned long bugaddr)
> +{
> +	return NULL;
> +}
> +
>  static inline enum bug_trap_type report_bug(unsigned long bug_addr,
>  					    struct pt_regs *regs)
>  {
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 452151e79535..5bdf47190f09 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -1514,7 +1514,8 @@ static int check_kprobe_address_safe(struct kprobe *p,
>  	/* Ensure it is not in reserved area nor out of text */
>  	if (!kernel_text_address((unsigned long) p->addr) ||
>  	    within_kprobe_blacklist((unsigned long) p->addr) ||
> -	    jump_label_text_reserved(p->addr, p->addr)) {
> +	    jump_label_text_reserved(p->addr, p->addr) ||
> +	    find_bug((unsigned long) p->addr)) {
>  		ret = -EINVAL;
>  		goto out;
>  	}


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

end of thread, other threads:[~2019-09-04 12:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-03 11:08 [PATCH -tip v2] kprobes: Prohibit probing on BUG() and WARN() address Masami Hiramatsu
2019-09-04  9:13 ` Naveen N. Rao
2019-09-04 12:29 ` Steven Rostedt

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.