Skip to content

Commit 1a010e2

Browse files
koct9iingomolnar
authored andcommitted
sched/rt: Check integer overflow at usec to nsec conversion
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>
1 parent bee9853 commit 1a010e2

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎kernel/sched/rt.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,6 +2555,8 @@ int sched_group_set_rt_runtime(struct task_group *tg, long rt_runtime_us)
25552555
rt_runtime = (u64)rt_runtime_us * NSEC_PER_USEC;
25562556
if (rt_runtime_us < 0)
25572557
rt_runtime = RUNTIME_INF;
2558+
else if ((u64)rt_runtime_us > U64_MAX / NSEC_PER_USEC)
2559+
return -EINVAL;
25582560

25592561
return tg_set_rt_bandwidth(tg, rt_period, rt_runtime);
25602562
}
@@ -2575,6 +2577,9 @@ int sched_group_set_rt_period(struct task_group *tg, u64 rt_period_us)
25752577
{
25762578
u64 rt_runtime, rt_period;
25772579

2580+
if (rt_period_us > U64_MAX / NSEC_PER_USEC)
2581+
return -EINVAL;
2582+
25782583
rt_period = rt_period_us * NSEC_PER_USEC;
25792584
rt_runtime = tg->rt_bandwidth.rt_runtime;
25802585

0 commit comments

Comments
 (0)