From: sashiko-bot@kernel.org
To: "Yushan Wang" <wangyushan12@huawei.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [RFT PATCH v2 4/7] perf-x86: iostat: Change iostat_prefix() to static
Date: Thu, 07 May 2026 21:21:54 +0000 [thread overview]
Message-ID: <20260507212154.BC064C2BCB2@smtp.kernel.org> (raw)
In-Reply-To: <20260507063737.3542950-5-wangyushan12@huawei.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Reassignment of `evlist` pointer passed by value in `iostat_prepare` leaves caller with a freed pointer.
- [High] Missing cast for time_t in sprintf leading to argument misalignment and potential segfault.
--
commit 8f78117186fde5ac8fb2f432eade998540fdbd61
Author: Yushan Wang <wangyushan12@huawei.com>
perf-x86: iostat: Change iostat_prefix() to static
This commit changes iostat_prefix() to a static function since it is not
used outside of the local file.
> diff --git a/tools/perf/util/x86-iostat.c b/tools/perf/util/x86-iostat.c
> index 7442a2cd87eda..f8d4c97185949 100644
> --- a/tools/perf/util/x86-iostat.c
> +++ b/tools/perf/util/x86-iostat.c
[ ... ]
> @@ -332,6 +332,28 @@ static int iostat_event_group(struct evlist *evl,
> return ret;
> }
>
> +static void iostat_prefix(struct evlist *evlist,
> + struct perf_stat_config *config,
> + char *prefix, struct timespec *ts)
> +{
> + struct iio_root_port *rp = evlist->selected->priv;
> +
> + if (rp) {
> + /*
> + * TODO: This is the incorrect format in JSON mode.
> + * See prepare_timestamp()
> + */
> + if (ts)
> + sprintf(prefix, "%6lu.%09lu%s%04x:%02x%s",
> + ts->tv_sec, ts->tv_nsec,
> + config->csv_sep, rp->domain, rp->bus,
> + config->csv_sep);
Does this format specifier cause a segmentation fault on 32-bit systems with
64-bit time support?
When _TIME_BITS=64 is used on a 32-bit system, time_t becomes 64-bit
(8 bytes), but unsigned long remains 32-bit (4 bytes).
Because sprintf() is a variadic function, passing the 64-bit ts->tv_sec takes
two 32-bit slots on the stack. The %6lu specifier reads the first 4 bytes,
%09lu reads the upper half of tv_sec, and the %s specifier reads ts->tv_nsec
as a pointer.
Dereferencing that integer as a string pointer would crash.
> + else
> + sprintf(prefix, "%04x:%02x%s", rp->domain, rp->bus,
> + config->csv_sep);
> + }
> +}
> +
> int iostat_prepare(struct evlist *evlist, struct perf_stat_config *config)
> {
> if (evlist->core.nr_entries > 0) {
Can this pointer reassignment cause a use-after-free regression for the
caller?
Looking at iostat_prepare(), it takes evlist as a pointer passed by value.
If the core entries are greater than zero, the evlist is deleted and a new
one is allocated:
tools/perf/util/x86-iostat.c:iostat_prepare() {
...
if (evlist->core.nr_entries > 0) {
...
evlist__delete(evlist);
evlist = evlist__new();
...
}
Since the evlist reassignment only modifies the local parameter variable,
the caller's pointer is left pointing to freed memory.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260507063737.3542950-1-wangyushan12@huawei.com?part=4
next prev parent reply other threads:[~2026-05-07 21:21 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-07 6:37 [RFT PATCH v2 0/7] perf tool: Support iostat for multiple platform Yushan Wang
2026-05-07 6:37 ` [RFT PATCH v2 1/7] perf stat: Check color's length instead of the pointer Yushan Wang
2026-05-07 15:33 ` Ian Rogers
2026-05-07 6:37 ` [RFT PATCH v2 2/7] perf stat: Save unnecessary print_metric() call Yushan Wang
2026-05-07 15:30 ` Ian Rogers
2026-05-07 6:37 ` [RFT PATCH v2 3/7] perf-x86: iostat: Move iostat arch-specific implementation to util Yushan Wang
2026-05-07 15:35 ` Ian Rogers
2026-05-08 10:34 ` Yushan Wang
2026-05-07 21:00 ` sashiko-bot
2026-05-07 6:37 ` [RFT PATCH v2 4/7] perf-x86: iostat: Change iostat_prefix() to static Yushan Wang
2026-05-07 15:39 ` Ian Rogers
2026-05-08 10:35 ` Yushan Wang
2026-05-07 21:21 ` sashiko-bot [this message]
2026-05-07 6:37 ` [RFT PATCH v2 5/7] perf-iostat: Extend iostat interface to support different iostat PMUs Yushan Wang
2026-05-07 15:47 ` Ian Rogers
2026-05-08 10:36 ` Yushan Wang
2026-05-07 21:52 ` sashiko-bot
2026-05-07 6:37 ` [RFT PATCH v2 6/7] perf-iostat: Make x86 iostat compatible with new iostat framework Yushan Wang
2026-05-07 16:17 ` Ian Rogers
2026-05-08 10:36 ` Yushan Wang
2026-05-07 22:13 ` sashiko-bot
2026-05-07 6:37 ` [RFT PATCH v2 7/7] perf-iostat: Enable iostat mode for HiSilicon PCIe PMU Yushan Wang
2026-05-07 16:20 ` Ian Rogers
2026-05-08 10:36 ` Yushan Wang
2026-05-07 22:35 ` sashiko-bot
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=20260507212154.BC064C2BCB2@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko@lists.linux.dev \
--cc=wangyushan12@huawei.com \
/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.