Skip to contentSkip to conversation

virtio_net: fix header access in big_packets mode

PATCH In review Wen Xin 3 participants 4 messages Oct 16, 2025 – Oct 22, 2025

Subsystems (4)
lore
Share & tools
lore

Wen Xin

author
#0 lore raw

PATCH 1/1 virtio_net: fix header access in big_packets mode

In Linux virtio-net driver's (drivers/net/virtio_net.c) big packets mode (vi->big_packets && vi->mergeable_rx_bufs), the buf pointer passed to receive_buf() is a struct page pointer, not a buffer
pointer. The current code incorrectly casts this page pointer directly as
a virtio_net_common_hdr, causing it to read flags from the page struct
memory instead of the actual packet data.

---
 drivers/net/virtio_net.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/virtio_net.c +7 -1
index 7646ddd9bef7..c10f5585bc88 100644
@@ -2566,7 +2566,13 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
 	 * virtnet_xdp_set()), so packets marked as
 	 * VIRTIO_NET_HDR_F_NEEDS_CSUM get dropped during XDP processing.
 	 */
-	flags = ((struct virtio_net_common_hdr *)buf)->hdr.flags;
+	if (vi->big_packets && !vi->mergeable_rx_bufs) {
+		struct virtio_net_common_hdr *hdr = page_address((struct page *)buf);
+
+		flags = hdr->hdr.flags;
+	} else {
+		flags = ((struct virtio_net_common_hdr *)buf)->hdr.flags;
+	}
 
 	if (vi->mergeable_rx_bufs)
 		skb = receive_mergeable(dev, vi, rq, buf, ctx, len, xdp_xmit,
Signature · 1 line
2.39.5 (Apple Git-154)
reviewer
#1 lore raw

http://lore.kernel.org/all/[email protected]

do the same thing.

Quoted 33 lines · Wen Xin

In Linux virtio-net driver's (drivers/net/virtio_net.c) big packets mode (vi->big_packets && vi->mergeable_rx_bufs), the buf pointer passed to receive_buf() is a struct page pointer, not a buffer
pointer. The current code incorrectly casts this page pointer directly as
a virtio_net_common_hdr, causing it to read flags from the page struct
memory instead of the actual packet data.

---
 drivers/net/virtio_net.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/virtio_net.c +7 -2
index 7646ddd9bef7..c10f5585bc88 100644
@@ -2566,7 +2566,13 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
 	 * virtnet_xdp_set()), so packets marked as
 	 * VIRTIO_NET_HDR_F_NEEDS_CSUM get dropped during XDP processing.
 	 */
-	flags = ((struct virtio_net_common_hdr *)buf)->hdr.flags;
+	if (vi->big_packets && !vi->mergeable_rx_bufs) {
+		struct virtio_net_common_hdr *hdr = page_address((struct page *)buf);
+
+		flags = hdr->hdr.flags;
+	} else {
+		flags = ((struct virtio_net_common_hdr *)buf)->hdr.flags;
+	}
 
 	if (vi->mergeable_rx_bufs)
 		skb = receive_mergeable(dev, vi, rq, buf, ctx, len, xdp_xmit,
--

2.39.5 (Apple Git-154)

reviewer
#3 lore raw
Quoted 7 lines · Jakub Kicinski
Quoted 3 lines · On Fri, 17 Oct 2025 08:57:36 +0800 Xuan Zhuo wrote:

http://lore.kernel.org/all/[email protected]

do the same thing.

Could you repost that? looks like there were some questions, but nobody sent review tags even tho they were answered..

YES. In my todo list.