Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp624925pxv; Thu, 15 Jul 2021 11:51:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw39kpdE5XfcCEa0tYX31tNoFLMMql1MEGp4hpHbOJKW5BGZ63dgn6wNraBmKHOE9TvdOf5 X-Received: by 2002:a05:6602:3404:: with SMTP id n4mr4307022ioz.19.1626375061938; Thu, 15 Jul 2021 11:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626375061; cv=none; d=google.com; s=arc-20160816; b=l9IGZy9TVpHUopS3/i9WStNPUlHs0VgPVHPPaT+2ZBJyN0pMOBAX0uPmb+x3jf0X8V rjqrlIPvC1knXkPqMWOWmPLHMhSFb7+5bPb/G3HaMP2sn7AJJZNn2ZjUZm+JhdZGcxOj I97Vo1Ti5o5TP4B3vfU65VzjT9iaK05WyCMdH/+6TNUrrCcth0BFvW4uMYJZxPh7CWvr YAnNcvZ9DpHu2GBUihDUZhfEdZnxTYZMjTN5EP/A5Satibt3fK+hfBSYrxaSAk1TVr5L I4pQDgHCm44Z1PK3Uao0HxCUiZ6fQqZ8vuGKZW7IdM5N0/JN5ciQRreX/vHol52kkmch SDGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tuY/7WIEktN/MzfRQEJsvUpJH1x8yKelUBdhcu0HlRM=; b=aLwvKZOAxcWKb7j8SSp+rpGzbwH6xYGKL6JZWRFTVwPVggpFJqMfFmozA5he1udKjV /m/rmv9dTAMh5jlm9zeKcxEtXB+vCYRWsVwNATubJb69bvtWMWP5V7CVI6wHSwqXrfsd JVL/3HqQ/Bsimq6iNl87W0HTBUaiLvSuWlrEwUZDhCgYL9f0a/kbx+QmLnc0ULnJV/0x YUpfUwwqUK7a+g4658UxL+JgIfbYiCOUqDLVZreGGGL720j7OW3bAAYoCFGUcGHae3MX LPs1kpMLbfZvRRFcqNg++XKKwwAUyzd9EpD7sDRrZmbuzH5+6Pnas6yNRAmY7aOVaan+ gx4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="BA63X/s0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y15si6482080ilv.136.2021.07.15.11.50.49; Thu, 15 Jul 2021 11:51:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="BA63X/s0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239147AbhGOSxO (ORCPT + 99 others); Thu, 15 Jul 2021 14:53:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:52636 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237240AbhGOSuC (ORCPT ); Thu, 15 Jul 2021 14:50:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8A429613E0; Thu, 15 Jul 2021 18:47:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626374829; bh=NX1TIJWaTV/AjJIqmKifqpT9XXRB1KbOKzYJANsPTK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BA63X/s0ykfSXvMRTqJkrnxLbZSrr1r+pRcU+TlWdADQhACGPadorfeG6ZdL752v/ rLrL6HOn5sy/f0YCCgn28Dc8O01VXzHEIhpJQ4i36mrFbs50Ra6MNL1DxXJk5IvRTw fh+qoOAuY1p2yRKhaa8eQ3CXptTNp0GYm6bazifg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xie Yongji , Jason Wang , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10 043/215] virtio-net: Add validation for used length Date: Thu, 15 Jul 2021 20:36:55 +0200 Message-Id: <20210715182606.961244649@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182558.381078833@linuxfoundation.org> References: <20210715182558.381078833@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xie Yongji [ Upstream commit ad993a95c508417acdeb15244109e009e50d8758 ] This adds validation for used length (might come from an untrusted device) to avoid data corruption or loss. Signed-off-by: Xie Yongji Acked-by: Jason Wang Link: https://lore.kernel.org/r/20210531135852.113-1-xieyongji@bytedance.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/virtio_net.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 286f836a53bf..e2c6c5675ec6 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -660,6 +660,12 @@ static struct sk_buff *receive_small(struct net_device *dev, len -= vi->hdr_len; stats->bytes += len; + if (unlikely(len > GOOD_PACKET_LEN)) { + pr_debug("%s: rx error: len %u exceeds max size %d\n", + dev->name, len, GOOD_PACKET_LEN); + dev->stats.rx_length_errors++; + goto err_len; + } rcu_read_lock(); xdp_prog = rcu_dereference(rq->xdp_prog); if (xdp_prog) { @@ -763,6 +769,7 @@ err: err_xdp: rcu_read_unlock(); stats->xdp_drops++; +err_len: stats->drops++; put_page(page); xdp_xmit: @@ -816,6 +823,12 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, head_skb = NULL; stats->bytes += len - vi->hdr_len; + if (unlikely(len > truesize)) { + pr_debug("%s: rx error: len %u exceeds truesize %lu\n", + dev->name, len, (unsigned long)ctx); + dev->stats.rx_length_errors++; + goto err_skb; + } rcu_read_lock(); xdp_prog = rcu_dereference(rq->xdp_prog); if (xdp_prog) { @@ -943,13 +956,6 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, } rcu_read_unlock(); - if (unlikely(len > truesize)) { - pr_debug("%s: rx error: len %u exceeds truesize %lu\n", - dev->name, len, (unsigned long)ctx); - dev->stats.rx_length_errors++; - goto err_skb; - } - head_skb = page_to_skb(vi, rq, page, offset, len, truesize, !xdp_prog, metasize); curr_skb = head_skb; -- 2.30.2