Skip to content

Commit 6fcca0f

Browse files
surenbaghdasaryanIngo Molnar
authored andcommitted
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 <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Acked-by: Johannes Weiner <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 52262ee commit 6fcca0f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

kernel/sched/psi.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,9 @@ static ssize_t psi_write(struct file *file, const char __user *user_buf,
11991199
if (static_branch_likely(&psi_disabled))
12001200
return -EOPNOTSUPP;
12011201

1202+
if (!nbytes)
1203+
return -EINVAL;
1204+
12021205
buf_size = min(nbytes, sizeof(buf));
12031206
if (copy_from_user(buf, user_buf, buf_size))
12041207
return -EFAULT;

0 commit comments

Comments
 (0)