x86/ia32: State that IA32 emulation is disabled

Message ID 20231130155213.1407-1-bp@alien8.de
State New
Headers
Series x86/ia32: State that IA32 emulation is disabled |

Commit Message

Borislav Petkov Nov. 30, 2023, 3:52 p.m. UTC
  From: "Borislav Petkov (AMD)" <bp@alien8.de>

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.

Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Nikolay Borisov <nik.borisov@suse.com>
---
 arch/x86/include/asm/elf.h  | 2 +-
 arch/x86/include/asm/ia32.h | 9 ++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)
  

Comments

Nikolay Borisov Nov. 30, 2023, 3:59 p.m. UTC | #1
On 30.11.23 г. 17:52 ч., Borislav Petkov wrote:
> From: "Borislav Petkov (AMD)" <bp@alien8.de>
> 
> 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.
> 
> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
> Cc: Nikolay Borisov <nik.borisov@suse.com>

LGTM:

Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>

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.

> ---
>   arch/x86/include/asm/elf.h  | 2 +-
>   arch/x86/include/asm/ia32.h | 9 ++++++++-
>   2 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
> index a0234dfd1031..1e16bd5ac781 100644
> --- a/arch/x86/include/asm/elf.h
> +++ b/arch/x86/include/asm/elf.h
> @@ -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,
> diff --git a/arch/x86/include/asm/ia32.h b/arch/x86/include/asm/ia32.h
> index 5a2ae24b1204..43e02b52ad19 100644
> --- a/arch/x86/include/asm/ia32.h
> +++ b/arch/x86/include/asm/ia32.h
> @@ -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 */
  
Nikolay Borisov Nov. 30, 2023, 4 p.m. UTC | #2
On 30.11.23 г. 17:52 ч., Borislav Petkov wrote:
> From: "Borislav Petkov (AMD)" <bp@alien8.de>
> 
> 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.
> 
> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
> Cc: Nikolay Borisov <nik.borisov@suse.com>
> ---
>   arch/x86/include/asm/elf.h  | 2 +-
>   arch/x86/include/asm/ia32.h | 9 ++++++++-
>   2 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
> index a0234dfd1031..1e16bd5ac781 100644
> --- a/arch/x86/include/asm/elf.h
> +++ b/arch/x86/include/asm/elf.h
> @@ -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,
> diff --git a/arch/x86/include/asm/ia32.h b/arch/x86/include/asm/ia32.h
> index 5a2ae24b1204..43e02b52ad19 100644
> --- a/arch/x86/include/asm/ia32.h
> +++ b/arch/x86/include/asm/ia32.h
> @@ -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

Hang on, this is wrong, it should be CONFIG_IA32_EMULATION_DEFAULT_DISABLED
> +	pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");
> +#endif
> +	return ia32_enabled();
> +}
> +
>   #endif /* _ASM_X86_IA32_H */
  
Borislav Petkov Nov. 30, 2023, 4:03 p.m. UTC | #3
On Thu, Nov 30, 2023 at 06:00:16PM +0200, Nikolay Borisov wrote:
> 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?
  
Nikolay Borisov Nov. 30, 2023, 4:04 p.m. UTC | #4
On 30.11.23 г. 17:52 ч., Borislav Petkov wrote:
> From: "Borislav Petkov (AMD)" <bp@alien8.de>
> 
> 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.
> 
> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
> Cc: Nikolay Borisov <nik.borisov@suse.com>
> ---
>   arch/x86/include/asm/elf.h  | 2 +-
>   arch/x86/include/asm/ia32.h | 9 ++++++++-
>   2 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
> index a0234dfd1031..1e16bd5ac781 100644
> --- a/arch/x86/include/asm/elf.h
> +++ b/arch/x86/include/asm/elf.h
> @@ -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,
> diff --git a/arch/x86/include/asm/ia32.h b/arch/x86/include/asm/ia32.h
> index 5a2ae24b1204..43e02b52ad19 100644
> --- a/arch/x86/include/asm/ia32.h
> +++ b/arch/x86/include/asm/ia32.h
> @@ -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");

	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.

> +#endif
> +	return ia32_enabled();
> +}
> +
>   #endif /* _ASM_X86_IA32_H */
  
Borislav Petkov Nov. 30, 2023, 4:09 p.m. UTC | #5
On Thu, Nov 30, 2023 at 04:52:13PM +0100, Borislav Petkov wrote:
> +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.
  
Brian Gerst Nov. 30, 2023, 4:42 p.m. UTC | #6
On Thu, Nov 30, 2023 at 11:09 AM Borislav Petkov <bp@alien8.de> wrote:
>
> On Thu, Nov 30, 2023 at 04:52:13PM +0100, Borislav Petkov wrote:
> > +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;

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

Brian Gerst
  
Brian Gerst Nov. 30, 2023, 4:47 p.m. UTC | #7
On Thu, Nov 30, 2023 at 11:42 AM Brian Gerst <brgerst@gmail.com> wrote:
>
> On Thu, Nov 30, 2023 at 11:09 AM Borislav Petkov <bp@alien8.de> wrote:
> >
> > On Thu, Nov 30, 2023 at 04:52:13PM +0100, Borislav Petkov wrote:
> > > +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;
>
> 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
  

Patch

diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
index a0234dfd1031..1e16bd5ac781 100644
--- a/arch/x86/include/asm/elf.h
+++ b/arch/x86/include/asm/elf.h
@@ -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,
diff --git a/arch/x86/include/asm/ia32.h b/arch/x86/include/asm/ia32.h
index 5a2ae24b1204..43e02b52ad19 100644
--- a/arch/x86/include/asm/ia32.h
+++ b/arch/x86/include/asm/ia32.h
@@ -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 */