cross-arch: don't corrupt personality flags upon exec()
authorJiri Kosina <jkosina@suse.cz>
Fri, 5 Oct 2012 00:12:20 +0000 (17:12 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 5 Oct 2012 18:04:47 +0000 (03:04 +0900)
Historically, the top three bytes of personality have been used for
things such as ADDR_NO_RANDOMIZE, which made sense only for specific
architectures.

We now however have a flag there that is general no matter the
architecture (UNAME26); generally we have to be careful to preserve the
personality flags across exec().

This patch tries to fix all architectures that forcefully overwrite
personality flags during exec() (ppc32 and s390 have been fixed recently
by commits f9783ec862ea ("[S390] Do not clobber personality flags on
exec") and 59e4c3a2fe9c ("powerpc/32: Don't clobber personality flags on
exec") in a similar way already).

Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Cc: Haavard Skinnemoen <hskinnemoen@gmail.com>
Cc: Hans-Christian Egtvedt <egtvedt@samfundet.no>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Mark Salter <msalter@redhat.com>
Cc: Mikael Starvik <starvik@axis.com>
Cc: Jesper Nilsson <jesper.nilsson@axis.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Richard Kuo <rkuo@codeaurora.org>
Cc: Hirokazu Takata <takata@linux-m32r.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Koichi Yasutake <yasutake.koichi@jp.panasonic.com>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: Chen Liqin <liqin.chen@sunplusct.com>
Cc: Lennox Wu <lennox.wu@gmail.com>
Cc: Paul Mundt <lethal@linux-sh.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Chris Zankel <chris@zankel.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
16 files changed:
arch/avr32/include/asm/elf.h
arch/blackfin/include/asm/elf.h
arch/c6x/include/asm/elf.h
arch/cris/include/asm/elf.h
arch/frv/include/asm/elf.h
arch/h8300/include/asm/elf.h
arch/hexagon/include/asm/elf.h
arch/m32r/include/asm/elf.h
arch/m68k/include/asm/elf.h
arch/microblaze/include/asm/elf.h
arch/mn10300/include/asm/elf.h
arch/openrisc/include/asm/elf.h
arch/score/include/asm/elf.h
arch/sh/include/asm/elf.h
arch/sparc/include/asm/elf_32.h
arch/xtensa/include/asm/elf.h

index 3b3159b710d42de528b487bc9758cf04dfb9a7fa..e2c328739808f6d47651e09c226c6a709e929d96 100644 (file)
@@ -102,6 +102,7 @@ typedef struct user_fpu_struct elf_fpregset_t;
 
 #define ELF_PLATFORM  (NULL)
 
-#define SET_PERSONALITY(ex) set_personality(PER_LINUX_32BIT)
+#define SET_PERSONALITY(ex) \
+       set_personality(PER_LINUX_32BIT | (current->personality & (~PER_MASK)))
 
 #endif /* __ASM_AVR32_ELF_H */
index e6c6812a9abd7a48311dd87122a90be43b709ce1..14bc98ff668fb37b48b6ef80855f5a6f057e35f7 100644 (file)
@@ -132,6 +132,7 @@ do {                                                                                        \
 
 #define ELF_PLATFORM  (NULL)
 
-#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
+#define SET_PERSONALITY(ex) \
+       set_personality(PER_LINUX | (current->personality & (~PER_MASK)))
 
 #endif
index f4552db20b4a64f23733985c8bc98338270e5e54..32b997126adf76f00d5ab0fe9e08106d0856e6be 100644 (file)
@@ -77,7 +77,8 @@ do {                                                          \
 
 #define ELF_PLATFORM  (NULL)
 
-#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
+#define SET_PERSONALITY(ex) \
+       set_personality(PER_LINUX | (current->personality & (~PER_MASK)))
 
 /* C6X specific section types */
 #define SHT_C6000_UNWIND       0x70000001
index 8a3d8e2b33c1e41c384255ecb764cee17af4a3c4..8182f2dc89d04077c4a05fd302cf7fe46bf80996 100644 (file)
@@ -86,6 +86,7 @@ typedef unsigned long elf_fpregset_t;
 
 #define ELF_PLATFORM  (NULL)
 
-#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
+#define SET_PERSONALITY(ex) \
+       set_personality(PER_LINUX | (current->personality & (~PER_MASK)))
 
 #endif
index c3819804a74b104765c60a16051ffeea4063cbb1..9ccbc80f0b11fbcefcc0f2cdbfeb61eb88fbe81f 100644 (file)
@@ -137,6 +137,7 @@ do {                                                                                        \
 
 #define ELF_PLATFORM  (NULL)
 
-#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
+#define SET_PERSONALITY(ex) \
+       set_personality(PER_LINUX | (current->personality & (~PER_MASK)))
 
 #endif
index c24fa250d6533cdb3a5429c102323ca19d356e0d..41193c396bffecd20b353ff558e40f4e9dff03ac 100644 (file)
@@ -54,7 +54,8 @@ typedef unsigned long elf_fpregset_t;
 
 #define ELF_PLATFORM  (NULL)
 
-#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
+#define SET_PERSONALITY(ex) \
+       set_personality(PER_LINUX | (current->personality & (~PER_MASK)))
 
 #define R_H8_NONE       0
 #define R_H8_DIR32      1
index 37976a0d3650c60b6106b1ce8f0b8017ee93a3bd..82b499621e052f2a272cd137c81f23c84fe2ccf3 100644 (file)
@@ -217,7 +217,8 @@ do {                                        \
 #define ELF_PLATFORM  (NULL)
 
 #ifdef __KERNEL__
-#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
+#define SET_PERSONALITY(ex) \
+       set_personality(PER_LINUX | (current->personality & (~PER_MASK)))
 #endif
 
 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
index b8da7d0574d20635f489315ea8caf957d063be08..70896161c636e50fbe299504f9a41be3fc8ae47d 100644 (file)
@@ -128,6 +128,7 @@ typedef elf_fpreg_t elf_fpregset_t;
    intent than poking at uname or /proc/cpuinfo.  */
 #define ELF_PLATFORM   (NULL)
 
-#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
+#define SET_PERSONALITY(ex) \
+       set_personality(PER_LINUX | (current->personality & (~PER_MASK)))
 
 #endif  /* _ASM_M32R__ELF_H */
index e9b7cda597440b5696360307cf0124ab569645c5..f83c1d0a87cf046c42e546bdc86827f8747d421e 100644 (file)
@@ -113,6 +113,7 @@ typedef struct user_m68kfp_struct elf_fpregset_t;
 
 #define ELF_PLATFORM  (NULL)
 
-#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
+#define SET_PERSONALITY(ex) \
+       set_personality(PER_LINUX | (current->personality & (~PER_MASK)))
 
 #endif
index 834849f59ae8a5474e80d2e13cd4a3f0a9e2976f..640ddd4b6a9b2cf6bc58e159a46bf9490069e188 100644 (file)
@@ -116,7 +116,8 @@ do {                                                        \
 } while (0)
 
 #ifdef __KERNEL__
-#define SET_PERSONALITY(ex) set_personality(PER_LINUX_32BIT)
+#define SET_PERSONALITY(ex) \
+       set_personality(PER_LINUX_32BIT | (current->personality & (~PER_MASK)))
 #endif
 
 #endif /* __uClinux__ */
index 8157c9267f426ac7dabdd6f0dcef9a67bd2ff5a3..4ebd6b3a0a1ebf7bd5aebdd8dc42dac5460fc64a 100644 (file)
@@ -151,7 +151,8 @@ do {                                                \
 #define ELF_PLATFORM  (NULL)
 
 #ifdef __KERNEL__
-#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
+#define SET_PERSONALITY(ex) \
+       set_personality(PER_LINUX | (current->personality & (~PER_MASK)))
 #endif
 
 #endif /* _ASM_ELF_H */
index a8fe2c513070389cdf46c03155123a4ea5531fda..225a7ff320ad565329b7e399c8ce80c9f8cf963c 100644 (file)
@@ -110,7 +110,8 @@ extern void dump_elf_thread(elf_greg_t *dest, struct pt_regs *pt);
 
 #define ELF_PLATFORM   (NULL)
 
-#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
+#define SET_PERSONALITY(ex) \
+       set_personality(PER_LINUX | (current->personality & (~PER_MASK)))
 
 #endif /* __KERNEL__ */
 #endif
index f478ce94181fb349324bf836e9fe5a01abfaa13d..5d566c7a0af26c5cf65f7b5d37fc57c0f6f93e8a 100644 (file)
@@ -54,7 +54,7 @@ typedef elf_fpreg_t   elf_fpregset_t;
 
 #define SET_PERSONALITY(ex)                                    \
 do {                                                           \
-       set_personality(PER_LINUX);                             \
+       set_personality(PER_LINUX | (current->personality & (~PER_MASK))); \
 } while (0)
 
 struct task_struct;
index f38112be67d29555eb76042c57598e34c2b2e8a4..37924afa8d8a26781a2e8ebf4952144b141f9295 100644 (file)
@@ -183,7 +183,8 @@ do {                                                                        \
 } while (0)
 #endif
 
-#define SET_PERSONALITY(ex) set_personality(PER_LINUX_32BIT)
+#define SET_PERSONALITY(ex) \
+       set_personality(PER_LINUX_32BIT | (current->personality & (~PER_MASK)))
 
 #ifdef CONFIG_VSYSCALL
 /* vDSO has arch_setup_additional_pages */
index 2d4d755cba9ebcc67d8420cb927f66a98e00de74..ac74a2c98e6dde55417db847f9f103b2e8771457 100644 (file)
@@ -128,6 +128,7 @@ typedef struct {
 
 #define ELF_PLATFORM   (NULL)
 
-#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
+#define SET_PERSONALITY(ex) \
+       set_personality(PER_LINUX | (current->personality & (~PER_MASK)))
 
 #endif /* !(__ASMSPARC_ELF_H) */
index 6e65eadaae14c60c1972b3fe96c5bbae0c2a38bb..5293312bc6a4c55d842519ef6c16cede7e5e197b 100644 (file)
@@ -189,7 +189,8 @@ typedef struct {
 #endif
 } elf_xtregs_t;
 
-#define SET_PERSONALITY(ex) set_personality(PER_LINUX_32BIT)
+#define SET_PERSONALITY(ex) \
+       set_personality(PER_LINUX_32BIT | (current->personality & (~PER_MASK)))
 
 struct task_struct;