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] sched/core: check format and overflows in cgroup2 cpu.max
From
Date
Cgroup2 interface for cpu bandwidth limit has some flaws:

- on stack buffer overflow
- no checks for valid format or trailing garbage
- no checks for integer overflows

This patch fixes all these flaws.

Fixes: 0d5936344f30 ("sched: Implement interface for cgroup unified hierarchy")
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
---
kernel/sched/core.c | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 5f46aa335b28..123b1910bc2e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6947,19 +6947,34 @@ static int __maybe_unused cpu_period_quota_parse(char *buf,
u64 *periodp, u64 *quotap)
{
char tok[21]; /* U64_MAX */
+ int ret, len;

- if (!sscanf(buf, "%s %llu", tok, periodp))
+ if (sscanf(buf, "%20s %n", tok, &len) != 1)
return -EINVAL;

- *periodp *= NSEC_PER_USEC;
-
- if (sscanf(tok, "%llu", quotap))
- *quotap *= NSEC_PER_USEC;
- else if (!strcmp(tok, "max"))
+ ret = kstrtou64(tok, 10, quotap);
+ if (ret) {
+ if (strcmp(tok, "max"))
+ return ret;
*quotap = RUNTIME_INF;
- else
+ } else if (*quotap <= U64_MAX / NSEC_PER_USEC) {
+ *quotap *= NSEC_PER_USEC;
+ } else
return -EINVAL;

+ buf += len;
+ if (*buf) {
+ if (sscanf(buf, "%20s %n", tok, &len) != 1 || buf[len])
+ return -EINVAL;
+ ret = kstrtou64(tok, 10, periodp);
+ if (ret)
+ return ret;
+ if (*periodp > U64_MAX / NSEC_PER_USEC)
+ return -EINVAL;
+ }
+
+ *periodp *= NSEC_PER_USEC;
+
return 0;
}

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