> virtnet_get_hw_stats() allocates the reply buffer of the device
> statistics command with kmalloc(), and __virtnet_get_hw_stats() parses
> the whole buffer. When the device writes less than the buffer holds,
> stale heap bytes are reported as counters through ethtool -S and the
> per-queue netlink statistics.
> 
> Allocate the buffer with kzalloc(), so that the counters the device
> didn't write are zeroed. An unwritten record header then has size 0, so
> reject it when walking on that header to avoid an infinite loop.
> 
> The used length cannot replace the zeroing here, since the device can
> also report a larger value than it wrote.
> 
> Claude Opus 5.5 was used to audit the driver and draft this patch. To
> reproduce, the virtio-net device in QEMU was modified to offer device
> statistics and to leave the counters of a receive record unwritten. On
> an unmodified kernel, ethtool -S reported kernel pointers as rx0
> counters. With this patch, the counters are zeroed, and a reply with
> missing records or a record of size 0 is rejected. The
> drivers/net/stats.py selftest passes when the device answers with
> well-formed records.
> 
> Reported-by: Michael Bommarito <[email protected]>
> Link: 
> https://lore.kernel.org/all/[email protected]/
> Reported-by: Jakub Kicinski <[email protected]>
> Link: https://lore.kernel.org/all/[email protected]/
> Fixes: 941168f8b40e ("virtio_net: support device stats")
> Cc: [email protected]
> Signed-off-by: Lianjie Wang <[email protected]>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=2


Reply via email to