[<prev] [next>] [day] [month] [year] [list]
Message-ID: <1583761153-13876-1-git-send-email-cj.chengjian@huawei.com>
Date: Mon, 9 Mar 2020 21:39:13 +0800
From: Cheng Jian <cj.chengjian@...wei.com>
To: <linux-kernel@...r.kernel.org>
CC: <cj.chengjian@...wei.com>, <huawei.libin@...wei.com>,
<xiexiuqi@...wei.com>, <bobo.shaobowang@...wei.com>,
<naveen.n.rao@...ux.ibm.com>, <anil.s.keshavamurthy@...el.com>,
<davem@...emloft.net>, <mhiramat@...nel.org>
Subject: [PATCH v2] kretprobe: check re-registration of the same kretprobe earlier
Our system encountered a use-after-free when re-register the same
kretprobe, it access the kretprobe_instance in rp->free_instances
which has been released already.
Prevent re-registration has been implemented for kprobe before, but
it's too late for kretprobe. We must check the re-registration before
re-initializing the kretprobe, otherwise it will destroy the data and
struct of the kretprobe registered, it can lead to use-after-free,
memory leak, system crash, and even other unexpected behaviors.
Use check_kprobe_rereg() to check re-registration, also give a warning
message.
Signed-off-by: Cheng Jian <cj.chengjian@...wei.com>
Acked-by: Masami Hiramatsu <mhiramat@...nel.org>
---
kernel/kprobes.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 2625c24..9cb2a0d 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1946,6 +1946,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.7.4
Powered by blists - more mailing lists