* [Qemu-devel] [PATCH v3] virtio-blk: Fix double completion for werror=stop
@ 2015-11-17 10:20 Fam Zheng
2015-11-17 10:34 ` Stefan Hajnoczi
2015-11-22 19:41 ` Paolo Bonzini
0 siblings, 2 replies; 5+ messages in thread
From: Fam Zheng @ 2015-11-17 10:20 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, lvivier, qemu-block, pl, qemu-stable,
Stefan Hajnoczi, pbonzini, dgibson
When a request R is absorbed by request M, it is appended to the
"mr_next" queue led by M, and is completed together with the completion
of M, in virtio_blk_rw_complete.
During DMA restart in virtio_blk_dma_restart_bh, requests in s->rq are
parsed and submitted again, possibly with a stale req->mr_next. It could
be a problem if the request merging in virtio_blk_handle_request hasn't
refreshed every mr_next pointer, in which case, virtio_blk_rw_complete
could walk through unexpected requests following the stale pointers.
Fix this by unsetting the pointer in virtio_blk_rw_complete. It is safe
because this req is either completed and freed right away, or it will be
restarted and parsed from scratch out of the vq later.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
v3: Fix as Stefan suggested.
---
hw/block/virtio-blk.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index e70fccf..848f3fe 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -112,6 +112,10 @@ static void virtio_blk_rw_complete(void *opaque, int ret)
* happen on the other side of the migration).
*/
if (virtio_blk_handle_rw_error(req, -ret, is_read)) {
+ /* Break the link in case the next request is added to the
+ * restart queue and is going to be parsed from the ring again.
+ */
+ req->mr_next = NULL;
continue;
}
}
--
2.4.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v3] virtio-blk: Fix double completion for werror=stop
2015-11-17 10:20 [Qemu-devel] [PATCH v3] virtio-blk: Fix double completion for werror=stop Fam Zheng
@ 2015-11-17 10:34 ` Stefan Hajnoczi
2015-11-17 15:21 ` Laurent Vivier
2015-11-22 19:41 ` Paolo Bonzini
1 sibling, 1 reply; 5+ messages in thread
From: Stefan Hajnoczi @ 2015-11-17 10:34 UTC (permalink / raw)
To: Fam Zheng
Cc: Kevin Wolf, lvivier, qemu-block, pl, qemu-devel, qemu-stable,
pbonzini, dgibson
[-- Attachment #1: Type: text/plain, Size: 1097 bytes --]
On Tue, Nov 17, 2015 at 06:20:11PM +0800, Fam Zheng wrote:
> When a request R is absorbed by request M, it is appended to the
> "mr_next" queue led by M, and is completed together with the completion
> of M, in virtio_blk_rw_complete.
>
> During DMA restart in virtio_blk_dma_restart_bh, requests in s->rq are
> parsed and submitted again, possibly with a stale req->mr_next. It could
> be a problem if the request merging in virtio_blk_handle_request hasn't
> refreshed every mr_next pointer, in which case, virtio_blk_rw_complete
> could walk through unexpected requests following the stale pointers.
>
> Fix this by unsetting the pointer in virtio_blk_rw_complete. It is safe
> because this req is either completed and freed right away, or it will be
> restarted and parsed from scratch out of the vq later.
>
> Signed-off-by: Fam Zheng <famz@redhat.com>
>
> ---
>
> v3: Fix as Stefan suggested.
> ---
> hw/block/virtio-blk.c | 4 ++++
> 1 file changed, 4 insertions(+)
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v3] virtio-blk: Fix double completion for werror=stop
2015-11-17 10:34 ` Stefan Hajnoczi
@ 2015-11-17 15:21 ` Laurent Vivier
0 siblings, 0 replies; 5+ messages in thread
From: Laurent Vivier @ 2015-11-17 15:21 UTC (permalink / raw)
To: Stefan Hajnoczi, Fam Zheng
Cc: Kevin Wolf, qemu-block, pl, qemu-devel, qemu-stable, pbonzini, dgibson
On 17/11/2015 11:34, Stefan Hajnoczi wrote:
> On Tue, Nov 17, 2015 at 06:20:11PM +0800, Fam Zheng wrote:
>> When a request R is absorbed by request M, it is appended to the
>> "mr_next" queue led by M, and is completed together with the completion
>> of M, in virtio_blk_rw_complete.
>>
>> During DMA restart in virtio_blk_dma_restart_bh, requests in s->rq are
>> parsed and submitted again, possibly with a stale req->mr_next. It could
>> be a problem if the request merging in virtio_blk_handle_request hasn't
>> refreshed every mr_next pointer, in which case, virtio_blk_rw_complete
>> could walk through unexpected requests following the stale pointers.
>>
>> Fix this by unsetting the pointer in virtio_blk_rw_complete. It is safe
>> because this req is either completed and freed right away, or it will be
>> restarted and parsed from scratch out of the vq later.
>>
>> Signed-off-by: Fam Zheng <famz@redhat.com>
>>
>> ---
>>
>> v3: Fix as Stefan suggested.
>> ---
>> hw/block/virtio-blk.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>
> Thanks, applied to my block tree:
> https://github.com/stefanha/qemu/commits/block
I have also tested this one and it works fine.
Tested-by: Laurent Vivier <lvivier@redhat.com>
Laurent
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v3] virtio-blk: Fix double completion for werror=stop
2015-11-17 10:20 [Qemu-devel] [PATCH v3] virtio-blk: Fix double completion for werror=stop Fam Zheng
2015-11-17 10:34 ` Stefan Hajnoczi
@ 2015-11-22 19:41 ` Paolo Bonzini
2015-11-23 0:39 ` Fam Zheng
1 sibling, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2015-11-22 19:41 UTC (permalink / raw)
To: Fam Zheng, qemu-devel
Cc: Kevin Wolf, lvivier, qemu-block, pl, qemu-stable,
Stefan Hajnoczi, dgibson
On 17/11/2015 11:20, Fam Zheng wrote:
> When a request R is absorbed by request M, it is appended to the
> "mr_next" queue led by M, and is completed together with the completion
> of M, in virtio_blk_rw_complete.
>
> During DMA restart in virtio_blk_dma_restart_bh, requests in s->rq are
> parsed and submitted again, possibly with a stale req->mr_next. It could
> be a problem if the request merging in virtio_blk_handle_request hasn't
> refreshed every mr_next pointer, in which case, virtio_blk_rw_complete
> could walk through unexpected requests following the stale pointers.
>
> Fix this by unsetting the pointer in virtio_blk_rw_complete. It is safe
> because this req is either completed and freed right away, or it will be
> restarted and parsed from scratch out of the vq later.
>
> Signed-off-by: Fam Zheng <famz@redhat.com>
>
> ---
>
> v3: Fix as Stefan suggested.
> ---
> hw/block/virtio-blk.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> index e70fccf..848f3fe 100644
> --- a/hw/block/virtio-blk.c
> +++ b/hw/block/virtio-blk.c
> @@ -112,6 +112,10 @@ static void virtio_blk_rw_complete(void *opaque, int ret)
> * happen on the other side of the migration).
> */
> if (virtio_blk_handle_rw_error(req, -ret, is_read)) {
> + /* Break the link in case the next request is added to the
> + * restart queue and is going to be parsed from the ring again.
> + */
> + req->mr_next = NULL;
> continue;
> }
> }
>
This is now a write-after-free for rerror/werror=stop. The right place
to set req->mr_next is inside virtio_blk_handle_rw_error, I think.
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v3] virtio-blk: Fix double completion for werror=stop
2015-11-22 19:41 ` Paolo Bonzini
@ 2015-11-23 0:39 ` Fam Zheng
0 siblings, 0 replies; 5+ messages in thread
From: Fam Zheng @ 2015-11-23 0:39 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Kevin Wolf, lvivier, qemu-block, pl, qemu-devel, qemu-stable,
Stefan Hajnoczi, dgibson
On Sun, 11/22 20:41, Paolo Bonzini wrote:
> > diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> > index e70fccf..848f3fe 100644
> > --- a/hw/block/virtio-blk.c
> > +++ b/hw/block/virtio-blk.c
> > @@ -112,6 +112,10 @@ static void virtio_blk_rw_complete(void *opaque, int ret)
> > * happen on the other side of the migration).
> > */
> > if (virtio_blk_handle_rw_error(req, -ret, is_read)) {
> > + /* Break the link in case the next request is added to the
> > + * restart queue and is going to be parsed from the ring again.
> > + */
> > + req->mr_next = NULL;
> > continue;
> > }
> > }
> >
>
> This is now a write-after-free for rerror/werror=stop. The right place
> to set req->mr_next is inside virtio_blk_handle_rw_error, I think.
>
Oh yes :( Sending another patch.
Fam
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-11-23 0:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-17 10:20 [Qemu-devel] [PATCH v3] virtio-blk: Fix double completion for werror=stop Fam Zheng
2015-11-17 10:34 ` Stefan Hajnoczi
2015-11-17 15:21 ` Laurent Vivier
2015-11-22 19:41 ` Paolo Bonzini
2015-11-23 0:39 ` Fam Zheng
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.