From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751287AbdFDN25 (ORCPT ); Sun, 4 Jun 2017 09:28:57 -0400 Received: from terminus.zytor.com ([65.50.211.136]:52183 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751157AbdFDN2t (ORCPT ); Sun, 4 Jun 2017 09:28:49 -0400 Date: Sun, 4 Jun 2017 06:22:31 -0700 From: tip-bot for Thomas Gleixner Message-ID: Cc: tglx@linutronix.de, peterz@infradead.org, linux-kernel@vger.kernel.org, hpa@zytor.com, syzkaller@googlegroups.com, kcc@google.com, mingo@kernel.org, dvyukov@google.com, john.stultz@linaro.org Reply-To: john.stultz@linaro.org, kcc@google.com, mingo@kernel.org, dvyukov@google.com, hpa@zytor.com, syzkaller@googlegroups.com, tglx@linutronix.de, peterz@infradead.org, linux-kernel@vger.kernel.org In-Reply-To: <20170530211655.896767100@linutronix.de> References: <20170530211655.896767100@linutronix.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:timers/urgent] alarmtimer: Rate limit periodic intervals Git-Commit-ID: a90b040d8a7a206dd1863c60a47ace5319c99321 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: a90b040d8a7a206dd1863c60a47ace5319c99321 Gitweb: http://git.kernel.org/tip/a90b040d8a7a206dd1863c60a47ace5319c99321 Author: Thomas Gleixner AuthorDate: Tue, 30 May 2017 23:15:35 +0200 Committer: Thomas Gleixner CommitDate: Sun, 4 Jun 2017 15:18:28 +0200 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 Cc: Peter Zijlstra Cc: Kostya Serebryany Cc: syzkaller Cc: John Stultz Cc: Dmitry Vyukov Link: http://lkml.kernel.org/r/20170530211655.896767100@linutronix.de --- kernel/time/alarmtimer.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index 2b2e032..ee2f420 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) {