Skip to content

Commit 692117c

Browse files
committed
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
1 parent 68b2c8c commit 692117c

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

‎kernel/time/posix-cpu-timers.c‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ static int posix_cpu_timer_del(struct k_itimer *timer)
375375
struct sighand_struct *sighand;
376376
struct task_struct *p = timer->it.cpu.task;
377377

378-
WARN_ON_ONCE(p == NULL);
378+
if (WARN_ON_ONCE(!p))
379+
return -EINVAL;
379380

380381
/*
381382
* Protect against sighand release/switch in exit/exec and process/
@@ -581,7 +582,8 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
581582
u64 old_expires, new_expires, old_incr, val;
582583
int ret;
583584

584-
WARN_ON_ONCE(p == NULL);
585+
if (WARN_ON_ONCE(!p))
586+
return -EINVAL;
585587

586588
/*
587589
* Use the to_ktime conversion because that clamps the maximum
@@ -716,10 +718,11 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
716718

717719
static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp)
718720
{
719-
u64 now;
720721
struct task_struct *p = timer->it.cpu.task;
722+
u64 now;
721723

722-
WARN_ON_ONCE(p == NULL);
724+
if (WARN_ON_ONCE(!p))
725+
return;
723726

724727
/*
725728
* Easy part: convert the reload time.
@@ -1001,12 +1004,13 @@ static void check_process_timers(struct task_struct *tsk,
10011004
*/
10021005
static void posix_cpu_timer_rearm(struct k_itimer *timer)
10031006
{
1007+
struct task_struct *p = timer->it.cpu.task;
10041008
struct sighand_struct *sighand;
10051009
unsigned long flags;
1006-
struct task_struct *p = timer->it.cpu.task;
10071010
u64 now;
10081011

1009-
WARN_ON_ONCE(p == NULL);
1012+
if (WARN_ON_ONCE(!p))
1013+
return;
10101014

10111015
/*
10121016
* Fetch the current sample and update the timer's expiry time.
@@ -1203,7 +1207,9 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
12031207
u64 now;
12041208
int ret;
12051209

1206-
WARN_ON_ONCE(clock_idx == CPUCLOCK_SCHED);
1210+
if (WARN_ON_ONCE(clock_idx >= CPUCLOCK_SCHED))
1211+
return;
1212+
12071213
ret = cpu_timer_sample_group(clock_idx, tsk, &now);
12081214

12091215
if (oldval && ret != -EINVAL) {

0 commit comments

Comments
 (0)