All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix a potential memleak in rethook_alloc()
@ 2022-11-10 10:44 Yi Yang
  2022-11-11  0:30 ` Masami Hiramatsu
  0 siblings, 1 reply; 2+ messages in thread
From: Yi Yang @ 2022-11-10 10:44 UTC (permalink / raw)
  To: rostedt, mhiramat, ast, yiyang13; +Cc: linux-kernel

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

Fixes: 54ecbe6f1ed5 ("rethook: Add a generic return hook")
Signed-off-by: Yi Yang <yiyang13@huawei.com>
---
 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 01df98db2fbe..f50aebc7698e 100644
--- a/kernel/trace/rethook.c
+++ b/kernel/trace/rethook.c
@@ -91,8 +91,10 @@ struct rethook *rethook_alloc(void *data, rethook_handler_t handler, gfp_t gfp,
 {
 	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.17.1


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

* Re: [PATCH] fix a potential memleak in rethook_alloc()
  2022-11-10 10:44 [PATCH] fix a potential memleak in rethook_alloc() Yi Yang
@ 2022-11-11  0:30 ` Masami Hiramatsu
  0 siblings, 0 replies; 2+ messages in thread
From: Masami Hiramatsu @ 2022-11-11  0:30 UTC (permalink / raw)
  To: Yi Yang; +Cc: rostedt, ast, linux-kernel

On Thu, 10 Nov 2022 18:44:38 +0800
Yi Yang <yiyang13@huawei.com> wrote:

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

Oops, good catch!

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thank you!

> Fixes: 54ecbe6f1ed5 ("rethook: Add a generic return hook")
> Signed-off-by: Yi Yang <yiyang13@huawei.com>
> ---
>  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 01df98db2fbe..f50aebc7698e 100644
> --- a/kernel/trace/rethook.c
> +++ b/kernel/trace/rethook.c
> @@ -91,8 +91,10 @@ struct rethook *rethook_alloc(void *data, rethook_handler_t handler, gfp_t gfp,
>  {
>  	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.17.1
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

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

end of thread, other threads:[~2022-11-11  0:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10 10:44 [PATCH] fix a potential memleak in rethook_alloc() Yi Yang
2022-11-11  0:30 ` Masami Hiramatsu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.