linux-kernel.vger.kernel.org archive mirror
 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

* Re: [PATCH] psi: Fix OOB write when writing 0 bytes to psi files
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Johannes Weiner @ 2020-02-04 18:55 UTC (permalink / raw)
  To: Suren Baghdasaryan
  Cc: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, linux-kernel, kernel-team

On Mon, Feb 03, 2020 at 01:22:16PM -0800, Suren Baghdasaryan wrote:
> 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>

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

Thanks Suren.

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

* Re: [PATCH] psi: Fix OOB write when writing 0 bytes to psi files
  2020-02-04 18:55 ` Johannes Weiner
@ 2020-02-06 14:03   ` Peter Zijlstra
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Zijlstra @ 2020-02-06 14:03 UTC (permalink / raw)
  To: Johannes Weiner
  Cc: Suren Baghdasaryan, mingo, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, linux-kernel,
	kernel-team

On Tue, Feb 04, 2020 at 01:55:23PM -0500, Johannes Weiner wrote:
> On Mon, Feb 03, 2020 at 01:22:16PM -0800, Suren Baghdasaryan wrote:
> > 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>
> 
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>

Thanks!

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

* [tip: sched/urgent] sched/psi: Fix OOB write when writing 0 bytes to PSI files
  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-11 12:47 ` tip-bot2 for Suren Baghdasaryan
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot2 for Suren Baghdasaryan @ 2020-02-11 12:47 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Suren Baghdasaryan, Peter Zijlstra (Intel),
	Ingo Molnar, Johannes Weiner, x86, LKML

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     6fcca0fa48118e6d63733eb4644c6cd880c15b8f
Gitweb:        https://git.kernel.org/tip/6fcca0fa48118e6d63733eb4644c6cd880c15b8f
Author:        Suren Baghdasaryan <surenb@google.com>
AuthorDate:    Mon, 03 Feb 2020 13:22:16 -08:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 11 Feb 2020 13:00:02 +01:00

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 <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
---
 kernel/sched/psi.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index db7b50b..38ccd49 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;

^ 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;
as well as URLs for NNTP newsgroup(s).