mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Paolo 'Blaisorblade' Giarrusso" <blaisorblade@yahoo.it>
To: Andrew Morton <akpm@osdl.org>
Cc: Jeff Dike <jdike@addtoit.com>,
	linux-kernel@vger.kernel.org,
	user-mode-linux-devel@lists.sourceforge.net
Subject: [PATCH 5/7] uml: fix compilation and execution with hardened GCC
Date: Sun, 30 Apr 2006 16:16:19 +0200	[thread overview]
Message-ID: <20060430141619.9060.68951.stgit@zion.home.lan> (raw)
In-Reply-To: <20060430141512.9060.39338.stgit@zion.home.lan>

From: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>

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 <blaisorblade@yahoo.it>
---

 arch/um/Makefile             |    6 +++++-
 arch/um/kernel/skas/Makefile |    9 ++++++++-
 arch/um/sys-i386/Makefile    |    2 ++
 arch/um/sys-x86_64/Makefile  |    2 ++
 4 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/arch/um/Makefile b/arch/um/Makefile
index 930e006..bed604a 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -118,6 +118,10 @@ prepare: $(ARCH_DIR)/include/kern_consta
 LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
 LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib
 
+CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \
+	$(call cc-option, -fno-stack-protector,) \
+	$(call cc-option, -fno-stack-protector-all,)
+
 CPP_MODE-$(CONFIG_MODE_TT) := -DMODE_TT
 CONFIG_KERNEL_STACK_ORDER ?= 2
 STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )
@@ -227,4 +231,4 @@ $(ARCH_DIR)/include/kern_constants.h: $(
 	@echo '  SYMLINK $@'
 	$(Q)ln -sf ../../../include/asm-um/asm-offsets.h $@
 
-export SUBARCH USER_CFLAGS OS
+export SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING OS
diff --git a/arch/um/kernel/skas/Makefile b/arch/um/kernel/skas/Makefile
index 57181a9..ad84296 100644
--- a/arch/um/kernel/skas/Makefile
+++ b/arch/um/kernel/skas/Makefile
@@ -11,4 +11,11 @@ USER_OBJS := clone.o
 include arch/um/scripts/Makefile.rules
 
 # clone.o is in the stub, so it can't be built with profiling
-$(obj)/clone.o : c_flags = -Wp,-MD,$(depfile) $(call unprofile,$(USER_CFLAGS))
+# GCC hardened also auto-enables -fpic, but we need %ebx so it can't work ->
+# disable it
+
+CFLAGS_clone.o := $(CFLAGS_NO_HARDENING)
+
+# since we're setting c_flags we _must_ add $(CFLAGS_$(*F).o).
+
+$(obj)/clone.o : c_flags = -Wp,-MD,$(depfile) $(call unprofile,$(USER_CFLAGS)) $(CFLAGS_$(*F).o)
diff --git a/arch/um/sys-i386/Makefile b/arch/um/sys-i386/Makefile
index 82121ab..3734c3e 100644
--- a/arch/um/sys-i386/Makefile
+++ b/arch/um/sys-i386/Makefile
@@ -13,6 +13,8 @@ USER_OBJS := bugs.o ptrace_user.o sigcon
 USER_OBJS += user-offsets.s
 extra-y += user-offsets.s
 
+CFLAGS_stub_segv.o := $(CFLAGS_NO_HARDENING)
+
 extra-$(CONFIG_MODE_TT) += unmap.o
 
 include arch/um/scripts/Makefile.rules
diff --git a/arch/um/sys-x86_64/Makefile b/arch/um/sys-x86_64/Makefile
index f739bea..6d3b29c 100644
--- a/arch/um/sys-x86_64/Makefile
+++ b/arch/um/sys-x86_64/Makefile
@@ -21,6 +21,8 @@ USER_OBJS := ptrace_user.o sigcontext.o 
 USER_OBJS += user-offsets.s
 extra-y += user-offsets.s
 
+CFLAGS_stub_segv.o := $(CFLAGS_NO_HARDENING)
+
 extra-$(CONFIG_MODE_TT) += unmap.o
 
 include arch/um/scripts/Makefile.rules

  parent reply	other threads:[~2006-04-30 14:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-30 14:15 [PATCH 0/7] Uml fixes for 2.6.17 Paolo 'Blaisorblade' Giarrusso
2006-04-30 14:16 ` [PATCH 1/7] uml: fix patch mismerge Paolo 'Blaisorblade' Giarrusso
2006-04-30 14:16 ` [PATCH 2/7] uml: search from uml_net in a more reasonable PATH Paolo 'Blaisorblade' Giarrusso
2006-04-30 14:16 ` [PATCH 3/7] uml: make copy_*_user atomic Paolo 'Blaisorblade' Giarrusso
2006-04-30 15:32   ` Blaisorblade
2006-04-30 14:16 ` [PATCH 4/7] uml: use Kbuild tracking for all files and fix compilation output Paolo 'Blaisorblade' Giarrusso
2006-04-30 14:16 ` Paolo 'Blaisorblade' Giarrusso [this message]
2006-04-30 14:16 ` [PATCH 6/7] uml: cleanup unprofile expression and build infrastructure Paolo 'Blaisorblade' Giarrusso
2006-04-30 14:16 ` [PATCH 7/7] uml: export symbols added by GCC hardened Paolo 'Blaisorblade' Giarrusso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060430141619.9060.68951.stgit@zion.home.lan \
    --to=blaisorblade@yahoo.it \
    --cc=akpm@osdl.org \
    --cc=jdike@addtoit.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®