Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Namhyung Kim" <namhyung@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v3 7/7] perf trace: Update beautifier script for clone flags
Date: Tue, 12 May 2026 21:54:02 +0000	[thread overview]
Message-ID: <20260512215402.B5FFEC2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260510202346.49853-8-namhyung@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Adding 64-bit flag masks introduces an undefined behavior shift overflow on 32-bit platforms, causing corrupt perf trace output.
- [Medium] Missing empty input handling in `xargs` generates a buggy C array entry when compiled against older kernel headers.
--

commit 0277447cb377648d9d63a42e778d841a1fdaac29
Author: Namhyung Kim <namhyung@kernel.org>
perf trace: Update beautifier script for clone flags

This commit updates the clone beautifier script to parse newer clone flags
that use the 1ULL shift pattern. It extracts 64-bit clone3 flags up to bit
37 to generate the clone_flags array.

[ ... ]
>       [ilog2(0x80000000) + 1] = "IO",
>       [ilog2(0x00000080) + 1] = "NEWTIME",
>       [32 + 1] = "CLEAR_SIGHAND",
>       [33 + 1] = "INTO_CGROUP",
>       [34 + 1] = "AUTOREAP",
>       [35 + 1] = "NNP",
>       [36 + 1] = "PIDFD_AUTOKILL",
>       [37 + 1] = "EMPTY_MNTNS",
> };

Does this cause undefined behavior on 32-bit platforms?

The generated array now includes entries for bits up to 37. When perf trace
consumes this array in strarray__scnprintf_flags(), it computes the bit
mask using an unsigned long shift:

    unsigned long bit = 1UL << (i - 1);

On 32-bit architectures, unsigned long is 32 bits. Shifting by 32 or more
is undefined behavior and often wraps the shift count. This could cause
standard 32-bit clone syscalls to falsely match the new 64-bit flag names
if the corresponding wrapped lower bit is set, corrupting the tool's output.

> diff --git a/tools/perf/trace/beauty/clone.sh b/tools/perf/trace/beauty/clone.sh
> index 18b6c0d756937..98cb1f8d4a6ff 100755
> --- a/tools/perf/trace/beauty/clone.sh
> +++ b/tools/perf/trace/beauty/clone.sh
> @@ -14,4 +14,8 @@ regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+CLONE_([^_]+[[:alnum:]_]+)[[:
>  grep -E $regex ${linux_sched} | \
>  	sed -r "s/$regex/\2 \1/g"	| \
>  	xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n"
> +regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+CLONE_([^_]+[[:alnum:]_]+)[[:space:]]+\(1ULL[[:space:]]*<<[[:space:]]*([[:digit:]]+)\)[[:space:]]*.*'
> +grep -E $regex ${linux_sched} | \
> +	sed -r "s/$regex/\2 \1/g"	| \
> +	xargs printf "\t[%s + 1] = \"%s\",\n"

Should this use xargs -r? 

If the script is run against older kernel headers that lack the new clone3
flags using the 1ULL shift pattern, grep will yield no output. However,
xargs will still execute printf once with empty arguments.

This results in a generated entry of:

    [ + 1] = "",

which compiles as index 1 (mapping to bit 0) and could cause perf trace
to print confusing empty suffixes for syscalls that set bit 0.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260510202346.49853-1-namhyung@kernel.org?part=7

  reply	other threads:[~2026-05-12 21:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-10 20:23 [PATCH v3 0/7] perf build: Update kernel headers Namhyung Kim
2026-05-10 20:23 ` [PATCH v3 1/7] perf trace: Sync linux/socket.h with the kernel source Namhyung Kim
2026-05-10 20:23 ` [PATCH v3 2/7] perf trace: Sync uapi/linux/fs.h " Namhyung Kim
2026-05-10 20:23 ` [PATCH v3 3/7] perf trace: Sync uapi/linux/mount.h " Namhyung Kim
2026-05-10 20:23 ` [PATCH v3 4/7] perf trace: Sync uapi/linux/sched.h " Namhyung Kim
2026-05-12 21:53   ` sashiko-bot
2026-05-10 20:23 ` [PATCH v3 5/7] perf build: Add make check-headers target Namhyung Kim
2026-05-12 21:54   ` sashiko-bot
2026-05-10 20:23 ` [PATCH v3 6/7] perf trace: Add beautifier script for fsmount flags Namhyung Kim
2026-05-12 21:54   ` sashiko-bot
2026-05-10 20:23 ` [PATCH v3 7/7] perf trace: Update beautifier script for clone flags Namhyung Kim
2026-05-12 21:54   ` sashiko-bot [this message]
2026-05-11 18:22 ` [PATCH v3 0/7] perf build: Update kernel headers 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=20260512215402.B5FFEC2BCB0@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@kernel.org \
    --cc=sashiko@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