[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20251002153025.2209281-21-sashal@kernel.org>
Date: Thu, 2 Oct 2025 11:30:08 -0400
From: Sasha Levin <sashal@...nel.org>
To: patches@...ts.linux.dev,
stable@...r.kernel.org
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
Nathan Chancellor <nathan@...nel.org>,
Nicolas Schier <nicolas@...sle.eu>,
Borislav Petkov <bp@...en8.de>,
Sasha Levin <sashal@...nel.org>,
yamada.masahiro@...ionext.com,
michal.lkml@...kovi.net,
ast@...nel.org,
daniel@...earbox.net,
linux-kbuild@...r.kernel.org,
netdev@...r.kernel.org,
bpf@...r.kernel.org
Subject: [PATCH AUTOSEL 6.17-6.6] Unbreak 'make tools/*' for user-space targets
From: Linus Torvalds <torvalds@...ux-foundation.org>
[ Upstream commit ee916dccd4df6e2fd19c3606c4735282b72f1473 ]
This pattern isn't very documented, and apparently not used much outside
of 'make tools/help', but it has existed for over a decade (since commit
ea01fa9f63ae: "tools: Connect to the kernel build system").
However, it doesn't work very well for most cases, particularly the
useful "tools/all" target, because it overrides the LDFLAGS value with
an empty one.
And once overridden, 'make' will then not honor the tooling makefiles
trying to change it - which then makes any LDFLAGS use in the tooling
directory break, typically causing odd link errors.
Remove that LDFLAGS override, since it seems to be entirely historical.
The core kernel makefiles no longer modify LDFLAGS as part of the build,
and use kernel-specific link flags instead (eg 'KBUILD_LDFLAGS' and
friends).
This allows more of the 'make tools/*' cases to work. I say 'more',
because some of the tooling build rules make various other assumptions
or have other issues, so it's still a bit hit-or-miss. But those issues
tend to show up with the 'make -C tools xyz' pattern too, so now it's no
longer an issue of this particular 'tools/*' build rule being special.
Acked-by: Nathan Chancellor <nathan@...nel.org>
Cc: Nicolas Schier <nicolas@...sle.eu>
Cc: Borislav Petkov <bp@...en8.de>
Signed-off-by: Linus Torvalds <torvalds@...ux-foundation.org>
Signed-off-by: Sasha Levin <sashal@...nel.org>
---
LLM Generated explanations, may be completely bogus:
Based on my comprehensive analysis of this commit, here is my
determination:
## **Backport Status: YES**
### Detailed Analysis
#### Historical Context
The `LDFLAGS=` override was added in commit ea01fa9f63ae (2012) by
Borislav Petkov with the comment "Clear a bunch of variables before
executing the submake." This was done when the tools build system was
first connected to the kernel build system. However, this override is
now obsolete since modern kernel builds use `KBUILD_LDFLAGS` instead of
`LDFLAGS` (Makefile:1447-1448).
#### What the Commit Fixes
**Build Errors**: The commit fixes link errors when using `make
tools/all` or `make tools/<toolname>` from the top-level kernel
directory. By overriding `LDFLAGS=` (setting it to empty), the top-level
Makefile prevents tools' makefiles from setting their own linker flags,
causing link failures.
**Security Issue**: More critically, this prevents distribution-provided
security flags from being applied. As demonstrated by commit
0e0b27dbede5e ("tools/rv: Keep user LDFLAGS in build"), not honoring
`LDFLAGS` causes tools to be built without PIE (Position Independent
Executable), which prevents ASLR (Address Space Layout Randomization) -
a critical security mitigation against ROP attacks.
#### Evidence from Related Commits
Multiple tools have had to work around LDFLAGS issues:
- `d81bab116b485`: tools/bootconfig - explicitly specify LDFLAGS
- `0e0b27dbede5e`: tools/rv - Keep user LDFLAGS (security: PIE not
enabled)
- `9adc4dc96722b`: tools/runqslower - Fix LDFLAGS usage (caused link
failures)
#### Alignment with Stable Kernel Rules
>From Documentation/process/stable-kernel-rules.rst:
✅ **Line 18-20**: "It fixes a problem like... **a build error** (but not
for things marked CONFIG_BROKEN)"
✅ **Line 18**: "a real **security issue**" - Tools not being built with
PIE/ASLR
✅ **Line 10**: "obviously correct and tested" - Simple 2-line change,
Acked-by Nathan Chancellor
✅ **Line 11**: "cannot be bigger than 100 lines" - Only 4 lines changed
total
#### Risk Assessment
**Risk: VERY LOW**
- Removes obsolete override (kernel hasn't used LDFLAGS since switching
to KBUILD_LDFLAGS)
- Only affects `make tools/*` pattern from top-level Makefile
- Tools already work correctly with `make -C tools` pattern
- Change makes behavior consistent between both invocation methods
#### Code Analysis
The change at Makefile:1447-1448:
```diff
-$(Q)$(MAKE) LDFLAGS= O=$(abspath $(objtree)) subdir=tools -C
$(srctree)/tools/
+$(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/
```
This allows tools makefiles like tools/perf/Makefile.perf:528 and
tools/bpf/bpftool/Makefile:186 to properly use `LDFLAGS` during linking,
including distribution-provided flags for hardening (PIE, RELRO, etc.).
### Conclusion
This commit **should be backported** because it:
1. Fixes documented build errors (meets stable rule line 19-20)
2. Addresses a security issue where tools aren't built with hardening
flags (meets stable rule line 18)
3. Is minimal, safe, and obviously correct
4. Has been Acked by a kernel maintainer
5. Removes technical debt that has caused repeated issues across
multiple tools
The commit already appears to have been selected for backport via
AUTOSEL (evidenced by `Signed-off-by: Sasha Levin`), which is
appropriate given it fixes both build failures and a security concern.
Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 82bb9cdf73a32..76dddefde0540 100644
--- a/Makefile
+++ b/Makefile
@@ -1444,11 +1444,11 @@ endif
tools/: FORCE
$(Q)mkdir -p $(objtree)/tools
- $(Q)$(MAKE) LDFLAGS= O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/
+ $(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/
tools/%: FORCE
$(Q)mkdir -p $(objtree)/tools
- $(Q)$(MAKE) LDFLAGS= O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $*
+ $(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $*
# ---------------------------------------------------------------------------
# Kernel selftest
--
2.51.0
Powered by blists - more mailing lists