summaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorKonstantin Khlebnikov2019-02-27 09:10:17 +0100
committerGreg Kroah-Hartman2019-05-31 15:46:19 +0200
commit7053046e350f04cfabf9b2c08e1f0e9da33e7ad4 (patch)
treeebb0fdfc939cb4ac544bffb0768820a7b5fceca2 /kernel
parentsched/core: Check quota and period overflow at usec to nsec conversion (diff)
downloadkernel-qcow2-linux-7053046e350f04cfabf9b2c08e1f0e9da33e7ad4.tar.gz
kernel-qcow2-linux-7053046e350f04cfabf9b2c08e1f0e9da33e7ad4.tar.xz
kernel-qcow2-linux-7053046e350f04cfabf9b2c08e1f0e9da33e7ad4.zip
sched/rt: Check integer overflow at usec to nsec conversion
[ Upstream commit 1a010e29cfa00fee2888fd2fd4983f848cbafb58 ] 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> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/155125501739.293431.5252197504404771496.stgit@buzz Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/sched/rt.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 2e2955a8cf8f..b980cc96604f 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -2559,6 +2559,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);
}
@@ -2579,6 +2581,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;