* [PATCH] arch: um: Mark the stack non-executable to fix a binutils warning
@ 2022-08-23 1:08 David Gow
2022-08-26 15:39 ` Lukas Straub
2022-08-26 20:35 ` Randy Dunlap
0 siblings, 2 replies; 4+ messages in thread
From: David Gow @ 2022-08-23 1:08 UTC (permalink / raw)
To: Richard Weinberger, Anton Ivanov, Johannes Berg, Nick Desaulniers
Cc: David Gow, Thomas Gleixner, Ingo Molnar, Dave Hansen,
Linus Torvalds, Brendan Higgins, Daniel Latypov, linux-um,
linux-kernel, kunit-dev, x86
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.)
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ffcf9c5700e49c0aee42dcba9a12ba21338e8136
Link: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=ba951afb99912da01a6e8434126b8fac7aa75107
Signed-off-by: David Gow <davidgow@google.com>
---
arch/um/Makefile | 9 ++++++++-
arch/x86/um/vdso/Makefile | 2 +-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/arch/um/Makefile b/arch/um/Makefile
index f2fe63bfd819..75d5c704b3a8 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -132,10 +132,17 @@ 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.
+LINK_RWXSECTION = -Wl,-z,noexecstack
+ifeq ($(CONFIG_LD_IS_BFD),y)
+LINK_RWXSECTION += -Wl,--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 CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LINK_RWXSECTION) $(LD_FLAGS_CMDLINE)
# When cleaning we don't include .config, so we don't include
# TT or skas makefiles and don't clean skas_ptregs.h.
diff --git a/arch/x86/um/vdso/Makefile b/arch/x86/um/vdso/Makefile
index 8c0396fd0e6f..6fbe97c52c99 100644
--- a/arch/x86/um/vdso/Makefile
+++ b/arch/x86/um/vdso/Makefile
@@ -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.1.595.g718a3a8f04-goog
_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] arch: um: Mark the stack non-executable to fix a binutils warning
2022-08-23 1:08 [PATCH] arch: um: Mark the stack non-executable to fix a binutils warning David Gow
@ 2022-08-26 15:39 ` Lukas Straub
2022-08-26 20:35 ` Randy Dunlap
1 sibling, 0 replies; 4+ messages in thread
From: Lukas Straub @ 2022-08-26 15:39 UTC (permalink / raw)
To: linux-um
[-- Attachment #1.1: Type: text/plain, Size: 150 bytes --]
Looks good to me:
Reviewed-by: Lukas Straub <lukasstraub2@web.de>
Tested-by: Lukas Straub <lukasstraub2@web.de>
Regards,
Lukas Straub
--
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
[-- Attachment #2: Type: text/plain, Size: 152 bytes --]
_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] arch: um: Mark the stack non-executable to fix a binutils warning
2022-08-23 1:08 [PATCH] arch: um: Mark the stack non-executable to fix a binutils warning David Gow
2022-08-26 15:39 ` Lukas Straub
@ 2022-08-26 20:35 ` Randy Dunlap
2022-09-19 20:56 ` Richard Weinberger
1 sibling, 1 reply; 4+ messages in thread
From: Randy Dunlap @ 2022-08-26 20:35 UTC (permalink / raw)
To: David Gow, Richard Weinberger, Anton Ivanov, Johannes Berg,
Nick Desaulniers
Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, Linus Torvalds,
Brendan Higgins, Daniel Latypov, linux-um, linux-kernel,
kunit-dev, x86
On 8/22/22 18:08, David Gow wrote:
> 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.)
>
> Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ffcf9c5700e49c0aee42dcba9a12ba21338e8136
> Link: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=ba951afb99912da01a6e8434126b8fac7aa75107
> Signed-off-by: David Gow <davidgow@google.com>
Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
Thanks.
> ---
> arch/um/Makefile | 9 ++++++++-
> arch/x86/um/vdso/Makefile | 2 +-
> 2 files changed, 9 insertions(+), 2 deletions(-)
--
~Randy
_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] arch: um: Mark the stack non-executable to fix a binutils warning
2022-08-26 20:35 ` Randy Dunlap
@ 2022-09-19 20:56 ` Richard Weinberger
0 siblings, 0 replies; 4+ messages in thread
From: Richard Weinberger @ 2022-09-19 20:56 UTC (permalink / raw)
To: Randy Dunlap, davidgow
Cc: anton ivanov, Johannes Berg, Nick Desaulniers, tglx, mingo,
dave hansen, torvalds, Brendan Higgins, Daniel Latypov, linux-um,
linux-kernel, kunit-dev, x86
----- Ursprüngliche Mail -----
> Von: "Randy Dunlap" <rdunlap@infradead.org>
>> Link:
>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ffcf9c5700e49c0aee42dcba9a12ba21338e8136
>> Link:
>> https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=ba951afb99912da01a6e8434126b8fac7aa75107
>> Signed-off-by: David Gow <davidgow@google.com>
>
> Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
This patch causes a build error on one of my systems:
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: unrecognized option '--no-warn-rwx-segments'
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status
Just like in commit ffcf9c5700e4 ("x86: link vdso and boot with -z noexecstack --no-warn-rwx-segments") you need to
test for it.
Thanks,
//richard
_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-09-19 20:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-23 1:08 [PATCH] arch: um: Mark the stack non-executable to fix a binutils warning David Gow
2022-08-26 15:39 ` Lukas Straub
2022-08-26 20:35 ` Randy Dunlap
2022-09-19 20:56 ` Richard Weinberger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).