Skip to contentSkip to conversation

fprobe: Check rethook_alloc() return in rethook initialization

PATCH In review Rafael Mendonca 3 participants 3 messages Oct 25, 2022 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fprobe: Check rethook_alloc() return in rethook initialization

Check if fp->rethook succeeded to be allocated. Otherwise, if rethook_alloc() fails, then we end up dereferencing a NULL pointer in rethook_add_node().

Fixes 5b0ab78998e3 ("fprobe: Add exit_handler support")
---
 kernel/trace/fprobe.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/trace/fprobe.c +2 -0
index aac63ca9c3d1..71614b2a67ff 100644
@@ -141,6 +141,8 @@ static int fprobe_init_rethook(struct fprobe *fp, int num)
 		return -E2BIG;
 
 	fp->rethook = rethook_alloc((void *)fp, fprobe_exit_handler);
+	if (!fp->rethook)
+		return -ENOMEM;
 	for (i = 0; i < size; i++) {
 		struct fprobe_rethook_node *node;
 
Signature · 1 line
2.34.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · On Tue, 25 Oct 2022 00:12:08 -0300 Rafael Mendonca <[email protected]>…

Check if fp->rethook succeeded to be allocated. Otherwise, if rethook_alloc() fails, then we end up dereferencing a NULL pointer in rethook_add_node().

Good catch!

Thank you!

Quoted 23 lines
Fixes 5b0ab78998e3 ("fprobe: Add exit_handler support")
---
 kernel/trace/fprobe.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/trace/fprobe.c +2 -0
index aac63ca9c3d1..71614b2a67ff 100644
@@ -141,6 +141,8 @@ static int fprobe_init_rethook(struct fprobe *fp, int num)
 		return -E2BIG;
 
 	fp->rethook = rethook_alloc((void *)fp, fprobe_exit_handler);
+	if (!fp->rethook)
+		return -ENOMEM;
 	for (i = 0; i < size; i++) {
 		struct fprobe_rethook_node *node;
 
Signature · 1 line
2.34.1
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
maintainer Acked-by
#2 lore raw
Quoted 11 lines · On Tue, 25 Oct 2022 17:03:46 +0900 Masami Hiramatsu (Google)…
Quoted 3 lines · On Tue, 25 Oct 2022 00:12:08 -0300 Rafael Mendonca <[email protected]>…

Check if fp->rethook succeeded to be allocated. Otherwise, if rethook_alloc() fails, then we end up dereferencing a NULL pointer in rethook_add_node().

Good catch!

Masami, feel free to pull this in.

-- Steve