[-v2] x86/ia32: State that IA32 emulation is disabled

Message ID 20231206172022.GCZXCtVoZtt4t2TLpe@fat_crate.local
State New
Headers
Series [-v2] x86/ia32: State that IA32 emulation is disabled |

Commit Message

Borislav Petkov Dec. 6, 2023, 5:20 p.m. UTC
  From: "Borislav Petkov (AMD)" <bp@alien8.de>
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

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 | 11 ++++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)
  

Comments

Nikolay Borisov Dec. 8, 2023, 6:42 p.m. UTC | #1
On 6.12.23 г. 19:20 ч., Borislav Petkov wrote:
> From: "Borislav Petkov (AMD)" <bp@alien8.de>
> 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
> 
> 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>


> ---
>   arch/x86/include/asm/elf.h  |  2 +-
>   arch/x86/include/asm/ia32.h | 11 ++++++++++-
>   2 files changed, 11 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..094886a8717e 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,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)'

> +		pr_notice_once("32-bit emulation disabled. You can reenable with ia32_emulation=on\n");
> +
> +	return enabled;
> +}
> +
>   #endif /* _ASM_X86_IA32_H */
  
Borislav Petkov Dec. 8, 2023, 7:22 p.m. UTC | #2
On Fri, Dec 08, 2023 at 08:42:29PM +0200, Nikolay Borisov wrote:
> > +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)'
> 
> > +		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?
  
Nikolay Borisov Dec. 8, 2023, 7:28 p.m. UTC | #3
On 8.12.23 г. 21:22 ч., Borislav Petkov wrote:
> On Fri, Dec 08, 2023 at 08:42:29PM +0200, Nikolay Borisov wrote:
>>> +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)'
>>
>>> +		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...
  

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..094886a8717e 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,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 */