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.133.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 7900B20C029 for ; Wed, 10 Jun 2026 22:21:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781130119; cv=none; b=Qy/1HbMSkbZkUNp9Iy8JMUgTyaihPJQi2jEpNCqhFttdDNYP4rtMKxQlmU1R9w7Zq3IYVLYG0XyVPQZPu7KgVRb+bOeRE194agHYbU3Oo9aHBYGHL7ff2JvOQxEdWPlvmGBdvD95vWns2CYFjxAG2sAfJgn9Bg4gOSkiiKVbzX0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781130119; c=relaxed/simple; bh=8u+7DTzELirNm6wHvKOIo1/nebvVCwekSoFgUO2K8oE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Eych8kuUdmFmgBpjix1G7g4vhFb0ml3F2RGcVDemeUAkt8v/ot1BT3mcdUy6xt9W43SP//Ir4o+QgSDqX3Y/PBNFhg6/nQKqeHIZFgfDyUKqYB73yLl9df4+fOfDbE9fF+dVZKuGZOuZj8UShv3hdG48vtawBQbKJWkGLv8OSTE= 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=BizEUZZW; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=rbvTSUjv; arc=none smtp.client-ip=170.10.133.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="BizEUZZW"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="rbvTSUjv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781130116; 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=3XNDDsRWPntbc74MBmHORM39yXNnRzhKg57vrlJiACo=; b=BizEUZZW/Rcskxt6Wjuchpilmg87ygJOlp313AnpYpuhCswnLPbIG5eGH/8Ke5HDZZtVot YD+u5t7IlqcTfmlQKECtAL9eFuW9JUTVdtVHrPDI0HJOlN1iZcwZpuArP0tTwUWCdAGUUd GoVAKDhnZRGU+WjrREMORLu0fQdAdZo= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-618-7q9dZZfyMFydhlY9fSwIoA-1; Wed, 10 Jun 2026 18:21:55 -0400 X-MC-Unique: 7q9dZZfyMFydhlY9fSwIoA-1 X-Mimecast-MFC-AGG-ID: 7q9dZZfyMFydhlY9fSwIoA_1781130114 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-490ae3bcf4cso34699305e9.3 for ; Wed, 10 Jun 2026 15:21:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1781130114; x=1781734914; 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=3XNDDsRWPntbc74MBmHORM39yXNnRzhKg57vrlJiACo=; b=rbvTSUjvYnOAR0mFeUoMPoI7GXInjhe1Zim9VhHOarHcqOKSrEpVsfv18zjJ00kCY8 nVzBYXeGqIr8na29+bVOTQ403aeW0wVaDWK9KkiNaSwbzJi3mJi6aBMcOA+X4vyptvG1 fOnxnxVVHxQazD060MxGo/tmZ+Y88zdfmtqGgZHF4kYT2jImTLDETn+DczmHJgQ+4ija dU+rqv7h9y0J10ygg5W51lVCU9JYaOwmG193ptAvMwg973K4BWZzPzui2FKM1TmaiEjs VRuB74skxYJsNHJiE/zRKqbhNXoT2psH0eidm5NjRrZ6DpV/PBJJvSw44oV9rknzhtBR Hb9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781130114; x=1781734914; 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=3XNDDsRWPntbc74MBmHORM39yXNnRzhKg57vrlJiACo=; b=i5vKoNUJ64Pac16fie76XUrvPVBxwq4oYHnV04mOzEV0ldXqrTf4XYdFhYF+uTTK4c cvbuNCQJr7rJPb3g2VQDm8J3NFKmFJJOBHXhtfYE6ZLcM1RaBlqc47TR+zQ60q6y9U1k bPc4cj0Fk1a6tVA62LBrOmj1EK3fXSUMdiHcVE7q1pbke62GGo60lcsOigSBRL+7vDkh qUCFZqUG42PQ5d9A1WepDEMUVwHSl7gJL1eM13h5XVYgvQzli1ICyN08TPl6V3cXhXde lu3Mq+w3T8p2hRfGSSeExhLB8skRH2d8lokKjOy5c6mxMS+eUHJNB3Q864b/be7vVLdV rzFA== X-Forwarded-Encrypted: i=1; AFNElJ/z9jqIZ3zHzzpwF/dPbXVn08CTXk/KaOhQd4tSE6bqccniKK4XBJWq4RiwOWykHZe2LydtWDK4uDtdMDg=@vger.kernel.org X-Gm-Message-State: AOJu0YwRsLLsr6PgO62HOdcwvg9KRy59LybhsQs+w14ak1GC3NQbiTcK DXY+lvOhP8+ZmNLJEfC8G+M0UHUCLfIVGJft/98d2alNfgaqGiH89eZ1IJ041yyMjZLFe+DoP07 m0DPerU+JWenMbnsPv+rG1Cy7dFCM5wdOuxLRv58ttcCZi9U59j2US3v3l/X6/BER2pyFinDrqg == X-Gm-Gg: Acq92OF0ZtCDkzMaBZXFI+dVu8XF6BlyiCy3G2LSI32CU2XvHzPKSWY/6lvxoL07KW8 21uvIwAqIxll2ThqVOGFYa8k4Gqxp1M9BbVc3HVN8BmhmqXy975MhZxlFQP/S4uQWZhxZud3uvK GpU9Q0csOVaUZHaPWYzgv5c14XcFE1ddYOolF0VM1QSnocgu3vyBFgI2oKLXHpj1Jo0phhNd/Pr ZQcmex2ggSUEtPUU/jANv4dG9FFvxnkmXrVcBeCcjIzUCvU5JK0BwMfdW33zqC+8le3T/yO+Tzu mWGlpbo6kd42YEksl+amjpCMSWz8K2MXZD3a4B8EhU4gfDi/1y5i6kWBTRaAdxzfyKvQ5LDo4/w IX++3W3L0HdKp5HAoxLvMckrJfR6D74KCvLXotm/ZwkdQogzZ5hu8sw== X-Received: by 2002:a05:600c:6087:b0:48a:8b02:ae91 with SMTP id 5b1f17b1804b1-490c25b0231mr459511055e9.11.1781130114017; Wed, 10 Jun 2026 15:21:54 -0700 (PDT) X-Received: by 2002:a05:600c:6087:b0:48a:8b02:ae91 with SMTP id 5b1f17b1804b1-490c25b0231mr459510675e9.11.1781130113557; Wed, 10 Jun 2026 15:21:53 -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-4601f0a43e9sm74431249f8f.0.2026.06.10.15.21.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2026 15:21:53 -0700 (PDT) Date: Wed, 10 Jun 2026 18:21:49 -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] virtio-net: fix len check in receive_big() Message-ID: <20260610181911-mutt-send-email-mst@kernel.org> References: <20260610221606.1091465-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: <20260610221606.1091465-1-xmei5@asu.edu> On Wed, Jun 10, 2026 at 03:16:06PM -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 Let's instead (or additionally?), bound the frags array index. Seems more robust. > --- > drivers/net/virtio_net.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index f4adcfee7a80..afe73eda1491 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c > @@ -1999,15 +1999,17 @@ static struct sk_buff *receive_big(struct net_device *dev, > struct virtnet_rq_stats *stats) > { > struct page *page = buf; > + unsigned long max_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)) { > + max_len = vi->hdr_len + (PAGE_SIZE - sizeof(struct padded_vnet_hdr)) + > + vi->big_packets_num_skbfrags * 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