linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] sched/rt: check integer overflow at usec to nsec conversion
@ 2019-02-27  8:10 Konstantin Khlebnikov
  2019-02-27  8:10 ` [PATCH 2/3] sched/core: handle overflow in cpu_shares_write_u64 Konstantin Khlebnikov
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Konstantin Khlebnikov @ 2019-02-27  8:10 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, linux-kernel

Example of unhandled overflows:

# echo 18446744073709651 > cpu.rt_runtime_us
# cat cpu.rt_runtime_us
99

# echo 18446744073709900 > cpu.rt_period_us
# cat cpu.rt_period_us
348

After this patch they will fail with -EINVAL.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
---
 kernel/sched/rt.c |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index e4f398ad9e73..aa7ee3a0bf90 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -2555,6 +2555,8 @@ int sched_group_set_rt_runtime(struct task_group *tg, long rt_runtime_us)
 	rt_runtime = (u64)rt_runtime_us * NSEC_PER_USEC;
 	if (rt_runtime_us < 0)
 		rt_runtime = RUNTIME_INF;
+	else if ((u64)rt_runtime_us > U64_MAX / NSEC_PER_USEC)
+		return -EINVAL;
 
 	return tg_set_rt_bandwidth(tg, rt_period, rt_runtime);
 }
@@ -2575,6 +2577,9 @@ int sched_group_set_rt_period(struct task_group *tg, u64 rt_period_us)
 {
 	u64 rt_runtime, rt_period;
 
+	if (rt_period_us > U64_MAX / NSEC_PER_USEC)
+		return -EINVAL;
+
 	rt_period = rt_period_us * NSEC_PER_USEC;
 	rt_runtime = tg->rt_bandwidth.rt_runtime;
 


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

end of thread, other threads:[~2019-04-19 19:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-27  8:10 [PATCH 1/3] sched/rt: check integer overflow at usec to nsec conversion Konstantin Khlebnikov
2019-02-27  8:10 ` [PATCH 2/3] sched/core: handle overflow in cpu_shares_write_u64 Konstantin Khlebnikov
2019-04-19 12:16   ` [tip:sched/core] sched/core: Handle " tip-bot for Konstantin Khlebnikov
2019-02-27  8:10 ` [PATCH 3/3] sched/core: check quota and period overflow at usec to nsec conversion Konstantin Khlebnikov
2019-04-19 12:17   ` [tip:sched/core] sched/core: Check " tip-bot for Konstantin Khlebnikov
2019-04-19 12:16 ` [tip:sched/core] sched/rt: Check integer " tip-bot for Konstantin Khlebnikov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).