blob: f2e3183e41166f26620456f3813f87435319c93f [file] [log] [blame]
From f54303dfb1116786ac15c813e2d4ba8803748207 Mon Sep 17 00:00:00 2001
From: Suren Baghdasaryan <>
Date: Mon, 3 Feb 2020 13:22:16 -0800
Subject: [PATCH] sched/psi: Fix OOB write when writing 0 bytes to PSI files
commit 6fcca0fa48118e6d63733eb4644c6cd880c15b8f upstream.
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 <>
Signed-off-by: Paul Gortmaker <>
diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index ce8f6748678a..9154e745f097 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;