From 4eb6faf28cfe7c623b6d71ed61fe2e98b1bad7ca Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Sun, 27 Oct 2019 20:02:12 +0100 Subject: [PATCH] =?UTF-8?q?[amd64]=20Update=20"x86:=20Make=20x32=20syscall?= =?UTF-8?q?=20support=20conditional=20=E2=80=A6"=20for=205.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debian/changelog | 1 + ...make-x32-syscall-support-conditional.patch | 77 ++++++------------- debian/patches/series | 2 +- 3 files changed, 24 insertions(+), 56 deletions(-) diff --git a/debian/changelog b/debian/changelog index 6698514b99de..2ea5c6fef815 100644 --- a/debian/changelog +++ b/debian/changelog @@ -30,6 +30,7 @@ linux (5.4~rc7-1~exp1) UNRELEASED; urgency=medium - Enable SECURITY_LOCKDOWN_LSM, LOCK_DOWN_KERNEL_FORCE_NONE, LOCK_DOWN_IN_EFI_SECURE_BOOT * [armel/marvell] lockdown: Disable Lockdown as it now selects MODULE_SIG + * [amd64] Update "x86: Make x32 syscall support conditional …" for 5.4 [ Romain Perier ] * Rebased the following patches onto 5.4.x: diff --git a/debian/patches/features/x86/x86-make-x32-syscall-support-conditional.patch b/debian/patches/features/x86/x86-make-x32-syscall-support-conditional.patch index 09cfbecec3f7..cf6b4eda6ff9 100644 --- a/debian/patches/features/x86/x86-make-x32-syscall-support-conditional.patch +++ b/debian/patches/features/x86/x86-make-x32-syscall-support-conditional.patch @@ -21,16 +21,15 @@ Signed-off-by: Ben Hutchings --- Documentation/admin-guide/kernel-parameters.txt | 4 ++ arch/x86/Kconfig | 8 ++++ - arch/x86/entry/common.c | 11 +++++- - arch/x86/entry/syscall_64.c | 41 ++++++++++++++++++++++++ + arch/x86/entry/common.c | 3 + + arch/x86/entry/syscall_64.c | 46 ++++++++++++++++++++++++ arch/x86/include/asm/elf.h | 4 +- - arch/x86/include/asm/syscall.h | 13 +++++++ - arch/x86/include/asm/unistd.h | 4 +- - 7 files changed, 80 insertions(+), 5 deletions(-) + arch/x86/include/asm/syscall.h | 13 ++++++ + 6 files changed, 76 insertions(+), 2 deletions(-) --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt -@@ -4458,6 +4458,10 @@ +@@ -4678,6 +4678,10 @@ switches= [HW,M68k] @@ -43,7 +42,7 @@ Signed-off-by: Ben Hutchings on older distributions. When this option is enabled --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig -@@ -2893,6 +2893,14 @@ config COMPAT_32 +@@ -2901,6 +2901,14 @@ config COMPAT_32 select HAVE_UID16 select OLD_SIGSUSPEND3 @@ -60,31 +59,16 @@ Signed-off-by: Ben Hutchings depends on IA32_EMULATION || X86_X32 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c -@@ -284,12 +284,21 @@ __visible void do_syscall_64(unsigned lo - * table. The only functional difference is the x32 bit in - * regs->orig_ax, which changes the behavior of some syscalls. - */ -- nr &= __SYSCALL_MASK; -- if (likely(nr < NR_syscalls)) { -+ if (x32_enabled) { -+ nr &= ~__X32_SYSCALL_BIT; -+ if (unlikely(nr >= NR_syscalls)) -+ goto bad; +@@ -289,7 +289,8 @@ __visible void do_syscall_64(unsigned lo nr = array_index_nospec(nr, NR_syscalls); -+ goto good; -+ } else { -+ nr &= ~0U; -+ if (unlikely(nr >= NR_non_x32_syscalls)) -+ goto bad; -+ nr = array_index_nospec(nr, NR_non_x32_syscalls); -+good: regs->ax = sys_call_table[nr](regs); - } -- -+bad: - syscall_return_slowpath(regs); - } - #endif + #ifdef CONFIG_X86_X32_ABI +- } else if (likely((nr & __X32_SYSCALL_BIT) && ++ } else if (x32_enabled && ++ likely((nr & __X32_SYSCALL_BIT) && + (nr & ~__X32_SYSCALL_BIT) < X32_NR_syscalls)) { + nr = array_index_nospec(nr & ~__X32_SYSCALL_BIT, + X32_NR_syscalls); --- a/arch/x86/entry/syscall_64.c +++ b/arch/x86/entry/syscall_64.c @@ -4,6 +4,9 @@ @@ -97,13 +81,10 @@ Signed-off-by: Ben Hutchings #include #include -@@ -23,3 +26,50 @@ asmlinkage const sys_call_ptr_t sys_call - [0 ... __NR_syscall_max] = &sys_ni_syscall, - #include - }; -+ -+#ifdef CONFIG_X86_X32_ABI -+ +@@ -47,4 +50,47 @@ asmlinkage const sys_call_ptr_t x32_sys_ + #undef __SYSCALL_64 + #undef __SYSCALL_X32 + +/* Maybe enable x32 syscalls */ + +#if defined(CONFIG_X86_X32_DISABLED) @@ -147,7 +128,7 @@ Signed-off-by: Ben Hutchings + +arch_param_cb(x32, &x32_param_ops, NULL, 0444); + -+#endif + #endif --- a/arch/x86/include/asm/elf.h +++ b/arch/x86/include/asm/elf.h @@ -11,6 +11,7 @@ @@ -170,7 +151,7 @@ Signed-off-by: Ben Hutchings # error "The following code assumes __USER32_DS == __USER_DS" --- a/arch/x86/include/asm/syscall.h +++ b/arch/x86/include/asm/syscall.h -@@ -16,6 +16,7 @@ +@@ -13,6 +13,7 @@ #include #include #include @@ -178,8 +159,8 @@ Signed-off-by: Ben Hutchings #include /* For NR_syscalls */ #include /* for TS_COMPAT */ #include -@@ -39,6 +40,18 @@ extern const sys_call_ptr_t sys_call_tab - extern const sys_call_ptr_t ia32_sys_call_table[]; +@@ -40,6 +41,18 @@ extern const sys_call_ptr_t ia32_sys_cal + extern const sys_call_ptr_t x32_sys_call_table[]; #endif +#if defined(CONFIG_X86_X32_ABI) @@ -197,17 +178,3 @@ Signed-off-by: Ben Hutchings /* * Only the low 32 bits of orig_ax are meaningful, so we return int. * This importantly ignores the high bits on 64-bit, so comparisons ---- a/arch/x86/include/asm/unistd.h -+++ b/arch/x86/include/asm/unistd.h -@@ -6,9 +6,9 @@ - - - # ifdef CONFIG_X86_X32_ABI --# define __SYSCALL_MASK (~(__X32_SYSCALL_BIT)) -+# define NR_non_x32_syscalls 512 - # else --# define __SYSCALL_MASK (~0) -+# define NR_non_x32_syscalls NR_syscalls - # endif - - # ifdef CONFIG_X86_32 diff --git a/debian/patches/series b/debian/patches/series index 369cae02df94..db250680665a 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -75,7 +75,7 @@ bugfix/x86/x86-32-disable-3dnow-in-generic-config.patch # Arch features features/mips/MIPS-Loongson-3-Add-Loongson-LS3A-RS780E-1-way-machi.patch features/x86/x86-memtest-WARN-if-bad-RAM-found.patch -#features/x86/x86-make-x32-syscall-support-conditional.patch +features/x86/x86-make-x32-syscall-support-conditional.patch # Miscellaneous bug fixes bugfix/all/disable-some-marvell-phys.patch