All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 12/12] perf jitdump: Validate unwinding sizes against record payload
Date: Mon, 31 Aug 2026 13:35:19 +0000	[thread overview]
Message-ID: <20260831133519.A66CE1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260831131110.4681-13-acme@kernel.org>

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

Pre-existing issues:
- [High] Stale unwinding data leak and corruption in subsequent JIT ELF files due to missing cleanup when `eh_frame_hdr_size` is zero.
- [High] Missing bounds check in `jit_repipe_code_move` leaks uninitialized heap memory into `perf.data`.
--

commit 606a51d613d656e670cf8772d98c0b537c8eb055
Author: Arnaldo Carvalho de Melo <acme@redhat.com>

perf jitdump: Validate unwinding sizes against record payload

This commit validates unwinding sizes against the record payload to prevent
out-of-bounds heap reads when eh_frame_hdr_size exceeds unwinding_size. It
also updates mapped_size to use a uint64_t to avoid mmap2 length truncation.

> diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
> index 5898a7d8eb962..d25a9fe9b020c 100644
> --- a/tools/perf/util/jitdump.c
> +++ b/tools/perf/util/jitdump.c
> @@ -462,7 +462,8 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
>  	u16 idr_size;
>  	const char *sym;
>  	uint64_t count;
> -	int ret, csize, usize;
> +	int ret, csize;
> +	uint64_t usize;
>  	pid_t nspid, pid, tid;
>  	struct {
>  		u32 pid, tid;
>  		u64 time;
>  	} *id;

[Severity: High]
This is a pre-existing issue, but does jit_repipe_code_load() leak stale
unwinding data to subsequent JIT ELF files if eh_frame_hdr_size is zero?

A JIT dump can contain an unwinding record with unwinding_size > 0 but
eh_frame_hdr_size == 0, which is valid and permitted by the new size
validation. 

When processing the subsequent code_load event, it correctly uses this
unwinding data, but appears to skip the cleanup block because
jd->eh_frame_hdr_size is zero:

	if (jd->unwinding_data && jd->eh_frame_hdr_size) {
		zfree(&jd->unwinding_data);
		jd->eh_frame_hdr_size = 0;
		...
	}

Could this cause all subsequent code_load events to erroneously embed the
same stale unwinding table, corrupting the generated ELF files for unrelated
JIT methods?

[ ... ]

> @@ -612,7 +613,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
>  	char *filename;
>  	size_t size;
>  	struct stat st;
> -	int usize;
> +	uint64_t usize;
>  	u16 idr_size;
>  	int ret;
>  	pid_t nspid, pid, tid;

[Severity: High]
This is a pre-existing issue, but does jit_repipe_code_move() lack bounds
checking for the record payload?

A malformed JIT dump could provide a JIT_CODE_MOVE record with a total_size
smaller than sizeof(struct jr_code_move). jit_get_next_entry() reallocates
the buffer to exactly total_size bytes, but jit_repipe_code_move() doesn't
validate total_size before unconditionally accessing fields past the fixed
record prefix:

	nspid = jr->load.pid;
	...
	event->mmap2.start = jr->move.new_code_addr;
	event->mmap2.len   = usize ? ALIGN_8(jr->move.code_size) + usize
				   : jr->move.code_size;

Could this result in uninitialized out-of-bounds heap memory being assigned
to event fields that are subsequently written to the output perf.data stream?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260831131110.4681-1-acme@kernel.org?part=12

  reply	other threads:[~2026-08-31 13:35 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 13:10 [PATCHES v4 0/12] perf jitdump: Input validation hardening Arnaldo Carvalho de Melo
2026-08-31 13:10 ` [PATCH 01/12] perf jitdump: Fix extended header read that always fails Arnaldo Carvalho de Melo
2026-08-31 13:22   ` sashiko-bot
2026-08-31 13:10 ` [PATCH 02/12] perf jitdump: Fix debug_data and unwinding_data leaks Arnaldo Carvalho de Melo
2026-08-31 13:24   ` sashiko-bot
2026-08-31 13:10 ` [PATCH 03/12] perf jitdump: Validate code_size against total_size in code load Arnaldo Carvalho de Melo
2026-08-31 13:21   ` sashiko-bot
2026-08-31 13:11 ` [PATCH 04/12] perf jitdump: Prevent integer underflow in debug info size calculation Arnaldo Carvalho de Melo
2026-08-31 13:22   ` sashiko-bot
2026-08-31 13:11 ` [PATCH 05/12] perf jitdump: Bounds-check debug entry byte-swap loop Arnaldo Carvalho de Melo
2026-08-31 13:23   ` sashiko-bot
2026-08-31 13:11 ` [PATCH 06/12] perf jitdump: Check snprintf return before computing header size Arnaldo Carvalho de Melo
2026-08-31 13:23   ` sashiko-bot
2026-08-31 13:11 ` [PATCH 07/12] perf jitdump: Fix funlockfile on unlocked stream in jit_open() error path Arnaldo Carvalho de Melo
2026-08-31 13:23   ` sashiko-bot
2026-08-31 13:11 ` [PATCH 08/12] perf jitdump: Free event in jit_repipe_code_move() Arnaldo Carvalho de Melo
2026-08-31 13:21   ` sashiko-bot
2026-08-31 13:11 ` [PATCH 09/12] perf jitdump: Use dirname() return value in jit_open() Arnaldo Carvalho de Melo
2026-08-31 13:19   ` sashiko-bot
2026-08-31 13:11 ` [PATCH 10/12] perf jitdump: Validate debug entries on native (non-swap) path Arnaldo Carvalho de Melo
2026-08-31 13:23   ` sashiko-bot
2026-08-31 13:11 ` [PATCH 11/12] perf jitdump: Validate sym string NUL-termination in code load Arnaldo Carvalho de Melo
2026-08-31 13:31   ` sashiko-bot
2026-08-31 13:11 ` [PATCH 12/12] perf jitdump: Validate unwinding sizes against record payload Arnaldo Carvalho de Melo
2026-08-31 13:35   ` sashiko-bot [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-08-06 12:35 [PATCHES v3 0/12] perf jitdump: Input validation hardening Arnaldo Carvalho de Melo
2026-08-06 12:36 ` [PATCH 12/12] perf jitdump: Validate unwinding sizes against record payload Arnaldo Carvalho de Melo
2026-08-06 13:06   ` sashiko-bot
2026-08-05 21:26 [PATCHES v2 0/12] perf jitdump: Input validation hardening Arnaldo Carvalho de Melo
2026-08-05 21:27 ` [PATCH 12/12] perf jitdump: Validate unwinding sizes against record payload Arnaldo Carvalho de Melo
2026-08-05 21:53   ` sashiko-bot
2026-08-05 13:29 [PATCHES v1 0/12] perf jitdump: Input validation hardening Arnaldo Carvalho de Melo
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

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=20260831133519.A66CE1F00A3D@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 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.