Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

posix-cpu-timers: Sanitize bogus WARNONS

Warning when p == NULL and then proceeding and dereferencing p does not
make any sense as the kernel will crash with a NULL pointer dereference
right away.

Bailing out when p == NULL and returning an error code does not cure the
underlying problem which caused p to be NULL. Though it might allow to
do proper debugging.

Same applies to the clock id check in set_process_cpu_timer().

Clean them up and make them return without trying to do further damage.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
Link: https://lkml.kernel.org/r/20190819143801.846497772@linutronix.de

+13 -7
+13 -7
kernel/time/posix-cpu-timers.c
··· 375 375 struct sighand_struct *sighand; 376 376 struct task_struct *p = timer->it.cpu.task; 377 377 378 - WARN_ON_ONCE(p == NULL); 378 + if (WARN_ON_ONCE(!p)) 379 + return -EINVAL; 379 380 380 381 /* 381 382 * Protect against sighand release/switch in exit/exec and process/ ··· 582 581 u64 old_expires, new_expires, old_incr, val; 583 582 int ret; 584 583 585 - WARN_ON_ONCE(p == NULL); 584 + if (WARN_ON_ONCE(!p)) 585 + return -EINVAL; 586 586 587 587 /* 588 588 * Use the to_ktime conversion because that clamps the maximum ··· 718 716 719 717 static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp) 720 718 { 721 - u64 now; 722 719 struct task_struct *p = timer->it.cpu.task; 720 + u64 now; 723 721 724 - WARN_ON_ONCE(p == NULL); 722 + if (WARN_ON_ONCE(!p)) 723 + return; 725 724 726 725 /* 727 726 * Easy part: convert the reload time. ··· 1004 1001 */ 1005 1002 static void posix_cpu_timer_rearm(struct k_itimer *timer) 1006 1003 { 1004 + struct task_struct *p = timer->it.cpu.task; 1007 1005 struct sighand_struct *sighand; 1008 1006 unsigned long flags; 1009 - struct task_struct *p = timer->it.cpu.task; 1010 1007 u64 now; 1011 1008 1012 - WARN_ON_ONCE(p == NULL); 1009 + if (WARN_ON_ONCE(!p)) 1010 + return; 1013 1011 1014 1012 /* 1015 1013 * Fetch the current sample and update the timer's expiry time. ··· 1207 1203 u64 now; 1208 1204 int ret; 1209 1205 1210 - WARN_ON_ONCE(clock_idx == CPUCLOCK_SCHED); 1206 + if (WARN_ON_ONCE(clock_idx >= CPUCLOCK_SCHED)) 1207 + return; 1208 + 1211 1209 ret = cpu_timer_sample_group(clock_idx, tsk, &now); 1212 1210 1213 1211 if (oldval && ret != -EINVAL) {