aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuren Baghdasaryan <surenb@google.com>2020-02-03 13:22:16 -0800
committerTodd Kjos <tkjos@google.com>2020-05-01 16:53:28 -0700
commit2f47fdfdd0f315cf28005f512d7b2ec25f30947e (patch)
tree9d8df9328ecc644a0ca628770c61971600215771
parent6a8e9d45a7d303333c29b7ca58f91e406473da96 (diff)
UPSTREAM: sched/psi: Fix OOB write when writing 0 bytes to PSI filesASB-2020-05-05_4.9-q-release
Issuing write() with count parameter set to 0 on any file under /proc/pressure/ will cause an OOB write because of the access to buf[buf_size-1] when NUL-termination is performed. Fix this by checking for buf_size to be non-zero. Signed-off-by: Suren Baghdasaryan <surenb@google.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Link: https://lkml.kernel.org/r/20200203212216.7076-1-surenb@google.com (cherry picked from commit 6fcca0fa48118e6d63733eb4644c6cd880c15b8f) Bug: 148159562 Signed-off-by: Suren Baghdasaryan <surenb@google.com> Change-Id: I9ec7acfc6e1083c677a95b0ea1c559ab50152873
-rw-r--r--kernel/sched/psi.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index ced758792ded..6167b5b5e177 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -1190,6 +1190,9 @@ static ssize_t psi_write(struct file *file, const char __user *user_buf,
if (static_branch_likely(&psi_disabled))
return -EOPNOTSUPP;
+ if (!nbytes)
+ return -EINVAL;
+
buf_size = min(nbytes, (sizeof(buf) - 1));
if (copy_from_user(buf, user_buf, buf_size))
return -EFAULT;