sched/psi: Fix OOB write when writing 0 bytes to PSI files
authorSuren Baghdasaryan <surenb@google.com>
Mon, 3 Feb 2020 21:22:16 +0000 (13:22 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 28 Feb 2020 16:22:21 +0000 (17:22 +0100)
commite61c236dcf3416211008774b6c2bfa01753a82c1
tree2fa50fd3fee93f469a10f6f0ffe3788018273631
parent26ae0493c181e989fc1e339a92f703228bae4c0c
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 <surenb@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Link: https://lkml.kernel.org/r/20200203212216.7076-1-surenb@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/sched/psi.c