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 7908829C328 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=1781130118; cv=none; b=SBre86YciwAtQXb52EGwtBQeieOkMx8VeI/XRdNCVjMIciuZXJnGuB601utapxEcyJ6nKXraLoH6jfTz/H5E9ZC2eW7lSCQ/5enyKKn7KufPW/Ew6JUw2RmK/8MlQw60kMXj/lE+D1sznNCZeK0K1zHMtJ2U5IN4f1PbxZM8770= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781130118; 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=awgBaa+OxdE+UHXFLxUVN5+KajG7UiHKTd4czntdxxaR8imRxBt2uAksQ8DSIRAglTgWLFNEUpXN0wgsNzMgYBrHqqrCQnYplumr6goT3Uc1iuXYIAAQXVwSXNh/JGqkbiONiRUcSO5dW1eGkV/5kHZPtmQ3xBX25nShGSA0Kx0= 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-650-wrydmmV5OiyjknSrPYWIQA-1; Wed, 10 Jun 2026 18:21:55 -0400 X-MC-Unique: wrydmmV5OiyjknSrPYWIQA-1 X-Mimecast-MFC-AGG-ID: wrydmmV5OiyjknSrPYWIQA_1781130114 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-490b37e1f47so62681425e9.0 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=mHbnqMqQ7r2uNyFsTESDKVd/5AJggDD4VYDX33b/Kg1r7TVYTrfCmm2Qba5caHGYsx pM2GNnTJTRKhyMSiNMmKwOJQQRIEek6TZRZ3LpoFYXMK14DXltZRxLyc+IEJNCX7TUB6 t7DFF/IyCc7UufswzgRWexc4jjk+ZIkUdZ/zvpzzstdZPHECaEwlxxOgnSW+q37n7o/q 47dV+j58R5H/1vtK/wUDGM6xu7qP3P9cZLLJf1fVuxIQiIj87t9laRrlxmMyL1q4M4WO 3UXOZYicHvIpOCn3HFaZ3BrXJFIQ8il7FhgjMJLxogFA6BWfGxXvgtPEIFfNHTdfrors PkZA== X-Forwarded-Encrypted: i=1; AFNElJ9ShFuVheJ+oNVeZbYpbp/gcXgHoCDJrVKBIQTaoHqr1Up5SeFlAcRbDHSxgV10m8W9S54HQw0=@vger.kernel.org X-Gm-Message-State: AOJu0YyKFc5AgCSBMbqI446lqWkxOhOnrrobJqG6Rrvhs28+YARqoKRU u7GeMJwtGhEf1a37y3gKyj0USz+f9RKKuTOWtblCsmnkvNjOi+e5FTwiTunRWHHC36ZDZ9FJ/Hu pYtjaWNkXvrfjjei/lmlu7VQY2LtttxRojqtBO0AlwlV1QZsukQO/lgEoUw== X-Gm-Gg: Acq92OHGPxZOU/3YQ1WL0GP5E4W905lpC9MOA+5rttNJmeUQHG1U4TbpPpmVKnpWwSW 8He2HcVHeP+oqHcYXCWMLKaeVYwJCGFUh9c2f6uCgYzF4DYy2s1b9P5F8Zgazt1piLFNa7XRARQ cUqKIax27abkhs2TNqnrJehtaafpEBIVVJTrO2+tAK+Ep7ViMHejPt6oqBdEF+Xna7UNDQaA8Z/ TNWlHbFHdbPxpkxZNpwg8t0E0MVwR6jDYQMRNAhKIg1Bw0CLwDN2G94pD922fP2B89zs+2YCKjI 8ZZFEB6m62lQ8/3BoMZiWEJykighcOGTMy9JK92QC38vfI5Dbu6NuFVPUHGX+X/ykItiN1aayhU i0ZU0ZO+lhZkJwyjQdsYnVzKWsmoIG4kMY3nVCTJMKbpAQhV5KsikPQ== X-Received: by 2002:a05:600c:6087:b0:48a:8b02:ae91 with SMTP id 5b1f17b1804b1-490c25b0231mr459511025e9.11.1781130114013; 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: netdev@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