[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201124115719.11799-1-bobo.shaobowang@huawei.com>
Date: Tue, 24 Nov 2020 19:57:19 +0800
From: Wang ShaoBo <bobo.shaobowang@...wei.com>
To: <naveen.n.rao@...ux.ibm.com>
CC: <anil.s.keshavamurthy@...el.com>, <davem@...emloft.net>,
<rostedt@...dmis.org>, <linux-kernel@...r.kernel.org>,
<huawei.libin@...wei.com>, <cj.chengjian@...wei.com>
Subject: [PATCH] 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 calling register_kretprobe(), for giving a warning message and
terminate registration process.
Signed-off-by: Wang ShaoBo <bobo.shaobowang@...wei.com>
Signed-off-by: Cheng Jian <cj.chengjian@...wei.com>
---
kernel/kprobes.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 41fdbb7953c6..7f54a70136f3 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2117,6 +2117,14 @@ int register_kretprobe(struct kretprobe *rp)
}
}
+ /*
+ * Return error if it's being re-registered,
+ * also give a warning message to the developer.
+ */
+ ret = check_kprobe_rereg(&rp->kp);
+ if (WARN_ON(ret))
+ return ret;
+
rp->kp.pre_handler = pre_handler_kretprobe;
rp->kp.post_handler = NULL;
rp->kp.fault_handler = NULL;
--
2.17.1
Powered by blists - more mailing lists