Skip to content

Commit 6392b4e

Browse files
minipliolsajiri
authored andcommitted
perf x86: Fix perf to use non-executable stack, again
arch/x86/tests/regs_load.S is missing the linker note about the stack requirements, therefore making the linker fall back to an executable stack. As this object gets linked against the final perf binary, it'll needlessly end up with an executable stack. Fix this by adding the appropriate linker note. Also add a global linker flag to prevent future regressions, as suggested by Jiri. This way perf won't get an executable stack even if we fail to add the .GNU-stack linker note to future assembler files. Though, doing so might create regressions the other way around, when (statically) linking against libraries needing an executable stack. But, apparently, regressing in that direction is wanted as it is an indicator of poor code quality -- or just missing linker notes. Fixes: 3c8b06f ("perf tests x86: Introduce perf_regs_load function") Signed-off-by: Mathias Krause <minipli@googlemail.com> Acked-by: Ingo Molnar <mingo@kernel.org> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1398617466-22749-1-git-send-email-minipli@googlemail.com Signed-off-by: Jiri Olsa <jolsa@kernel.org>
1 parent 603940b commit 6392b4e

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎tools/perf/arch/x86/tests/regs_load.S‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#include <linux/linkage.h>
32

43
#define AX 0
@@ -90,3 +89,10 @@ ENTRY(perf_regs_load)
9089
ret
9190
ENDPROC(perf_regs_load)
9291
#endif
92+
93+
/*
94+
* We need to provide note.GNU-stack section, saying that we want
95+
* NOT executable stack. Otherwise the final linking will assume that
96+
* the ELF stack should not be restricted at all and set it RWX.
97+
*/
98+
.section .note.GNU-stack,"",@progbits

‎tools/perf/config/Makefile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ CFLAGS += -Wall
117117
CFLAGS += -Wextra
118118
CFLAGS += -std=gnu99
119119

120+
# Enforce a non-executable stack, as we may regress (again) in the future by
121+
# adding assembler files missing the .GNU-stack linker note.
122+
LDFLAGS += -Wl,-z,noexecstack
123+
120124
EXTLIBS = -lelf -lpthread -lrt -lm -ldl
121125

122126
ifneq ($(OUTPUT),)

0 commit comments

Comments
 (0)