From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EAC02EA731 for ; Thu, 11 Jun 2026 06:04:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781157862; cv=none; b=ugOsV5L2tDzaRkNbEsbiLH1vluaavDF1WpM9p8YdVYyaql+ge9ZxTvd2DCOnxNZpXu+vLJRfqKSata0KQmEHaldCrQ0Ubvp8OZMkMx07I60I/AInvC8gKOoyCbFfE4CpncN7rA+uANVheiraqZx0pKU4fOdssp8vZT/+tdzyJqM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781157862; c=relaxed/simple; bh=THJuQE2MrTb5ZIYu3BzOWvVCOA5+CKpxg+aLafJ1Wfw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mCLl+Bc1HNnPLpu+bAo4jJYKnd6rsUxgluPGzI9tNNY31UIc2PpybR6mHo9+1rCL3eBr61lQupgaIk0hyrkoZ8/jUBj+KQB5mmJQlwqRw3CkQi/dAT1GE8PczaT+dvb1GN9Y7PSJAP5X1M5c4DgDz7ZSG0yQKMR4sbzucJeeb5E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=BlagH+E6; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=U6Qo/yc2; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BlagH+E6"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="U6Qo/yc2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781157859; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=HRTToFtG9hV0gA1EWdpPvRzBaGUtoQe1flCF2qnScak=; b=BlagH+E6wk25ON9Gy7riL9mUXcJsoKPW9y1MHsi8Wak8RfgSS5TZ4VTicrIy/H5aor3crx aYrPZvFjLbFeK7Bcm2cLpEC7/Q1o4BlfRluqjHcUq5U2KpCgb3Udfr/rSZA3osaF7uqiOb DJZhjMVAIlQOxA4uNvwvhNdSfQ0a8nw= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-Spyl7sOXOAWIh6A1yWJk0w-1; Thu, 11 Jun 2026 02:04:17 -0400 X-MC-Unique: Spyl7sOXOAWIh6A1yWJk0w-1 X-Mimecast-MFC-AGG-ID: Spyl7sOXOAWIh6A1yWJk0w_1781157856 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-460198535bcso4844700f8f.3 for ; Wed, 10 Jun 2026 23:04:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1781157856; x=1781762656; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=HRTToFtG9hV0gA1EWdpPvRzBaGUtoQe1flCF2qnScak=; b=U6Qo/yc2aejiW4N1bmB9FzVythbgXP8ovnzGNGiFgcG0pY09snaH2eOmTnp+Gi2iXe p1hlL7PU2lBkQfO3YMiQ1PAFWFhM786i/pz4k387uoyWKQjDBix2h8DPms7F/T6iqp5/ 91vWPVOED29YPs05gvIICX8Nh4To7Gcd/FjK5NL1ZvhoSxNgRatDFvfzEozx3kHKoTRl 1PobtvuhdwUolx22c6Xro8NEsll4SpYdY/uB+CFxkIHzzMl3eTI4knO1qOZzV/8efGg+ Ok/tzD488vjcqsEppT2WQU64J4trfdziqECxJboxVJjNcfkIMv8srJoOGQcwQSH6DA8I v8zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781157856; x=1781762656; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HRTToFtG9hV0gA1EWdpPvRzBaGUtoQe1flCF2qnScak=; b=D+YMVQZiJNFGP947VHIqfh7qS3815eIF451vcGVHXrh7UlO3DbzxnQSxXZA5+CcJ/6 ReofxCeiJQhbKCJPuBBtHZpLXkUngCOwU+0shnjoZEuStoo3K9dshCZTIdXAUcJcSLey eMpRfnSwakur1GtAw1XzvjPim9orMAS8Q3MDVq0icjT8Rd8npj7/szr3M2YLHp9njwix koUnh+oa7qXODjgFzn2c3iFjqtqb1NH9iIu/+6Yiv5o5uavyP8XbUr2e8r+ncHPs7B/T XoKw9rdosDL4Yt7FM3Vvamhp6sdTi3grI7fJDMYte7DuGHLm0cOkxBLIdlpVovR4H1Xt Vuhw== X-Forwarded-Encrypted: i=1; AFNElJ9VcoNkonvV1kaeYIAu6+uQ2JqdbHTUGjDBgsUzvvsle6dxmKfUzf4wXBp/N/pWneF5rd8pg9XO/LO61FY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0w4GK6fmTR9j2OmYo9BiD1ikbGfsUYyYDXguTB5aQeR8OwgSP j8+bZNQ0t1oC7cAWQPSRi6u4kZy8dDkGlytEeWNTeI4mfMj3CctPQNkCOfb6xNSXvzZR/+L3sMv RDHTusp8L7+xCQEIwI9IFKxym3Y+LDBY4/nhmsywJOSJFfwzWCk9ITlLTpibPeafQlA== X-Gm-Gg: Acq92OHsBAYffdySmDNvt5L3nL9T6nU3r03iSe11Kc6arfla+0OquSDww+guYKBPrwe EyAoofSQajue2RriE4nNEYV8OX7RtDNbd20W2T2HTrzl0QcuGGvbucX6PbEyD9QZawk4ysVxRQ3 h9PnhyBKjJRpuxUhlPWGwFtPKnpWVQ8+K+1TVdYhVrJf6TZ6HWPzgcZyc26PTcsL4pscvT2cRT5 +dQF2PxrqRJjMBWMMu71QHlB07JiaV2MHBzEkSIz8UW+cNf56fJUErZsKRHwzNnyVdq8bQyhqY8 2DpdX3MeAi0EbCnKrocjML+pLPah6T1KaXyPXD2Ci5PnBq0jcfUzt7SRZORuN0PFKtwufQkcKbB u/wbXMj0rDbVH4pI9Juied81UhZcIKYHuAp9awK63WWXaNNZRY3sNKw== X-Received: by 2002:a05:6000:460a:b0:460:3233:beeb with SMTP id ffacd0b85a97d-460677b4012mr1689559f8f.43.1781157856465; Wed, 10 Jun 2026 23:04:16 -0700 (PDT) X-Received: by 2002:a05:6000:460a:b0:460:3233:beeb with SMTP id ffacd0b85a97d-460677b4012mr1689509f8f.43.1781157855948; Wed, 10 Jun 2026 23:04:15 -0700 (PDT) Received: from redhat.com (IGLD-80-230-85-71.inter.net.il. [80.230.85.71]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f351ac0sm135110395f8f.27.2026.06.10.23.04.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2026 23:04:14 -0700 (PDT) Date: Thu, 11 Jun 2026 02:04:11 -0400 From: "Michael S. Tsirkin" To: Xuan Zhuo Cc: Xiang Mei , andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, minhquangbui99@gmail.com, bestswngs@gmail.com, jasowang@redhat.com, eperezma@redhat.com Subject: Re: [PATCH net v2 2/2] virtio-net: harden page_to_skb() big-packet frag loop Message-ID: <20260611015712-mutt-send-email-mst@kernel.org> References: <20260610232936.1176094-1-xmei5@asu.edu> <20260610232936.1176094-2-xmei5@asu.edu> <1781144329.8069873-2-xuanzhuo@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1781144329.8069873-2-xuanzhuo@linux.alibaba.com> On Thu, Jun 11, 2026 at 10:18:49AM +0800, Xuan Zhuo wrote: > On Wed, 10 Jun 2026 16:29:36 -0700, Xiang Mei 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. i don't get it, and then what? > > > > 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. I will be frank, I'm never sure where the confidential computing guys draw the line. Are speculative things of concern, for example? > > > > Signed-off-by: Xiang Mei > > --- > > 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) { don't see why we would check page > > unsigned int frag_size = min((unsigned)PAGE_SIZE - offset, len); > > + > > + if (unlikely(skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS)) > > + break; so do we want BUG_ON here maybe? > > skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, offset, > > frag_size, truesize); > > len -= frag_size; > > -- > > 2.43.0 > >