summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYi Yang <yiyang13@huawei.com>2022-11-18 10:15:34 +0900
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-11-26 09:27:42 +0100
commitcbc5d1f9a8cc40ba2bc6779b36d2ea1f65bc027c (patch)
tree9cb7a3a896347fefae2e9f92bf6ed1a80ae10bf7
parent510c12f93674ea0a1423b24f36c67357168a262a (diff)
rethook: fix a potential memleak in rethook_alloc()
commit 0a1ebe35cb3b7aa1f4b26b37e2a0b9ae68dc4ffb upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--kernel/trace/rethook.c4
1 files changed, 3 insertions, 1 deletions
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;