Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v1] perf stat: Avoid uninitialized memory read on error
Date: Tue, 08 Sep 2026 22:23:33 +0000	[thread overview]
Message-ID: <20260908222333.DC4B51F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260908220720.564614-1-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Atomic Conclusion: Unchecked ERR_PTR from hashmap__new() causes predictable application crashes. The return value is incorrectly checked against NULL instead of IS_ERR().
--

commit 525c560536a62c39331ec585b1ce897decf7179c
Author: Ian Rogers <irogers@google.com>

perf stat: Avoid uninitialized memory read on error
    
If has_supported_counters fails then msg was passed to ui__error
regardless of whether an error was written into msg leading to reading
uninitialized memory. Avoid this by always terminating msg at
initialization.

> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index c50cf230f16ed..37752d6bfef45 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c

[ ... ]

[Severity: High]
This isn't a bug introduced by this patch, but I noticed that the return
value of hashmap__new() is incorrectly checked against NULL instead of
IS_ERR().

Since hashmap__new() returns an ERR_PTR on failure, this will
cause predictable crashes under memory pressure instead of graceful error
handling.

For example, in tools/perf/util/pmu.c:perf_pmu__init():

        pmu->aliases = hashmap__new(aliases__hash, aliases__equal, /*ctx=*/ NULL);
        if (!pmu->aliases)
                return -ENOMEM;

And similarly in tools/perf/util/pmu.c:perf_pmu__create_placeholder_core_pmu():

        pmu->aliases = hashmap__new(aliases__hash, aliases__equal, /*ctx=*/ NULL);
        INIT_LIST_HEAD(&pmu->caps);

Also in tools/perf/util/fncache.c:fncache__init():

        fncache = hashmap__new(fncache__hash, fncache__equal, /*ctx=*/NULL);

Should these locations be updated to use IS_ERR() when validating the result
of hashmap__new()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260908220720.564614-1-irogers@google.com?part=1

  reply	other threads:[~2026-09-08 22:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08 22:07 [PATCH v1] perf stat: Avoid uninitialized memory read on error Ian Rogers
2026-09-08 22:23 ` sashiko-bot [this message]
2026-09-08 22:37   ` Ian Rogers
2026-09-09 11:10 ` Arnaldo Carvalho de Melo

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=20260908222333.DC4B51F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=irogers@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox