Skip to contentSkip to conversation

qiov: prevent double free or use-after-free

PATCH In review Paolo Bonzini 2 participants 3 messages Nov 25, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qiov: prevent double free or use-after-free

qemu_iovec_destroy does not clear the QEMUIOVector fully, and the data could thus be used after free or freed again. While I do not know any example in the tree, I observed this using virtio-scsi (and SCSI scatter/gather) when canceling DMA requests.

---
 cutils.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
cutils.c +3 -0
index 5d995bc..731a27e 100644
@@ -217,7 +217,10 @@ void qemu_iovec_destroy(QEMUIOVector *qiov)
 {
     assert(qiov->nalloc != -1);
 
+    qemu_iovec_reset(qiov);
     g_free(qiov->iov);
+    qiov->nalloc = 0;
+    qiov->iov = NULL;
 }
 
 void qemu_iovec_reset(QEMUIOVector *qiov)
Signature · 1 line
1.7.7.1
#1 lore raw

Am 25.11.2011 12:06, schrieb Paolo Bonzini:

Quoted 6 lines

qemu_iovec_destroy does not clear the QEMUIOVector fully, and the data could thus be used after free or freed again. While I do not know any example in the tree, I observed this using virtio-scsi (and SCSI scatter/gather) when canceling DMA requests.

This isn't a bug fix for itself, it just makes bugs in other code more visible, right? It probably makes sense to do this change, but I'm not sure about doing it for 1.0.

Kevin

Quoted 19 lines
---
 cutils.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
cutils.c +3 -0
index 5d995bc..731a27e 100644
@@ -217,7 +217,10 @@ void qemu_iovec_destroy(QEMUIOVector *qiov)
 {
     assert(qiov->nalloc != -1);
 
+    qemu_iovec_reset(qiov);
     g_free(qiov->iov);
+    qiov->nalloc = 0;
+    qiov->iov = NULL;
 }
 
 void qemu_iovec_reset(QEMUIOVector *qiov)
#2 lore raw
Quoted 9 lines · Kevin Wolf
Quoted 6 lines

qemu_iovec_destroy does not clear the QEMUIOVector fully, and the data

Quoted 5 lines

could thus be used after free or freed again. While I do not know any example in the tree, I observed this using virtio-scsi (and SCSI scatter/gather) when canceling DMA requests.

This isn't a bug fix for itself, it just makes bugs in other code more visible, right? It probably makes sense to do this change, but I'm not sure about doing it for 1.0.

It is a fix. NULLing the pointer prevents double-free bugs, and setting niov/nalloc to 0 should prevent use-after-free.

Paolo