summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWang ShaoBo <bobo.shaobowang@huawei.com>2021-01-28 20:44:27 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-02-10 09:25:30 +0100
commitd0f36951ead4a5fc8411fbdf206cd4f18ead5963 (patch)
tree8fecb1a869b21ab5fe50be5d0bb31a1a161aa52c
parente80f9021d5be80b05c8f75709d23811a831af565 (diff)
downloadlinux-stable-d0f36951ead4a5fc8411fbdf206cd4f18ead5963.tar.gz
linux-stable-d0f36951ead4a5fc8411fbdf206cd4f18ead5963.tar.bz2
linux-stable-d0f36951ead4a5fc8411fbdf206cd4f18ead5963.zip
kretprobe: Avoid re-registration of the same kretprobe earlier
commit 0188b87899ffc4a1d36a0badbe77d56c92fd91dc upstream. 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/20210128124427.2031088-1-bobo.shaobowang@huawei.com Cc: stable@vger.kernel.org Fixes: 1f0ab40976460 ("kprobes: Prevent re-registration of the same kprobe") [ The above commit should have been done for kretprobes too ] Acked-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Acked-by: Ananth N Mavinakayanahalli <ananth@linux.ibm.com> Acked-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Wang ShaoBo <bobo.shaobowang@huawei.com> Signed-off-by: Cheng Jian <cj.chengjian@huawei.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--kernel/kprobes.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 283c8b01ce78..26ae92c12fc2 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1972,6 +1972,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))