Skip to contentSkip to conversation

alarmtimer: don't rate limit one-shot timers

PATCH Applied Greg Hackmann 4 participants 12 messages Jul 24, 2017 – Jul 25, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 alarmtimer: don't rate limit one-shot timers

Commit ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals") sets a minimum bound on the alarm timer interval. This minimum bound shouldn't be applied if the interval is 0. Otherwise, one-shot timers will be converted into periodic ones.

This patch is against 4.9.39, and is only needed in -stable trees. 4.13-rc2 isn't impacted due to a later refactoring.

Fixes ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals")
---
 kernel/time/alarmtimer.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/time/alarmtimer.c +2 -1
index 9ba04aa740b9..d67ef56ca9bc 100644
@@ -629,7 +629,8 @@ static int alarm_timer_set(struct k_itimer *timr, int flags,
 	 * Rate limit to the tick as a hot fix to prevent DOS. Will be
 	 * mopped up later.
 	 */
-	if (ktime_to_ns(timr->it.alarm.interval) < TICK_NSEC)
+	if (timr->it.alarm.interval.tv64 &&
+			ktime_to_ns(timr->it.alarm.interval) < TICK_NSEC)
 		timr->it.alarm.interval = ktime_set(0, TICK_NSEC);
 
 	exp = timespec_to_ktime(new_setting->it_value);
Signature · 1 line
2.14.0.rc0.284.gd933b75aa4-goog
#1 lore raw
Quoted 7 lines · Greg Hackmann

Commit ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals") sets a minimum bound on the alarm timer interval. This minimum bound shouldn't be applied if the interval is 0. Otherwise, one-shot timers will be converted into periodic ones.

This patch is against 4.9.39, and is only needed in -stable trees. 4.13-rc2 isn't impacted due to a later refactoring.

What refactoring patch fixed this up?

Quoted 1 line
Fixes ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals")

As this was a 4.12 patch, 4.12-stable needs this fix as well, right?

Also, was there some test-case that you caught this with that perhaps could be added to LTP or kselftests?

thanks,

greg k-h

#2 lore raw
Quoted 10 lines · Greg KH
Quoted 7 lines · Greg Hackmann

Commit ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals") sets a minimum bound on the alarm timer interval. This minimum bound shouldn't be applied if the interval is 0. Otherwise, one-shot timers will be converted into periodic ones.

This patch is against 4.9.39, and is only needed in -stable trees. 4.13-rc2 isn't impacted due to a later refactoring.

What refactoring patch fixed this up?

f2c45807d399 ("alarmtimer: Switch over to generic set/get/rearm routine")

Quoted 1 line

As this was a 4.12 patch, 4.12-stable needs this fix as well, right?

Looks like it, but I haven't actually tried 4.12 yet to confirm.

Quoted 2 lines

Also, was there some test-case that you caught this with that perhaps could be added to LTP or kselftests?

Unfortunately not a direct testcase. This first showed up as a regression in AOSP's userspace Bluetooth stack, which uses CLOCK_BOOTTIME_ALARM internally.

I'm working on a patch to add one-shot timer testcases to set-timer-lat.c, which would have caught this. (I wrote a very rough test program to make sure this patch fixes the regression, but set-timer-lat.c already exists and is more comprehensive.)

#3 lore raw
Quoted 7 lines · Greg Hackmann
Quoted 6 lines · Greg KH
Quoted 5 lines · Greg Hackmann

Commit ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals") sets a minimum bound on the alarm timer interval. This minimum bound shouldn't be applied if the interval is 0. Otherwise, one-shot timers will be converted into periodic ones.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

This patch is against 4.9.39, and is only needed in -stable trees. 4.13-rc2 isn't impacted due to a later refactoring.

What refactoring patch fixed this up?

f2c45807d399 ("alarmtimer: Switch over to generic set/get/rearm routine")

Ick, yeah, that's not a stable patch :)

Quoted 7 lines
Quoted 1 line

As this was a 4.12 patch, 4.12-stable needs this fix as well, right?

Looks like it, but I haven't actually tried 4.12 yet to confirm.

Quoted 2 lines

Also, was there some test-case that you caught this with that perhaps could be added to LTP or kselftests?

Quoted 8 lines

Unfortunately not a direct testcase. This first showed up as a regression in AOSP's userspace Bluetooth stack, which uses CLOCK_BOOTTIME_ALARM internally.

I'm working on a patch to add one-shot timer testcases to set-timer-lat.c, which would have caught this. (I wrote a very rough test program to make sure this patch fixes the regression, but set-timer-lat.c already exists and is more comprehensive.)

Ok, thanks for the information.

John and Thomas, any objection for me to take the original patch here in the stable trees to fix this issue?

thanks,

greg k-h

Reviewed-by
#4 lore raw
Quoted 33 lines · Greg KH
Quoted 7 lines · Greg Hackmann
Quoted 6 lines · Greg KH
Quoted 5 lines · Greg Hackmann

Commit ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals") sets a minimum bound on the alarm timer interval. This minimum bound shouldn't be applied if the interval is 0. Otherwise, one-shot timers will be converted into periodic ones.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

This patch is against 4.9.39, and is only needed in -stable trees. 4.13-rc2 isn't impacted due to a later refactoring.

What refactoring patch fixed this up?

f2c45807d399 ("alarmtimer: Switch over to generic set/get/rearm routine")

Ick, yeah, that's not a stable patch :)

Quoted 7 lines
Quoted 1 line

As this was a 4.12 patch, 4.12-stable needs this fix as well, right?

Looks like it, but I haven't actually tried 4.12 yet to confirm.

Quoted 2 lines

Also, was there some test-case that you caught this with that perhaps could be added to LTP or kselftests?

Quoted 8 lines

Unfortunately not a direct testcase. This first showed up as a regression in AOSP's userspace Bluetooth stack, which uses CLOCK_BOOTTIME_ALARM internally.

I'm working on a patch to add one-shot timer testcases to set-timer-lat.c, which would have caught this. (I wrote a very rough test program to make sure this patch fixes the regression, but set-timer-lat.c already exists and is more comprehensive.)

Quoted 4 lines

Ok, thanks for the information.

John and Thomas, any objection for me to take the original patch here in the stable trees to fix this issue?

No. I borked that when I was 'fixing' that DoS issue :(

#5 lore raw
Quoted 35 lines · Thomas Gleixner
Quoted 33 lines · Greg KH
Quoted 7 lines · Greg Hackmann
Quoted 6 lines · Greg KH
Quoted 5 lines · Greg Hackmann

Commit ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals") sets a minimum bound on the alarm timer interval. This minimum bound shouldn't be applied if the interval is 0. Otherwise, one-shot timers will be converted into periodic ones.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

This patch is against 4.9.39, and is only needed in -stable trees. 4.13-rc2 isn't impacted due to a later refactoring.

What refactoring patch fixed this up?

f2c45807d399 ("alarmtimer: Switch over to generic set/get/rearm routine")

Ick, yeah, that's not a stable patch :)

Quoted 15 lines
Quoted 1 line

As this was a 4.12 patch, 4.12-stable needs this fix as well, right?

Looks like it, but I haven't actually tried 4.12 yet to confirm.

Quoted 2 lines

Also, was there some test-case that you caught this with that perhaps could be added to LTP or kselftests?

Unfortunately not a direct testcase. This first showed up as a regression in AOSP's userspace Bluetooth stack, which uses CLOCK_BOOTTIME_ALARM internally.

I'm working on a patch to add one-shot timer testcases to set-timer-lat.c, which would have caught this. (I wrote a very rough test program to make sure this patch fixes the regression, but set-timer-lat.c already exists and is more comprehensive.)

Quoted 8 lines
Quoted 4 lines

Ok, thanks for the information.

John and Thomas, any objection for me to take the original patch here in the stable trees to fix this issue?

No. I borked that when I was 'fixing' that DoS issue :(

Thanks for the review.

Greg, can you provide a version of this for 4.12-stable? It doesn't apply there as-is.

thanks,

greg k-h

#6 lore raw

PATCH 1/1 alarmtimer: don't rate limit one-shot timers

Commit ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals") sets a minimum bound on the alarm timer interval. This minimum bound shouldn't be applied if the interval is 0. Otherwise, one-shot timers will be converted into periodic ones.

This patch is specific to 4.11.y and 4.12.y. Older -stable trees have a slightly different patch, and 4.13-rc2 isn't impacted due to a later refactoring.

Fixes ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals")
---
 kernel/time/alarmtimer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/alarmtimer.c +1 -1
index ee2f4202d82a..11e70a38497c 100644
@@ -665,7 +665,7 @@ static int alarm_timer_set(struct k_itimer *timr, int flags,
 	 * Rate limit to the tick as a hot fix to prevent DOS. Will be
 	 * mopped up later.
 	 */
-	if (timr->it.alarm.interval < TICK_NSEC)
+	if (timr->it.alarm.interval && timr->it.alarm.interval < TICK_NSEC)
 		timr->it.alarm.interval = TICK_NSEC;
 
 	exp = timespec64_to_ktime(new_setting->it_value);
Signature · 1 line
2.14.0.rc0.284.gd933b75aa4-goog
maintainer Applied
#7 lore raw

Patch "alarmtimer: don't rate limit one-shot timers" has been added to the 4.12-stable tree

This is a note to let you know that I've just added the patch titled

alarmtimer: don't rate limit one-shot timers

to the 4.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
alarmtimer-don-t-rate-limit-one-shot-timers.patch
and it can be found in the queue-4.12 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From [email protected] Tue Jul 25 14:42:30 2017

From: Greg Hackmann <[email protected]>
Date: Tue, 25 Jul 2017 12:42:46 -0700
Subject: alarmtimer: don't rate limit one-shot timers
To: John Stultz <[email protected]>, Thomas Gleixner <[email protected]>
Cc: Ben Fennema <[email protected]>, [email protected], Greg Hackmann <[email protected]>, [email protected]
Message-ID: <[email protected]>

From: Greg Hackmann <[email protected]>

Commit ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals") sets a minimum bound on the alarm timer interval. This minimum bound shouldn't be applied if the interval is 0. Otherwise, one-shot timers will be converted into periodic ones.

This patch is specific to 4.11.y and 4.12.y. Older -stable trees have a slightly different patch, and 4.13-rc2 isn't impacted due to a later refactoring.

Fixes ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals")
Cc John Stultz <[email protected]>
---
 kernel/time/alarmtimer.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/alarmtimer.c +1 -1
@@ -665,7 +665,7 @@ static int alarm_timer_set(struct k_itim
 	 * Rate limit to the tick as a hot fix to prevent DOS. Will be
 	 * mopped up later.
 	 */
-	if (timr->it.alarm.interval < TICK_NSEC)
+	if (timr->it.alarm.interval && timr->it.alarm.interval < TICK_NSEC)
 		timr->it.alarm.interval = TICK_NSEC;
 
 	exp = timespec64_to_ktime(new_setting->it_value);

Patches currently in stable-queue which might be from [email protected] are

queue-4.12/alarmtimer-don-t-rate-limit-one-shot-timers.patch

#8 lore raw
In reply to Greg Hackmann
Quoted 9 lines · Greg Hackmann

Commit ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals") sets a minimum bound on the alarm timer interval. This minimum bound shouldn't be applied if the interval is 0. Otherwise, one-shot timers will be converted into periodic ones.

This patch is specific to 4.11.y and 4.12.y. Older -stable trees have a slightly different patch, and 4.13-rc2 isn't impacted due to a later refactoring.

Quoted 7 lines
Fixes ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals")
---
 kernel/time/alarmtimer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Thanks, now queued up.

greg k-h

maintainer Applied
#9 lore raw

Patch "alarmtimer: don't rate limit one-shot timers" has been added to the 3.18-stable tree

In reply to Greg Hackmann

This is a note to let you know that I've just added the patch titled

alarmtimer: don't rate limit one-shot timers

to the 3.18-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
alarmtimer-don-t-rate-limit-one-shot-timers.patch
and it can be found in the queue-3.18 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From [email protected] Tue Jul 25 10:58:26 2017

From: Greg Hackmann <[email protected]>
Date: Mon, 24 Jul 2017 10:19:24 -0700
Subject: alarmtimer: don't rate limit one-shot timers
To: John Stultz <[email protected]>, Thomas Gleixner <[email protected]>
Cc: Ben Fennema <[email protected]>, [email protected], Greg Hackmann <[email protected]>, [email protected]
Message-ID: <[email protected]>

From: Greg Hackmann <[email protected]>

Commit ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals") sets a minimum bound on the alarm timer interval. This minimum bound shouldn't be applied if the interval is 0. Otherwise, one-shot timers will be converted into periodic ones.

Fixes ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals")
Cc John Stultz <[email protected]>
---
 kernel/time/alarmtimer.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/time/alarmtimer.c +2 -1
@@ -619,7 +619,8 @@ static int alarm_timer_set(struct k_itim
 	 * Rate limit to the tick as a hot fix to prevent DOS. Will be
 	 * mopped up later.
 	 */
-	if (ktime_to_ns(timr->it.alarm.interval) < TICK_NSEC)
+	if (timr->it.alarm.interval.tv64 &&
+			ktime_to_ns(timr->it.alarm.interval) < TICK_NSEC)
 		timr->it.alarm.interval = ktime_set(0, TICK_NSEC);
 
 	exp = timespec_to_ktime(new_setting->it_value);

Patches currently in stable-queue which might be from [email protected] are

queue-3.18/alarmtimer-don-t-rate-limit-one-shot-timers.patch

maintainer Applied
#10 lore raw

Patch "alarmtimer: don't rate limit one-shot timers" has been added to the 4.4-stable tree

In reply to Greg Hackmann

This is a note to let you know that I've just added the patch titled

alarmtimer: don't rate limit one-shot timers

to the 4.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
alarmtimer-don-t-rate-limit-one-shot-timers.patch
and it can be found in the queue-4.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From [email protected] Tue Jul 25 10:58:26 2017

From: Greg Hackmann <[email protected]>
Date: Mon, 24 Jul 2017 10:19:24 -0700
Subject: alarmtimer: don't rate limit one-shot timers
To: John Stultz <[email protected]>, Thomas Gleixner <[email protected]>
Cc: Ben Fennema <[email protected]>, [email protected], Greg Hackmann <[email protected]>, [email protected]
Message-ID: <[email protected]>

From: Greg Hackmann <[email protected]>

Commit ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals") sets a minimum bound on the alarm timer interval. This minimum bound shouldn't be applied if the interval is 0. Otherwise, one-shot timers will be converted into periodic ones.

Fixes ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals")
Cc John Stultz <[email protected]>
---
 kernel/time/alarmtimer.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/time/alarmtimer.c +2 -1
@@ -616,7 +616,8 @@ static int alarm_timer_set(struct k_itim
 	 * Rate limit to the tick as a hot fix to prevent DOS. Will be
 	 * mopped up later.
 	 */
-	if (ktime_to_ns(timr->it.alarm.interval) < TICK_NSEC)
+	if (timr->it.alarm.interval.tv64 &&
+			ktime_to_ns(timr->it.alarm.interval) < TICK_NSEC)
 		timr->it.alarm.interval = ktime_set(0, TICK_NSEC);
 
 	exp = timespec_to_ktime(new_setting->it_value);

Patches currently in stable-queue which might be from [email protected] are

queue-4.4/alarmtimer-don-t-rate-limit-one-shot-timers.patch

maintainer Applied
#11 lore raw

Patch "alarmtimer: don't rate limit one-shot timers" has been added to the 4.9-stable tree

In reply to Greg Hackmann

This is a note to let you know that I've just added the patch titled

alarmtimer: don't rate limit one-shot timers

to the 4.9-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
alarmtimer-don-t-rate-limit-one-shot-timers.patch
and it can be found in the queue-4.9 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From [email protected] Tue Jul 25 10:58:26 2017

From: Greg Hackmann <[email protected]>
Date: Mon, 24 Jul 2017 10:19:24 -0700
Subject: alarmtimer: don't rate limit one-shot timers
To: John Stultz <[email protected]>, Thomas Gleixner <[email protected]>
Cc: Ben Fennema <[email protected]>, [email protected], Greg Hackmann <[email protected]>, [email protected]
Message-ID: <[email protected]>

From: Greg Hackmann <[email protected]>

Commit ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals") sets a minimum bound on the alarm timer interval. This minimum bound shouldn't be applied if the interval is 0. Otherwise, one-shot timers will be converted into periodic ones.

Fixes ff86bf0c65f1 ("alarmtimer: Rate limit periodic intervals")
Cc John Stultz <[email protected]>
---
 kernel/time/alarmtimer.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/time/alarmtimer.c +2 -1
@@ -629,7 +629,8 @@ static int alarm_timer_set(struct k_itim
 	 * Rate limit to the tick as a hot fix to prevent DOS. Will be
 	 * mopped up later.
 	 */
-	if (ktime_to_ns(timr->it.alarm.interval) < TICK_NSEC)
+	if (timr->it.alarm.interval.tv64 &&
+			ktime_to_ns(timr->it.alarm.interval) < TICK_NSEC)
 		timr->it.alarm.interval = ktime_set(0, TICK_NSEC);
 
 	exp = timespec_to_ktime(new_setting->it_value);

Patches currently in stable-queue which might be from [email protected] are

queue-4.9/alarmtimer-don-t-rate-limit-one-shot-timers.patch