[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tip-1a8b4540db732ca16c9e43ac7c08b1b8f0b252d8@git.kernel.org>
Date: Fri, 19 Apr 2019 05:17:45 -0700
From: tip-bot for Konstantin Khlebnikov <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: hpa@...or.com, a.p.zijlstra@...llo.nl, peterz@...radead.org,
tglx@...utronix.de, linux-kernel@...r.kernel.org, mingo@...nel.org,
torvalds@...ux-foundation.org, khlebnikov@...dex-team.ru
Subject: [tip:sched/core] sched/core: Check quota and period overflow at
usec to nsec conversion
Commit-ID: 1a8b4540db732ca16c9e43ac7c08b1b8f0b252d8
Gitweb: https://git.kernel.org/tip/1a8b4540db732ca16c9e43ac7c08b1b8f0b252d8
Author: Konstantin Khlebnikov <khlebnikov@...dex-team.ru>
AuthorDate: Wed, 27 Feb 2019 11:10:20 +0300
Committer: Ingo Molnar <mingo@...nel.org>
CommitDate: Fri, 19 Apr 2019 13:42:10 +0200
sched/core: Check quota and period overflow at usec to nsec conversion
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@...dex-team.ru>
Acked-by: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Thomas Gleixner <tglx@...utronix.de>
Link: http://lkml.kernel.org/r/155125502079.293431.3947497929372138600.stgit@buzz
Signed-off-by: Ingo Molnar <mingo@...nel.org>
---
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 685b1541ce51..de8ab411826c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6611,8 +6611,10 @@ static 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);
}
@@ -6634,6 +6636,9 @@ static 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;
Powered by blists - more mailing lists