All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Xie <xiehuan09@gmail.com>
To: rostedt@goodmis.org
Cc: mingo@redhat.com, mhiramat@kernel.org, zanussi@kernel.org,
	linux-kernel@vger.kernel.org, Jeff Xie <xiehuan09@gmail.com>
Subject: [PATCH] tracing: Fix possible crash in ftrace_free_ftrace_ops()
Date: Mon,  9 May 2022 00:18:27 +0800	[thread overview]
Message-ID: <20220508161827.1014186-1-xiehuan09@gmail.com> (raw)

Currently if the ftrace_allocate_ftrace_ops() return -ENOMEM,
the ftrace_free_ftrace_ops() will kfree(NULL).
 
trace_array_create()
{
	...
	if (ftrace_allocate_ftrace_ops(tr) < 0)
		goto out_free_tr;
	...
out_free_tr:
        ftrace_free_ftrace_ops(tr);
	...
}

ftrace_allocate_ftrace_ops()
{
	...
	ops = kzalloc(sizeof(*ops), GFP_KERNEL);
        if (!ops)
                return -ENOMEM;
	...
}

ftrace_free_ftrace_ops()
{
        kfree(tr->ops);
        tr->ops = NULL;
}

Signed-off-by: Jeff Xie <xiehuan09@gmail.com>
---
 kernel/trace/trace_functions.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
index 9f1bfbe105e8..d186d6101695 100644
--- a/kernel/trace/trace_functions.c
+++ b/kernel/trace/trace_functions.c
@@ -73,6 +73,9 @@ int ftrace_allocate_ftrace_ops(struct trace_array *tr)
 
 void ftrace_free_ftrace_ops(struct trace_array *tr)
 {
+	if (!tr->ops)
+		return;
+
 	kfree(tr->ops);
 	tr->ops = NULL;
 }
-- 
2.25.1


             reply	other threads:[~2022-05-08 16:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-08 16:18 Jeff Xie [this message]
2022-05-09  1:33 ` [PATCH] tracing: Fix possible crash in ftrace_free_ftrace_ops() Jeff Xie
2022-05-09  7:34   ` Ammar Faizi
2022-05-09 22:54   ` 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=20220508161827.1014186-1-xiehuan09@gmail.com \
    --to=xiehuan09@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=zanussi@kernel.org \
    /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 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.