On Wed, Jun 10, 2026 at 7:41 PM Xuan Zhuo <[email protected]> wrote: > > On Wed, 10 Jun 2026 19:24:03 -0700, Xiang Mei <[email protected]> wrote: > > Thanks for the review. I agree with that as I replied at the end of > > v1. If we obsolete 2/2 but keep 1/2, is it okay to just leave it as > > is? > > You should post a new version. > Thanks for the tips! V3 has been sent out.
Xiang > Thanks. > > > > > Xiang > > > > On Wed, Jun 10, 2026 at 7:19 PM Xuan Zhuo <[email protected]> > > wrote: > > > > > > On Wed, 10 Jun 2026 16:29:36 -0700, Xiang Mei <[email protected]> wrote: > > > > This is a robustness hardening patch. The slow-path frag loop in > > > > page_to_skb() walks the page chain via page->private until the > > > > device-reported len is consumed, implicitly trusting that len fits the > > > > chain. It does not stop when the chain is exhausted (page becomes NULL > > > > at the tail), nor when nr_frags reaches the end of the static > > > > skb_shinfo()->frags[MAX_SKB_FRAGS] array. > > > > > > > > Both bounds are needed: the chain length is big_packets_num_skbfrags + 1 > > > > pages, which for an MTU-driven configuration can be well below > > > > MAX_SKB_FRAGS, so neither guard implies the other. > > > > > > > > Make the loop self-defending so it no longer relies on the caller having > > > > validated len: stop once the chain is exhausted, and never index past > > > > MAX_SKB_FRAGS. No functional change for well-formed input. > > > > > > At this point, we are assuming that len represents the correct packet > > > length. If > > > there is a bug in the validation, it can be fixed, just like in your > > > previous > > > patch. Indeed, not checking nr_frags is also based on the overall design. > > > However, I do not recommend adding this kind of enhancement. If we follow > > > this logic, we would end up adding similar code in many other places, > > > which > > > doesn't make much sense. > > > > > > Thanks. > > > > > > > > > > > Signed-off-by: Xiang Mei <[email protected]> > > > > --- > > > > v2: robustness patch > > > > > > > > drivers/net/virtio_net.c | 5 ++++- > > > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > > > > index afe73eda1491..518c22fa1b68 100644 > > > > --- a/drivers/net/virtio_net.c > > > > +++ b/drivers/net/virtio_net.c > > > > @@ -906,8 +906,11 @@ static struct sk_buff *page_to_skb(struct > > > > virtnet_info *vi, > > > > } > > > > > > > > BUG_ON(offset >= PAGE_SIZE); > > > > - while (len) { > > > > + while (len && page) { > > > > unsigned int frag_size = min((unsigned)PAGE_SIZE - > > > > offset, len); > > > > + > > > > + if (unlikely(skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS)) > > > > + break; > > > > skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, > > > > offset, > > > > frag_size, truesize); > > > > len -= frag_size; > > > > -- > > > > 2.43.0 > > > >

