From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>,
Max Reitz <mreitz@redhat.com>, Alexander Bulekov <alxndr@bu.edu>,
"Gonglei \(Arei\)" <arei.gonglei@huawei.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PATCH v2 0/3] virtio: restore elem->in/out_sg after iov_discard_front/back()
Date: Thu, 17 Sep 2020 10:44:52 +0100 [thread overview]
Message-ID: <20200917094455.822379-1-stefanha@redhat.com> (raw)
v2:
* Add missing undo in virtio-blk write zeroes error path [Li Qiang]
Both virtio-blk and virtio-crypto use destructive iov_discard_front/back()
operations on elem->in/out_sg. virtqueue_push() calls dma_memory_unmap() on the
modified iovec arrays. The memory addresses may not match those originally
mapped with dma_memory_map().
This raises several issues:
1. MemoryRegion references can be leaked.
2. Dirty memory may not be tracked.
3. The non-RAM bounce buffer can be leaked.
This patch series solves the issue in two ways:
1. virtio-blk uses a new iov_discard_undo() API to restore iovec arrays.
2. virtio-crypto uses g_memdup() to avoid modifying the original iovec arrays.
The g_memdup() approach is slower than iov_discard_undo() but less
complex/fragile. I am less familiar with the virtio-crypto code and it uses
more complex sequences of iov_discard_front/back() calls than virtio-blk. If
anyone feels like optimizing virtio-crypto, please go ahead.
The virtio-blk bug was found by Alexander Bulekov's fuzzing effort. I found the
virtio-crypto bug through code inspection.
Stefan Hajnoczi (3):
util/iov: add iov_discard_undo()
virtio-blk: undo destructive iov_discard_*() operations
virtio-crypto: don't modify elem->in/out_sg
include/hw/virtio/virtio-blk.h | 2 +
include/qemu/iov.h | 23 +++++
hw/block/virtio-blk.c | 11 ++-
hw/virtio/virtio-crypto.c | 17 +++-
tests/test-iov.c | 165 +++++++++++++++++++++++++++++++++
util/iov.c | 50 +++++++++-
6 files changed, 259 insertions(+), 9 deletions(-)
--
2.26.2
next reply other threads:[~2020-09-17 9:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-17 9:44 Stefan Hajnoczi [this message]
2020-09-17 9:44 ` [PATCH v2 1/3] util/iov: add iov_discard_undo() Stefan Hajnoczi
2020-09-17 9:44 ` [PATCH v2 2/3] virtio-blk: undo destructive iov_discard_*() operations Stefan Hajnoczi
2020-09-17 14:54 ` Li Qiang
2020-09-17 9:44 ` [PATCH v2 3/3] virtio-crypto: don't modify elem->in/out_sg Stefan Hajnoczi
2020-09-22 7:59 ` [PATCH v2 0/3] virtio: restore elem->in/out_sg after iov_discard_front/back() Stefan Hajnoczi
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=20200917094455.822379-1-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=alxndr@bu.edu \
--cc=arei.gonglei@huawei.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-block@nongnu.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).