2023-06-16 13:13:53

by Nikolay Borisov

[permalink] [raw]
Subject: [PATCH v3 1/5] x86: Make IA32_EMULATION boot time configurable

Distributions would like to reduce their attack surface as much as
possible but at the same time they'd want to retain flexibility to cater
to a variety of legacy software. One such avenue where a balance has to
be struck is in supporting 32bit syscalls/processes on 64bit kernels. Ideally
it should be possible for the distribution to set their own policy and
give users the ability to override those policies as appropriate.

In order to support this usecase, introduce
CONFIG_IA32_EMULATION_DEFAULT_DISABLED compile time option, which
controls whether 32bit processes/syscalls should be allowed or not. This
allows distributions to set their preferred default behavior in their
kernel configs.

On the other hand, in order to allow users to override the distro's
policy, introduce the 'ia32_mode' parameter which allows overriding
CONFIG_IA32_EMULATION_DEFAULT_DISABLED state at boot time.

Signed-off-by: Nikolay Borisov <[email protected]>
---
Documentation/admin-guide/kernel-parameters.txt | 5 +++++
arch/x86/Kconfig | 9 +++++++++
arch/x86/entry/common.c | 16 ++++++++++++++++
arch/x86/include/asm/ia32.h | 16 +++++++++++++++-
4 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 9e5bab29685f..59b1e86ecd9d 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1865,6 +1865,11 @@
0 -- machine default
1 -- force brightness inversion

+ ia32_mode= [X86-64]
+ Format: ia32_mode=disabled, ia32_mode=enabled
+ Allows overriding the compile-time state of
+ IA32_EMULATION_DEFAULT_DISABLED at boot time
+
icn= [HW,ISDN]
Format: <io>[,<membase>[,<icn_id>[,<icn_id2>]]]

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 53bab123a8ee..8bec431c97ce 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -3038,6 +3038,15 @@ config IA32_EMULATION
64-bit kernel. You should likely turn this on, unless you're
100% sure that you don't have any 32-bit programs left.

+config IA32_EMULATION_DEFAULT_DISABLED
+ bool "IA32 emulation disabled by default"
+ default n
+ depends on IA32_EMULATION
+ help
+ Make IA32 emulation disabled by default. This prevents loading 32bit
+ processes and access to 32bit syscalls. If unsure, leave it to its
+ default value.
+
config X86_X32_ABI
bool "x32 ABI for 64-bit mode"
depends on X86_64
diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c
index 6c2826417b33..35bacf2f8be5 100644
--- a/arch/x86/entry/common.c
+++ b/arch/x86/entry/common.c
@@ -19,6 +19,7 @@
#include <linux/nospec.h>
#include <linux/syscalls.h>
#include <linux/uaccess.h>
+#include <linux/init.h>

#ifdef CONFIG_XEN_PV
#include <xen/xen-ops.h>
@@ -96,6 +97,21 @@ static __always_inline int syscall_32_enter(struct pt_regs *regs)
return (int)regs->orig_ax;
}

+#ifdef CONFIG_IA32_EMULATION
+bool __ia32_enabled = !IS_ENABLED(CONFIG_IA32_EMULATION_DEFAULT_DISABLED);
+
+static int ia32_mode_override_cmdline(char *arg)
+{
+ if (!strcmp(arg, "disabled"))
+ __ia32_enabled = false;
+ else if (!strcmp(arg, "enabled"))
+ __ia32_enabled = true;
+
+ return 1;
+}
+__setup("ia32_mode=", ia32_mode_override_cmdline);
+#endif
+
/*
* Invoke a 32-bit syscall. Called with IRQs on in CONTEXT_KERNEL.
*/
diff --git a/arch/x86/include/asm/ia32.h b/arch/x86/include/asm/ia32.h
index fada857f0a1e..c35e4a6d3317 100644
--- a/arch/x86/include/asm/ia32.h
+++ b/arch/x86/include/asm/ia32.h
@@ -68,6 +68,20 @@ extern void ia32_pick_mmap_layout(struct mm_struct *mm);

#endif

-#endif /* CONFIG_IA32_EMULATION */
+extern bool __ia32_enabled;
+
+static inline bool ia32_enabled(void)
+{
+ return __ia32_enabled;
+}
+
+#else /* CONFIG_IA32_EMULATION */
+
+static inline bool ia32_enabled(void)
+{
+ return IS_ENABLED(CONFIG_X86_32);
+}
+
+#endif

#endif /* _ASM_X86_IA32_H */
--
2.34.1



2023-06-19 22:32:23

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH v3 1/5] x86: Make IA32_EMULATION boot time configurable



On 6/16/23 05:57, Nikolay Borisov wrote:
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index 53bab123a8ee..8bec431c97ce 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -3038,6 +3038,15 @@ config IA32_EMULATION
> 64-bit kernel. You should likely turn this on, unless you're
> 100% sure that you don't have any 32-bit programs left.
>
> +config IA32_EMULATION_DEFAULT_DISABLED
> + bool "IA32 emulation disabled by default"
> + default n
> + depends on IA32_EMULATION
> + help
> + Make IA32 emulation disabled by default. This prevents loading 32bit

32-bit

> + processes and access to 32bit syscalls. If unsure, leave it to its

32-bit

> + default value.

--
~Randy

2023-06-21 18:52:14

by Borislav Petkov

[permalink] [raw]
Subject: Re: [PATCH v3 1/5] x86: Make IA32_EMULATION boot time configurable

On Fri, Jun 16, 2023 at 03:57:26PM +0300, Nikolay Borisov wrote:
> Distributions would like to reduce their attack surface as much as
> possible but at the same time they'd want to retain flexibility to cater
> to a variety of legacy software. One such avenue where a balance has to
> be struck is in supporting 32bit syscalls/processes on 64bit kernels. Ideally
> it should be possible for the distribution to set their own policy and
> give users the ability to override those policies as appropriate.
>
> In order to support this usecase, introduce
> CONFIG_IA32_EMULATION_DEFAULT_DISABLED compile time option, which
> controls whether 32bit processes/syscalls should be allowed or not. This
> allows distributions to set their preferred default behavior in their
> kernel configs.
>
> On the other hand, in order to allow users to override the distro's
> policy, introduce the 'ia32_mode' parameter which allows overriding
> CONFIG_IA32_EMULATION_DEFAULT_DISABLED state at boot time.
>
> Signed-off-by: Nikolay Borisov <[email protected]>
> ---
> Documentation/admin-guide/kernel-parameters.txt | 5 +++++
> arch/x86/Kconfig | 9 +++++++++
> arch/x86/entry/common.c | 16 ++++++++++++++++
> arch/x86/include/asm/ia32.h | 16 +++++++++++++++-
> 4 files changed, 45 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index 9e5bab29685f..59b1e86ecd9d 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -1865,6 +1865,11 @@
> 0 -- machine default
> 1 -- force brightness inversion
>
> + ia32_mode= [X86-64]
> + Format: ia32_mode=disabled, ia32_mode=enabled

ia32_mode=(on|off)

is less typing. Especially if you're standing somewhere in a server room
and trying to type on some weird keyboard which always has the wrong
layout.

:-)

> + Allows overriding the compile-time state of
> + IA32_EMULATION_DEFAULT_DISABLED at boot time

Just say what "=on" and "=off" does here - loading of 32-bit programs
and 32-bit syscalls is enabled/disabled.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette

2023-06-21 19:15:32

by Nikolay Borisov

[permalink] [raw]
Subject: Re: [PATCH v3 1/5] x86: Make IA32_EMULATION boot time configurable



On 21.06.23 г. 21:27 ч., Borislav Petkov wrote:
> On Fri, Jun 16, 2023 at 03:57:26PM +0300, Nikolay Borisov wrote:
>> Distributions would like to reduce their attack surface as much as
>> possible but at the same time they'd want to retain flexibility to cater
>> to a variety of legacy software. One such avenue where a balance has to
>> be struck is in supporting 32bit syscalls/processes on 64bit kernels. Ideally
>> it should be possible for the distribution to set their own policy and
>> give users the ability to override those policies as appropriate.
>>
>> In order to support this usecase, introduce
>> CONFIG_IA32_EMULATION_DEFAULT_DISABLED compile time option, which
>> controls whether 32bit processes/syscalls should be allowed or not. This
>> allows distributions to set their preferred default behavior in their
>> kernel configs.
>>
>> On the other hand, in order to allow users to override the distro's
>> policy, introduce the 'ia32_mode' parameter which allows overriding
>> CONFIG_IA32_EMULATION_DEFAULT_DISABLED state at boot time.
>>
>> Signed-off-by: Nikolay Borisov <[email protected]>
>> ---
>> Documentation/admin-guide/kernel-parameters.txt | 5 +++++
>> arch/x86/Kconfig | 9 +++++++++
>> arch/x86/entry/common.c | 16 ++++++++++++++++
>> arch/x86/include/asm/ia32.h | 16 +++++++++++++++-
>> 4 files changed, 45 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
>> index 9e5bab29685f..59b1e86ecd9d 100644
>> --- a/Documentation/admin-guide/kernel-parameters.txt
>> +++ b/Documentation/admin-guide/kernel-parameters.txt
>> @@ -1865,6 +1865,11 @@
>> 0 -- machine default
>> 1 -- force brightness inversion
>>
>> + ia32_mode= [X86-64]
>> + Format: ia32_mode=disabled, ia32_mode=enabled
>
> ia32_mode=(on|off)

In the next version I called this ia32_emulation=on|off seems more
descriptive.
>
> is less typing. Especially if you're standing somewhere in a server room
> and trying to type on some weird keyboard which always has the wrong
> layout.
>
> :-)
>
>> + Allows overriding the compile-time state of
>> + IA32_EMULATION_DEFAULT_DISABLED at boot time
>
> Just say what "=on" and "=off" does here - loading of 32-bit programs
> and 32-bit syscalls is enabled/disabled.

ack
>