mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Yuanjun Gong <ruc_gongyuanjun@163.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 1/1] tracing: fix possible null pointer dereference
Date: Tue, 17 May 2022 12:06:39 +0200	[thread overview]
Message-ID: <YoNzr1ciY12Bg6Rv@kroah.com> (raw)
In-Reply-To: <20220517095723.7426-1-ruc_gongyuanjun@163.com>

On Tue, May 17, 2022 at 05:57:23PM +0800, Yuanjun Gong wrote:
> From: Gong Yuanjun <ruc_gongyuanjun@163.com>
> 
> In hist_trigger_elt_data_alloc(), elt_data is freed by
> hist_elt_data_free() if kcalloc fails.
> 
> static int hist_trigger_elt_data_alloc(struct tracing_map_elt *elt)
> {
> ...
> elt_data->field_var_str = kcalloc(n_str, sizeof(char *), GFP_KERNEL);
>         if (!elt_data->field_var_str) {
>                 hist_elt_data_free(elt_data);
>                 return -EINVAL;
>         }
> ...}
> 
> In hist_elt_data_free() the elt_data->field_var_str field should be
> checked before dereference.
> 
> Signed-off-by: Gong Yuanjun <ruc_gongyuanjun@163.com>
> ---
>  kernel/trace/trace_events_hist.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index 44db5ba9cabb..73177c9f94b2 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -1576,11 +1576,11 @@ static void hist_elt_data_free(struct hist_elt_data *elt_data)
>  {
>  	unsigned int i;
>  
> -	for (i = 0; i < elt_data->n_field_var_str; i++)
> -		kfree(elt_data->field_var_str[i]);
> -
> -	kfree(elt_data->field_var_str);
> -
> +	if (elt_data->field_var_str) {
> +		for (i = 0; i < elt_data->n_field_var_str; i++)
> +			kfree(elt_data->field_var_str[i]);
> +		kfree(elt_data->field_var_str);
> +	}
>  	kfree(elt_data->comm);
>  	kfree(elt_data);
>  }
> -- 
> 2.17.1
> 

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read:
    https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

  reply	other threads:[~2022-05-17 10:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-17  9:57 Yuanjun Gong
2022-05-17 10:06 ` Greg KH [this message]
2022-05-18 19:28 ` 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=YoNzr1ciY12Bg6Rv@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=ruc_gongyuanjun@163.com \
    --cc=stable@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®