Skip to content

Commit b952caf

Browse files
Qianli ZhaoKAGA-KOKO
authored andcommitted
timers: Mask invalid flags in do_init_timer()
do_init_timer() accepts any combination of timer flags handed in by the caller without a sanity check, but only TIMER_DEFFERABLE, TIMER_PINNED and TIMER_IRQSAFE are valid. If the supplied flags have other bits set, this could result in malfunction. If bits are set in TIMER_CPUMASK the first timer usage could deference a cpu base which is outside the range of possible CPUs. If TIMER_MIGRATION is set, then the switch_timer_base() will live lock. Prevent that with a sanity check which warns when invalid flags are supplied and masks them out. [ tglx: Made it WARN_ON_ONCE() and added context to the changelog ] Signed-off-by: Qianli Zhao <zhaoqianli@xiaomi.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/9d79a8aa4eb56713af7379f99f062dedabcde140.1597326756.git.zhaoqianli@xiaomi.com
1 parent ec02821 commit b952caf

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

include/linux/timer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct timer_list {
6767
#define TIMER_DEFERRABLE 0x00080000
6868
#define TIMER_PINNED 0x00100000
6969
#define TIMER_IRQSAFE 0x00200000
70+
#define TIMER_INIT_FLAGS (TIMER_DEFERRABLE | TIMER_PINNED | TIMER_IRQSAFE)
7071
#define TIMER_ARRAYSHIFT 22
7172
#define TIMER_ARRAYMASK 0xFFC00000
7273

kernel/time/timer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ static void do_init_timer(struct timer_list *timer,
794794
{
795795
timer->entry.pprev = NULL;
796796
timer->function = func;
797+
if (WARN_ON_ONCE(flags & ~TIMER_INIT_FLAGS))
798+
flags &= TIMER_INIT_FLAGS;
797799
timer->flags = flags | raw_smp_processor_id();
798800
lockdep_init_map(&timer->lockdep_map, name, key, 0);
799801
}

0 commit comments

Comments
 (0)