[PATCH] mips: vdso: conditionalize 32-bit time functions on COMPAT_32BIT_TIME
From: Jason A. Donenfeld
Date: Tue Dec 24 2019 - 08:54:32 EST
When the VDSO falls back to 32-bit time functions on kernels with
COMPAT_32BIT_TIME=n, userspace becomes corrupted and appears to crash
shortly after, with something like:
[ 0.359617] do_page_fault(): sending SIGSEGV to init for invalid read access from 000000007ff790d0
[ 0.359843] epc = 0000000077e45df4 in libc.so[77da6000+de000]
[ 0.360319] ra = 0000000010000c50 in init[10000000+2000]
[ 0.364456] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
This can be reproduced with simply calling `clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts)`,
since `CLOCK_PROCESS_CPUTIME_ID` is not exported to the VDSO, invoking
the syscall callback branch. This crash was observed with musl 1.20's
clock_gettime implementation:
int __clock_gettime(clockid_t clk, struct timespec *ts)
{
int r;
int (*f)(clockid_t, struct timespec *) =
(int (*)(clockid_t, struct timespec *))vdso_func;
if (f) {
r = f(clk, ts);
if (!r) {
return r;
}
if (r == -EINVAL)
return __syscall_ret(r);
}
r = __syscall(SYS_clock_gettime, clk, ts); // <-- CRASH
if (r == -ENOSYS) {
if (clk == CLOCK_REALTIME) {
__syscall(SYS_gettimeofday, ts, 0);
ts->tv_nsec = (int)ts->tv_nsec * 1000;
return 0;
}
r = -EINVAL;
}
return __syscall_ret(r);
}
The particular kernel and libc are built as part of the MIPS64 CI on
build.wireguard.com which generally uses as minimal configurations as
possible.
Signed-off-by: Jason A. Donenfeld <Jason@xxxxxxxxx>
Cc: Paul Burton <paulburton@xxxxxxxxxx>
Cc: Arnd Bergmann <arnd@xxxxxxxx>
Cc: Vincenzo Frascino <vincenzo.frascino@xxxxxxx>
Cc: Christian Brauner <christian.brauner@xxxxxxxxxxxxx>
Fixes: 942437c97fd9 ("y2038: allow disabling time32 system calls")
---
arch/mips/include/asm/vdso/gettimeofday.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/mips/include/asm/vdso/gettimeofday.h b/arch/mips/include/asm/vdso/gettimeofday.h
index b08825531e9f..7f1aa610e68e 100644
--- a/arch/mips/include/asm/vdso/gettimeofday.h
+++ b/arch/mips/include/asm/vdso/gettimeofday.h
@@ -107,7 +107,7 @@ static __always_inline int clock_getres_fallback(
return error ? -ret : ret;
}
-#if _MIPS_SIM != _MIPS_SIM_ABI64
+#if _MIPS_SIM != _MIPS_SIM_ABI64 && defined(CONFIG_COMPAT_32BIT_TIME)
#define VDSO_HAS_32BIT_FALLBACK 1
--
2.24.1