From: sashiko-bot@kernel.org
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 04/12] perf jitdump: Bounds-check debug entry byte-swap loop
Date: Wed, 05 Aug 2026 14:27:59 +0000 [thread overview]
Message-ID: <20260805142800.C063B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260805133013.235016-5-acme@kernel.org>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Incomplete fix for out-of-bounds read/write in JIT_CODE_DEBUG_INFO parsing
- [High] Missing bounds validation for JIT_CODE_UNWINDING_INFO sizes leads to OOB heap read and information leak
- [High] Missing null-terminator validation for JIT_CODE_LOAD symbol string causes OOB read and information leak
--
--- Patch [4]: [PATCH 04/12] perf jitdump: Bounds-check debug entry byte-swap loop ---
commit 2ca1b158f7ca3eafd8478fe7713f2806ce7b4fce
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: perf jitdump: Bounds-check debug entry byte-swap loop
This commit replaces array indexing with debug_entry_next() pointer arithmetic
for JIT_CODE_DEBUG_INFO records, and adds bounds-checking against the record's
total_size. This prevents out-of-bounds reads during byte-swapping of untrusted
jitdump input.
> diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
> index 787f8a03dae87..078d3304d2b7e 100644
> --- a/tools/perf/util/jitdump.c
> +++ b/tools/perf/util/jitdump.c
> @@ -318,14 +318,32 @@ jit_get_next_entry(struct jit_buf_desc *jd)
> switch(id) {
> case JIT_CODE_DEBUG_INFO:
> if (jd->needs_bswap) {
> + void *end = (void *)jr + jr->prefix.total_size;
[Severity: High]
This is a pre-existing issue, but does this skip validation for native-endian
files?
The bounds checking and clamping are only performed when jd->needs_bswap is true.
If the file is native-endian, the untrusted nr_entry is passed directly to the
downstream loop without validation:
tools/perf/util/genelf_debug.c:jit_process_debug_info() {
...
for (i = 0; i < nr_debug_entries; i++) {
ent->addr = ent->addr - code_addr;
ent = debug_entry_next(ent);
}
...
}
Could this lead to out-of-bounds heap reads and writes when processing a crafted
JIT_CODE_DEBUG_INFO record with native endianness?
[ ... ]
> + /* clamp so downstream consumers don't overrun */
> + jr->info.nr_entry = n;
> }
> break;
> case JIT_CODE_UNWINDING_INFO:
[Severity: High]
This is a pre-existing issue, but is the unwinding_size bounded by the actual
record size?
In jit_repipe_unwinding_info(), jd->unwinding_size is set directly from the
untrusted jr->unwinding.unwinding_size. Later, this unvalidated size is passed
to libelf:
tools/perf/util/genelf.c:jit_add_eh_frame_info() {
...
d->d_size = unwinding_table_size;
...
}
Could this cause an out-of-bounds heap read and embed adjacent heap memory into
the generated ELF file?
> if (jd->needs_bswap) {
> jr->unwinding.unwinding_size = bswap_64(jr->unwinding.unwinding_size);
> jr->unwinding.eh_frame_hdr_size = bswap_64(jr->unwinding.eh_frame_hdr_size);
> jr->unwinding.mapped_size = bswap_64(jr->unwinding.mapped_size);
> }
> break;
> case JIT_CODE_CLOSE:
> break;
> case JIT_CODE_LOAD:
[Severity: High]
This is a pre-existing issue, but is the symbol string in JIT_CODE_LOAD checked
for null-termination within the record bounds?
In jit_repipe_code_load(), the string pointer is derived from the record
without validation:
tools/perf/util/jitdump.c:jit_repipe_code_load() {
...
sym = (void *)((unsigned long)jr + sizeof(jr->load));
...
}
This unvalidated string is later passed to strlen() and strcpy() in
jit_write_elf(), which could scan past the record into adjacent heap memory and
leak data into the generated ELF string table.
> if (jd->needs_bswap) {
> jr->load.pid = bswap_32(jr->load.pid);
> jr->load.tid = bswap_32(jr->load.tid);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260805133013.235016-1-acme@kernel.org?part=4
next prev parent reply other threads:[~2026-08-05 14:28 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 13:29 [PATCHES v1 0/12] perf jitdump: Input validation hardening Arnaldo Carvalho de Melo
2026-08-05 13:30 ` [PATCH 01/12] perf jitdump: Fix extended header read that always fails Arnaldo Carvalho de Melo
2026-08-05 13:46 ` sashiko-bot
2026-08-05 18:51 ` Ian Rogers
2026-08-05 13:30 ` [PATCH 02/12] perf jitdump: Validate code_size against total_size in code load Arnaldo Carvalho de Melo
2026-08-05 13:59 ` sashiko-bot
2026-08-05 18:58 ` Ian Rogers
2026-08-05 13:30 ` [PATCH 03/12] perf jitdump: Prevent integer underflow in debug info size calculation Arnaldo Carvalho de Melo
2026-08-05 14:56 ` sashiko-bot
2026-08-05 18:59 ` Ian Rogers
2026-08-05 13:30 ` [PATCH 04/12] perf jitdump: Bounds-check debug entry byte-swap loop Arnaldo Carvalho de Melo
2026-08-05 14:27 ` sashiko-bot [this message]
2026-08-05 19:00 ` Ian Rogers
2026-08-05 13:30 ` [PATCH 05/12] perf jitdump: Check snprintf return before computing header size Arnaldo Carvalho de Melo
2026-08-05 14:25 ` sashiko-bot
2026-08-05 19:07 ` Ian Rogers
2026-08-05 19:45 ` Arnaldo Carvalho de Melo
2026-08-05 21:29 ` Ian Rogers
2026-08-07 12:00 ` Arnaldo Carvalho de Melo
2026-08-05 13:30 ` [PATCH 06/12] perf jitdump: Fix funlockfile on unlocked stream in jit_open() error path Arnaldo Carvalho de Melo
2026-08-05 15:48 ` sashiko-bot
2026-08-05 19:09 ` Ian Rogers
2026-08-05 13:30 ` [PATCH 07/12] perf jitdump: Free event in jit_repipe_code_move() Arnaldo Carvalho de Melo
2026-08-05 14:33 ` sashiko-bot
2026-08-05 19:09 ` Ian Rogers
2026-08-05 13:30 ` [PATCH 08/12] perf jitdump: Fix debug_data and unwinding_data leaks Arnaldo Carvalho de Melo
2026-08-05 14:35 ` sashiko-bot
2026-08-05 19:10 ` Ian Rogers
2026-08-05 13:30 ` [PATCH 09/12] perf jitdump: Use dirname() return value in jit_open() Arnaldo Carvalho de Melo
2026-08-05 14:13 ` sashiko-bot
2026-08-05 19:16 ` Ian Rogers
2026-08-05 13:30 ` [PATCH 10/12] perf jitdump: Validate debug entries on native (non-swap) path Arnaldo Carvalho de Melo
2026-08-05 14:26 ` sashiko-bot
2026-08-05 19:19 ` Ian Rogers
2026-08-05 13:30 ` [PATCH 11/12] perf jitdump: Validate sym string NUL-termination in code load Arnaldo Carvalho de Melo
2026-08-05 19:19 ` Ian Rogers
2026-08-05 13:30 ` [PATCH 12/12] perf jitdump: Validate unwinding sizes against record payload Arnaldo Carvalho de Melo
2026-08-05 19:20 ` Ian Rogers
-- strict thread matches above, loose matches on Subject: below --
2026-08-05 21:26 [PATCHES v2 0/12] perf jitdump: Input validation hardening Arnaldo Carvalho de Melo
2026-08-05 21:26 ` [PATCH 04/12] perf jitdump: Bounds-check debug entry byte-swap loop Arnaldo Carvalho de Melo
2026-08-05 21:40 ` 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=20260805142800.C063B1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=acme@kernel.org \
--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