Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Leo Yan" <leo.yan@arm.com>
Cc: linux-perf-users@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH v5 06/26] tools build: Append -fzero-init-padding-bits=all to extra cflags
Date: Thu, 13 Aug 2026 21:59:52 +0000	[thread overview]
Message-ID: <20260813215952.A7F641F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260318-tools_build_fix_zero_init-v5-6-bbeffd8da199@arm.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Unconditional appending to `EXTRA_CFLAGS` breaks default optimization and debug flags for `libbpf`.
- [High] The `try-run` macro attempts to write to the source tree during Makefile parsing, breaking out-of-tree builds on read-only filesystems.
- [Medium] The compiler flag `-fzero-init-padding-bits=all` is appended to `HOST_EXTRACFLAGS`, which is never evaluated by the tools build framework, resulting in silent omission of the flag for host programs like bpftool.
- [Medium] The `try-run` macro uses a predictable temporary directory name (`.tmp_$$`), exposing the build process to a local symlink attack (CWE-377).
--

--- Patch [6]: [PATCH v5 06/26] tools build: Append -fzero-init-padding-bits=all to extra cflags ---
commit 526bce400539d6fdc8b0869f05e77b5305dcbce2
Author: Leo Yan <leo.yan@arm.com>

tools build: Append -fzero-init-padding-bits=all to extra cflags

This commit adds -fzero-init-padding-bits=all for tools building to
mitigate a new GCC-15 union initialization behavior. It implements cc-option
and host-cc-option macros to dynamically detect support for this flag.

Link: https://gcc.gnu.org/gcc-15/changes.html

> diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include
> index b5ecf137febca..a2397ceae512c 100644
> --- a/tools/scripts/Makefile.include
> +++ b/tools/scripts/Makefile.include

[ ... ]

> @@ -137,6 +137,36 @@ else
>  EXTRA_WARNINGS += -Wshadow
>  endif
>  
> +# output directory for tests below
> +TMPOUT = .tmp_$$$$
> +
> +# try-run
> +# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
> +# Exit code chooses option. "$$TMP" serves as a temporary file and is
> +# automatically cleaned up.
> +try-run = $(shell set -e;		\
> +	TMP=$(TMPOUT)/tmp;		\

[Severity: Medium]
Is this predictable temporary directory safe against local symlink attacks?

If a user builds the kernel tools in a shared directory, an attacker could
pre-create .tmp_<PID> directories containing a symlink named tmp pointing
to a target file. Because mkdir -p succeeds on existing directories, the
compiler command overwrites the attacker's symlink target.

> +	trap "rm -rf $(TMPOUT)" EXIT;	\
> +	mkdir -p $(TMPOUT);		\

[Severity: High]
Does this directory creation break out-of-tree builds on read-only trees?

Unlike Kbuild, tools Makefiles evaluate shell commands in the source tree
directory. This attempts to write to the source tree instead of the
designated output directory. The mkdir fails on a read-only filesystem,
and set -e aborts the snippet, dropping the compiler flag check.

> +	if ($(1)) >/dev/null 2>&1;	\
> +	then echo "$(2)";		\
> +	else echo "$(3)";		\
> +	fi)

[ ... ]

> +# Explicitly clear padding bits with the initializer '{ 0 }'
> +FLAG_ZERO_INIT := $(call cc-option,-fzero-init-padding-bits=all)
> +override EXTRA_CFLAGS += $(FLAG_ZERO_INIT)

[Severity: High]
Will unconditionally appending to EXTRA_CFLAGS break the default optimization
and debug flags for libraries like libbpf?

Because Makefile.include is included before libbpf evaluates its flags,
EXTRA_CFLAGS is always defined. This forces libbpf to bypass its fallback
logic:

tools/lib/bpf/Makefile:
  ifdef EXTRA_CFLAGS
    CFLAGS := $(EXTRA_CFLAGS)
  else
    CFLAGS := -g -O2
  endif

and builds the library without debug symbols and optimizations.

> +HOST_FLAG_ZERO_INIT := $(call host-cc-option,-fzero-init-padding-bits=all)
> +override HOST_EXTRACFLAGS += $(HOST_FLAG_ZERO_INIT)

[Severity: Medium]
Is HOST_EXTRACFLAGS evaluated by the standalone tools build framework?

The tools build framework relies exclusively on HOSTCFLAGS for host programs,
so appending to HOST_EXTRACFLAGS causes the flag to be ignored for tools
like bpftool.

> +
>  ifneq ($(findstring $(MAKEFLAGS), w),w)
>  PRINT_DIR = --no-print-directory
>  else

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260318-tools_build_fix_zero_init-v5-0-bbeffd8da199@arm.com?part=6

  parent reply	other threads:[~2026-08-13 21:59 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-18  9:16 [PATCH v5 00/26] tools build: Append -fzero-init-padding-bits=all option Leo Yan
2026-03-18  9:16 ` [PATCH v5 01/26] tools: lib: thermal: Fix typo Leo Yan
2026-03-18  9:16 ` [PATCH v5 02/26] tools/thermal: " Leo Yan
2026-03-18  9:16 ` [PATCH v5 03/26] tools: lib: thermal: Initialize CFLAGS before including Makefile.include Leo Yan
2026-03-18  9:16 ` [PATCH v5 04/26] tools/thermal: " Leo Yan
2026-03-18  9:16 ` [PATCH v5 05/26] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS Leo Yan
2026-03-18  9:16 ` [PATCH v5 06/26] tools build: Append -fzero-init-padding-bits=all to extra cflags Leo Yan
2026-03-18 16:38   ` Ian Rogers
2026-03-23 14:23     ` Leo Yan
2026-08-13 21:59   ` sashiko-bot [this message]
2026-03-18  9:16 ` [PATCH v5 07/26] bpftool: Append extra host flags Leo Yan
2026-03-18  9:16 ` [PATCH v5 08/26] perf build: " Leo Yan
2026-03-18  9:16 ` [PATCH v5 09/26] tools build: Append extra host cflags Leo Yan
2026-03-18  9:16 ` [PATCH v5 10/26] tools: bootconfig: Append extra cflags Leo Yan
2026-03-18  9:16 ` [PATCH v5 11/26] tools: counter: " Leo Yan
2026-03-18  9:16 ` [PATCH v5 12/26] tools: dma: " Leo Yan
2026-03-18  9:16 ` [PATCH v5 13/26] tools: gpio: " Leo Yan
2026-03-18  9:16 ` [PATCH v5 14/26] tools: hv: " Leo Yan
2026-03-18  9:16 ` [PATCH v5 15/26] tools: iio: " Leo Yan
2026-03-18  9:17 ` [PATCH v5 16/26] tools: mm: " Leo Yan
2026-03-18  9:17 ` [PATCH v5 17/26] tools: objtool: Append extra host cflags Leo Yan
2026-03-18  9:17 ` [PATCH v5 18/26] tools: power: acpi: Append extra cflags Leo Yan
2026-03-18  9:17 ` [PATCH v5 19/26] tools: power: x86/intel-speed-select: " Leo Yan
2026-03-18  9:17 ` [PATCH v5 20/26] tools: sched_ext: " Leo Yan
2026-03-18  9:17 ` [PATCH v5 21/26] tools: spi: " Leo Yan
2026-03-18  9:17 ` [PATCH v5 22/26] tools: tracing: " Leo Yan
2026-03-18  9:17 ` [PATCH v5 23/26] tools: usb: " Leo Yan
2026-03-18  9:17 ` [PATCH v5 24/26] selftests/hid: " Leo Yan
2026-03-18  9:17 ` [PATCH v5 25/26] selftests/nolibc: " Leo Yan
2026-03-18  9:17 ` [PATCH v5 26/26] selftests/sched_ext: " Leo Yan
2026-03-18 11:53 ` [PATCH v5 00/26] tools build: Append -fzero-init-padding-bits=all option Peter Zijlstra
2026-03-18 15:13   ` Leo Yan
2026-03-18 14:56 ` Quentin Monnet
2026-03-18 15:09   ` Leo Yan

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=20260813215952.A7F641F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=leo.yan@arm.com \
    --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