All of lore.kernel.org
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] alarmtimer: Rate limit periodic intervals" failed to apply to 4.11-stable tree
@ 2017-06-18 10:53 gregkh
  2017-06-18 12:24 ` [PATCH backport 4.11] alarmtimer: Rate limit periodic intervals Thomas Gleixner
  0 siblings, 1 reply; 3+ messages in thread
From: gregkh @ 2017-06-18 10:53 UTC (permalink / raw)
  To: tglx, dvyukov, john.stultz, kcc, peterz, syzkaller; +Cc: stable


The patch below does not apply to the 4.11-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

>From ff86bf0c65f14346bf2440534f9ba5ac232c39a0 Mon Sep 17 00:00:00 2001
From: Thomas Gleixner <tglx@linutronix.de>
Date: Tue, 30 May 2017 23:15:35 +0200
Subject: [PATCH] alarmtimer: Rate limit periodic intervals

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 <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Kostya Serebryany <kcc@google.com>
Cc: syzkaller <syzkaller@googlegroups.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/20170530211655.896767100@linutronix.de

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 2b2e032b4eb4..ee2f4202d82a 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -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) {

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH backport 4.11] alarmtimer: Rate limit periodic intervals
  2017-06-18 10:53 FAILED: patch "[PATCH] alarmtimer: Rate limit periodic intervals" failed to apply to 4.11-stable tree gregkh
@ 2017-06-18 12:24 ` Thomas Gleixner
  2017-06-18 14:48   ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Gleixner @ 2017-06-18 12:24 UTC (permalink / raw)
  To: gregkh; +Cc: dvyukov, john.stultz, kcc, peterz, syzkaller, stable

commit ff86bf0c65f14346bf2440534f9ba5ac232c39a0 upstream.

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 <tglx@linutronix.de>
Cc: peterz@infradead.org
Cc: stable@vger.kernel.org
Cc: kcc@google.com
Cc: syzkaller@googlegroups.com
Cc: john.stultz@linaro.org
Cc: dvyukov@google.com
Link: http://lkml.kernel.org/r/20170530211655.896767100@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

---
 kernel/time/alarmtimer.c |    8 ++++++++
 1 file changed, 8 insertions(+)

--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -660,6 +660,14 @@ static int alarm_timer_set(struct k_itim
 
 	/* start the timer */
 	timr->it.alarm.interval = timespec_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 = timespec_to_ktime(new_setting->it_value);
 	/* Convert (if necessary) to absolute time */
 	if (flags != TIMER_ABSTIME) {

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH backport 4.11] alarmtimer: Rate limit periodic intervals
  2017-06-18 12:24 ` [PATCH backport 4.11] alarmtimer: Rate limit periodic intervals Thomas Gleixner
@ 2017-06-18 14:48   ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2017-06-18 14:48 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: dvyukov, john.stultz, kcc, peterz, syzkaller, stable

On Sun, Jun 18, 2017 at 02:24:37PM +0200, Thomas Gleixner wrote:
> commit ff86bf0c65f14346bf2440534f9ba5ac232c39a0 upstream.
> 
> 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.

<snip>

thanks for the backport, now applied to all stable trees.

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-06-18 14:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-18 10:53 FAILED: patch "[PATCH] alarmtimer: Rate limit periodic intervals" failed to apply to 4.11-stable tree gregkh
2017-06-18 12:24 ` [PATCH backport 4.11] alarmtimer: Rate limit periodic intervals Thomas Gleixner
2017-06-18 14:48   ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.