All of lore.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: sashiko-reviews@lists.linux.dev
Cc: Gu Bin <gubin@cmss.chinamobile.com>, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf trace: guard free(new_filter) to avoid double-free on OOM
Date: Wed, 18 Nov 2026 23:51:08 -0800	[thread overview]
Message-ID: <av6qbBy6Zkq1PiQ1@google.com> (raw)
In-Reply-To: <sashiko-outbox-210269@kernel.org>

On Thu, Nov 12, 2026 at 03:25:15AM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found no new issues
> in this patch, but noticed 1 related pre-existing issue it does not
> introduce:
> - [Medium] perf trace: unhandled -ENOMEM in trace__expand_filter() [1]
> --
> 
> commit e8aa93f0bab0450d21dc93c231c980b9474cb264
> Author: Gu Bin <gubin@cmss.chinamobile.com>
> 
> perf trace: guard free(new_filter) to avoid double-free on OOM
> 
> This commit guards free(new_filter) on the asprintf() failure path in
> trace__expand_filter() so that evsel->filter is not freed when new_filter
> still aliases it.
> 
> > diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> > index 4094141461f91..f4a67491f5be1 100644
> > --- a/tools/perf/builtin-trace.c
> > +++ b/tools/perf/builtin-trace.c
> > @@ -4679,7 +4679,8 @@ static int trace__expand_filter(struct trace *trace, struct evsel *evsel)
> >  
> >  					if (asprintf(&n, "%.*s%s%s", expansion_offset, new_filter, expansion, right_end) < 0) {
> >  						pr_debug(" out of memory!\n");
> > -						free(new_filter);
> > +						if (new_filter != evsel->filter)
> > +							free(new_filter);
> >  						return -1;
> >  					}
> >  					if (new_filter != evsel->filter)
> 
> [Severity: Medium]
> This problem wasn't introduced by this patch, but at the end of
> trace__expand_filter(), should the return value of evsel__set_filter() be
> checked [1]?

Yep, this is a separate issue.  I think it's ok to take this patch as
is.

Gu, are you willing to fix the reported problem too?

Thanks,
Namhyung

> 
> tools/perf/builtin-trace.c:trace__expand_filter() {
> 	...
> 	if (new_filter != evsel->filter) {
> 		pr_debug("New filter for %s: %s\n", evsel->name, new_filter);
> 		evsel__set_filter(evsel, new_filter);
> 		free(new_filter);
> 	}
> 
> 	return 0;
> }
> 
> If strdup() inside evsel__set_filter() fails with -ENOMEM, the failure is
> silently ignored and trace__expand_filter() returns 0, leaving the
> unexpanded filter in place.
> 
> [1] https://sashiko.dev/#/bug/linux-cbf4bb01-a981-47dc-b440-68e5c9c3e81c
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20261112031810.1899-1-gubin@cmss.chinamobile.com?part=1

  reply	other threads:[~2026-11-19  7:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  3:18 [PATCH] perf trace: guard free(new_filter) to avoid double-free on OOM Gu Bin
2026-11-12  3:25 ` sashiko-bot
2026-11-19  7:51   ` Namhyung Kim [this message]
2026-11-20  3:54 ` Namhyung Kim

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=av6qbBy6Zkq1PiQ1@google.com \
    --to=namhyung@kernel.org \
    --cc=gubin@cmss.chinamobile.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.