linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kprobes: Warn if the kprobe is reregistered
@ 2021-02-03 14:59 Masami Hiramatsu
  2021-02-04  6:55 ` Naveen N . Rao
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2021-02-03 14:59 UTC (permalink / raw)
  To: Ingo Molnar, Steven Rostedt
  Cc: Naveen N . Rao, Ananth N Mavinakayanahalli, Wang ShaoBo,
	Cheng Jian, linux-kernel, mhiramat

Warn if the kprobe is reregistered, since there must be
a software bug (actively used resource must not be re-registered)
and caller must be fixed.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/kprobes.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index d5a3eb74a657..dd1d027455c4 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1520,13 +1520,16 @@ static struct kprobe *__get_valid_kprobe(struct kprobe *p)
 	return ap;
 }
 
-/* Return error if the kprobe is being re-registered */
-static inline int check_kprobe_rereg(struct kprobe *p)
+/*
+ * Warn and return error if the kprobe is being re-registered since
+ * there must be a software bug.
+ */
+static inline int warn_kprobe_rereg(struct kprobe *p)
 {
 	int ret = 0;
 
 	mutex_lock(&kprobe_mutex);
-	if (__get_valid_kprobe(p))
+	if (WARN_ON_ONCE(__get_valid_kprobe(p)))
 		ret = -EINVAL;
 	mutex_unlock(&kprobe_mutex);
 
@@ -1614,7 +1617,7 @@ int register_kprobe(struct kprobe *p)
 		return PTR_ERR(addr);
 	p->addr = addr;
 
-	ret = check_kprobe_rereg(p);
+	ret = warn_kprobe_rereg(p);
 	if (ret)
 		return ret;
 
@@ -1995,7 +1998,7 @@ int register_kretprobe(struct kretprobe *rp)
 		return ret;
 
 	/* If only rp->kp.addr is specified, check reregistering kprobes */
-	if (rp->kp.addr && check_kprobe_rereg(&rp->kp))
+	if (rp->kp.addr && warn_kprobe_rereg(&rp->kp))
 		return -EINVAL;
 
 	if (kretprobe_blacklist_size) {


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

* Re: [PATCH] kprobes: Warn if the kprobe is reregistered
  2021-02-03 14:59 [PATCH] kprobes: Warn if the kprobe is reregistered Masami Hiramatsu
@ 2021-02-04  6:55 ` Naveen N . Rao
  2021-02-04  7:36 ` Ananth N Mavinakayanahalli
  2021-02-09 17:45 ` Steven Rostedt
  2 siblings, 0 replies; 4+ messages in thread
From: Naveen N . Rao @ 2021-02-04  6:55 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Ingo Molnar, Steven Rostedt, Ananth N Mavinakayanahalli,
	Wang ShaoBo, Cheng Jian, linux-kernel

On 2021/02/03 11:59PM, Masami Hiramatsu wrote:
> Warn if the kprobe is reregistered, since there must be
> a software bug (actively used resource must not be re-registered)
> and caller must be fixed.
> 
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
>  kernel/kprobes.c |   13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)

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


Thanks,
Naveen


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

* Re: [PATCH] kprobes: Warn if the kprobe is reregistered
  2021-02-03 14:59 [PATCH] kprobes: Warn if the kprobe is reregistered Masami Hiramatsu
  2021-02-04  6:55 ` Naveen N . Rao
@ 2021-02-04  7:36 ` Ananth N Mavinakayanahalli
  2021-02-09 17:45 ` Steven Rostedt
  2 siblings, 0 replies; 4+ messages in thread
From: Ananth N Mavinakayanahalli @ 2021-02-04  7:36 UTC (permalink / raw)
  To: Masami Hiramatsu, Ingo Molnar, Steven Rostedt
  Cc: Naveen N . Rao, Wang ShaoBo, Cheng Jian, linux-kernel

On 2/3/21 8:29 PM, Masami Hiramatsu wrote:
> Warn if the kprobe is reregistered, since there must be
> a software bug (actively used resource must not be re-registered)
> and caller must be fixed.
> 
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>

Acked-by: Ananth N Mavinakayanahalli <ananth@linux.ibm.com>

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

* Re: [PATCH] kprobes: Warn if the kprobe is reregistered
  2021-02-03 14:59 [PATCH] kprobes: Warn if the kprobe is reregistered Masami Hiramatsu
  2021-02-04  6:55 ` Naveen N . Rao
  2021-02-04  7:36 ` Ananth N Mavinakayanahalli
@ 2021-02-09 17:45 ` Steven Rostedt
  2 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2021-02-09 17:45 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Ingo Molnar, Naveen N . Rao, Ananth N Mavinakayanahalli,
	Wang ShaoBo, Cheng Jian, linux-kernel

On Wed,  3 Feb 2021 23:59:27 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> Warn if the kprobe is reregistered, since there must be
> a software bug (actively used resource must not be re-registered)
> and caller must be fixed.
> 
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---

Applied. Thanks Masami!

-- Steve

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

end of thread, other threads:[~2021-02-09 18:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-03 14:59 [PATCH] kprobes: Warn if the kprobe is reregistered Masami Hiramatsu
2021-02-04  6:55 ` Naveen N . Rao
2021-02-04  7:36 ` Ananth N Mavinakayanahalli
2021-02-09 17:45 ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).