Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tanushree Shah" <tshah@linux.ibm.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [RFC PATCH v3 2/5] perf/trace-event: Write trace.dat metadata sections during parsing
Date: Mon, 03 Aug 2026 15:14:10 +0000	[thread overview]
Message-ID: <20260803151411.4B35C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260803145958.299956-3-tshah@linux.ibm.com>

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

New issues:
- [Medium] Missing checks for `fseek` errors when patching section sizes can silently corrupt the output trace file.
- [Low] Missing explicit inclusion of `<stdint.h>` in `trace-dat.h`.

Pre-existing issues:
- [Critical] Integer overflow in `malloc(size + 1)` leads to a massive heap buffer overflow.
--

--- Patch [2]: [RFC PATCH v3 2/5] perf/trace-event: Write trace.dat metadata sections during parsing ---
commit 9121c22ee8da1e40687be01e1d9fb0edd88a10cd
Author: Tanushree Shah <tshah@linux.ibm.com>

perf/trace-event: Write trace.dat metadata sections during parsing

This commit modifies the perf trace event parsing logic to write trace.dat
compatible metadata sections when trace_dat_fp is set. It introduces
byte-order helpers and adds support for writing FTRACE EVENT FORMATS,
KALLSYMS, CMDLINES, and STRINGS sections.

> diff --git a/tools/perf/util/trace-dat.h b/tools/perf/util/trace-dat.h
> index 9aec37b708d41..5985083b275ac 100644
> --- a/tools/perf/util/trace-dat.h
> +++ b/tools/perf/util/trace-dat.h
> @@ -8,9 +8,13 @@
>  #define __PERF_TRACE_DAT_H
>  
>  #include <stdio.h>
> +#include <stdbool.h>
> +#include <event-parse.h>
> +#include <byteswap.h>
> +#include "util.h"

[Severity: Low]
This isn't a bug, but could the lack of an explicit <stdint.h> inclusion here
cause build failures on musl libc? The file uses uint16_t, uint32_t, and
uint64_t, and according to subsystem guidelines, all files using POSIX libc
types must explicitly include the declaring header.

[ ... ]
> --- a/tools/perf/util/trace-event-read.c
> +++ b/tools/perf/util/trace-event-read.c
[ ... ]
> @@ -338,6 +538,18 @@ static int read_event_files(struct tep_handle *pevent)
>  		}
>  		free(sys);
>  	}
> +	/* Fill in section size after writing all event files */
> +	if (trace_dat_fp && !trace_dat_write_failed) {
> +		end_pos = ftell(trace_dat_fp);
> +		section_size = to_file_u64(pevent, end_pos - sys_count_pos);
> +		fseek(trace_dat_fp, section_size_pos, SEEK_SET);
> +		if (!fwrite(&section_size, sizeof(unsigned long long), 1, trace_dat_fp)) {
> +			pr_warning("Failed to write trace.dat event formats section\n");
> +			trace_dat_write_failed = true;
> +		}
> +		fseek(trace_dat_fp, end_pos, SEEK_SET);

[Severity: Medium]
Can a failed fseek() here silently corrupt the output trace.dat file?

If the first fseek() fails due to an underlying I/O error, the subsequent
fwrite() would overwrite data at the wrong location. Since the second
fseek() is also unchecked, subsequent writes would also land at invalid
offsets.

> +	}
> +
>  	return 0;
>  }
[ ... ]
> @@ -349,8 +561,28 @@ static int read_saved_cmdline(struct tep_handle *pevent)
>  
>  	/* it can have 0 size */
>  	size = read8(pevent);
> -	if (!size)
> +	/* Write cmdlines section with empty payload if no data */
> +	if (!size) {
> +		if (trace_dat_fp && !trace_dat_write_failed) {
[ ... ]
> +		}
>  		return 0;
> +	}
>  
>  	buf = malloc(size + 1);

[Severity: Critical]
This is a pre-existing issue, but could this malloc(size + 1) trigger a heap
buffer overflow regression when parsing an untrusted perf.data file?

For example, in read_ftrace_printk(), size is a 32-bit unsigned int. If
size is UINT_MAX, size + 1 deterministically wraps to 0. This results in a
0-byte allocation, into which do_read() subsequently attempts to read
UINT_MAX bytes.

A similar issue exists here in read_saved_cmdline() on 32-bit architectures
where size_t is 32-bit.

>  	if (buf == NULL) {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260803145958.299956-1-tshah@linux.ibm.com?part=2

  reply	other threads:[~2026-08-03 15:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 14:59 [RFC PATCH v3 0/5] Add perf.data tracepoint events to trace.dat conversion Tanushree Shah
2026-08-03 14:59 ` [RFC PATCH v3 1/5] perf/trace-dat: Add trace.dat export infrastructure Tanushree Shah
2026-08-03 15:14   ` sashiko-bot
2026-08-03 14:59 ` [RFC PATCH v3 2/5] perf/trace-event: Write trace.dat metadata sections during parsing Tanushree Shah
2026-08-03 15:14   ` sashiko-bot [this message]
2026-08-03 14:59 ` [RFC PATCH v3 3/5] perf data-convert: Add perf.data to trace.dat conversion backend Tanushree Shah
2026-08-03 15:11   ` sashiko-bot
2026-08-03 14:59 ` [RFC PATCH v3 4/5] perf data: Add --to-trace-dat option for converting perf.data tracepoint events into trace.dat format Tanushree Shah
2026-08-03 15:13   ` sashiko-bot
2026-08-03 14:59 ` [RFC PATCH v3 5/5] perf test: Add test validating trace.dat generated by 'perf data convert --to-trace-dat' Tanushree Shah
2026-08-03 15:19   ` sashiko-bot
2026-08-06  0:15     ` Ian Rogers
2026-08-06  9:20       ` Tanushree Shah
2026-08-06  0:18 ` [RFC PATCH v3 0/5] Add perf.data tracepoint events to trace.dat conversion 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=20260803151411.4B35C1F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox