Skip to content

Commit b155d93

Browse files
lauraltandreeaflorescu
authored andcommitted
vsock: use the len from the header for the data size
Even though the driver is allowed to set a size for the payload that is > than the size from the header, the size of the data should be the `len` header field. Updated the code accordingly on the TX path (where the buffers are filled by the driver). On RX path we can't use the `len` field because it is = 0 when parsing the chain. Signed-off-by: Laura Loghin <lauralg@amazon.com>
1 parent bb0f847 commit b155d93

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

crates/devices/virtio-vsock/src/packet.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl<'a, B: BitmapSlice> VsockPacket<'a, B> {
369369
}
370370

371371
let data_slice = {
372-
mem.get_slice(data_desc.addr(), data_desc.len() as usize)
372+
mem.get_slice(data_desc.addr(), pkt.len() as usize)
373373
.map_err(Error::InvalidMemoryAccess)?
374374
};
375375

@@ -784,7 +784,7 @@ mod tests {
784784
let v = vec![
785785
Descriptor::new(0x5_0000, 0x100, 0, 0),
786786
// A data length < the length of data as described by the header.
787-
Descriptor::new(0x8_0000, LEN as u32 - 1, 0, 0),
787+
Descriptor::new(0x8_0000, LEN - 1, 0, 0),
788788
];
789789
let mut chain = queue.build_desc_chain(&v[..2]);
790790
assert_eq!(
@@ -808,14 +808,14 @@ mod tests {
808808
);
809809
assert_eq!(header_slice.len(), PKT_HEADER_SIZE);
810810
// The `len` field of the header was set to 16.
811-
assert_eq!(packet.len(), LEN as u32);
811+
assert_eq!(packet.len(), LEN);
812812

813813
let data = packet.data_slice().unwrap();
814814
assert_eq!(
815815
data.as_ptr(),
816816
mem.get_host_address(GuestAddress(0x8_0000)).unwrap()
817817
);
818-
assert_eq!(data.len(), 0x100);
818+
assert_eq!(data.len(), LEN as usize);
819819

820820
// If we try to get a vsock packet again, it fails because we already consumed all the
821821
// descriptors from the chain.

0 commit comments

Comments
 (0)