From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Tom Stellard <tstellar@redhat.com>,
Andrii Nakryiko <andrii@kernel.org>,
Quentin Monnet <qmo@kernel.org>, Sasha Levin <sashal@kernel.org>,
nathan@kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev
Subject: [PATCH AUTOSEL 6.17-6.1] bpftool: Fix -Wuninitialized-const-pointer warnings with clang >= 21
Date: Thu, 9 Oct 2025 11:54:33 -0400 [thread overview]
Message-ID: <20251009155752.773732-7-sashal@kernel.org> (raw)
In-Reply-To: <20251009155752.773732-1-sashal@kernel.org>
From: Tom Stellard <tstellar@redhat.com>
[ Upstream commit 5612ea8b554375d45c14cbb0f8ea93ec5d172891 ]
This fixes the build with -Werror -Wall.
btf_dumper.c:71:31: error: variable 'finfo' is uninitialized when passed as a const pointer argument here [-Werror,-Wuninitialized-const-pointer]
71 | info.func_info = ptr_to_u64(&finfo);
| ^~~~~
prog.c:2294:31: error: variable 'func_info' is uninitialized when passed as a const pointer argument here [-Werror,-Wuninitialized-const-pointer]
2294 | info.func_info = ptr_to_u64(&func_info);
|
v2:
- Initialize instead of using memset.
Signed-off-by: Tom Stellard <tstellar@redhat.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Quentin Monnet <qmo@kernel.org>
Link: https://lore.kernel.org/bpf/20250917183847.318163-1-tstellar@redhat.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
YES
**Rationale**
- Fixes a real build failure with modern toolchains: clang ≥ 21 warns
about passing the address of an uninitialized object to a function
taking a const pointer; with `-Werror -Wall` this breaks bpftool
builds.
- Change is minimal, localized, and non-functional: it only zero-
initializes two local `struct bpf_func_info` instances so the address
isn’t of an uninitialized object.
- Consistent with existing code in the same tool: other bpftool paths
already initialize `bpf_func_info` similarly, so this aligns style and
avoids surprises.
**Code References**
- In `tools/bpf/bpftool/btf_dumper.c:41`, `struct bpf_func_info finfo;`
is currently uninitialized but its address is passed to `ptr_to_u64()`
at `tools/bpf/bpftool/btf_dumper.c:71`, which triggers clang’s
`-Wuninitialized-const-pointer`. The patch changes the declaration to
`struct bpf_func_info finfo = {};`, preventing the warning.
- In `tools/bpf/bpftool/prog.c:2265`, `struct bpf_func_info func_info;`
is uninitialized, and its address is passed to `ptr_to_u64()` at
`tools/bpf/bpftool/prog.c:2294`. The patch changes the declaration to
`struct bpf_func_info func_info = {};`, removing the warning.
- `ptr_to_u64()` is declared as taking a `const void *`
(`tools/bpf/bpftool/main.h:25`), which is why clang applies the const-
pointer uninitialized check when the address of an uninitialized
object is passed.
- A precedent in the same codebase already initializes the same type:
`tools/bpf/bpftool/common.c:416` uses `struct bpf_func_info finfo =
{};`, demonstrating this is the established and safe pattern.
**Why It’s Safe**
- The variables are used strictly as output buffers for
`bpf_prog_get_info_by_fd()`:
- `btf_dumper.c`: Only after `info.nr_func_info` is non-zero and the
second `bpf_prog_get_info_by_fd()` succeeds do we read
`finfo.type_id` (`tools/bpf/bpftool/btf_dumper.c:80`). On error
paths we don’t read `finfo`.
- `prog.c`: We check `info.nr_func_info != 0` before issuing the
second `bpf_prog_get_info_by_fd()`, and only on success read
`func_info.type_id` (`tools/bpf/bpftool/prog.c:2308`).
- Zero-initialization does not change runtime semantics; the kernel
overwrites these structures on success, and on failure paths they
aren’t consumed.
**Stable Backport Criteria**
- Important bugfix: restores bpftool buildability with clang ≥ 21 under
`-Werror -Wall`.
- Small and contained: two initializations; no ABI or behavioral
changes.
- No architectural changes; no risk to core kernel subsystems (user-
space tools only).
- Low regression risk; aligns with existing initialization pattern
already present elsewhere in bpftool.
Given the above, this commit is an excellent candidate for stable
backport to keep tools building with current compilers and to maintain
consistency within bpftool.
tools/bpf/bpftool/btf_dumper.c | 2 +-
tools/bpf/bpftool/prog.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c
index 4e896d8a2416e..ff12628593aec 100644
--- a/tools/bpf/bpftool/btf_dumper.c
+++ b/tools/bpf/bpftool/btf_dumper.c
@@ -38,7 +38,7 @@ static int dump_prog_id_as_func_ptr(const struct btf_dumper *d,
__u32 info_len = sizeof(info);
const char *prog_name = NULL;
struct btf *prog_btf = NULL;
- struct bpf_func_info finfo;
+ struct bpf_func_info finfo = {};
__u32 finfo_rec_size;
char prog_str[1024];
int err;
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index 9722d841abc05..a89629a9932b5 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -2262,7 +2262,7 @@ static void profile_print_readings(void)
static char *profile_target_name(int tgt_fd)
{
- struct bpf_func_info func_info;
+ struct bpf_func_info func_info = {};
struct bpf_prog_info info = {};
__u32 info_len = sizeof(info);
const struct btf_type *t;
--
2.51.0
next prev parent reply other threads:[~2025-10-09 15:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20251009155752.773732-1-sashal@kernel.org>
2025-10-09 15:54 ` [PATCH AUTOSEL 6.17-5.4] bpf: Don't use %pK through printk Sasha Levin
2025-10-09 15:54 ` Sasha Levin [this message]
2025-10-09 15:54 ` [PATCH AUTOSEL 6.17-6.12] bpf: Use tnums for JEQ/JNE is_branch_taken logic Sasha Levin
2025-10-09 15:54 ` [PATCH AUTOSEL 6.17-6.16] selftests/bpf: Fix incorrect array size calculation Sasha Levin
2025-10-09 15:54 ` [PATCH AUTOSEL 6.17-6.12] selftests/bpf: Fix selftest verifier_arena_large failure Sasha Levin
2025-10-09 15:55 ` [PATCH AUTOSEL 6.17-6.1] bpf: Clear pfmemalloc flag when freeing all fragments Sasha Levin
2025-10-09 15:55 ` [PATCH AUTOSEL 6.17-5.4] selftests/bpf: Fix bpf_prog_detach2 usage in test_lirc_mode2 Sasha Levin
2025-10-09 15:55 ` [PATCH AUTOSEL 6.17-6.12] selftests/bpf: Fix flaky bpf_cookie selftest Sasha Levin
2025-10-09 15:55 ` [PATCH AUTOSEL 6.17] selftests: drv-net: Pull data before parsing headers Sasha Levin
2025-10-09 15:55 ` [PATCH AUTOSEL 6.17-6.12] libbpf: Fix USDT SIB argument handling causing unrecognized register error Sasha Levin
2025-10-09 15:55 ` [PATCH AUTOSEL 6.17-6.12] bpftool: Add CET-aware symbol matching for x86_64 architectures Sasha Levin
2025-10-09 15:55 ` [PATCH AUTOSEL 6.17-6.6] bpf: Do not limit bpf_cgroup_from_id to current's namespace Sasha Levin
2025-10-09 15:55 ` [PATCH AUTOSEL 6.17-6.1] selftests/bpf: Upon failures, exit with code 1 in test_xsk.sh Sasha Levin
2025-10-09 15:55 ` [PATCH AUTOSEL 6.17-6.16] selftests/bpf: Fix arena_spin_lock selftest failure Sasha Levin
2025-10-09 15:56 ` [PATCH AUTOSEL 6.17-6.6] riscv: bpf: Fix uninitialized symbol 'retval_off' Sasha Levin
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=20251009155752.773732-7-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=patches@lists.linux.dev \
--cc=qmo@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tstellar@redhat.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