qemu/include/net
Peter Maydell b1e73b2ddb net: Correct padding check in qemu_receive_packet()
In qemu_receive_packet() we check to see if we should pad a short
packet.  This is doing the wrong test: because this function is used
when the device adds a packet to its own incoming queue (i.e.  for
loopback), we should be checking the NetClientState's own do_not_pad
flag, not that for its peer.

We didn't notice this earlier, because at the moment all the real
peers of a network device (i.e.  the network backends) do not set
do_not_pad, so net_peer_needs_padding() always returns true except in
the corner case where the network device has no peer at all.

The effect of this is that if a network device has no peer (e.g.
because QEMU was started with -net none or with -nodefaults) then we
can still let through the kind of "guest misprograms the network
device to loopback-transmit a short packet and then we mishandle it
in the receive path" bug like #3043 which commit a01344d9d7 was
trying to fix.

Since the distinction between "we should check nc->do_not_pad"
and "we should check nc->peer->do_not_pad" is a bit subtle, add
enough documentation commentary to make it more obvious.

Cc: qemu-stable@nongnu.org
Fixes: a01344d9d7 ("net: pad packets to minimum length in qemu_receive_packet()")
Suggested-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Bin Meng <bin.meng@processmission.com>
Message-ID: <20260629164246.2028947-1-peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
2026-07-21 12:18:36 +02:00
..
announce.h net: remove AnnounceTimer from typedefs.h 2024-05-03 15:47:48 +02:00
can_emu.h qom: remove redundant typedef when use OBJECT_DECLARE_SIMPLE_TYPE 2025-10-28 08:08:04 +01:00
can_host.h qom: fix objects with improper parent type 2020-10-12 11:50:22 -04:00
checksum.h net: checksum: Convert data to void * 2024-11-25 13:59:50 +08:00
eth.h net: mark struct ip6_header as QEMU_PACKED 2026-05-12 22:35:54 +02:00
filter.h qapi: Move @String out of common.json to discourage reuse 2024-02-12 10:04:32 +01:00
net.h net: Correct padding check in qemu_receive_packet() 2026-07-21 12:18:36 +02:00
queue.h net: Remove deadcode 2024-10-03 17:26:05 +03:00
slirp.h net: Remove the deprecated -tftp, -bootp, -redir and -smb options 2018-08-31 09:53:03 +02:00
tap.h net: Add get_vhost_net callback to NetClientInfo 2025-07-14 13:27:09 +08:00
vhost-vdpa.h net: Consolidate vhost feature bits into vhost_net structure 2025-07-14 13:27:09 +08:00
vhost_net.h vhost-net: implement extended features support 2025-10-04 10:50:37 -04:00