From 223d2f61ad25aa36bc2a45942c4ac4af2bddd631 Mon Sep 17 00:00:00 2001 From: Aurelien Jarno Date: Tue, 23 Apr 2019 19:35:04 +0200 Subject: [PATCH] [mips] Fix indirect syscall tracing & seccomp filtering for big endian MIPS64 kernels with 32-bit userland. --- debian/changelog | 4 ++ ...o32-Fix-indirect-syscall-number-load.patch | 52 +++++++++++++++++++ debian/patches/series | 1 + 3 files changed, 57 insertions(+) create mode 100644 debian/patches/bugfix/mips/MIPS-scall64-o32-Fix-indirect-syscall-number-load.patch diff --git a/debian/changelog b/debian/changelog index 2ae5c2e77..2cc4ff1b1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -827,6 +827,10 @@ linux (4.19.34-1) UNRELEASED; urgency=medium * ACPICA: Namespace: remove address node from global list after method termination + [ Aurelien Jarno ] + * [mips] Fix indirect syscall tracing & seccomp filtering for big endian + MIPS64 kernels with 32-bit userland. + -- Ben Hutchings Mon, 18 Mar 2019 22:50:08 +0000 linux (4.19.28-2) unstable; urgency=medium diff --git a/debian/patches/bugfix/mips/MIPS-scall64-o32-Fix-indirect-syscall-number-load.patch b/debian/patches/bugfix/mips/MIPS-scall64-o32-Fix-indirect-syscall-number-load.patch new file mode 100644 index 000000000..f9502d050 --- /dev/null +++ b/debian/patches/bugfix/mips/MIPS-scall64-o32-Fix-indirect-syscall-number-load.patch @@ -0,0 +1,52 @@ +From: Aurelien Jarno +Date: Tue, 9 Apr 2019 16:53:55 +0200 +Subject: MIPS: scall64-o32: Fix indirect syscall number load +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +Origin: https://git.kernel.org/linus/79b4a9cf0e2ea8203ce777c8d5cfa86c71eae86e + +Commit 4c21b8fd8f14 (MIPS: seccomp: Handle indirect system calls (o32)) +added indirect syscall detection for O32 processes running on MIPS64, +but it did not work correctly for big endian kernel/processes. The +reason is that the syscall number is loaded from ARG1 using the lw +instruction while this is a 64-bit value, so zero is loaded instead of +the syscall number. + +Fix the code by using the ld instruction instead. When running a 32-bit +processes on a 64 bit CPU, the values are properly sign-extended, so it +ensures the value passed to syscall_trace_enter is correct. + +Recent systemd versions with seccomp enabled whitelist the getpid +syscall for their internal processes (e.g. systemd-journald), but call +it through syscall(SYS_getpid). This fix therefore allows O32 big endian +systems with a 64-bit kernel to run recent systemd versions. + +Signed-off-by: Aurelien Jarno +Cc: # v3.15+ +Reviewed-by: Philippe Mathieu-Daudé +Signed-off-by: Paul Burton +Cc: Ralf Baechle +Cc: James Hogan +Cc: linux-mips@vger.kernel.org +Cc: linux-kernel@vger.kernel.org +--- + arch/mips/kernel/scall64-o32.S | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S +index f158c5894a9a..feb2653490df 100644 +--- a/arch/mips/kernel/scall64-o32.S ++++ b/arch/mips/kernel/scall64-o32.S +@@ -125,7 +125,7 @@ trace_a_syscall: + subu t1, v0, __NR_O32_Linux + move a1, v0 + bnez t1, 1f /* __NR_syscall at offset 0 */ +- lw a1, PT_R4(sp) /* Arg1 for __NR_syscall case */ ++ ld a1, PT_R4(sp) /* Arg1 for __NR_syscall case */ + .set pop + + 1: jal syscall_trace_enter +-- +2.20.1 + diff --git a/debian/patches/series b/debian/patches/series index ce3800942..8356a6077 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -81,6 +81,7 @@ bugfix/arm/ARM-dts-sun8i-h3-add-sy8106a-to-orange-pi-plus.patch bugfix/arm64/arm64-dts-allwinner-a64-Enable-A64-timer-workaround.patch bugfix/mips/MIPS-Loongson-Introduce-and-use-loongson_llsc_mb.patch bugfix/powerpc/powerpc-vdso-make-vdso32-installation-conditional-in.patch +bugfix/mips/MIPS-scall64-o32-Fix-indirect-syscall-number-load.patch # Arch features features/mips/MIPS-increase-MAX-PHYSMEM-BITS-on-Loongson-3-only.patch