mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <krisman@collabora.com>
To: jdike@addtoit.com
Cc: richard@nod.at, anton.ivanov@cambridgegreys.com,
	linux-um@lists.infradead.org, linux-kernel@vger.kernel.org,
	Gabriel Krisman Bertazi <krisman@collabora.com>,
	kernel@collabora.com, Martyn Welch <martyn.welch@collabora.com>
Subject: [PATCH 1/2] um: ubd: Prevent buffer overrun on command completion
Date: Mon, 16 Mar 2020 20:45:06 -0400	[thread overview]
Message-ID: <20200317004507.1513370-2-krisman@collabora.com> (raw)
In-Reply-To: <20200317004507.1513370-1-krisman@collabora.com>

On the hypervisor side, when completing commands and the pipe is full,
we retry writing only the entries that failed, by offsetting
io_req_buffer, but we don't reduce the number of bytes written, which
can cause a buffer overrun of io_req_buffer, and write garbage to the
pipe.

Cc: Martyn Welch <martyn.welch@collabora.com>
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
---
 arch/um/drivers/ubd_kern.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
index 6627d7c30f37..0f5d0a699a49 100644
--- a/arch/um/drivers/ubd_kern.c
+++ b/arch/um/drivers/ubd_kern.c
@@ -1606,7 +1606,9 @@ int io_thread(void *arg)
 		written = 0;
 
 		do {
-			res = os_write_file(kernel_fd, ((char *) io_req_buffer) + written, n);
+			res = os_write_file(kernel_fd,
+					    ((char *) io_req_buffer) + written,
+					    n - written);
 			if (res >= 0) {
 				written += res;
 			}
-- 
2.25.0


  reply	other threads:[~2020-03-17  0:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-17  0:45 [PATCH 0/2] fixes to the hypervisor ubd thread Gabriel Krisman Bertazi
2020-03-17  0:45 ` Gabriel Krisman Bertazi [this message]
2020-03-17  0:45 ` [PATCH 2/2] um: ubd: Retry buffer read on any kind of error Gabriel Krisman Bertazi
2020-03-29 21:40 ` [PATCH 0/2] fixes to the hypervisor ubd thread Richard Weinberger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200317004507.1513370-2-krisman@collabora.com \
    --to=krisman@collabora.com \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=jdike@addtoit.com \
    --cc=kernel@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=martyn.welch@collabora.com \
    --cc=richard@nod.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®