linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kretprobe: check re-registration of the same kretprobe earlier
@ 2020-03-06  9:35 Cheng Jian
  2020-03-06 15:21 ` Masami Hiramatsu
  0 siblings, 1 reply; 5+ messages in thread
From: Cheng Jian @ 2020-03-06  9:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: cj.chengjian, huawei.libin, xiexiuqi, bobo.shaobowang,
	naveen.n.rao, anil.s.keshavamurthy, davem, mhiramat

Our system encountered a use-after-free when re-register a
same kretprobe. it access the hlist node 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 memory
leak and use-after-free.

Signed-off-by: Cheng Jian <cj.chengjian@huawei.com>
---
 kernel/kprobes.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 2625c24..f1fc921 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1946,6 +1946,11 @@ int register_kretprobe(struct kretprobe *rp)
 		}
 	}
 
+	/* Return error if it's being re-registered */
+	ret = check_kprobe_rereg(&rp->kp);
+	if (ret)
+		return ret;
+
 	rp->kp.pre_handler = pre_handler_kretprobe;
 	rp->kp.post_handler = NULL;
 	rp->kp.fault_handler = NULL;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-03-09  7:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-06  9:35 [PATCH] kretprobe: check re-registration of the same kretprobe earlier Cheng Jian
2020-03-06 15:21 ` Masami Hiramatsu
2020-03-07  2:16   ` chengjian (D)
2020-03-07  9:54     ` Masami Hiramatsu
2020-03-09  7:38       ` chengjian (D)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).