From: "Michael S. Tsirkin" <mst@redhat.com>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org,
edumazet@google.com, pabeni@redhat.com, horms@kernel.org,
andrew+netdev@lunn.ch, jasowangio@gmail.com, eperezma@redhat.com,
Willem de Bruijn <willemb@google.com>
Subject: Re: [PATCH net] virtio-net: fix frag overflow in big packets receive
Date: Tue, 20 Oct 2026 06:33:06 -0400 [thread overview]
Message-ID: <20261020003357-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20261020032108.81879-1-willemdebruijn.kernel@gmail.com>
On Mon, Oct 19, 2026 at 11:15:50PM -0400, Willem de Bruijn wrote:
> From: Willem de Bruijn <willemb@google.com>
>
> In big packets mode with guest GSO, add_recvbuf_big() posts a chain of
> MAX_SKB_FRAGS + 1 pages. page_to_skb() copies only ETH_HLEN of the
> first page into the linear area and adds the rest of that page as a
> frag, then one frag per remaining page. A device that fills the entire
> buffer therefore causes MAX_SKB_FRAGS + 1 frags, writing one
> skb_frag_t past the end of skb_shinfo(skb)->frags[].
>
> Post one page less. The buffer still fits a maximal GSO packet. A well
> behaved device does not trigger this, as GSO packets are at most 64KB.
>
> Also check the frag count in page_to_skb() before adding any frag as
> defense in depth.
>
> Fixes: 9ab86bbcf8be ("virtio_net: Defer skb allocation in receive path Date: Wed, 13 Jan 2010 12:53:38 -0800")
Wow an old one.
> Signed-off-by: Willem de Bruijn <willemb@google.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>
> The "Date: ..." in the Fixes tag is literally part of the subject
> line of commit 9ab86bbcf8be in git history.
Caused me a double take, too.
>
> Reported by an offline AI review of a related virtio-net patch.
> ---
> drivers/net/virtio_net.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index daab43ac92ce..cb7ed53fd55e 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -906,6 +906,15 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi,
> }
>
> BUG_ON(offset >= PAGE_SIZE);
> +
> + /* The first frag starts at offset, each next frag is a full page. */
> + if (unlikely(DIV_ROUND_UP(offset + len, PAGE_SIZE) > MAX_SKB_FRAGS)) {
> + pr_debug("%s: rx error: len %u needs more than %d frags\n",
> + vi->dev->name, len, MAX_SKB_FRAGS);
> + kfree_skb(skb);
> + return NULL;
> + }
> +
> while (len) {
> unsigned int frag_size = min((unsigned)PAGE_SIZE - offset, len);
> skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, offset,
> @@ -6717,7 +6726,8 @@ static void virtnet_set_big_packets(struct virtnet_info *vi, const int mtu)
> */
> if (mtu > ETH_DATA_LEN || guest_gso) {
> vi->big_packets = true;
> - vi->big_packets_num_skbfrags = guest_gso ? MAX_SKB_FRAGS : DIV_ROUND_UP(mtu, PAGE_SIZE);
> + vi->big_packets_num_skbfrags = guest_gso ? MAX_SKB_FRAGS - 1 :
> + DIV_ROUND_UP(mtu, PAGE_SIZE);
The two most common issues in computer science are off by one bugs.
> }
> }
>
> --
> 2.56.0.212.g129ede20d9-goog
prev parent reply other threads:[~2026-10-20 10:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 3:15 [PATCH net] virtio-net: fix frag overflow in big packets receive Willem de Bruijn
2026-10-20 10:33 ` Michael S. Tsirkin [this message]
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=20261020003357-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eperezma@redhat.com \
--cc=horms@kernel.org \
--cc=jasowangio@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
--cc=willemdebruijn.kernel@gmail.com \
/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