public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	stable@vger.kernel.org, Yi Yang <yiyang13@huawei.com>
Subject: [for-linus][PATCH 4/7] rethook: fix a potential memleak in rethook_alloc()
Date: Sun, 20 Nov 2022 15:12:00 -0500	[thread overview]
Message-ID: <20221120201222.349027009@goodmis.org> (raw)
In-Reply-To: 20221120201156.868430827@goodmis.org

From: Yi Yang <yiyang13@huawei.com>

In rethook_alloc(), the variable rh is not freed or passed out
if handler is NULL, which could lead to a memleak, fix it.

Link: https://lore.kernel.org/all/20221110104438.88099-1-yiyang13@huawei.com/
[Masami: Add "rethook:" tag to the title.]

Fixes: 54ecbe6f1ed5 ("rethook: Add a generic return hook")
Cc: stable@vger.kernel.org
Signed-off-by: Yi Yang <yiyang13@huawei.com>
Acke-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 kernel/trace/rethook.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c
index c69d82273ce7..32c3dfdb4d6a 100644
--- a/kernel/trace/rethook.c
+++ b/kernel/trace/rethook.c
@@ -83,8 +83,10 @@ struct rethook *rethook_alloc(void *data, rethook_handler_t handler)
 {
 	struct rethook *rh = kzalloc(sizeof(struct rethook), GFP_KERNEL);
 
-	if (!rh || !handler)
+	if (!rh || !handler) {
+		kfree(rh);
 		return NULL;
+	}
 
 	rh->data = data;
 	rh->handler = handler;
-- 
2.35.1



  parent reply	other threads:[~2022-11-20 20:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-20 20:11 [for-linus][PATCH 0/7] probes: Fixes for 6.1 Steven Rostedt
2022-11-20 20:11 ` [for-linus][PATCH 1/7] tracing: kprobe: Fix potential null-ptr-deref on trace_event_file in kprobe_event_gen_test_exit() Steven Rostedt
2022-11-20 20:11 ` [for-linus][PATCH 2/7] tracing: kprobe: Fix potential null-ptr-deref on trace_array " Steven Rostedt
2022-11-20 20:11 ` [for-linus][PATCH 3/7] tracing/eprobe: Fix memory leak of filter string Steven Rostedt
2022-11-20 20:12 ` Steven Rostedt [this message]
2022-11-20 20:12 ` [for-linus][PATCH 5/7] kprobes: Skip clearing aggrprobes post_handler in kprobe-on-ftrace case Steven Rostedt
2022-11-20 20:12 ` [for-linus][PATCH 6/7] tracing/eprobe: Fix warning in filter creation Steven Rostedt
2022-11-20 20:12 ` [for-linus][PATCH 7/7] tracing/eprobe: Fix eprobe filter to make a filter correctly Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221120201222.349027009@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=yiyang13@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox