From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E0CE286D5E for ; Tue, 16 Jun 2026 04:28:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781584128; cv=none; b=QMHEwzDlv4ZpBP7SXk5mwIYWYEKyMBDdsP//7I9IepG2+0yHGHdfyQKJp5gpYK6OaV08OxPHILoD9sbbQeQtrHfv1oLw07pH9ByfXYuRJqXfdb+Tc3tRQJFM0BKlcBz8o22a+6nSYvRMBQ7HpOeDiTffKG3abDDE6jjvZG1Opcs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781584128; c=relaxed/simple; bh=iSnCoy0wOHnjTetJKmG/nh8R5MUt1SEexf5yDRqPPro=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Ax9MpSQzoLBzO4LCvmUZB9ATckkz2sYhW2DsVI/BoanuIQ8DFX2aaPlvmB6cmti1DpE38qZUeg04vq5gLbCclv0p6s4NwyJgsPpVxA8IGrj4q/v2mU7oks2ySkGHgzs1464lW5npQA4Ynhp3PddaFgD/DOWGAZzYrIyV8dsOGDU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=asu.edu; spf=pass smtp.mailfrom=asu.edu; dkim=pass (2048-bit key) header.d=asu.edu header.i=@asu.edu header.b=EIFJnLpT; arc=none smtp.client-ip=209.85.216.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=asu.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=asu.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=asu.edu header.i=@asu.edu header.b="EIFJnLpT" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-36baeec21dcso2578339a91.3 for ; Mon, 15 Jun 2026 21:28:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asu.edu; s=google; t=1781584126; x=1782188926; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+s4R842SAMDVeGmCPYwOESmnuBNOdgsUtTVh5NI/emg=; b=EIFJnLpTZBCcq5alsJF8JAYyScIc9SkIQbZk9cXvZWk/SCcoO9iTmvQ/UOLGbnozW7 d/HXS9CSqJSUjddGGC/mpvzYZPG6qWWsY7Jn72piEEmGoEkNVE3p8RUf9578wIWl1yc6 737nsA36nMm4NaoqmEES5EJF9H5/IaDCXWCxlWIOiqeYhrJlzuPp2PAjJGGGRXTJTrSq 9bUi6slKn5yNo7fmnHyBBN8L9zBM2OTMRXCfVhkSlZ9eNQv56ibc1HerLc/SZKFNfJNA aU8gcEepmH8/1REt3qBdBVGLZZR+FUHMq415ed6KhlDzCyjudCQxGsao95Hd/MztMWtV Upww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781584126; x=1782188926; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+s4R842SAMDVeGmCPYwOESmnuBNOdgsUtTVh5NI/emg=; b=Pakw2p89IeghiSIajnuAfyMiIKhdRA2gJVqFVEMOGL+UNG0fI/k2tsBZHmt0epbVCk 5JQdLMknhIJd2Ie0kSk3AkQ3cPlj4u49epE4KFEYO5JlgRx0Sq46ZHg7eoS5rD0VyZa4 Y9wJ9fDQeacleJyxuE+vQr7sQLlNwdfzxvor0xrcXyJgnbAIuhIt2JzU5tfL0WtTBza6 m0Bvnd69x7H4VKdHm38HM+sz1YYq4OmluKaCGC1Zo6C2NHvheblJ4v4j9ZR6Km3TDbj3 oSmMkyD2ahmjkViqQg4g20xCb9jV6GqNXnLpygBc6e/LAh32ZVPKrwvfmEccmhlXRFho taMg== X-Forwarded-Encrypted: i=1; AFNElJ9X4USizkFRudKZjYSnolJH7tcd9+vjk7wkXnFe3D97IHExEeFI7rhCqp8ygpDuMqthC2I4p27gr8xI9xA=@vger.kernel.org X-Gm-Message-State: AOJu0YwV+aSxqSJxCr9q4uEOYnGzrogvStD9NDl9jsxVQpalixtba6Oj Hh4EHFtSvTRZFdDw8Sc/9v3ij2/LymxhHI31SWMcM7XL1xsV/IrGjQJSxVDAkJtyjg== X-Gm-Gg: Acq92OHnRktIWyeC+wA2B40NpJ3/PxKHYRswWEURbKM1CpnJ+28z+axKjMCPbdOO4mh LAlaOFmJRoG36qORQZmTIfvrg0NzukfKcKzfZ8qVUGPd61n7vFigbSrRaMv9MSUvojYBkUs9zOS FSvDXSjxqXZG56T96endTe4SQaK2gyN2xJ0fOc1tvoRWUpekZg95MU/lr2U2QIrhzccxLtQED9X 56Ail54l05ab7QX+EK6z+9yOItqrfIc66f3VYjS/WA4kk7jPyZzMUwTsqoT03Habx/GAMfKh7WK VVIKBV+fo4tc2qWZr3p0rsZBFIU8PStLHHu7rVTOdjByE239yX2WUvtEEdK+QsxxDlVxuwgE2Mw xsCnQK6jPGqXKn6I4FHIOWxkuMyty3zmpw6L9yueVHeQoPsMCfpBbcaFoWMvI9+m8A3vDI9wYFp 7eS8le X-Received: by 2002:a17:90b:58c4:b0:35b:9894:f6f9 with SMTP id 98e67ed59e1d1-37a040adfbbmr17185832a91.18.1781584125653; Mon, 15 Jun 2026 21:28:45 -0700 (PDT) Received: from p1.. ([73.140.210.38]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-37c5208fd0fsm1244221a91.0.2026.06.15.21.28.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2026 21:28:45 -0700 (PDT) From: Xiang Mei To: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com Cc: 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, Xiang Mei Subject: [PATCH net v4] virtio-net: fix len check in receive_big() Date: Mon, 15 Jun 2026 21:28:37 -0700 Message-ID: <20260616042837.2249468-1-xmei5@asu.edu> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- v4: use easy to understand math to compute the max_len v3: revoke 2/2 and add Xuan Zhuo's Reviewed-by tag 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