From: Jason Wang <jasowang@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
qemu-stable@nongnu.org,
Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>,
Jason Wang <jasowang@redhat.com>
Subject: [PULL 5/5] net: pad packets to minimum length in qemu_receive_packet()
Date: Fri, 14 Nov 2025 11:48:06 +0800 [thread overview]
Message-ID: <20251114034806.2440-6-jasowang@redhat.com> (raw)
In-Reply-To: <20251114034806.2440-1-jasowang@redhat.com>
From: Peter Maydell <peter.maydell@linaro.org>
In commits like 969e50b61a28 ("net: Pad short frames to minimum size
before sending from SLiRP/TAP") we switched away from requiring
network devices to handle short frames to instead having the net core
code do the padding of short frames out to the ETH_ZLEN minimum size.
We then dropped the code for handling short frames from the network
devices in a series of commits like 140eae9c8f7 ("hw/net: e1000:
Remove the logic of padding short frames in the receive path").
This missed one route where the device's receive code can still see a
short frame: if the device is in loopback mode and it transmits a
short frame via the qemu_receive_packet() function, this will be fed
back into its own receive code without being padded.
Add the padding logic to qemu_receive_packet().
This fixes a buffer overrun which can be triggered in the
e1000_receive_iov() logic via the loopback code path.
Other devices that use qemu_receive_packet() to implement loopback
are cadence_gem, dp8393x, lan9118, msf2-emac, pcnet, rtl8139
and sungem.
Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3043
Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
net/net.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/net/net.c b/net/net.c
index 27e0d27807..8aefdb3424 100644
--- a/net/net.c
+++ b/net/net.c
@@ -775,10 +775,20 @@ ssize_t qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size)
ssize_t qemu_receive_packet(NetClientState *nc, const uint8_t *buf, int size)
{
+ uint8_t min_pkt[ETH_ZLEN];
+ size_t min_pktsz = sizeof(min_pkt);
+
if (!qemu_can_receive_packet(nc)) {
return 0;
}
+ if (net_peer_needs_padding(nc)) {
+ if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) {
+ buf = min_pkt;
+ size = min_pktsz;
+ }
+ }
+
return qemu_net_queue_receive(nc->incoming_queue, buf, size);
}
--
2.42.0
next prev parent reply other threads:[~2025-11-14 3:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 3:48 [PULL 0/5] Net patches Jason Wang
2025-11-14 3:48 ` [PULL 1/5] net/hub: make net_hub_port_cleanup idempotent Jason Wang
2025-11-14 3:48 ` [PULL 2/5] hw/net/e1000e_core: Don't advance desc_offset for NULL buffer RX descriptors Jason Wang
2025-11-14 3:48 ` [PULL 3/5] hw/net/e1000e_core: Correct rx oversize packet checks Jason Wang
2025-11-14 3:48 ` [PULL 4/5] hw/net/e1000e_core: Adjust e1000e_write_payload_frag_to_rx_buffers() assert Jason Wang
2025-11-14 3:48 ` Jason Wang [this message]
2025-11-14 16:58 ` [PULL 0/5] Net patches Richard Henderson
2025-11-21 4:02 ` Jason Wang
2025-11-21 12:27 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251114034806.2440-6-jasowang@redhat.com \
--to=jasowang@redhat.com \
--cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).