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 7D046282F1A for ; Tue, 16 Jun 2026 04:40:07 +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=1781584808; cv=none; b=f9X7oF/wmtzFjvAExbG/z02KaTL0cA/raPYangvd1SeINf1yGMyD+ZGR32yAKqGDGWE3m24keanPYmLGpW6r0e/frklFb+XoawGQxrxauEMuHQJVhDdXeFqOmmX4w/XLqdmgy681/7LzM+9ZD9jE3VHGWHLkEVDvFRNWO3W+Qz0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781584808; c=relaxed/simple; bh=K0KBXkkerxODXYIYqDg633MvdlbzP4uKtATH407a6no=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tpfDFrpuo/SQH+WlgH5qi9gw+1RWQJ/UXQw8+Zo7Nr67k5VTRcAztj6Qo4FsTfXm7aFwoS4hZUhCv7eII/xUPpSRmCTp/SGeQ/7VNzGNxjyDCBKXvOb/+dAGQhDgTHgeMpITIh16oIoo0bQViXNFBvkXasCdlCnHpbT5dJfTvtw= 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=adEh8vTW; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=tghicQev; 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="adEh8vTW"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="tghicQev" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781584806; 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=Fa+y+4svYLao6WVKf5RjVtNUrFzhHWJGrO40meUSAic=; b=adEh8vTWHQ6tTp7RWjgsNgt8iVkp7bWttAuD2lRlK1YAU3q47DKMM++SN4p/53BScyIREX 90cDTTQi1uGH+NKZMV6QhGaV0MGX1XGJwf3WVH7HW0fBu6z+Gteu/HnUapSTb9uk3J+llI xOP7o1fWS19nPV7CGiOATrhOD3h5pk4= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-151-SrhKzwG4NJqfv9klkZvgWg-1; Tue, 16 Jun 2026 00:40:04 -0400 X-MC-Unique: SrhKzwG4NJqfv9klkZvgWg-1 X-Mimecast-MFC-AGG-ID: SrhKzwG4NJqfv9klkZvgWg_1781584804 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-490ae0167ceso20813865e9.1 for ; Mon, 15 Jun 2026 21:40:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1781584804; x=1782189604; 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=Fa+y+4svYLao6WVKf5RjVtNUrFzhHWJGrO40meUSAic=; b=tghicQevZwa8a6gK49qTwBiyiLQjaBBx7ClfpZFyOHxTBoMSfQHu5w7h4RGvqhtYFM kQO9PYeUMmWqsWTLECQwTsC6Nd8Zpcwa/oHDTCiWvdTuaYA/h69fNKN1EWc75vJVhnUb auoB3kpP5F2HIVl/umEeI4cYbX3df9RFZMgn0AWtAx/3oVwYf2Euzni8yM/uNaPSOWJl 6MJFrn6lqhMVKQU++Ksbga8sDaUJ6/iWjS9gFVvdV47KE1OKNObXWtevriO9aqdum19H 2duFEqEfBQPs7sJH4mT7GbwlXbKtehPt6rt0RQTOzmoMpk4yLeKojcykKXIrLt6mUxAG hFrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781584804; x=1782189604; 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=Fa+y+4svYLao6WVKf5RjVtNUrFzhHWJGrO40meUSAic=; b=g4zjOQ7xhrt+uDwuk0po3YgeKiBxqlTSxEMJJdRI3AkXce8ayQMvc8hUF2jJMARPhf DER9s33l2ilL2PXfT57ESsngwsBx3gECfTrnyEs4LyIqqAUAWw42TSvv8hXb9UcV0zSH R/oeteeh9pFy20olAgdDPG4tMsEzmwsc55m0E6tH5dwf4W+zi/rQpSF3spMQXNK81G6O KXaP3DeAtcQ0IRE4/3xTeeDpoIIU93Dg/L1yOe36Xj03dvdG37kBiHTlTdDJD4w2lDsD X0iWzrlBAwLuHmPLjCc51q4KNO4TNEOhIE+Y79/kQcYFATSb2TKUEzGcu/HOYhB0Ajdf mF+A== X-Forwarded-Encrypted: i=1; AFNElJ/zYn44n/vBXU9bZhNKA09uP/rDdb3+A72T6nSZRTbOme/S4sjAbPXZEDl08fV4MDjBLAFhOUOolLRwgno=@vger.kernel.org X-Gm-Message-State: AOJu0YzgRrhBqxyWF9wD08lXFtPPt0o1jQvj/P8xGxcbdkGgpmCeMs9Z 7Z8FMsYNzEBPVvWBQlMyo6etI+WSlV9TGthKjxl2AWkGcnTDW25Hqzz8gPmY0QGIJadLkjqrdAN kYfBz8gD0yN+fVn8aY/NGgba2L/QL++U0EjzJBkPxiXi0dYdqjOWA6GsTvLQg2s1pIQ== X-Gm-Gg: Acq92OFxuBI1r2YX5/nO9UT6EojQc6VqUfU9u3aToGC9Wfi+0Pqm7c4Q6coORs7euL8 B0qOwW8m7ByXzt4ZoKZDzhy+i44Iy7m1ngI6Qm1INK3pqnFfhfiAJw6+D7KfOy7JxSHciNNHRYt hsxLSd1F50Q7/K3LMZZjeAAoFjnLfa+JLro00QB1yy6bGUURVJuSFXGblTFysx2F2qNbSsbJCyx faa0W0FMbttYFXajNLTvo6HhLGovkNyK8YyBAveDMFMVaO/4wv2WM1UR2CiihVBRojGLNRVl3iU mBlOJQjnObXMX824nLkncwYWAG9lYhqs/UCtthnKz/53cyQnP2/6TEGcJ8tD9DbLJKQ08PLDFoj XibsHahzEsTluMu6fY0862kjIYX531mhR+VJ7VGdBI8c= X-Received: by 2002:a05:600c:4e8c:b0:492:3173:b17 with SMTP id 5b1f17b1804b1-49231730dafmr4650655e9.17.1781584803461; Mon, 15 Jun 2026 21:40:03 -0700 (PDT) X-Received: by 2002:a05:600c:4e8c:b0:492:3173:b17 with SMTP id 5b1f17b1804b1-49231730dafmr4650265e9.17.1781584802949; Mon, 15 Jun 2026 21:40:02 -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 5b1f17b1804b1-49230a4ff67sm23740805e9.6.2026.06.15.21.40.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2026 21:40:01 -0700 (PDT) Date: Tue, 16 Jun 2026 00:39:58 -0400 From: "Michael S. Tsirkin" To: Xiang Mei Cc: jasowang@redhat.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, 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 Subject: Re: [PATCH net v4] virtio-net: fix len check in receive_big() Message-ID: <20260616003903-mutt-send-email-mst@kernel.org> References: <20260616042837.2249468-1-xmei5@asu.edu> 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: <20260616042837.2249468-1-xmei5@asu.edu> On Mon, Jun 15, 2026 at 09:28:37PM -0700, Xiang Mei wrote: > receive_big() bounds the device-announced length by > (big_packets_num_skbfrags + 1) * PAGE_SIZE. That is still too loose: > add_recvbuf_big() sets sg[1] to start at offset > sizeof(struct padded_vnet_hdr) into the first page, so the chain > actually carries hdr_len + (PAGE_SIZE - sizeof(padded_vnet_hdr)) + > big_packets_num_skbfrags * PAGE_SIZE bytes -- 20 bytes less than the > check allows for the common hdr_len == 12 case. > > A malicious virtio backend can announce a len in that gap. page_to_skb() > then walks one frag past the page chain, storing a NULL page->private > into skb_shinfo()->frags[MAX_SKB_FRAGS], which is both an out-of-bounds > write past the static frag array and a NULL frag handed up the rx path. > > Bound len by the size add_recvbuf_big() actually advertised. > > Fixes: 0c716703965f ("virtio-net: fix received length check in big packets") > Reported-by: Weiming Shi > Signed-off-by: Xiang Mei > Reviewed-by: Xuan Zhuo Acked-by: Michael S. Tsirkin > --- > v4: use easy to understand math to compute the max_len > v3: revoke 2/2 and add Xuan Zhuo's Reviewed-by tag I still feel 2/2 is good defence in depth but it can be pursued separately. > v2: add additiona check as 2/2 > > drivers/net/virtio_net.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index f4adcfee7a80..8f4562316aaa 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c > @@ -1999,15 +1999,16 @@ static struct sk_buff *receive_big(struct net_device *dev, > struct virtnet_rq_stats *stats) > { > struct page *page = buf; > + unsigned long max_len = (vi->big_packets_num_skbfrags + 1) * PAGE_SIZE - > + sizeof(struct padded_vnet_hdr) + vi->hdr_len; > struct sk_buff *skb; > > /* Make sure that len does not exceed the size allocated in > * add_recvbuf_big. > */ > - if (unlikely(len > (vi->big_packets_num_skbfrags + 1) * PAGE_SIZE)) { > + if (unlikely(len > max_len)) { > pr_debug("%s: rx error: len %u exceeds allocated size %lu\n", > - dev->name, len, > - (vi->big_packets_num_skbfrags + 1) * PAGE_SIZE); > + dev->name, len, max_len); > goto err; > } > > -- > 2.43.0