arch: um: Mark the stack non-executable to fix a binutils warning
Subsystems (3)
PATCH v2 1/1 arch: um: Mark the stack non-executable to fix a binutils warning
Since binutils 2.39, ld will print a warning if any stack section is executable, which is the default for stack sections on files without a .note.GNU-stack section.
This was fixed for x86 in commit ffcf9c5700e4 ("x86: link vdso and boot with -z noexecstack --no-warn-rwx-segments"), but remained broken for UML, resulting in several warnings:
/usr/bin/ld: warning: arch/x86/um/vdso/vdso.o: missing .note.GNU-stack section implies executable stack /usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker /usr/bin/ld: warning: .tmp_vmlinux.kallsyms1 has a LOAD segment with RWX permissions /usr/bin/ld: warning: .tmp_vmlinux.kallsyms1.o: missing .note.GNU-stack section implies executable stack /usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker /usr/bin/ld: warning: .tmp_vmlinux.kallsyms2 has a LOAD segment with RWX permissions /usr/bin/ld: warning: .tmp_vmlinux.kallsyms2.o: missing .note.GNU-stack section implies executable stack /usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker /usr/bin/ld: warning: vmlinux has a LOAD segment with RWX permissions
Link both the VDSO and vmlinux with -z noexecstack, fixing the warnings about .note.GNU-stack sections. In addition, pass --no-warn-rwx-segments to dodge the remaining warnings about LOAD segments with RWX permissions in the kallsyms objects. (Note that this flag is apparently not available on lld, so hide it behind a test for BFD, which is what the x86 patch does.)
---
Note that this still doesn't seem to be working properly with make LLVM=1. It doesn't appear to break anything, and still is an improvement for gcc, so seems worthwhile anyway...
Changes since v1:
http://lists.infradead.org/pipermail/linux-um/2022-August/004234.html
- Pass the -z noexecstack and --no-warn-rwx-segments flags as LDFLAGS, rather than as CFLAGS via -Wl
- Check that --no-warn-rwx-segments exists with the ld-option function (Thanks Richard)
- Add Lukas and Randy's tags.
arch/um/Makefile | 8 ++++++++ arch/x86/um/vdso/Makefile | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-)
arch/um/Makefile +8 -0
@@ -132,10 +132,18 @@ export LDS_ELF_FORMAT := $(ELF_FORMAT) # The wrappers will select whether using "malloc" or the kernel allocator. LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc +# Avoid binutils 2.39+ warnings by marking the stack non-executable and +# ignorning warnings for the kallsyms sections. +LDFLAGS_EXECSTACK = -z noexecstack +ifeq ($(CONFIG_LD_IS_BFD),y) +LDFLAGS_EXECSTACK += $(call ld-option,--no-warn-rwx-segments) +endif + LD_FLAGS_CMDLINE = $(foreach opt,$(KBUILD_LDFLAGS),-Wl,$(opt)) # Used by link-vmlinux.sh which has special support for um link export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE) +export LDFLAGS_vmlinux := $(LDFLAGS_EXECSTACK) # When cleaning we don't include .config, so we don't include # TT or skas makefiles and don't clean skas_ptregs.h.
arch/x86/um/vdso/Makefile +1 -1
@@ -65,7 +65,7 @@ quiet_cmd_vdso = VDSO $@ -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \ sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@' -VDSO_LDFLAGS = -fPIC -shared -Wl,--hash-style=sysv +VDSO_LDFLAGS = -fPIC -shared -Wl,--hash-style=sysv -z noexecstack GCOV_PROFILE := n #
Signature · 1 line
2.37.3.968.ga6b4b080e4-goog
Richard Weinberger
maintainer----- Ursprüngliche Mail -----
Quoted 9 lines
Von: "davidgow" <[email protected]>
Changes since v1:
http://lists.infradead.org/pipermail/linux-um/2022-August/004234.html
- Pass the -z noexecstack and --no-warn-rwx-segments flags as LDFLAGS, rather than as CFLAGS via -Wl
- Check that --no-warn-rwx-segments exists with the ld-option function (Thanks Richard)
- Add Lukas and Randy's tags.
Now it passes the test. :)
Applied.
Thanks,
//richard
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Quoted 31 lines · David Gow
Since binutils 2.39, ld will print a warning if any stack section is executable, which is the default for stack sections on files without a .note.GNU-stack section.
This was fixed for x86 in commit
ffcf9c5700e4("x86: link vdso and boot with -z noexecstack --no-warn-rwx-segments"), but remained broken for UML, resulting in several warnings:
/usr/bin/ld: warning:arch/x86/um/vdso/vdso.o: missing .note.GNU-stack section implies executable stack/usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker/usr/bin/ld: warning: .tmp_vmlinux.kallsyms1 has a LOAD segment with RWX permissions/usr/bin/ld: warning: .tmp_vmlinux.kallsyms1.o: missing .note.GNU-stack section implies executable stack/usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker/usr/bin/ld: warning: .tmp_vmlinux.kallsyms2 has a LOAD segment with RWX permissions/usr/bin/ld: warning: .tmp_vmlinux.kallsyms2.o: missing .note.GNU-stack section implies executable stack/usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker/usr/bin/ld: warning: vmlinux has a LOAD segment with RWX permissionsLink both the VDSO and vmlinux with -z noexecstack, fixing the warnings about .note.GNU-stack sections. In addition, pass --no-warn-rwx-segments to dodge the remaining warnings about LOAD segments with RWX permissions in the kallsyms objects. (Note that this flag is apparently not available on lld, so hide it behind a test for BFD, which is what the x86 patch does.)
Quoted 5 lines
---
Note that this still doesn't seem to be working properly with make LLVM=1. It doesn't appear to break anything, and still is an improvement for gcc, so seems worthwhile anyway...
Hi David,
Do you have more info about this comment? Perhaps there's more hermiticity issues with ARCH=um when a linker is explicitly specified via LD= or HOSTLD=, or implied via LLVM=1.
Looking at our CI for ARCH=um builds...
https://github.com/ClangBuiltLinux/continuous-integration2/actions/runs/3095779516/jobs/5012260390
warnings from /usr/bin/ld. That's...unexpected.
I've filed https://github.com/ClangBuiltLinux/linux/issues/1715 to follow up on this.
Quoted 53 lines
Changes since v1:
http://lists.infradead.org/pipermail/linux-um/2022-August/004234.html
- Pass the -z noexecstack and --no-warn-rwx-segments flags as LDFLAGS, rather than as CFLAGS via -Wl
- Check that --no-warn-rwx-segments exists with the ld-option function (Thanks Richard)
- Add Lukas and Randy's tags.arch/um/Makefile | 8 ++++++++ arch/x86/um/vdso/Makefile | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-)arch/um/Makefile +8
-0@@ -132,10 +132,18 @@ export LDS_ELF_FORMAT := $(ELF_FORMAT) # The wrappers will select whether using "malloc" or the kernel allocator. LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc +# Avoid binutils 2.39+ warnings by marking the stack non-executable and +# ignorning warnings for the kallsyms sections. +LDFLAGS_EXECSTACK = -z noexecstack +ifeq ($(CONFIG_LD_IS_BFD),y) +LDFLAGS_EXECSTACK += $(call ld-option,--no-warn-rwx-segments) +endif + LD_FLAGS_CMDLINE = $(foreach opt,$(KBUILD_LDFLAGS),-Wl,$(opt)) # Used by link-vmlinux.sh which has special support for um link export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE) +export LDFLAGS_vmlinux := $(LDFLAGS_EXECSTACK) # When cleaning we don't include .config, so we don't include # TT or skas makefiles and don't clean skas_ptregs.h.arch/x86/um/vdso/Makefile +1
-2@@ -65,7 +65,7 @@ quiet_cmd_vdso = VDSO $@ -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \ sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@' -VDSO_LDFLAGS = -fPIC -shared -Wl,--hash-style=sysv +VDSO_LDFLAGS = -fPIC -shared -Wl,--hash-style=sysv -z noexecstack GCOV_PROFILE := n # --2.37.3.968.ga6b4b080e4-goog
Signature · 2 lines
Thanks, ~Nick Desaulniers
PATCH v2 1/1 arch: um: Mark the stack non-executable to fix a binutils warning
If there's a reply, I'll cc in kbuild...for now just a heads up.
---------- Forwarded message ---------
From: Nick Desaulniers <[email protected]>
Date: Wed, Sep 21, 2022 at 10:47 AM
Subject: Re: [PATCH v2] arch: um: Mark the stack non-executable to fix a binutils warning
To: David Gow <[email protected]>
Cc: Richard Weinberger <[email protected]>, Anton Ivanov <[email protected]>, Johannes Berg <[email protected]>, David Gow <[email protected]>, Thomas Gleixner <[email protected]>, Ingo Molnar <[email protected]>, Dave Hansen <[email protected]>, Linus Torvalds <[email protected]>, Brendan Higgins <[email protected]>, Daniel Latypov <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, Lukas Straub <[email protected]>, Randy Dunlap <[email protected]>, clang-built-linux <[email protected]>
Quoted 31 lines · David Gow
Since binutils 2.39, ld will print a warning if any stack section is executable, which is the default for stack sections on files without a .note.GNU-stack section.
This was fixed for x86 in commit
ffcf9c5700e4("x86: link vdso and boot with -z noexecstack --no-warn-rwx-segments"), but remained broken for UML, resulting in several warnings:
/usr/bin/ld: warning:arch/x86/um/vdso/vdso.o: missing .note.GNU-stack section implies executable stack/usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker/usr/bin/ld: warning: .tmp_vmlinux.kallsyms1 has a LOAD segment with RWX permissions/usr/bin/ld: warning: .tmp_vmlinux.kallsyms1.o: missing .note.GNU-stack section implies executable stack/usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker/usr/bin/ld: warning: .tmp_vmlinux.kallsyms2 has a LOAD segment with RWX permissions/usr/bin/ld: warning: .tmp_vmlinux.kallsyms2.o: missing .note.GNU-stack section implies executable stack/usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker/usr/bin/ld: warning: vmlinux has a LOAD segment with RWX permissionsLink both the VDSO and vmlinux with -z noexecstack, fixing the warnings about .note.GNU-stack sections. In addition, pass --no-warn-rwx-segments to dodge the remaining warnings about LOAD segments with RWX permissions in the kallsyms objects. (Note that this flag is apparently not available on lld, so hide it behind a test for BFD, which is what the x86 patch does.)
Quoted 5 lines
---
Note that this still doesn't seem to be working properly with make LLVM=1. It doesn't appear to break anything, and still is an improvement for gcc, so seems worthwhile anyway...
Hi David,
Do you have more info about this comment? Perhaps there's more hermiticity issues with ARCH=um when a linker is explicitly specified via LD= or HOSTLD=, or implied via LLVM=1.
Looking at our CI for ARCH=um builds...
https://github.com/ClangBuiltLinux/continuous-integration2/actions/runs/3095779516/jobs/5012260390
warnings from /usr/bin/ld. That's...unexpected.
I've filed https://github.com/ClangBuiltLinux/linux/issues/1715 to follow up on this.
Quoted 51 lines
Changes since v1:
http://lists.infradead.org/pipermail/linux-um/2022-August/004234.html
- Pass the -z noexecstack and --no-warn-rwx-segments flags as LDFLAGS, rather than as CFLAGS via -Wl
- Check that --no-warn-rwx-segments exists with the ld-option function (Thanks Richard)
- Add Lukas and Randy's tags.arch/um/Makefile | 8 ++++++++ arch/x86/um/vdso/Makefile | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-)arch/um/Makefile +8
-0@@ -132,10 +132,18 @@ export LDS_ELF_FORMAT := $(ELF_FORMAT) # The wrappers will select whether using "malloc" or the kernel allocator. LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc +# Avoid binutils 2.39+ warnings by marking the stack non-executable and +# ignorning warnings for the kallsyms sections. +LDFLAGS_EXECSTACK = -z noexecstack +ifeq ($(CONFIG_LD_IS_BFD),y) +LDFLAGS_EXECSTACK += $(call ld-option,--no-warn-rwx-segments) +endif + LD_FLAGS_CMDLINE = $(foreach opt,$(KBUILD_LDFLAGS),-Wl,$(opt)) # Used by link-vmlinux.sh which has special support for um link export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE) +export LDFLAGS_vmlinux := $(LDFLAGS_EXECSTACK) # When cleaning we don't include .config, so we don't include # TT or skas makefiles and don't clean skas_ptregs.h.arch/x86/um/vdso/Makefile +1
-2@@ -65,7 +65,7 @@ quiet_cmd_vdso = VDSO $@ -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \ sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@' -VDSO_LDFLAGS = -fPIC -shared -Wl,--hash-style=sysv +VDSO_LDFLAGS = -fPIC -shared -Wl,--hash-style=sysv -z noexecstack GCOV_PROFILE := n # --
Quoted 2 lines
2.37.3.968.ga6b4b080e4-goog
--
Thanks,
~Nick Desaulniers
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 44 lines · Nick Desaulniers' via KUnit Development
Quoted 31 lines · David Gow
Since binutils 2.39, ld will print a warning if any stack section is executable, which is the default for stack sections on files without a .note.GNU-stack section.
This was fixed for x86 in commit
ffcf9c5700e4("x86: link vdso and boot with -z noexecstack --no-warn-rwx-segments"), but remained broken for UML, resulting in several warnings:
/usr/bin/ld: warning:arch/x86/um/vdso/vdso.o: missing .note.GNU-stack section implies executable stack/usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker/usr/bin/ld: warning: .tmp_vmlinux.kallsyms1 has a LOAD segment with RWX permissions/usr/bin/ld: warning: .tmp_vmlinux.kallsyms1.o: missing .note.GNU-stack section implies executable stack/usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker/usr/bin/ld: warning: .tmp_vmlinux.kallsyms2 has a LOAD segment with RWX permissions/usr/bin/ld: warning: .tmp_vmlinux.kallsyms2.o: missing .note.GNU-stack section implies executable stack/usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker/usr/bin/ld: warning: vmlinux has a LOAD segment with RWX permissionsLink both the VDSO and vmlinux with -z noexecstack, fixing the warnings about .note.GNU-stack sections. In addition, pass --no-warn-rwx-segments to dodge the remaining warnings about LOAD segments with RWX permissions in the kallsyms objects. (Note that this flag is apparently not available on lld, so hide it behind a test for BFD, which is what the x86 patch does.)
Quoted 5 lines
---
Note that this still doesn't seem to be working properly with make LLVM=1. It doesn't appear to break anything, and still is an improvement for gcc, so seems worthwhile anyway...
Hi David,
Do you have more info about this comment? Perhaps there's more hermiticity issues with ARCH=um when a linker is explicitly specified via LD= or HOSTLD=, or implied via LLVM=1.
Quoted 6 lines
Looking at our CI for ARCH=um builds...
https://github.com/ClangBuiltLinux/continuous-integration2/actions/runs/3095779516/jobs/5012260390
warnings from/usr/bin/ld. That's...unexpected.
I've filed https://github.com/ClangBuiltLinux/linux/issues/1715 to follow up on this.
Thanks for following up on this.
Yeah: what I'm seeing seems to match it does look like ld is being used instead of lld.
I tried -fuse-ld=lld via the following patch, though, and got a whole bunch of "error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC" errors, so I think there's probably more issues with UML and LLD that need working out. (I had no luck with CONFIG_STATIC_LINK=y, nor with an attempt to use $(LD) directly, instead of via $(CC)).
---
arch/um/Makefile +0 -0
@@ -139,6 +139,9 @@ ifeq ($(CONFIG_LD_IS_BFD),y)
LDFLAGS_EXECSTACK += $(call ld-option,--no-warn-rwx-segments) endif
+# Since we're using CC as the driver, we need to force LLD if it is requested. +LINK-$(CONFIG_LD_IS_LLD) += $(call cc-option,--ld-path=$(LD),-fuse-ld=lld) +LD_FLAGS_CMDLINE = $(foreach opt,$(KBUILD_LDFLAGS),-Wl,$(opt))
# Used by link-vmlinux.sh which has special support for um link
---
I'll update the GitHub issue with these notes as well, but I definitely think it'd be best not to make UML use lld here until it actually builds something: even with the warnings, ld is at least latting us run at all.
Cheers,
-- David
Quoted 63 lines
Quoted 51 lines
Changes since v1:
http://lists.infradead.org/pipermail/linux-um/2022-August/004234.html
- Pass the -z noexecstack and --no-warn-rwx-segments flags as LDFLAGS, rather than as CFLAGS via -Wl
- Check that --no-warn-rwx-segments exists with the ld-option function (Thanks Richard)
- Add Lukas and Randy's tags.arch/um/Makefile | 8 ++++++++ arch/x86/um/vdso/Makefile | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-)arch/um/Makefile +8
-0@@ -132,10 +132,18 @@ export LDS_ELF_FORMAT := $(ELF_FORMAT) # The wrappers will select whether using "malloc" or the kernel allocator. LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc +# Avoid binutils 2.39+ warnings by marking the stack non-executable and +# ignorning warnings for the kallsyms sections. +LDFLAGS_EXECSTACK = -z noexecstack +ifeq ($(CONFIG_LD_IS_BFD),y) +LDFLAGS_EXECSTACK += $(call ld-option,--no-warn-rwx-segments) +endif + LD_FLAGS_CMDLINE = $(foreach opt,$(KBUILD_LDFLAGS),-Wl,$(opt)) # Used by link-vmlinux.sh which has special support for um link export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE) +export LDFLAGS_vmlinux := $(LDFLAGS_EXECSTACK) # When cleaning we don't include .config, so we don't include # TT or skas makefiles and don't clean skas_ptregs.h.arch/x86/um/vdso/Makefile +1
-2@@ -65,7 +65,7 @@ quiet_cmd_vdso = VDSO $@ -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \ sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@' -VDSO_LDFLAGS = -fPIC -shared -Wl,--hash-style=sysv +VDSO_LDFLAGS = -fPIC -shared -Wl,--hash-style=sysv -z noexecstack GCOV_PROFILE := n # --Quoted 2 lines
2.37.3.968.ga6b4b080e4-goog
--
Thanks,
~Nick Desaulniers--
You received this message because you are subscribed to the Google Groups "KUnit Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/CAKwvOdnLaDn%3DEfGFhjhcZe4EzvjU7Cws3z3KjLGwW%3DxnqnmHyw%40mail.gmail.com.