9p: init_in_iov_from_pdu can truncate the size
commit16724a173049ac29c7b5ade741da93a0f46edff7
authorGreg Kurz <groug@kaod.org>
Mon, 20 Jan 2020 14:11:39 +0000 (20 15:11 +0100)
committerGreg Kurz <groug@kaod.org>
Mon, 20 Jan 2020 14:11:39 +0000 (20 15:11 +0100)
tree1585a3ff4437d15c176b36a1be9f2b5ed45e583f
parent846cf408a4c8055063f4a5a71ccf7ed030cdad30
9p: init_in_iov_from_pdu can truncate the size

init_in_iov_from_pdu might not be able to allocate the full buffer size
requested, which comes from the client and could be larger than the
transport has available at the time of the request. Specifically, this
can happen with read operations, with the client requesting a read up to
the max allowed, which might be more than the transport has available at
the time.

Today the implementation of init_in_iov_from_pdu throws an error, both
Xen and Virtio.

Instead, change the V9fsTransport interface so that the size becomes a
pointer and can be limited by the implementation of
init_in_iov_from_pdu.

Change both the Xen and Virtio implementations to set the size to the
size of the buffer they managed to allocate, instead of throwing an
error. However, if the allocated buffer size is less than P9_IOHDRSZ
(the size of the header) still throw an error as the case is unhandable.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
CC: groug@kaod.org
CC: anthony.perard@citrix.com
CC: roman@zededa.com
CC: qemu_oss@crudebyte.com
[groug: fix 32-bit build]
Signed-off-by: Greg Kurz <groug@kaod.org>
hw/9pfs/9p.c
hw/9pfs/9p.h
hw/9pfs/virtio-9p-device.c
hw/9pfs/xen-9p-backend.c