Skip to content

Commit 275e6e1

Browse files
Paolo 'Blaisorblade' GiarrussoLinus Torvalds
authored andcommitted
[PATCH] uml: fix compilation and execution with hardened GCC
To make some half-assembly stubs compile, disable various "hardened" GCC features: *) we can't make it build PIC code as we need %ebx to do syscalls and GCC wants it free for PIC *) we can't leave stack protection as the stub is moved (not relocated!) in memory so the RIP-relative access to the canary tries reading from an unmapped address and causes a segfault, since we move the stub of various megabytes (the exact amount will be decided at runtime) away from the link-time address. Signed-off-by: Paolo 'Blaisorblade' Giarrusso <[email protected]> Acked-by: Jeff Dike <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent cb8aa3d commit 275e6e1

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

arch/um/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ prepare: $(ARCH_DIR)/include/kern_constants.h
118118
LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
119119
LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib
120120

121+
CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \
122+
$(call cc-option, -fno-stack-protector,) \
123+
$(call cc-option, -fno-stack-protector-all,)
124+
121125
CPP_MODE-$(CONFIG_MODE_TT) := -DMODE_TT
122126
CONFIG_KERNEL_STACK_ORDER ?= 2
123127
STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )
@@ -227,4 +231,4 @@ $(ARCH_DIR)/include/kern_constants.h: $(objtree)/$(ARCH_DIR)/include
227231
@echo ' SYMLINK $@'
228232
$(Q)ln -sf ../../../include/asm-um/asm-offsets.h $@
229233

230-
export SUBARCH USER_CFLAGS OS
234+
export SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING OS

arch/um/kernel/skas/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,11 @@ USER_OBJS := clone.o
1111
include arch/um/scripts/Makefile.rules
1212

1313
# clone.o is in the stub, so it can't be built with profiling
14-
$(obj)/clone.o : c_flags = -Wp,-MD,$(depfile) $(call unprofile,$(USER_CFLAGS))
14+
# GCC hardened also auto-enables -fpic, but we need %ebx so it can't work ->
15+
# disable it
16+
17+
CFLAGS_clone.o := $(CFLAGS_NO_HARDENING)
18+
19+
# since we're setting c_flags we _must_ add $(CFLAGS_$(*F).o).
20+
21+
$(obj)/clone.o : c_flags = -Wp,-MD,$(depfile) $(call unprofile,$(USER_CFLAGS)) $(CFLAGS_$(*F).o)

arch/um/sys-i386/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ USER_OBJS := bugs.o ptrace_user.o sigcontext.o fault.o stub_segv.o
1313
USER_OBJS += user-offsets.s
1414
extra-y += user-offsets.s
1515

16+
CFLAGS_stub_segv.o := $(CFLAGS_NO_HARDENING)
17+
1618
extra-$(CONFIG_MODE_TT) += unmap.o
1719

1820
include arch/um/scripts/Makefile.rules

arch/um/sys-x86_64/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ USER_OBJS := ptrace_user.o sigcontext.o stub_segv.o
2121
USER_OBJS += user-offsets.s
2222
extra-y += user-offsets.s
2323

24+
CFLAGS_stub_segv.o := $(CFLAGS_NO_HARDENING)
25+
2426
extra-$(CONFIG_MODE_TT) += unmap.o
2527

2628
include arch/um/scripts/Makefile.rules

0 commit comments

Comments
 (0)