Skip to contentSkip to conversation

virtio-blk: force 1st s/g to match header

RFC PATCH In review Michael S. Tsirkin 6 participants 11 messages Nov 27, 2014 – Dec 1, 2014

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 virtio-blk: force 1st s/g to match header

We leak cpu mappings when 1st s/g is not exactly the header. As we don't set ANY_LAYOUT, we can at this point simply assert the correct length.

This will have to be fixed once ANY_LAYOUT is set.

---

Untested: posting for early feedback.

 hw/block/virtio-blk.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/block/virtio-blk.c +6 -0
index b19b102..1404b3f 100644
@@ -381,6 +381,12 @@ void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb)
         exit(1);
     }
 
+    /* We don't advertize ANY_LAYOUT, so first s/g is exactly the header. */
+    if (iov[0].iov_len != sizeof(req->out)) {
+        error_report("virtio-blk request outhdr too long");
+        exit(1);
+    }
+
     iov_discard_front(&iov, &out_num, sizeof(req->out));
 
     if (in_num < 1 ||
Signature · 1 line
MST
#2 lore raw
Quoted 5 lines · Stefan Hajnoczi
Quoted 4 lines · Michael S. Tsirkin

We leak cpu mappings when 1st s/g is not exactly the header. As we don't set ANY_LAYOUT, we can at this point simply assert the correct length.

Quoted 8 lines
Quoted 6 lines

This will have to be fixed once ANY_LAYOUT is set.

---

Untested: posting for early feedback.

Stefan, you are going to merge this for 2.2?
Peter, if Stefan is merging this one, we can
take Jason's patch for -net and that should be
enough for 2.2.

Signature · 1 line
MST
#3 lore raw
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Stefan Hajnoczi
Quoted 9 lines · Michael S. Tsirkin

We leak cpu mappings when 1st s/g is not exactly the header. As we don't set ANY_LAYOUT, we can at this point simply assert the correct length.

This will have to be fixed once ANY_LAYOUT is set.

---

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Untested: posting for early feedback.

Stefan, you are going to merge this for 2.2?
Peter, if Stefan is merging this one, we can
take Jason's patch for -net and that should be
enough for 2.2.

My test bot saw a failure of "make check":

qemu-system-x86_64: virtio-blk request outhdr too long
Broken pipe
GTester: last random seed: R02S44c5a09d74c0603f0091ed20d1395121
qemu-system-x86_64: virtio-blk request outhdr too long
Broken pipe
GTester: last random seed: R02Sfdf270c8e1ed75c1f2047e3f0fb89b88
qemu-system-x86_64: virtio-blk request outhdr too long
Broken pipe
GTester: last random seed: R02Sd292c540929b963ed9d7d155f3db5452
qemu-system-x86_64: virtio-blk request outhdr too long
Broken pipe
GTester: last random seed: R02Sfc775a34a844c39f376aa478eda7573f [vmxnet3][WR][vmxnet3_peer_has_vnet_hdr]: Peer has no virtio extension. Task offloads will be emulated.
make: *** [check-qtest-x86_64] Error 1

Fam

#4 lore raw
Quoted 39 lines · Fam Zheng
Quoted 12 lines · Michael S. Tsirkin
Quoted 1 line · Stefan Hajnoczi

On Thu, Nov 27, 2014 at 4:33 PM, Michael S. Tsirkin

Quoted 9 lines · <[email protected]> wrote:
Quoted 9 lines

We leak cpu mappings when 1st s/g is not exactly the header. As we don't set ANY_LAYOUT, we can at this point simply assert the correct length.

This will have to be fixed once ANY_LAYOUT is set.

---

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Untested: posting for early feedback.

Stefan, you are going to merge this for 2.2?
Peter, if Stefan is merging this one, we can
take Jason's patch for -net and that should be
enough for 2.2.

My test bot saw a failure of "make check":

qemu-system-x86_64: virtio-blk request outhdr too long
Broken pipe
GTester: last random seed: R02S44c5a09d74c0603f0091ed20d1395121
qemu-system-x86_64: virtio-blk request outhdr too long
Broken pipe
GTester: last random seed: R02Sfdf270c8e1ed75c1f2047e3f0fb89b88
qemu-system-x86_64: virtio-blk request outhdr too long
Broken pipe
GTester: last random seed: R02Sd292c540929b963ed9d7d155f3db5452
qemu-system-x86_64: virtio-blk request outhdr too long
Broken pipe
GTester: last random seed: R02Sfc775a34a844c39f376aa478eda7573f [vmxnet3][WR][vmxnet3_peer_has_vnet_hdr]: Peer has no virtio extension. Task offloads will be emulated.
make: *** [check-qtest-x86_64] Error 1

Quoted 1 line

Fam

This probably because of the test itself.

But anyway all kinds of guests (especially Windows drivers) need to be tested.

#5 lore raw
Quoted 44 lines · Jason Wang
Quoted 41 lines · Fam Zheng
Quoted 13 lines · Michael S. Tsirkin
Quoted 1 line · Stefan Hajnoczi

On Thu, Nov 27, 2014 at 4:33 PM, Michael S. Tsirkin <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines

We leak cpu mappings when 1st s/g is not exactly the header. As we don't set ANY_LAYOUT, we can at this point simply assert the correct length.

This will have to be fixed once ANY_LAYOUT is set.

---

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

Untested: posting for early feedback.

Stefan, you are going to merge this for 2.2?
Peter, if Stefan is merging this one, we can
take Jason's patch for -net and that should be
enough for 2.2.

My test bot saw a failure of "make check":

qemu-system-x86_64: virtio-blk request outhdr too long Broken pipe
GTester: last random seed: R02S44c5a09d74c0603f0091ed20d1395121
qemu-system-x86_64: virtio-blk request outhdr too long Broken pipe
GTester: last random seed: R02Sfdf270c8e1ed75c1f2047e3f0fb89b88
qemu-system-x86_64: virtio-blk request outhdr too long Broken pipe
GTester: last random seed: R02Sd292c540929b963ed9d7d155f3db5452
qemu-system-x86_64: virtio-blk request outhdr too long Broken pipe
GTester: last random seed: R02Sfc775a34a844c39f376aa478eda7573f [vmxnet3][WR][vmxnet3_peer_has_vnet_hdr]: Peer has no virtio extension. Task offloads will be emulated.
make: *** [check-qtest-x86_64] Error 1

Quoted 7 lines
Quoted 1 line

Fam

This probably because of the test itself.

But anyway all kinds of guests (especially Windows drivers) need to be tested.

Right, the test case explicitly tests different descriptor layouts, even though virtio-blk-pci does not set the ANY_LAYOUT feature bit.

Either the test case needs to check ANY_LAYOUT before using the 2-descriptor layout or it needs to expect QEMU to refuse (in this case exit(1), which is not very graceful).

The quick fix is to skip the 2-descriptor layout tests and re-enable them once virtio-blk actually supports ANY_LAYOUT. Any objections?

Stefan

#6 lore raw
Quoted 58 lines · El Fri, 28 Nov 2014 11:43:59 +0000 Stefan Hajnoczi <[email protected]>…
Quoted 45 lines · Jason Wang
Quoted 42 lines · Fam Zheng
Quoted 14 lines · Michael S. Tsirkin
Quoted 2 lines · Stefan Hajnoczi

On Thu, Nov 27, 2014 at 4:33 PM, Michael S. Tsirkin <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines

We leak cpu mappings when 1st s/g is not exactly the header. As we don't set ANY_LAYOUT, we can at this point simply assert the correct length.

This will have to be fixed once ANY_LAYOUT is set.

---

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

Untested: posting for early feedback.

Stefan, you are going to merge this for 2.2?
Peter, if Stefan is merging this one, we can
take Jason's patch for -net and that should be
enough for 2.2.

My test bot saw a failure of "make check":

qemu-system-x86_64: virtio-blk request outhdr too long Broken pipe
GTester: last random seed: R02S44c5a09d74c0603f0091ed20d1395121
qemu-system-x86_64: virtio-blk request outhdr too long Broken pipe
GTester: last random seed: R02Sfdf270c8e1ed75c1f2047e3f0fb89b88
qemu-system-x86_64: virtio-blk request outhdr too long Broken pipe
GTester: last random seed: R02Sd292c540929b963ed9d7d155f3db5452
qemu-system-x86_64: virtio-blk request outhdr too long Broken pipe
GTester: last random seed: R02Sfc775a34a844c39f376aa478eda7573f [vmxnet3][WR][vmxnet3_peer_has_vnet_hdr]: Peer has no virtio extension. Task offloads will be emulated.
make: *** [check-qtest-x86_64] Error 1

Quoted 7 lines
Quoted 1 line

Fam

This probably because of the test itself.

But anyway all kinds of guests (especially Windows drivers) need to be tested.

Right, the test case explicitly tests different descriptor layouts, even though virtio-blk-pci does not set the ANY_LAYOUT feature bit.

Quoted 8 lines

Either the test case needs to check ANY_LAYOUT before using the 2-descriptor layout or it needs to expect QEMU to refuse (in this case exit(1), which is not very graceful).

The quick fix is to skip the 2-descriptor layout tests and re-enable them once virtio-blk actually supports ANY_LAYOUT. Any objections?

Stefan

To be compliant with the specs, the test should check for ANY_LAYOUT feature before testing with 2 descriptor layout. I'll add it with the other changes pending for the test.

Marc

#7 lore raw
In reply to Stefan Hajnoczi
Quoted 9 lines · Stefan Hajnoczi

Right, the test case explicitly tests different descriptor layouts, even though virtio-blk-pci does not set the ANY_LAYOUT feature bit.

Either the test case needs to check ANY_LAYOUT before using the 2-descriptor layout or it needs to expect QEMU to refuse (in this case exit(1), which is not very graceful).

The quick fix is to skip the 2-descriptor layout tests and re-enable them once virtio-blk actually supports ANY_LAYOUT. Any objections?

So what do we want to do with this for 2.2? We have I think two choices:
(1) say that this isn't causing problems in practice, and defer all this to 2.3
(2) add something like this patch plus fix the 'make check' tests (but turning "maybe something misbehaves" into "qemu definitely blows up and exits" doesn't seem like a great improvement to me)

I started looking at virtio-blk initially because I wasn't sure if we should fix the virtio-net issue in the core virtio code. But since we've decided not to do that, whether virtio-blk's problems are release-blockers or not is something that we can decide on their own merits.

My current thought is that we don't need to address this for 2.2; is there something I'm missing that means we shouldn't defer to 2.3?

thanks
-- PMM

#8 lore raw
Quoted 25 lines · Peter Maydell
Quoted 9 lines · Stefan Hajnoczi

Right, the test case explicitly tests different descriptor layouts, even though virtio-blk-pci does not set the ANY_LAYOUT feature bit.

Either the test case needs to check ANY_LAYOUT before using the 2-descriptor layout or it needs to expect QEMU to refuse (in this case exit(1), which is not very graceful).

The quick fix is to skip the 2-descriptor layout tests and re-enable them once virtio-blk actually supports ANY_LAYOUT. Any objections?

So what do we want to do with this for 2.2? We have I think two choices:
(1) say that this isn't causing problems in practice, and defer all this to 2.3
(2) add something like this patch plus fix the 'make check' tests (but turning "maybe something misbehaves" into "qemu definitely blows up and exits" doesn't seem like a great improvement to me)

I started looking at virtio-blk initially because I wasn't sure if we should fix the virtio-net issue in the core virtio code. But since we've decided not to do that, whether virtio-blk's problems are release-blockers or not is something that we can decide on their own merits.

Quoted 5 lines

My current thought is that we don't need to address this for 2.2; is there something I'm missing that means we shouldn't defer to 2.3?

thanks
-- PMM

The result of this is host mapping leak.
What effect does this have? Can this DOS host?
If not, I agree.

#9 lore raw
Quoted 2 lines · Michael S. Tsirkin

The result of this is host mapping leak.
What effect does this have? Can this DOS host?

I don't think we can DOS the host here.

If Xen, we crash (but you can't use virtio-blk with Xen anyway) Otherwise, if you managed to get address_space_map() to hand you the bounce-buffer (by asking for dma to something other than RAM) then we'll either hit an assertion or just end up never allowing dma to/from non-RAM ever again for this guest.
The usual case would be that this was dma to/from ram, in which case it's harmless if the virtio-backend never wrote to the memory, and will fail to update dirty bitmaps for migration etc if the backend did write.

In any case I think that none of these outcomes are worse than the "exit(1)" the current patch proposes.

-- PMM

#10 lore raw
Quoted 16 lines · Peter Maydell
Quoted 2 lines · Michael S. Tsirkin

The result of this is host mapping leak.
What effect does this have? Can this DOS host?

I don't think we can DOS the host here.

If Xen, we crash (but you can't use virtio-blk with Xen anyway) Otherwise, if you managed to get address_space_map() to hand you the bounce-buffer (by asking for dma to something other than RAM) then we'll either hit an assertion or just end up never allowing dma to/from non-RAM ever again for this guest.
The usual case would be that this was dma to/from ram, in which case it's harmless if the virtio-backend never wrote to the memory, and will fail to update dirty bitmaps for migration etc if the backend did write.

Quoted 4 lines

In any case I think that none of these outcomes are worse than the "exit(1)" the current patch proposes.

-- PMM

Fair enough.
Pls disregard the patch then, and we'll fix it properly for 2.3 when we set ANY_LAYOUT.