mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/7] Uml fixes for 2.6.17
@ 2006-04-30 14:15 Paolo 'Blaisorblade' Giarrusso
  2006-04-30 14:16 ` [PATCH 1/7] uml: fix patch mismerge Paolo 'Blaisorblade' Giarrusso
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Paolo 'Blaisorblade' Giarrusso @ 2006-04-30 14:15 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Jeff Dike, linux-kernel, user-mode-linux-devel

This series fixes one "regression" in the 2.6.17 cycle (the mismerge of a
patch broke some code), makes UML compile & run with GCC hardened and fixes
some regressions of the compile infrastructure - special CFLAGS settings for
some files, needed in some configurations (say with profiling enabled) weren't
applied due to bad interactions with Kbuild. Finally, we make UML compatible
with Debian settings for uml_utilities (which conform to the FHS).

>From stg series:

+ uml-diagnose-64-bit-broken-padding    | uml: fix patch mismerge
+ uml-PATH-for-uml_net.patch            | uml: search from uml_net in a more
	reasonable PATH
+ uml-copy_user-inatomic-v2.patch       | uml: make copy_*_user atomic
+ uml-makefile-nicer                    | uml: use Kbuild tracking for all
	files and fix compilation output
+ uml-compile-nopic-clone-stub          | uml: fix compilation and execution
	with hardened GCC
+ uml-fix-unprofile-kbuild-interaction  | uml: cleanup unprofile expression
	and build infrastructure
+ uml-export-stack-protector-symbols    | uml: export symbols added by GCC
	hardened

-- 
Inform me of my mistakes, so I can keep imitating Homer Simpson's "Doh!".
Paolo Giarrusso, aka Blaisorblade (Skype ID "PaoloGiarrusso", ICQ 215621894)
http://www.user-mode-linux.org/~blaisorblade

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/7] uml: fix patch mismerge
  2006-04-30 14:15 [PATCH 0/7] Uml fixes for 2.6.17 Paolo 'Blaisorblade' Giarrusso
@ 2006-04-30 14:16 ` Paolo 'Blaisorblade' Giarrusso
  2006-04-30 14:16 ` [PATCH 2/7] uml: search from uml_net in a more reasonable PATH Paolo 'Blaisorblade' Giarrusso
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Paolo 'Blaisorblade' Giarrusso @ 2006-04-30 14:16 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Jeff Dike, linux-kernel, user-mode-linux-devel

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

I sent a patch, it was applied as cda402b283c34a24b091f78eee116963e9494762, then
it was applied again as 181ae4005d0a4010802be534d929b38c42b9ac06 by mistake. But
while the 1st time it modified (correctly) cow_header_v3, the 2nd it modified
cow_header_v3_broken.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
---

 arch/um/drivers/cow_user.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/um/drivers/cow_user.c b/arch/um/drivers/cow_user.c
index 6ab852b..0ec4052 100644
--- a/arch/um/drivers/cow_user.c
+++ b/arch/um/drivers/cow_user.c
@@ -100,7 +100,7 @@ struct cow_header_v3_broken {
 	__u32 alignment;
 	__u32 cow_format;
 	char backing_file[PATH_LEN_V3];
-} __attribute__((packed));
+};
 
 /* COW format definitions - for now, we have only the usual COW bitmap */
 #define COW_BITMAP 0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/7] uml: search from uml_net in a more reasonable PATH
  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 ` Paolo 'Blaisorblade' Giarrusso
  2006-04-30 14:16 ` [PATCH 3/7] uml: make copy_*_user atomic Paolo 'Blaisorblade' Giarrusso
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Paolo 'Blaisorblade' Giarrusso @ 2006-04-30 14:16 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Jeff Dike, linux-kernel, user-mode-linux-devel

From: Mattia Dongili <malattia@linux.it>

Append /usr/lib/uml to the existing PATH environment variable to let
execvp() search uml_net in FHS compliant locations.

Signed-off-by: Mattia Dongili <malattia@linux.it>
Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
---

 arch/um/os-Linux/main.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/arch/um/os-Linux/main.c b/arch/um/os-Linux/main.c
index 2878e89..02cf668 100644
--- a/arch/um/os-Linux/main.c
+++ b/arch/um/os-Linux/main.c
@@ -74,6 +74,33 @@ static void last_ditch_exit(int sig)
 	exit(1);
 }
 
+#define UML_LIB_PATH	":/usr/lib/uml"
+
+static void setup_env_path(void) {
+	char *new_path = NULL;
+	char *old_path = NULL;
+	int path_len = 0;
+
+	old_path = getenv("PATH");
+	/* if no PATH variable is set or it has an empty value
+	 * just use the default + /usr/lib/uml
+	 */
+	if (!old_path || (path_len = strlen(old_path)) == 0) {
+		putenv("PATH=:/bin:/usr/bin/" UML_LIB_PATH);
+		return;
+	}
+
+	/* append /usr/lib/uml to the existing path */
+	path_len += strlen("PATH=" UML_LIB_PATH) + 1;
+	new_path = malloc(path_len);
+	if (!new_path) {
+		perror("coudn't malloc to set a new PATH");
+		return;
+	}
+	snprintf(new_path, path_len, "PATH=%s" UML_LIB_PATH, old_path);
+	putenv(new_path);
+}
+
 extern int uml_exitcode;
 
 extern void scan_elf_aux( char **envp);
@@ -114,6 +141,8 @@ int main(int argc, char **argv, char **e
 
 	set_stklim();
 
+	setup_env_path();
+
 	new_argv = malloc((argc + 1) * sizeof(char *));
 	if(new_argv == NULL){
 		perror("Mallocing argv");

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/7] uml: make copy_*_user atomic
  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 ` 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
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 9+ messages in thread
From: Paolo 'Blaisorblade' Giarrusso @ 2006-04-30 14:16 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Jeff Dike, linux-kernel, user-mode-linux-devel

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

Make __copy_*_user_inatomic really atomic to avoid "Sleeping function called in
atomic context" warnings, especially from futex code.

This is made by adding another kmap_atomic slot and making copy_*_user_skas use
kmap_atomic; also copy_*_user() becomes atomic, but that's true and is not a
problem for i386 (and we can always add might_sleep there as done elsewhere).
For TT mode kmap is not used, so there's no need for this.

I've had to use another slot since both KM_USER0 and KM_USER1 are used elsewhere
and could cause conflicts. Till now we reused the kmap_atomic slot list from the
subarch, but that's not needed as that list must contain the common ones (used
by generic code) + the ones used in architecture specific code (and Uml till now
used none); so I've taken the i386 one after comparing it with ones from other
archs, and added KM_UML_USERCOPY.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
---

 arch/um/kernel/skas/uaccess.c |   15 +++++++++------
 include/asm-um/kmap_types.h   |   20 +++++++++++++++++++-
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/arch/um/kernel/skas/uaccess.c b/arch/um/kernel/skas/uaccess.c
index 5992c32..8912cec 100644
--- a/arch/um/kernel/skas/uaccess.c
+++ b/arch/um/kernel/skas/uaccess.c
@@ -8,6 +8,7 @@
 #include "linux/kernel.h"
 #include "linux/string.h"
 #include "linux/fs.h"
+#include "linux/hardirq.h"
 #include "linux/highmem.h"
 #include "asm/page.h"
 #include "asm/pgtable.h"
@@ -38,7 +39,7 @@ static unsigned long maybe_map(unsigned 
 	return((unsigned long) phys);
 }
 
-static int do_op(unsigned long addr, int len, int is_write,
+static int do_op_one_page(unsigned long addr, int len, int is_write,
 		 int (*op)(unsigned long addr, int len, void *arg), void *arg)
 {
 	struct page *page;
@@ -49,9 +50,11 @@ static int do_op(unsigned long addr, int
 		return(-1);
 
 	page = phys_to_page(addr);
-	addr = (unsigned long) kmap(page) + (addr & ~PAGE_MASK);
+	addr = (unsigned long) kmap_atomic(page, KM_UML_USERCOPY) + (addr & ~PAGE_MASK);
+
 	n = (*op)(addr, len, arg);
-	kunmap(page);
+
+	kunmap_atomic(page, KM_UML_USERCOPY);
 
 	return(n);
 }
@@ -77,7 +80,7 @@ static void do_buffer_op(void *jmpbuf, v
 	remain = len;
 
 	current->thread.fault_catcher = jmpbuf;
-	n = do_op(addr, size, is_write, op, arg);
+	n = do_op_one_page(addr, size, is_write, op, arg);
 	if(n != 0){
 		*res = (n < 0 ? remain : 0);
 		goto out;
@@ -91,7 +94,7 @@ static void do_buffer_op(void *jmpbuf, v
 	}
 
 	while(addr < ((addr + remain) & PAGE_MASK)){
-		n = do_op(addr, PAGE_SIZE, is_write, op, arg);
+		n = do_op_one_page(addr, PAGE_SIZE, is_write, op, arg);
 		if(n != 0){
 			*res = (n < 0 ? remain : 0);
 			goto out;
@@ -105,7 +108,7 @@ static void do_buffer_op(void *jmpbuf, v
 		goto out;
 	}
 
-	n = do_op(addr, remain, is_write, op, arg);
+	n = do_op_one_page(addr, remain, is_write, op, arg);
 	if(n != 0)
 		*res = (n < 0 ? remain : 0);
 	else *res = 0;
diff --git a/include/asm-um/kmap_types.h b/include/asm-um/kmap_types.h
index 0b22ad7..6c03acd 100644
--- a/include/asm-um/kmap_types.h
+++ b/include/asm-um/kmap_types.h
@@ -6,6 +6,24 @@
 #ifndef __UM_KMAP_TYPES_H
 #define __UM_KMAP_TYPES_H
 
-#include "asm/arch/kmap_types.h"
+/* No more #include "asm/arch/kmap_types.h" ! */
+
+enum km_type {
+	KM_BOUNCE_READ,
+	KM_SKB_SUNRPC_DATA,
+	KM_SKB_DATA_SOFTIRQ,
+	KM_USER0,
+	KM_USER1,
+	KM_UML_USERCOPY,	/* UML specific, for copy_*_user - used in do_op_one_page */
+	KM_BIO_SRC_IRQ,
+	KM_BIO_DST_IRQ,
+	KM_PTE0,
+	KM_PTE1,
+	KM_IRQ0,
+	KM_IRQ1,
+	KM_SOFTIRQ0,
+	KM_SOFTIRQ1,
+	KM_TYPE_NR
+};
 
 #endif

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/7] uml: use Kbuild tracking for all files and fix compilation output
  2006-04-30 14:15 [PATCH 0/7] Uml fixes for 2.6.17 Paolo 'Blaisorblade' Giarrusso
                   ` (2 preceding siblings ...)
  2006-04-30 14:16 ` [PATCH 3/7] uml: make copy_*_user atomic Paolo 'Blaisorblade' Giarrusso
@ 2006-04-30 14:16 ` Paolo 'Blaisorblade' Giarrusso
  2006-04-30 14:16 ` [PATCH 5/7] uml: fix compilation and execution with hardened GCC Paolo 'Blaisorblade' Giarrusso
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Paolo 'Blaisorblade' Giarrusso @ 2006-04-30 14:16 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Jeff Dike, linux-kernel, user-mode-linux-devel

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

Move the build of user-offsets to arch/um/sys-$(SUBARCH), where it's located. So
we can also build it via Kbuild with its dependency tracking rather than by hand.
While hacking here, fix also a lot of little cosmetic things.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
---

 arch/um/Makefile            |   13 ++++++-------
 arch/um/sys-i386/Makefile   |    5 ++++-
 arch/um/sys-x86_64/Makefile |    5 ++++-
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/arch/um/Makefile b/arch/um/Makefile
index a508e7a..930e006 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -96,7 +96,8 @@ PHONY += linux
 all: linux
 
 linux: vmlinux
-	ln -f $< $@
+	@echo '  SYMLINK $@'
+	$(Q)ln -f $< $@
 
 define archhelp
   echo '* linux		- Binary kernel image (./linux) - for backward'
@@ -203,8 +204,8 @@ endef
 $(ARCH_DIR)/include/uml-config.h : include/linux/autoconf.h
 	$(call filechk,umlconfig)
 
-$(ARCH_DIR)/user-offsets.s: $(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.c
-	$(CC) $(USER_CFLAGS) -S -o $@ $<
+$(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.s: FORCE
+	$(Q)$(MAKE) $(build)=$(ARCH_DIR)/sys-$(SUBARCH) $@
 
 define filechk_gen-asm-offsets
         (set -e; \
@@ -219,13 +220,11 @@ define filechk_gen-asm-offsets
          echo ""; )
 endef
 
-$(ARCH_DIR)/include/user_constants.h: $(ARCH_DIR)/user-offsets.s
+$(ARCH_DIR)/include/user_constants.h: $(ARCH_DIR)/sys-$(SUBARCH)/user-offsets.s
 	$(call filechk,gen-asm-offsets)
 
-CLEAN_FILES += $(ARCH_DIR)/user-offsets.s
-
 $(ARCH_DIR)/include/kern_constants.h: $(objtree)/$(ARCH_DIR)/include
 	@echo '  SYMLINK $@'
-	$(Q) ln -sf ../../../include/asm-um/asm-offsets.h $@
+	$(Q)ln -sf ../../../include/asm-um/asm-offsets.h $@
 
 export SUBARCH USER_CFLAGS OS
diff --git a/arch/um/sys-i386/Makefile b/arch/um/sys-i386/Makefile
index 98b20b7..82121ab 100644
--- a/arch/um/sys-i386/Makefile
+++ b/arch/um/sys-i386/Makefile
@@ -10,9 +10,12 @@ subarch-obj-$(CONFIG_MODULES) += kernel/
 
 USER_OBJS := bugs.o ptrace_user.o sigcontext.o fault.o stub_segv.o
 
-include arch/um/scripts/Makefile.rules
+USER_OBJS += user-offsets.s
+extra-y += user-offsets.s
 
 extra-$(CONFIG_MODE_TT) += unmap.o
 
+include arch/um/scripts/Makefile.rules
+
 $(obj)/stub_segv.o $(obj)/unmap.o: \
 	_c_flags = $(call unprofile,$(CFLAGS))
diff --git a/arch/um/sys-x86_64/Makefile b/arch/um/sys-x86_64/Makefile
index b5fc22b..f739bea 100644
--- a/arch/um/sys-x86_64/Makefile
+++ b/arch/um/sys-x86_64/Makefile
@@ -18,9 +18,12 @@ ldt-y = ../sys-i386/ldt.o
 
 USER_OBJS := ptrace_user.o sigcontext.o stub_segv.o
 
-include arch/um/scripts/Makefile.rules
+USER_OBJS += user-offsets.s
+extra-y += user-offsets.s
 
 extra-$(CONFIG_MODE_TT) += unmap.o
 
+include arch/um/scripts/Makefile.rules
+
 $(obj)/stub_segv.o $(obj)/unmap.o: \
 	_c_flags = $(call unprofile,$(CFLAGS))

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/7] uml: fix compilation and execution with hardened GCC
  2006-04-30 14:15 [PATCH 0/7] Uml fixes for 2.6.17 Paolo 'Blaisorblade' Giarrusso
                   ` (3 preceding siblings ...)
  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
  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
  6 siblings, 0 replies; 9+ messages in thread
From: Paolo 'Blaisorblade' Giarrusso @ 2006-04-30 14:16 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Jeff Dike, linux-kernel, user-mode-linux-devel

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 6/7] uml: cleanup unprofile expression and build infrastructure
  2006-04-30 14:15 [PATCH 0/7] Uml fixes for 2.6.17 Paolo 'Blaisorblade' Giarrusso
                   ` (4 preceding siblings ...)
  2006-04-30 14:16 ` [PATCH 5/7] uml: fix compilation and execution with hardened GCC Paolo 'Blaisorblade' Giarrusso
@ 2006-04-30 14:16 ` Paolo 'Blaisorblade' Giarrusso
  2006-04-30 14:16 ` [PATCH 7/7] uml: export symbols added by GCC hardened Paolo 'Blaisorblade' Giarrusso
  6 siblings, 0 replies; 9+ messages in thread
From: Paolo 'Blaisorblade' Giarrusso @ 2006-04-30 14:16 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Jeff Dike, linux-kernel, user-mode-linux-devel

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

*) Rather than duplicate in various buggy ways the application of
CFLAGS_NO_HARDENING and UNPROFILE (which apply to the same files), centralize it
in Makefile.rules. UNPROFILE_OBJS mustn't be listed in USER_OBJS but are
compiled as such.

I've also verified that unprofile didn't work in the current form, because we
set _c_flags directly (using CFLAGS and not USER_CFLAGS, which is wrong), which
is normally used by c_flags, but we also override c_flags for all USER_OBJS, and
there we don't call unprofile.

Instead it only worked for unmap.o, the only one which wasn't a USER_OBJ.

We need to set c_flags (which is not a public Kbuild API) to clear a lot of
compilation flags like -nostdinc which Kbuild forces on everything.

*) Rather than $(CFLAGS_$(notdir $@)), which expands to CFLAGS_anObj.s when
building "anObj.s", use $(CFLAGS_$(*F).o) which always accesses
CFLAGS_anObj.o, like done by Kbuild.

*) Make c_flags apply to all targets having the same basename, rather than
listing .s, .i, .lst and .o, with the use (which I tested) of
	$(USER_OBJS:.o=.%): c_flags = ...

and of
 -      $(obj)/unmap.c: _c_flags = ...
 +      $(obj)/unmap.%: _c_flags = ...

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
---

 arch/um/kernel/skas/Makefile   |    9 ++-------
 arch/um/scripts/Makefile.rules |   12 ++++++++++--
 arch/um/sys-i386/Makefile      |   10 +++++-----
 arch/um/sys-x86_64/Makefile    |   10 +++++-----
 4 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/arch/um/kernel/skas/Makefile b/arch/um/kernel/skas/Makefile
index ad84296..ea3a8e4 100644
--- a/arch/um/kernel/skas/Makefile
+++ b/arch/um/kernel/skas/Makefile
@@ -6,16 +6,11 @@
 obj-y := clone.o exec_kern.o mem.o mmu.o process_kern.o \
 	syscall.o tlb.o uaccess.o
 
-USER_OBJS := clone.o
-
-include arch/um/scripts/Makefile.rules
-
 # clone.o is in the stub, so it can't be built with profiling
 # GCC hardened also auto-enables -fpic, but we need %ebx so it can't work ->
 # disable it
 
 CFLAGS_clone.o := $(CFLAGS_NO_HARDENING)
+UNPROFILE_OBJS := clone.o
 
-# 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)
+include arch/um/scripts/Makefile.rules
diff --git a/arch/um/scripts/Makefile.rules b/arch/um/scripts/Makefile.rules
index 5e7a9c3..1347dc6 100644
--- a/arch/um/scripts/Makefile.rules
+++ b/arch/um/scripts/Makefile.rules
@@ -7,11 +7,19 @@ USER_SINGLE_OBJS := \
 USER_OBJS += $(filter %_user.o,$(obj-y) $(obj-m)  $(USER_SINGLE_OBJS))
 USER_OBJS := $(foreach file,$(USER_OBJS),$(obj)/$(file))
 
-$(USER_OBJS) $(USER_OBJS:.o=.i) $(USER_OBJS:.o=.s) $(USER_OBJS:.o=.lst): \
-	c_flags = -Wp,-MD,$(depfile) $(USER_CFLAGS) $(CFLAGS_$(notdir $@))
+$(USER_OBJS:.o=.%): \
+	c_flags = -Wp,-MD,$(depfile) $(USER_CFLAGS) $(CFLAGS_$(*F).o)
 $(USER_OBJS) : CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ \
 	-Dunix -D__unix__ -D__$(SUBARCH)__
 
+# These are like USER_OBJS but filter USER_CFLAGS through unprofile instead of
+# using it directly.
+UNPROFILE_OBJS := $(foreach file,$(UNPROFILE_OBJS),$(obj)/$(file))
+
+$(UNPROFILE_OBJS:.o=.%): \
+	c_flags = -Wp,-MD,$(depfile) $(call unprofile,$(USER_CFLAGS)) $(CFLAGS_$(*F).o)
+$(UNPROFILE_OBJS) : CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ \
+	-Dunix -D__unix__ -D__$(SUBARCH)__
 
 # The stubs and unmap.o can't try to call mcount or update basic block data
 define unprofile
diff --git a/arch/um/sys-i386/Makefile b/arch/um/sys-i386/Makefile
index 3734c3e..374d61a 100644
--- a/arch/um/sys-i386/Makefile
+++ b/arch/um/sys-i386/Makefile
@@ -8,16 +8,16 @@ subarch-obj-y = lib/bitops.o kernel/sema
 subarch-obj-$(CONFIG_HIGHMEM) += mm/highmem.o
 subarch-obj-$(CONFIG_MODULES) += kernel/module.o
 
-USER_OBJS := bugs.o ptrace_user.o sigcontext.o fault.o stub_segv.o
+USER_OBJS := bugs.o ptrace_user.o sigcontext.o fault.o
 
 USER_OBJS += user-offsets.s
 extra-y += user-offsets.s
 
-CFLAGS_stub_segv.o := $(CFLAGS_NO_HARDENING)
-
 extra-$(CONFIG_MODE_TT) += unmap.o
 
+UNPROFILE_OBJS := stub_segv.o
+CFLAGS_stub_segv.o := $(CFLAGS_NO_HARDENING)
+
 include arch/um/scripts/Makefile.rules
 
-$(obj)/stub_segv.o $(obj)/unmap.o: \
-	_c_flags = $(call unprofile,$(CFLAGS))
+$(obj)/unmap.%: _c_flags = $(call unprofile,$(CFLAGS))
diff --git a/arch/um/sys-x86_64/Makefile b/arch/um/sys-x86_64/Makefile
index 6d3b29c..c19794d 100644
--- a/arch/um/sys-x86_64/Makefile
+++ b/arch/um/sys-x86_64/Makefile
@@ -16,16 +16,16 @@ subarch-obj-$(CONFIG_MODULES) += kernel/
 
 ldt-y = ../sys-i386/ldt.o
 
-USER_OBJS := ptrace_user.o sigcontext.o stub_segv.o
+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
 
+UNPROFILE_OBJS := stub_segv.o
+CFLAGS_stub_segv.o := $(CFLAGS_NO_HARDENING)
+
 include arch/um/scripts/Makefile.rules
 
-$(obj)/stub_segv.o $(obj)/unmap.o: \
-	_c_flags = $(call unprofile,$(CFLAGS))
+$(obj)/unmap.%: _c_flags = $(call unprofile,$(CFLAGS))

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 7/7] uml: export symbols added by GCC hardened
  2006-04-30 14:15 [PATCH 0/7] Uml fixes for 2.6.17 Paolo 'Blaisorblade' Giarrusso
                   ` (5 preceding siblings ...)
  2006-04-30 14:16 ` [PATCH 6/7] uml: cleanup unprofile expression and build infrastructure Paolo 'Blaisorblade' Giarrusso
@ 2006-04-30 14:16 ` Paolo 'Blaisorblade' Giarrusso
  6 siblings, 0 replies; 9+ messages in thread
From: Paolo 'Blaisorblade' Giarrusso @ 2006-04-30 14:16 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Jeff Dike, linux-kernel, user-mode-linux-devel

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

GCC hardened introduces additional symbol refererences (for the canary and
friends), also in modules - add weak export_symbols for them. We already tested
that the weak declaration creates no problem on both GCC's providing the
function definition and on GCC's which don't provide it.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
---

 arch/um/os-Linux/user_syms.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/arch/um/os-Linux/user_syms.c b/arch/um/os-Linux/user_syms.c
index 2598158..3f33165 100644
--- a/arch/um/os-Linux/user_syms.c
+++ b/arch/um/os-Linux/user_syms.c
@@ -96,6 +96,13 @@ EXPORT_SYMBOL_PROTO(getuid);
 EXPORT_SYMBOL_PROTO(fsync);
 EXPORT_SYMBOL_PROTO(fdatasync);
 
+/* Export symbols used by GCC for the stack protector. */
+extern void __stack_smash_handler(void *) __attribute__((weak));
+EXPORT_SYMBOL(__stack_smash_handler);
+
+extern long __guard __attribute__((weak));
+EXPORT_SYMBOL(__guard);
+
 /*
  * Overrides for Emacs so that we follow Linus's tabbing style.
  * Emacs will notice this stuff at the end of the file and automatically

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/7] uml: make copy_*_user atomic
  2006-04-30 14:16 ` [PATCH 3/7] uml: make copy_*_user atomic Paolo 'Blaisorblade' Giarrusso
@ 2006-04-30 15:32   ` Blaisorblade
  0 siblings, 0 replies; 9+ messages in thread
From: Blaisorblade @ 2006-04-30 15:32 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Jeff Dike, linux-kernel, user-mode-linux-devel

On Sunday 30 April 2006 16:16, Paolo 'Blaisorblade' Giarrusso wrote:
> From: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
>
> Make __copy_*_user_inatomic really atomic to avoid "Sleeping function
> called in atomic context" warnings, especially from futex code.
>
> This is made by adding another kmap_atomic slot and making copy_*_user_skas
> use kmap_atomic; also copy_*_user() becomes atomic, but that's true and is
> not a problem for i386 (and we can always add might_sleep there as done
> elsewhere). For TT mode kmap is not used, so there's no need for this.
>
> I've had to use another slot since both KM_USER0 and KM_USER1 are used
> elsewhere and could cause conflicts. Till now we reused the kmap_atomic
> slot list from the subarch, but that's not needed as that list must contain
> the common ones (used by generic code) + the ones used in architecture
> specific code (and Uml till now used none); so I've taken the i386 one
> after comparing it with ones from other archs, and added KM_UML_USERCOPY.

> Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>

Ok, I didn't want indeed to send this one _for merging_, even if I consider it 
correct and it indeed fixes the warnings; additionally, since HIGHMEM support 
is not very used (it's slow and less tested), there shouldn't be problems 
anyway.

Please keep it in -mm however, it should be ok and there it could get more 
exposure - and this is about interaction with the core kernel so it could get 
valid review from people outside UML.

Jeff, give a look to this one please. You need CONFIG_DEBUG_SPINLOCK_SLEEP and 
a futex user (for instance starting threaded apache inside the guest) to 
trigger the warnings.
-- 
Inform me of my mistakes, so I can keep imitating Homer Simpson's "Doh!".
Paolo Giarrusso, aka Blaisorblade (Skype ID "PaoloGiarrusso", ICQ 215621894)
http://www.user-mode-linux.org/~blaisorblade
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2006-04-30 17:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 5/7] uml: fix compilation and execution with hardened GCC Paolo 'Blaisorblade' Giarrusso
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome