Skip to contentSkip to conversation

x86: Reject x32 executables if x32 ABI not supported

PATCH RESEND In review Ben Hutchings 3 participants 5 messages Sep 7, 2014 – Oct 8, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 x86: Reject x32 executables if x32 ABI not supported

It is currently possible to execve() an x32 executable on an x86_64 kernel that has only ia32 compat enabled. However all its syscalls will fail, even _exit(). This usually causes it to segfault.

Change the ELF compat architecture check so that x32 executables are rejected if we don't support the x32 ABI.

---
 arch/x86/include/asm/elf.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/include/asm/elf.h +3 -2
index 1a055c8..ca3347a 100644
@@ -160,8 +160,9 @@ do {						\
 #define elf_check_arch(x)			\
 	((x)->e_machine == EM_X86_64)
 
-#define compat_elf_check_arch(x)		\
-	(elf_check_arch_ia32(x) || (x)->e_machine == EM_X86_64)
+#define compat_elf_check_arch(x)					\
+	(elf_check_arch_ia32(x) ||					\
+	 (IS_ENABLED(CONFIG_X86_X32_ABI) && (x)->e_machine == EM_X86_64))
 
 #if __USER32_DS != __USER_DS
 # error "The following code assumes __USER32_DS == __USER_DS"
Signature · 3 lines
Ben Hutchings
Experience is directly proportional to the value of equipment destroyed.
                                                         - Carolyn Scheppner
#1 lore raw

Can one of you please respond to this patch?

Ben.

Quoted 30 lines · Ben Hutchings

It is currently possible to execve() an x32 executable on an x86_64 kernel that has only ia32 compat enabled. However all its syscalls will fail, even _exit(). This usually causes it to segfault.

Change the ELF compat architecture check so that x32 executables are rejected if we don't support the x32 ABI.

---
 arch/x86/include/asm/elf.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/include/asm/elf.h +3 -2
index 1a055c8..ca3347a 100644
@@ -160,8 +160,9 @@ do {						\
 #define elf_check_arch(x)			\
 	((x)->e_machine == EM_X86_64)
 
-#define compat_elf_check_arch(x)		\
-	(elf_check_arch_ia32(x) || (x)->e_machine == EM_X86_64)
+#define compat_elf_check_arch(x)					\
+	(elf_check_arch_ia32(x) ||					\
+	 (IS_ENABLED(CONFIG_X86_X32_ABI) && (x)->e_machine == EM_X86_64))
 
 #if __USER32_DS != __USER_DS
 # error "The following code assumes __USER32_DS == __USER_DS"
Signature · 2 lines
Ben Hutchings
One of the nice things about standards is that there are so many of them.
#2 lore raw
Quoted 1 line · Ben Hutchings

Can one of you please respond to this patch?

Oops. Slipped through the cracks. Picked it up. Shouldn't it be tagged for stable?

Thanks,

tglx

#3 lore raw
Quoted 6 lines · Thomas Gleixner
Quoted 1 line · Ben Hutchings

Can one of you please respond to this patch?

Oops. Slipped through the cracks. Picked it up. Shouldn't it be tagged for stable?

Right. Please add:

Fixes d1a797f388d6 ("x32: Handle process creation")
Cc <[email protected]> # v3.4+

Ben.

Signature · 3 lines
Ben Hutchings
Klipstein's 4th Law of Prototyping and Production:
                                    A fail-safe circuit will destroy others.
#4 lore raw
In reply to Ben Hutchings
x86: Reject x32 executables if x32 ABI not supported
Commit-ID:  0e6d3112a4e95d55cf6dca88f298d5f4b8f29bd1
Gitweb:     http://git.kernel.org/tip/0e6d3112a4e95d55cf6dca88f298d5f4b8f29bd1
Author:     Ben Hutchings <[email protected]>
AuthorDate: Sun, 7 Sep 2014 21:05:05 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Wed, 8 Oct 2014 11:17:42 +0200

x86: Reject x32 executables if x32 ABI not supported

It is currently possible to execve() an x32 executable on an x86_64 kernel that has only ia32 compat enabled. However all its syscalls will fail, even _exit(). This usually causes it to segfault.

Change the ELF compat architecture check so that x32 executables are rejected if we don't support the x32 ABI.

---
 arch/x86/include/asm/elf.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/include/asm/elf.h +3 -2
index 1a055c8..ca3347a 100644
@@ -160,8 +160,9 @@ do {						\
 #define elf_check_arch(x)			\
 	((x)->e_machine == EM_X86_64)
 
-#define compat_elf_check_arch(x)		\
-	(elf_check_arch_ia32(x) || (x)->e_machine == EM_X86_64)
+#define compat_elf_check_arch(x)					\
+	(elf_check_arch_ia32(x) ||					\
+	 (IS_ENABLED(CONFIG_X86_X32_ABI) && (x)->e_machine == EM_X86_64))
 
 #if __USER32_DS != __USER_DS
 # error "The following code assumes __USER32_DS == __USER_DS"