public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] psi: Fix OOB write when writing 0 bytes to psi files
@ 2020-02-03 21:22 Suren Baghdasaryan
  2020-02-04 18:55 ` Johannes Weiner
  2020-02-11 12:47 ` [tip: sched/urgent] sched/psi: Fix OOB write when writing 0 bytes to PSI files tip-bot2 for Suren Baghdasaryan
  0 siblings, 2 replies; 4+ messages in thread
From: Suren Baghdasaryan @ 2020-02-03 21:22 UTC (permalink / raw)
  To: surenb
  Cc: mingo, peterz, hannes, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, linux-kernel,
	kernel-team

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>
---
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-11 12:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-03 21:22 [PATCH] psi: Fix OOB write when writing 0 bytes to psi files Suren Baghdasaryan
2020-02-04 18:55 ` Johannes Weiner
2020-02-06 14:03   ` Peter Zijlstra
2020-02-11 12:47 ` [tip: sched/urgent] sched/psi: Fix OOB write when writing 0 bytes to PSI files tip-bot2 for Suren Baghdasaryan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox