Sashiko discussions
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: sashiko@lists.linux.dev
Cc: Ian Rogers <irogers@google.com>, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v10 04/29] perf evsel: Refactor evsel tracepoint sample accessors perf_sample
Date: Sun, 12 Apr 2026 13:11:04 -0700	[thread overview]
Message-ID: <adv8WGAZUBy3q4MV@google.com> (raw)
In-Reply-To: <20260412023420.44E47C116C6@smtp.kernel.org>

On Sun, Apr 12, 2026 at 02:34:19AM +0000, sashiko-bot@kernel.org wrote:
> Sashiko AI review found 1 potential issue(s):
> - [High] Removal of `strdup` in `sched_work_init` introduces a Use-After-Free vulnerability when storing the task name.
> --
> 
> commit 0d7b6945ae0c6b8ad53d53aacf54fb3b747a99a7
> Author: Ian Rogers <irogers@google.com>
> 
> perf evsel: Refactor evsel tracepoint sample accessors perf_sample
> 
> This commit removes the evsel argument from tracepoint sample accessor
> functions, renaming them to reflect that the data is being read directly
> from the sample.
> 
> Please note that the issue discussed below was resolved in a later commit
> upstream, specifically commit 5e8ad46aaa11f37f17084b59fcd84e6b4bbc3d6e
> (perf kwork: Fix memory management of kwork_work). It is included here
> for completeness regarding this specific patch.
> 
> [ ... ]
> > diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c
> > index d4bb19ed91b59..8ba5ea201bf94 100644
> > --- a/tools/perf/builtin-kwork.c
> > +++ b/tools/perf/builtin-kwork.c
> [ ... ]
> > @@ -1310,11 +1309,11 @@ static void sched_work_init(struct perf_kwork *kwork __maybe_unused,
> >  	work->cpu = sample->cpu;
> >  
> >  	if (src_type == KWORK_TRACE_EXIT) {
> > -		work->id = evsel__intval(evsel, sample, "prev_pid");
> > -		work->name = strdup(evsel__strval(evsel, sample, "prev_comm"));
> > +		work->id = perf_sample__intval(sample, "prev_pid");
> > +		work->name = perf_sample__strval(sample, "prev_comm");
> 
> Does removing the strdup call here leave work->name pointing directly to
> the raw data inside the memory mapped ring buffer?
> 
> If perf_sample__strval returns a pointer to the sample data, that memory
> will be overwritten as new events arrive. When the reporting phase later
> iterates over the kwork_work tree, could this result in a use-after-free
> and output garbage strings?

I've removed this part for now.

Thanks,
Namhyung

> 
> >  	} else if (src_type == KWORK_TRACE_ENTRY) {
> > -		work->id = evsel__intval(evsel, sample, "next_pid");
> > -		work->name = strdup(evsel__strval(evsel, sample, "next_comm"));
> > +		work->id = perf_sample__intval(sample, "next_pid");
> > +		work->name = perf_sample__strval(sample, "next_comm");
> >  	}
> >  }
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20260412020833.641177-1-irogers@google.com?part=4

           reply	other threads:[~2026-04-12 20:11 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20260412023420.44E47C116C6@smtp.kernel.org>]

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=adv8WGAZUBy3q4MV@google.com \
    --to=namhyung@kernel.org \
    --cc=irogers@google.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox