[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200203212216.7076-1-surenb@google.com>
Date: Mon, 3 Feb 2020 13:22:16 -0800
From: Suren Baghdasaryan <surenb@...gle.com>
To: surenb@...gle.com
Cc: mingo@...hat.com, peterz@...radead.org, hannes@...xchg.org,
juri.lelli@...hat.com, vincent.guittot@...aro.org,
dietmar.eggemann@....com, rostedt@...dmis.org, bsegall@...gle.com,
mgorman@...e.de, linux-kernel@...r.kernel.org,
kernel-team@...roid.com
Subject: [PATCH] psi: Fix OOB write when writing 0 bytes to psi files
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@...gle.com>
---
kernel/sched/psi.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index db7b50bba3f1..38ccd49b9bf6 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -1199,6 +1199,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));
if (copy_from_user(buf, user_buf, buf_size))
return -EFAULT;
--
2.25.0.341.g760bfbb309-goog
Powered by blists - more mailing lists