Skip to content

Commit

Permalink
alarmtimer: Rate limit periodic intervals
Browse files Browse the repository at this point in the history
The alarmtimer code has another source of potentially rearming itself too
fast. Interval timers with a very samll interval have a similar CPU hog
effect as the previously fixed overflow issue.

The reason is that alarmtimers do not implement the normal protection
against this kind of problem which the other posix timer use:

  timer expires -> queue signal -> deliver signal -> rearm timer

This scheme brings the rearming under scheduler control and prevents
permanently firing timers which hog the CPU.

Bringing this scheme to the alarm timer code is a major overhaul because it
lacks all the necessary mechanisms completely.

So for a quick fix limit the interval to one jiffie. This is not
problematic in practice as alarmtimers are usually backed by an RTC for
suspend which have 1 second resolution. It could be therefor argued that
the resolution of this clock should be set to 1 second in general, but
that's outside the scope of this fix.

Signed-off-by: Thomas Gleixner <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Kostya Serebryany <[email protected]>
Cc: syzkaller <[email protected]>
Cc: John Stultz <[email protected]>
Cc: Dmitry Vyukov <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
  • Loading branch information
KAGA-KOKO committed Jun 4, 2017
1 parent f4781e7 commit ff86bf0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions kernel/time/alarmtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,14 @@ static int alarm_timer_set(struct k_itimer *timr, int flags,

/* start the timer */
timr->it.alarm.interval = timespec64_to_ktime(new_setting->it_interval);

/*
* Rate limit to the tick as a hot fix to prevent DOS. Will be
* mopped up later.
*/
if (timr->it.alarm.interval < TICK_NSEC)
timr->it.alarm.interval = TICK_NSEC;

exp = timespec64_to_ktime(new_setting->it_value);
/* Convert (if necessary) to absolute time */
if (flags != TIMER_ABSTIME) {
Expand Down

0 comments on commit ff86bf0

Please sign in to comment.