cloud-hypervisor/virtio-devices/src
Alyssa Ross ec8fceb4a6 virtio-devices: stop corrupting vsock commands
The read_exact() call was introduced in 82ac114b8 ("virtio-devices:
vsock: handle short read in muxer") to solve a crash when a connection
disconnected without sending any data, but it introduced a problem of
its own: because the socket is non-blocking, read_exact() may read
some data, then return ErrorKind::WouldBlock.  In that case, the data
it read will be discarded.  So for example if it read "CONNECT ",
and then nothing else was available to read yet, "CONNECT " would be
discarded, and so the next time this function was called, when epoll
triggered again for the socket, only the following data would end up
in command.buf, causing an error due to just a port number being an
invalid command.

Contrary to that commit message, this code was actually designed to
handle short reads just fine — in the case of a short read, it stores
the data it has read in command, and returns
Error::UnixRead(ErrorKind::WouldBlock), which is ignored by the
caller, and the function gets called again when there is more data to
read, building up command potentially over the course of several
reads.  The only thing it didn't handle correctly, as far as I can
tell, was a 0-byte read, which happens when a client disconnects from
the socket without writing anything.  All that's needed to fix this is
to avoid an invalid subtraction in that case, so this change reverts
82ac114b8, fixing the issue with partial commands being discarded, and
instead handles the 0-byte read by using slice::get, and treating an
empty command as an incomplete command, which of course it is.

Fixes: 82ac114b8 ("virtio-devices: vsock: handle short read in muxer")
Signed-off-by: Alyssa Ross <hi@alyssa.is>
2025-07-14 18:07:07 +00:00
..
transport misc: virtio-devices: streamline error Display::fmt() 2025-06-13 19:55:54 +00:00
vhost_user build: Bump vfio and all the dependent crates to latest version 2025-07-07 03:05:38 +00:00
vsock virtio-devices: stop corrupting vsock commands 2025-07-14 18:07:07 +00:00
balloon.rs misc: virtio-devices: streamline error Display::fmt() 2025-06-13 19:55:54 +00:00
block.rs misc: virtio-devices: manual adjustment of special case 2025-06-13 19:55:54 +00:00
console.rs misc: virtio-devices: streamline error Display::fmt() 2025-06-13 19:55:54 +00:00
device.rs virtio-devices: Automatically fix operator precedence clippy warning 2025-01-07 17:44:41 +00:00
epoll_helper.rs misc: virtio-devices: streamline error Display::fmt() 2025-06-13 19:55:54 +00:00
iommu.rs virtio-devices: remove unnecessary parentheses 2025-07-11 22:02:15 +00:00
lib.rs misc: virtio-devices: streamline error Display::fmt() 2025-06-13 19:55:54 +00:00
mem.rs misc: virtio-devices: streamline error Display::fmt() 2025-06-13 19:55:54 +00:00
net.rs misc: virtio-devices: streamline error Display::fmt() 2025-06-13 19:55:54 +00:00
pmem.rs misc: virtio-devices: streamline error Display::fmt() 2025-06-13 19:55:54 +00:00
rng.rs misc: virtio-devices: streamline error Display::fmt() 2025-06-13 19:55:54 +00:00
seccomp_filters.rs misc: Further improve imports styling 2024-09-29 16:13:48 +00:00
thread_helper.rs misc: Further improve imports styling 2024-09-29 16:13:48 +00:00
vdpa.rs build: Bump vfio and all the dependent crates to latest version 2025-07-07 03:05:38 +00:00
watchdog.rs misc: virtio-devices: streamline error Display::fmt() 2025-06-13 19:55:54 +00:00