Skip to contentSkip to conversation

x86/ia32: State that IA32 emulation is disabled

PATCH Applied Borislav Petkov 4 participants 13 messages Nov 30, 2023 – Dec 11, 2023

Subsystems (2)
lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw

PATCH 1/1 x86/ia32: State that IA32 emulation is disabled

From: "Borislav Petkov (AMD)" <[email protected]>

Issue a short message once, on the first try to load a 32-bit process to save people time when wondering why it won't load and says:

-bash: ./strsep32: cannot execute binary file: Exec format error

No functional changes.

---
 arch/x86/include/asm/elf.h  | 2 +-
 arch/x86/include/asm/ia32.h | 9 ++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)
arch/x86/include/asm/elf.h +1 -1
index a0234dfd1031..1e16bd5ac781 100644
@@ -150,7 +150,7 @@ do {						\
 	((x)->e_machine == EM_X86_64)
 
 #define compat_elf_check_arch(x)					\
-	((elf_check_arch_ia32(x) && ia32_enabled()) ||			\
+	((elf_check_arch_ia32(x) && ia32_enabled_verbose()) ||		\
 	 (IS_ENABLED(CONFIG_X86_X32_ABI) && (x)->e_machine == EM_X86_64))
 
 static inline void elf_common_init(struct thread_struct *t,
arch/x86/include/asm/ia32.h +8 -1
index 5a2ae24b1204..43e02b52ad19 100644
@@ -2,7 +2,6 @@
 #ifndef _ASM_X86_IA32_H
 #define _ASM_X86_IA32_H
 
-
 #ifdef CONFIG_IA32_EMULATION
 
 #include <linux/compat.h>
@@ -84,4 +83,12 @@ static inline bool ia32_enabled(void)
 
 #endif
 
+static inline bool ia32_enabled_verbose(void)
+{
+#ifdef CONFIG_IA32_EMULATION
+	pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");
+#endif
+	return ia32_enabled();
+}
+
 #endif /* _ASM_X86_IA32_H */
Signature · 1 line
2.42.0.rc0.25.ga82fb66fed25
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Borislav Petkov

From: "Borislav Petkov (AMD)" <[email protected]>

Issue a short message once, on the first try to load a 32-bit process to save people time when wondering why it won't load and says:

-bash: ./strsep32: cannot execute binary file: Exec format error

No functional changes.

LGTM:

Would have liked for this function to replace the non-verbose variant but since it's used in syscall it might be easier to miss.

Quoted 43 lines
---
  arch/x86/include/asm/elf.h  | 2 +-
  arch/x86/include/asm/ia32.h | 9 ++++++++-
  2 files changed, 9 insertions(+), 2 deletions(-)
arch/x86/include/asm/elf.h +1 -1
index a0234dfd1031..1e16bd5ac781 100644
@@ -150,7 +150,7 @@ do {						\
  	((x)->e_machine == EM_X86_64)
 
  #define compat_elf_check_arch(x)					\
-	((elf_check_arch_ia32(x) && ia32_enabled()) ||			\
+	((elf_check_arch_ia32(x) && ia32_enabled_verbose()) ||		\
  	 (IS_ENABLED(CONFIG_X86_X32_ABI) && (x)->e_machine == EM_X86_64))
 
  static inline void elf_common_init(struct thread_struct *t,
arch/x86/include/asm/ia32.h +8 -1
index 5a2ae24b1204..43e02b52ad19 100644
@@ -2,7 +2,6 @@
  #ifndef _ASM_X86_IA32_H
  #define _ASM_X86_IA32_H
 
-
  #ifdef CONFIG_IA32_EMULATION
 
  #include <linux/compat.h>
@@ -84,4 +83,12 @@ static inline bool ia32_enabled(void)
 
  #endif
 
+static inline bool ia32_enabled_verbose(void)
+{
+#ifdef CONFIG_IA32_EMULATION
+	pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");
+#endif
+	return ia32_enabled();
+}
+
  #endif /* _ASM_X86_IA32_H */
#2 lore raw
In reply to Borislav Petkov
Quoted 42 lines · Borislav Petkov

From: "Borislav Petkov (AMD)" <[email protected]>

Issue a short message once, on the first try to load a 32-bit process to save people time when wondering why it won't load and says:

-bash: ./strsep32: cannot execute binary file: Exec format error

No functional changes.

---
  arch/x86/include/asm/elf.h  | 2 +-
  arch/x86/include/asm/ia32.h | 9 ++++++++-
  2 files changed, 9 insertions(+), 2 deletions(-)
arch/x86/include/asm/elf.h +1 -1
index a0234dfd1031..1e16bd5ac781 100644
@@ -150,7 +150,7 @@ do {						\
  	((x)->e_machine == EM_X86_64)
 
  #define compat_elf_check_arch(x)					\
-	((elf_check_arch_ia32(x) && ia32_enabled()) ||			\
+	((elf_check_arch_ia32(x) && ia32_enabled_verbose()) ||		\
  	 (IS_ENABLED(CONFIG_X86_X32_ABI) && (x)->e_machine == EM_X86_64))
 
  static inline void elf_common_init(struct thread_struct *t,
arch/x86/include/asm/ia32.h +0 -1
index 5a2ae24b1204..43e02b52ad19 100644
@@ -2,7 +2,6 @@
  #ifndef _ASM_X86_IA32_H
  #define _ASM_X86_IA32_H
 
-
  #ifdef CONFIG_IA32_EMULATION
 
  #include <linux/compat.h>

arch/x86/include/asm/ia32.h static inline bool ia32_enabled(void) · line 88

Quoted 6 lines
arch/x86/include/asm/ia32.h +3 -0
@@ -84,4 +83,12 @@ static inline bool ia32_enabled(void)
 
  #endif
 
+static inline bool ia32_enabled_verbose(void)
+{
+#ifdef CONFIG_IA32_EMULATION

Hang on, this is wrong, it should be CONFIG_IA32_EMULATION_DEFAULT_DISABLED

Quoted 6 lines
arch/x86/include/asm/ia32.h +5 -0
+	pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");
+#endif
+	return ia32_enabled();
+}
+
  #endif /* _ASM_X86_IA32_H */
author maintainer
#3 lore raw
Quoted 1 line · Nikolay Borisov

Hang on, this is wrong, it should be CONFIG_IA32_EMULATION_DEFAULT_DISABLED

Slow down pls and think: what happens if I boot with ia32_emulation=off and CONFIG_IA32_EMULATION_DEFAULT_DISABLED is not set?

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#4 lore raw
In reply to Borislav Petkov
Quoted 42 lines · Borislav Petkov

From: "Borislav Petkov (AMD)" <[email protected]>

Issue a short message once, on the first try to load a 32-bit process to save people time when wondering why it won't load and says:

-bash: ./strsep32: cannot execute binary file: Exec format error

No functional changes.

---
  arch/x86/include/asm/elf.h  | 2 +-
  arch/x86/include/asm/ia32.h | 9 ++++++++-
  2 files changed, 9 insertions(+), 2 deletions(-)
arch/x86/include/asm/elf.h +1 -1
index a0234dfd1031..1e16bd5ac781 100644
@@ -150,7 +150,7 @@ do {						\
  	((x)->e_machine == EM_X86_64)
 
  #define compat_elf_check_arch(x)					\
-	((elf_check_arch_ia32(x) && ia32_enabled()) ||			\
+	((elf_check_arch_ia32(x) && ia32_enabled_verbose()) ||		\
  	 (IS_ENABLED(CONFIG_X86_X32_ABI) && (x)->e_machine == EM_X86_64))
 
  static inline void elf_common_init(struct thread_struct *t,
arch/x86/include/asm/ia32.h +0 -1
index 5a2ae24b1204..43e02b52ad19 100644
@@ -2,7 +2,6 @@
  #ifndef _ASM_X86_IA32_H
  #define _ASM_X86_IA32_H
 
-
  #ifdef CONFIG_IA32_EMULATION
 
  #include <linux/compat.h>

arch/x86/include/asm/ia32.h static inline bool ia32_enabled(void) · line 89

Quoted 7 lines
arch/x86/include/asm/ia32.h +4 -0
@@ -84,4 +83,12 @@ static inline bool ia32_enabled(void)
 
  #endif
 
+static inline bool ia32_enabled_verbose(void)
+{
+#ifdef CONFIG_IA32_EMULATION
+	pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");

Actually this will result in a false-positive, even with the
DEFAULT_DISABLED but booting with ia32_emulation = 0 so it's best if it's predicated on the output of ia32_enabled. This means we'll always pay the price of the branch even if it's disabled but removes a spurious notice in a certain case.

Quoted 5 lines
arch/x86/include/asm/ia32.h +4 -0
+#endif
+	return ia32_enabled();
+}
+
  #endif /* _ASM_X86_IA32_H */
author maintainer
#5 lore raw
In reply to Borislav Petkov

arch/x86/include/asm/ia32.h static inline bool ia32_enabled(void) · line 92

Quoted 7 lines · Borislav Petkov
arch/x86/include/asm/ia32.h +7 -0
+static inline bool ia32_enabled_verbose(void)
+{
+#ifdef CONFIG_IA32_EMULATION
+	pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");
+#endif
+	return ia32_enabled();
+}

As Nik rightfully points out offlist, this should rather be something like:

---

	bool enabled = ia32_enabled();
#ifdef CONFIG_IA32_EMULATION
	if (!enabled)
		pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");

#endif

	return enabled;

---

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#6 lore raw
Quoted 14 lines · Borislav Petkov

arch/x86/include/asm/ia32.h static inline bool ia32_enabled(void) · line 92

Quoted 7 lines · Borislav Petkov
arch/x86/include/asm/ia32.h +7 -0
+static inline bool ia32_enabled_verbose(void)
+{
+#ifdef CONFIG_IA32_EMULATION
+     pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");
+#endif
+     return ia32_enabled();
+}

As Nik rightfully points out offlist, this should rather be something like:

---

Quoted 8 lines
        bool enabled = ia32_enabled();
#ifdef CONFIG_IA32_EMULATION
        if (!enabled)
                pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");

#endif

        return enabled;

The #ifdef isn't necessary, as ia32_enabled() will always return false in that case.

Brian Gerst

#7 lore raw
Quoted 23 lines · Brian Gerst
Quoted 21 lines · Borislav Petkov

arch/x86/include/asm/ia32.h static inline bool ia32_enabled(void) · line 92

Quoted 7 lines · Borislav Petkov
arch/x86/include/asm/ia32.h +7 -0
+static inline bool ia32_enabled_verbose(void)
+{
+#ifdef CONFIG_IA32_EMULATION
+     pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");
+#endif
+     return ia32_enabled();
+}

As Nik rightfully points out offlist, this should rather be something like:

---

        bool enabled = ia32_enabled();
#ifdef CONFIG_IA32_EMULATION
        if (!enabled)
                pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");

#endif

Quoted 4 lines
Quoted 1 line
        return enabled;

The #ifdef isn't necessary, as ia32_enabled() will always return false in that case.

Scratch that, I misread it. If compat is disabled at build time you don't want the message to appear, or at least would want a different message.

Brian Gerst

author maintainer
#8 lore raw

PATCH 1/1 x86/ia32: State that IA32 emulation is disabled

In reply to Borislav Petkov

From: "Borislav Petkov (AMD)" <[email protected]>
Date: Thu, 30 Nov 2023 16:39:33 +0100

Issue a short message once, on the first try to load a 32-bit process to save people time when wondering why it won't load and trying to execute it, would say:

-bash: ./strsep32: cannot execute binary file: Exec format error

---
 arch/x86/include/asm/elf.h  |  2 +-
 arch/x86/include/asm/ia32.h | 11 ++++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)
arch/x86/include/asm/elf.h +1 -1
index a0234dfd1031..1e16bd5ac781 100644
@@ -150,7 +150,7 @@ do {						\
 	((x)->e_machine == EM_X86_64)
 
 #define compat_elf_check_arch(x)					\
-	((elf_check_arch_ia32(x) && ia32_enabled()) ||			\
+	((elf_check_arch_ia32(x) && ia32_enabled_verbose()) ||		\
 	 (IS_ENABLED(CONFIG_X86_X32_ABI) && (x)->e_machine == EM_X86_64))
 
 static inline void elf_common_init(struct thread_struct *t,
arch/x86/include/asm/ia32.h +10 -1
index 5a2ae24b1204..094886a8717e 100644
@@ -2,7 +2,6 @@
 #ifndef _ASM_X86_IA32_H
 #define _ASM_X86_IA32_H
 
-
 #ifdef CONFIG_IA32_EMULATION
 
 #include <linux/compat.h>
@@ -84,4 +83,14 @@ static inline bool ia32_enabled(void)
 
 #endif
 
+static inline bool ia32_enabled_verbose(void)
+{
+	bool enabled = ia32_enabled();
+
+	if (IS_ENABLED(CONFIG_IA32_EMULATION) && !enabled)
+		pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");
+
+	return enabled;
+}
+
 #endif /* _ASM_X86_IA32_H */
Signature · 7 lines
2.42.0.rc0.25.ga82fb66fed25

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
Reviewed-by on v1 1/1
#9 lore raw
Quoted 11 lines · Borislav Petkov

From: "Borislav Petkov (AMD)" <[email protected]>
Date: Thu, 30 Nov 2023 16:39:33 +0100

Issue a short message once, on the first try to load a 32-bit process to save people time when wondering why it won't load and trying to execute it, would say:

-bash: ./strsep32: cannot execute binary file: Exec format error

LGTM:

Quoted 31 lines
---
  arch/x86/include/asm/elf.h  |  2 +-
  arch/x86/include/asm/ia32.h | 11 ++++++++++-
  2 files changed, 11 insertions(+), 2 deletions(-)
arch/x86/include/asm/elf.h +1 -1
index a0234dfd1031..1e16bd5ac781 100644
@@ -150,7 +150,7 @@ do {						\
  	((x)->e_machine == EM_X86_64)
 
  #define compat_elf_check_arch(x)					\
-	((elf_check_arch_ia32(x) && ia32_enabled()) ||			\
+	((elf_check_arch_ia32(x) && ia32_enabled_verbose()) ||		\
  	 (IS_ENABLED(CONFIG_X86_X32_ABI) && (x)->e_machine == EM_X86_64))
 
  static inline void elf_common_init(struct thread_struct *t,
arch/x86/include/asm/ia32.h +0 -1
index 5a2ae24b1204..094886a8717e 100644
@@ -2,7 +2,6 @@
  #ifndef _ASM_X86_IA32_H
  #define _ASM_X86_IA32_H
 
-
  #ifdef CONFIG_IA32_EMULATION
 
  #include <linux/compat.h>

arch/x86/include/asm/ia32.h static inline bool ia32_enabled(void) · line 90

Quoted 8 lines
arch/x86/include/asm/ia32.h +5 -0
@@ -84,4 +83,14 @@ static inline bool ia32_enabled(void)
 
  #endif
 
+static inline bool ia32_enabled_verbose(void)
+{
+	bool enabled = ia32_enabled();
+
+	if (IS_ENABLED(CONFIG_IA32_EMULATION) && !enabled)

nit: But why check config_ia32_emulation explicitly, its state should already be accounted for in ia32_enabled's value? So this check can simply be 'if (!enabled)'

Quoted 6 lines
arch/x86/include/asm/ia32.h +5 -0
+		pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");
+
+	return enabled;
+}
+
  #endif /* _ASM_X86_IA32_H */
author maintainer
#10 lore raw
Quoted 11 lines · Nikolay Borisov

arch/x86/include/asm/ia32.h static inline bool ia32_enabled(void) · line 90

Quoted 5 lines
arch/x86/include/asm/ia32.h +5 -0
+static inline bool ia32_enabled_verbose(void)
+{
+	bool enabled = ia32_enabled();
+
+	if (IS_ENABLED(CONFIG_IA32_EMULATION) && !enabled)

nit: But why check config_ia32_emulation explicitly, its state should already be accounted for in ia32_enabled's value? So this check can simply be 'if (!enabled)'

arch/x86/include/asm/ia32.h static inline bool ia32_enabled(void) · line 91

Quoted 1 line
arch/x86/include/asm/ia32.h +1 -0
+		pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");
				^^^^^^^^^^

If CONFIG_IA32_EMULATION is disabled, is there any 32-bit emulation to be enabled, at all?

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#11 lore raw
Quoted 11 lines · Borislav Petkov
Quoted 10 lines · Nikolay Borisov

arch/x86/include/asm/ia32.h static inline bool ia32_enabled(void) · line 90

Quoted 5 lines
arch/x86/include/asm/ia32.h +5 -0
+static inline bool ia32_enabled_verbose(void)
+{
+	bool enabled = ia32_enabled();
+
+	if (IS_ENABLED(CONFIG_IA32_EMULATION) && !enabled)

nit: But why check config_ia32_emulation explicitly, its state should already be accounted for in ia32_enabled's value? So this check can simply be 'if (!enabled)'

Quoted 6 lines
Quoted 1 line

arch/x86/include/asm/ia32.h static inline bool ia32_enabled(void) · line 91

Quoted 1 line
arch/x86/include/asm/ia32.h +1 -0
+		pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");
				^^^^^^^^^^

If CONFIG_IA32_EMULATION is disabled, is there any 32-bit emulation to be enabled, at all?

Ah, the !enabled condition will then trigger so it will result in a false print. Fair enough...

#12 lore raw
In reply to Borislav Petkov
The following commit has been merged into the x86/misc branch of tip:

The following commit has been merged into the x86/misc branch of tip:

Commit-ID:     f789383fa34a266d0c1a76f272043a15a8edf733
Gitweb:        https://git.kernel.org/tip/f789383fa34a266d0c1a76f272043a15a8edf733
Author:        Borislav Petkov (AMD) <[email protected]>
AuthorDate:    Thu, 30 Nov 2023 16:39:33 +01:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Mon, 11 Dec 2023 10:14:28 +01:00

x86/ia32: State that IA32 emulation is disabled

Issue a short message once, on the first try to load a 32-bit process to save people time when wondering why it won't load and trying to execute it, would say:

-bash: ./strsep32: cannot execute binary file: Exec format error

---
 arch/x86/include/asm/elf.h  |  2 +-
 arch/x86/include/asm/ia32.h | 11 ++++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)
arch/x86/include/asm/elf.h +1 -1
index a0234df..1e16bd5 100644
@@ -150,7 +150,7 @@ do {						\
 	((x)->e_machine == EM_X86_64)
 
 #define compat_elf_check_arch(x)					\
-	((elf_check_arch_ia32(x) && ia32_enabled()) ||			\
+	((elf_check_arch_ia32(x) && ia32_enabled_verbose()) ||		\
 	 (IS_ENABLED(CONFIG_X86_X32_ABI) && (x)->e_machine == EM_X86_64))
 
 static inline void elf_common_init(struct thread_struct *t,
arch/x86/include/asm/ia32.h +10 -1
index 5a2ae24..094886a 100644
@@ -2,7 +2,6 @@
 #ifndef _ASM_X86_IA32_H
 #define _ASM_X86_IA32_H
 
-
 #ifdef CONFIG_IA32_EMULATION
 
 #include <linux/compat.h>
@@ -84,4 +83,14 @@ static inline bool ia32_enabled(void)
 
 #endif
 
+static inline bool ia32_enabled_verbose(void)
+{
+	bool enabled = ia32_enabled();
+
+	if (IS_ENABLED(CONFIG_IA32_EMULATION) && !enabled)
+		pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");
+
+	return enabled;
+}
+
 #endif /* _ASM_X86_IA32_H */