lkml.org 
[lkml]   [2019]   [Feb]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH 3/3] sched/core: check quota and period overflow at usec to nsec conversion
From
Date
Large values could overflow u64 and pass following sanity checks.

# echo 18446744073750000 > cpu.cfs_period_us
# cat cpu.cfs_period_us
40448

# echo 18446744073750000 > cpu.cfs_quota_us
# cat cpu.cfs_quota_us
40448

After this patch they will fail with -EINVAL.

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

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index a626fbd9fdc7..5f46aa335b28 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6606,8 +6606,10 @@ int tg_set_cfs_quota(struct task_group *tg, long cfs_quota_us)
period = ktime_to_ns(tg->cfs_bandwidth.period);
if (cfs_quota_us < 0)
quota = RUNTIME_INF;
- else
+ else if ((u64)cfs_quota_us <= U64_MAX / NSEC_PER_USEC)
quota = (u64)cfs_quota_us * NSEC_PER_USEC;
+ else
+ return -EINVAL;

return tg_set_cfs_bandwidth(tg, period, quota);
}
@@ -6629,6 +6631,9 @@ int tg_set_cfs_period(struct task_group *tg, long cfs_period_us)
{
u64 quota, period;

+ if ((u64)cfs_period_us > U64_MAX / NSEC_PER_USEC)
+ return -EINVAL;
+
period = (u64)cfs_period_us * NSEC_PER_USEC;
quota = tg->cfs_bandwidth.quota;

\
 
 \ /
  Last update: 2019-02-27 09:10    [W:0.070 / U:0.200 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site