From: sashiko-bot@kernel.org
To: "Tanushree Shah" <tshah@linux.ibm.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v3 5/5] perf trace-event: Fix infinite loop in skip()
Date: Fri, 24 Jul 2026 14:57:10 +0000 [thread overview]
Message-ID: <20260724145711.53ECA1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260724141316.99507-6-tshah@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but there is a heap buffer overflow in `read_saved_cmdline()` due to an integer overflow when allocating memory for a buffer based on an untrusted `size`.
--
--- Patch [5]: [PATCH v3 5/5] perf trace-event: Fix infinite loop in skip() ---
commit 31b13f3b8b045b8ed6e1e9aaefa3637fac096e0b
Author: Tanushree Shah <tshah@linux.ibm.com>
perf trace-event: Fix infinite loop in skip()
This patch fixes an infinite loop in skip() where do_read()'s return value
was ignored. By checking the return value, the loop now breaks correctly on
failure or EOF.
> diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c
> index 147a3b95ce06b..529a56c3730fa 100644
> --- a/tools/perf/util/trace-event-read.c
> +++ b/tools/perf/util/trace-event-read.c
> @@ -71,12 +71,16 @@ static ssize_t do_read(void *data, size_t size)
> static void skip(size_t size)
> {
> char buf[BUFSIZ];
> - size_t r;
> + ssize_t ret;
>
> while (size) {
> - r = size > BUFSIZ ? BUFSIZ : size;
> - do_read(buf, r);
> - size -= r;
> + size_t len = size > BUFSIZ ? BUFSIZ : size;
> +
> + ret = do_read(buf, len);
> + if (ret <= 0)
> + break;
> +
> + size -= ret;
> }
> }
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing this file I
noticed a potential heap buffer overflow in read_saved_cmdline() due to an
integer overflow when allocating memory:
tools/perf/util/trace-event-read.c:read_saved_cmdline() {
...
size = read8(pevent);
if (!size)
return 0;
buf = malloc(size + 1);
if (buf == NULL) {
pr_debug("memory allocation failure\n");
return -1;
}
ret = do_read(buf, size);
...
}
If size is large enough, does size + 1 overflow to 0?
Could malloc(0) succeed and return a small valid pointer, causing do_read()
to overflow the buffer with size bytes?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260724141316.99507-1-tshah@linux.ibm.com?part=5
prev parent reply other threads:[~2026-07-24 14:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 14:13 [PATCH v3 0/5] perf trace-event: Fix security bugs in trace-event-read.c and trace-event.c Tanushree Shah
2026-07-24 14:13 ` [PATCH v3 1/5] perf trace-event: Fix buffer overflow in read_string() Tanushree Shah
2026-07-24 14:47 ` sashiko-bot
2026-07-24 14:13 ` [PATCH v3 2/5] perf trace-event: Fix integer truncation in do_read() and skip() Tanushree Shah
2026-07-24 14:47 ` sashiko-bot
2026-07-24 14:13 ` [PATCH v3 3/5] perf trace-event: Avoid double free in trace_event__cleanup() Tanushree Shah
2026-07-24 14:55 ` sashiko-bot
2026-07-24 14:13 ` [PATCH v3 4/5] perf trace-event: Fix heap buffer overflow in read_ftrace_printk() Tanushree Shah
2026-07-24 14:54 ` sashiko-bot
2026-07-24 14:13 ` [PATCH v3 5/5] perf trace-event: Fix infinite loop in skip() Tanushree Shah
2026-07-24 14:57 ` sashiko-bot [this message]
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=20260724145711.53ECA1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tshah@linux.ibm.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.