* [PATCH v2] kretprobe: avoid re-registration of the same kretprobe earlier
@ 2021-01-28 12:44 Wang ShaoBo
2021-01-28 18:06 ` Steven Rostedt
[not found] ` <20210129095347.GD117@DESKTOP-TDPLP67.localdomain>
0 siblings, 2 replies; 4+ messages in thread
From: Wang ShaoBo @ 2021-01-28 12:44 UTC (permalink / raw)
Cc: cj.chengjian, huawei.libin, xiexiuqi, bobo.shaobowang, rostedt,
naveen.n.rao, anil.s.keshavamurthy, davem, linux-kernel
Our system encountered a re-init error when re-registering same kretprobe,
where the kretprobe_instance in rp->free_instances is illegally accessed
after re-init.
Implementation to avoid re-registration has been introduced for kprobe
before, but lags for register_kretprobe(). We must check if kprobe has
been re-registered before re-initializing kretprobe, otherwise it will
destroy the data struct of kretprobe registered, which can lead to memory
leak, system crash, also some unexpected behaviors.
We use check_kprobe_rereg() to check if kprobe has been re-registered
before running register_kretprobe()'s body, for giving a warning message
and terminate registration process.
Signed-off-by: Wang ShaoBo <bobo.shaobowang@huawei.com>
Signed-off-by: Cheng Jian <cj.chengjian@huawei.com>
---
kernel/kprobes.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index f7fb5d135930..5c4a884953e9 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1978,6 +1978,10 @@ int register_kretprobe(struct kretprobe *rp)
if (!kprobe_on_func_entry(rp->kp.addr, rp->kp.symbol_name, rp->kp.offset))
return -EINVAL;
+ /* If only rp->kp.addr is specified, check reregistering kprobes */
+ if (rp->kp.addr && check_kprobe_rereg(&rp->kp))
+ return -EINVAL;
+
if (kretprobe_blacklist_size) {
addr = kprobe_addr(&rp->kp);
if (IS_ERR(addr))
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] kretprobe: avoid re-registration of the same kretprobe earlier
2021-01-28 12:44 [PATCH v2] kretprobe: avoid re-registration of the same kretprobe earlier Wang ShaoBo
@ 2021-01-28 18:06 ` Steven Rostedt
[not found] ` <20210129222947.f873666f4e6110c62b7439f1@kernel.org>
[not found] ` <20210129095347.GD117@DESKTOP-TDPLP67.localdomain>
1 sibling, 1 reply; 4+ messages in thread
From: Steven Rostedt @ 2021-01-28 18:06 UTC (permalink / raw)
To: Wang ShaoBo, Masami Hiramatsu
Cc: cj.chengjian, huawei.libin, xiexiuqi, naveen.n.rao,
anil.s.keshavamurthy, davem, linux-kernel
Masami,
Care to review?
Thanks!
-- Steve
On Thu, 28 Jan 2021 20:44:27 +0800
Wang ShaoBo <bobo.shaobowang@huawei.com> wrote:
> Our system encountered a re-init error when re-registering same kretprobe,
> where the kretprobe_instance in rp->free_instances is illegally accessed
> after re-init.
>
> Implementation to avoid re-registration has been introduced for kprobe
> before, but lags for register_kretprobe(). We must check if kprobe has
> been re-registered before re-initializing kretprobe, otherwise it will
> destroy the data struct of kretprobe registered, which can lead to memory
> leak, system crash, also some unexpected behaviors.
>
> We use check_kprobe_rereg() to check if kprobe has been re-registered
> before running register_kretprobe()'s body, for giving a warning message
> and terminate registration process.
>
> Signed-off-by: Wang ShaoBo <bobo.shaobowang@huawei.com>
> Signed-off-by: Cheng Jian <cj.chengjian@huawei.com>
> ---
> kernel/kprobes.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index f7fb5d135930..5c4a884953e9 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -1978,6 +1978,10 @@ int register_kretprobe(struct kretprobe *rp)
> if (!kprobe_on_func_entry(rp->kp.addr, rp->kp.symbol_name, rp->kp.offset))
> return -EINVAL;
>
> + /* If only rp->kp.addr is specified, check reregistering kprobes */
> + if (rp->kp.addr && check_kprobe_rereg(&rp->kp))
> + return -EINVAL;
> +
> if (kretprobe_blacklist_size) {
> addr = kprobe_addr(&rp->kp);
> if (IS_ERR(addr))
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] kretprobe: avoid re-registration of the same kretprobe earlier
[not found] ` <20210129095347.GD117@DESKTOP-TDPLP67.localdomain>
@ 2021-01-29 16:28 ` Steven Rostedt
0 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2021-01-29 16:28 UTC (permalink / raw)
To: Naveen N. Rao
Cc: Wang ShaoBo, cj.chengjian, huawei.libin, xiexiuqi, naveen.n.rao,
anil.s.keshavamurthy, davem, linux-kernel, ananth
On Fri, 29 Jan 2021 15:23:47 +0530
"Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> wrote:
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index f7fb5d135930fa..63a36f33565354 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -1530,6 +1530,7 @@ static inline int check_kprobe_rereg(struct kprobe *p)
> ret = -EINVAL;
> mutex_unlock(&kprobe_mutex);
>
> + WARN_ON(ret);
> return ret;
> }
Please use WARN_ON_ONCE(ret);
Thanks,
-- Steve
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] kretprobe: avoid re-registration of the same kretprobe earlier
[not found] ` <20210129222947.f873666f4e6110c62b7439f1@kernel.org>
@ 2021-01-29 16:29 ` Steven Rostedt
0 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2021-01-29 16:29 UTC (permalink / raw)
To: Masami Hiramatsu
Cc: Wang ShaoBo, cj.chengjian, huawei.libin, xiexiuqi, naveen.n.rao,
anil.s.keshavamurthy, davem, linux-kernel
On Fri, 29 Jan 2021 22:29:47 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:
> I'll send a patch over this to replace those check with WARN_ON() since
> it's a software bug and should be fixed.
Please use WARN_ON_ONCE()
Thanks!
-- Steve
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-01-29 16:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-28 12:44 [PATCH v2] kretprobe: avoid re-registration of the same kretprobe earlier Wang ShaoBo
2021-01-28 18:06 ` Steven Rostedt
[not found] ` <20210129222947.f873666f4e6110c62b7439f1@kernel.org>
2021-01-29 16:29 ` Steven Rostedt
[not found] ` <20210129095347.GD117@DESKTOP-TDPLP67.localdomain>
2021-01-29 16:28 ` 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.