path: root/kernel
diff options
authorSuren Baghdasaryan <>2020-02-03 13:22:16 -0800
committerIngo Molnar <>2020-02-11 13:00:02 +0100
commit6fcca0fa48118e6d63733eb4644c6cd880c15b8f (patch)
tree115c2c04cbf09859e5e81c0c13aafe7959ffa617 /kernel
parent52262ee567ad14c9606be25f3caddcefa3c514e4 (diff)
sched/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 <> Signed-off-by: Peter Zijlstra (Intel) <> Signed-off-by: Ingo Molnar <> Acked-by: Johannes Weiner <> Link:
Diffstat (limited to 'kernel')
1 files changed, 3 insertions, 0 deletions
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))
+ if (!nbytes)
+ return -EINVAL;
buf_size = min(nbytes, sizeof(buf));
if (copy_from_user(buf, user_buf, buf_size))
return -EFAULT;