Skip to content

Commit 0188b87

Browse files
Wang ShaoBorostedt
authored andcommitted
kretprobe: Avoid re-registration of the same kretprobe earlier
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. Link: https://lkml.kernel.org/r/[email protected] Cc: [email protected] Fixes: 1f0ab40 ("kprobes: Prevent re-registration of the same kprobe") [ The above commit should have been done for kretprobes too ] Acked-by: Naveen N. Rao <[email protected]> Acked-by: Ananth N Mavinakayanahalli <[email protected]> Acked-by: Masami Hiramatsu <[email protected]> Signed-off-by: Wang ShaoBo <[email protected]> Signed-off-by: Cheng Jian <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 97c753e commit 0188b87

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

kernel/kprobes.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,10 @@ int register_kretprobe(struct kretprobe *rp)
19941994
if (ret)
19951995
return ret;
19961996

1997+
/* If only rp->kp.addr is specified, check reregistering kprobes */
1998+
if (rp->kp.addr && check_kprobe_rereg(&rp->kp))
1999+
return -EINVAL;
2000+
19972001
if (kretprobe_blacklist_size) {
19982002
addr = kprobe_addr(&rp->kp);
19992003
if (IS_ERR(addr))

0 commit comments

Comments
 (0)