android_kernel_asus_sm8350/kernel/time
Jann Horn c8157f67b0 timers: Prevent union confusion from unexpected restart_syscall()
[ Upstream commit 9f76d59173d9d146e96c66886b671c1915a5c5e5 ]

The nanosleep syscalls use the restart_block mechanism, with a quirk:
The `type` and `rmtp`/`compat_rmtp` fields are set up unconditionally on
syscall entry, while the rest of the restart_block is only set up in the
unlikely case that the syscall is actually interrupted by a signal (or
pseudo-signal) that doesn't have a signal handler.

If the restart_block was set up by a previous syscall (futex(...,
FUTEX_WAIT, ...) or poll()) and hasn't been invalidated somehow since then,
this will clobber some of the union fields used by futex_wait_restart() and
do_restart_poll().

If userspace afterwards wrongly calls the restart_syscall syscall,
futex_wait_restart()/do_restart_poll() will read struct fields that have
been clobbered.

This doesn't actually lead to anything particularly interesting because
none of the union fields contain trusted kernel data, and
futex(..., FUTEX_WAIT, ...) and poll() aren't syscalls where it makes much
sense to apply seccomp filters to their arguments.

So the current consequences are just of the "if userspace does bad stuff,
it can damage itself, and that's not a problem" flavor.

But still, it seems like a hazard for future developers, so invalidate the
restart_block when partly setting it up in the nanosleep syscalls.

Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20230105134403.754986-1-jannh@google.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-03-11 16:43:54 +01:00
..
alarmtimer.c alarmtimer: Prevent starvation by small intervals and SIG_IGN 2023-02-25 11:53:26 +01:00
clockevents.c
clocksource.c clocksource: Retry clock read if long delays detected 2021-07-14 16:53:18 +02:00
hrtimer.c timers: Prevent union confusion from unexpected restart_syscall() 2023-03-11 16:43:54 +01:00
itimer.c time: Prevent undefined behaviour in timespec64_to_ns() 2020-11-18 19:20:15 +01:00
jiffies.c
Kconfig
Makefile
ntp_internal.h
ntp.c
posix-clock.c
posix-cpu-timers.c Revert "posix-cpu-timers: Force next expiration recalc after itimer reset" 2021-09-16 12:56:13 +02:00
posix-stubs.c timers: Prevent union confusion from unexpected restart_syscall() 2023-03-11 16:43:54 +01:00
posix-timers.c timers: Prevent union confusion from unexpected restart_syscall() 2023-03-11 16:43:54 +01:00
posix-timers.h
sched_clock.c
test_udelay.c
tick-broadcast-hrtimer.c
tick-broadcast.c
tick-common.c tick/common: Touch watchdog in tick_unfreeze() on all CPUs 2020-11-18 19:20:26 +01:00
tick-internal.h hrtimer: Ensure timerfd notification for HIGHRES=n 2021-09-15 09:47:26 +02:00
tick-oneshot.c
tick-sched.c tick/nohz: Use WARN_ON_ONCE() to prevent console saturation 2022-04-20 09:19:39 +02:00
tick-sched.h
time.c
timeconst.bc
timeconv.c
timecounter.c
timekeeping_debug.c
timekeeping_internal.h
timekeeping.c timekeeping: contribute wall clock to rng on time change 2022-08-25 11:18:15 +02:00
timekeeping.h
timer_list.c
timer.c timers: Move clearing of base::timer_running under base:: Lock 2021-08-12 13:21:03 +02:00
vsyscall.c