From: Jan Dakinevich <jan.dakinevich@gmail.com>
To: Greg Kurz <groug@kaod.org>, qemu-devel@nongnu.org
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>,
Jan Dakinevich <jan.dakinevich@gmail.com>
Subject: [Qemu-devel] [PATCH v2] 9pfs: check the size of transport buffer before marshaling
Date: Sun, 17 Sep 2017 03:38:11 +0300 [thread overview]
Message-ID: <1505608691-11975-1-git-send-email-jan.dakinevich@gmail.com> (raw)
v9fs_do_readdir_with_stat() should check for a maximum buffer size
before an attempt to marshal gathered data. Otherwise, buffers assumed
as misconfigured and the transport would be broken.
The patch brings v9fs_do_readdir_with_stat() in conformity with
v9fs_do_readdir() behavior.
Signed-off-by: Jan Dakinevich <jan.dakinevich@gmail.com>
---
hw/9pfs/9p.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 144c330..4d4ed85 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -1754,17 +1754,26 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu,
if (err < 0) {
break;
}
+ if ((count + v9stat.size + 2) > max_count) {
+ v9fs_readdir_unlock(&fidp->fs.dir);
+
+ /* Ran out of buffer. Set dir back to old position and return */
+ v9fs_co_seekdir(pdu, fidp, saved_dir_pos);
+ v9fs_stat_free(&v9stat);
+ v9fs_path_free(&path);
+ return count;
+ }
+
/* 11 = 7 + 4 (7 = start offset, 4 = space for storing count) */
len = pdu_marshal(pdu, 11 + count, "S", &v9stat);
v9fs_readdir_unlock(&fidp->fs.dir);
- if ((len != (v9stat.size + 2)) || ((count + len) > max_count)) {
- /* Ran out of buffer. Set dir back to old position and return */
+ if (len < 0) {
v9fs_co_seekdir(pdu, fidp, saved_dir_pos);
v9fs_stat_free(&v9stat);
v9fs_path_free(&path);
- return count;
+ return len;
}
count += len;
v9fs_stat_free(&v9stat);
--
2.1.4
reply other threads:[~2017-09-17 0:36 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1505608691-11975-1-git-send-email-jan.dakinevich@gmail.com \
--to=jan.dakinevich@gmail.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=groug@kaod.org \
--cc=qemu-devel@nongnu.org \
/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;
as well as URLs for NNTP newsgroup(s).