Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3319412pxf; Mon, 15 Mar 2021 07:04:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwe+JWi2+MGOCGsGBbzgJCIvP2vxVea8ZZdZzUqvOlaKFWul0zW7mskldpBzIg5QetjQa21 X-Received: by 2002:aa7:db15:: with SMTP id t21mr30196360eds.145.1615817069059; Mon, 15 Mar 2021 07:04:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615817069; cv=none; d=google.com; s=arc-20160816; b=cYJndDTbdKHQCT+k+tllbHaBON5H7hx/EtNU5RPVCRFCYahD3SYncRXq3ITxpCU28F gpHj+45NspsqijmnkRkJXN1/1WF18pYBTcPpuJ7NIn25ZShf6BXzEvem/qcCERbGcrSH EbEoHiwYPeUOBXVUakaQPpve2/SMNmInai8bB9W3A0SMK97Gj9SF+ATxJEC60u3sIAjC KfjMbSOsOqmbbjuGzDGAc9sgMsXZWFh1yiVvcy0vSn/1gdRZ76F/iaa+VDM4TOX2nnNM WiOX6FTJaVPPUdpiIhwBc+0mJ7yd5pxA1v5zL2vxpcYJuyhR/9BlscKB3hMIjC0eibjc 8dZw== 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=j/VuWRiDSQizyzQZMVVmllWDew/g84C+2jZu1/PrVhM=; b=Ta7J12XJke1NauEoRQbzVwLTUaFb3jwDmQRFIebpLaqgGF6uCNA27vCRu8NDegll8z Zw5ko3vHPYXrQf19cmFh0nV6rsoe4ZBeWG3Tl78cyp3tkBBm+dN5vwd5goxYVKsLWU6z yOp2yj0/zL/7fsDnzbeCWLcp08LswA4grrBy+k8f0WANtBi8ZKDNqdKRTWrN3s5S02ql U+0tH/anpiIFn5uKixjhvGQ6qEwAErRHnhHyR3XwHQd/96Pi+mX9FlehSG8kj+dnuj5s 7WUzKdTfauvdBXN/olf6j66ELkmoEjJXfEQeuv7im+ZtsTdWj1v1WyBwERorPkIfMA9f GMEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="c4/eGxQF"; 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 e19si10677892ejj.523.2021.03.15.07.04.05; Mon, 15 Mar 2021 07:04:29 -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="c4/eGxQF"; 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 S233451AbhCOOBl (ORCPT + 99 others); Mon, 15 Mar 2021 10:01:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:33312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230145AbhCON4o (ORCPT ); Mon, 15 Mar 2021 09:56:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 17B3664F01; Mon, 15 Mar 2021 13:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816604; bh=mvbavpRwyDZocyv8ldOUoDiqHwnZizG1ECvHExjijLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c4/eGxQFHtGvMcwdBcn/RF4aaK1ZDNbRhDb9PwnDTj6m0GhIbhWwIOGbTq61nU5Pd Mqkw5H5SFd0y/tCnrEkWpDp27B3Zj2oXZpmnm8tiU7/aR13tGC7onZEDko/GtX2xXZ TjQkN6ZfMGIk0TfZgsi1JNiIuPxAtfxeNA/L4bog= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Balazs Nemeth , Willem de Bruijn , "David S. Miller" Subject: [PATCH 5.10 008/290] net: check if protocol extracted by virtio_net_hdr_set_proto is correct Date: Mon, 15 Mar 2021 14:51:41 +0100 Message-Id: <20210315135542.220384976@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@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: Greg Kroah-Hartman From: Balazs Nemeth commit 924a9bc362a5223cd448ca08c3dde21235adc310 upstream. For gso packets, virtio_net_hdr_set_proto sets the protocol (if it isn't set) based on the type in the virtio net hdr, but the skb could contain anything since it could come from packet_snd through a raw socket. If there is a mismatch between what virtio_net_hdr_set_proto sets and the actual protocol, then the skb could be handled incorrectly later on. An example where this poses an issue is with the subsequent call to skb_flow_dissect_flow_keys_basic which relies on skb->protocol being set correctly. A specially crafted packet could fool skb_flow_dissect_flow_keys_basic preventing EINVAL to be returned. Avoid blindly trusting the information provided by the virtio net header by checking that the protocol in the packet actually matches the protocol set by virtio_net_hdr_set_proto. Note that since the protocol is only checked if skb->dev implements header_ops->parse_protocol, packets from devices without the implementation are not checked at this stage. Fixes: 9274124f023b ("net: stricter validation of untrusted gso packets") Signed-off-by: Balazs Nemeth Acked-by: Willem de Bruijn Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/linux/virtio_net.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/include/linux/virtio_net.h +++ b/include/linux/virtio_net.h @@ -79,8 +79,13 @@ static inline int virtio_net_hdr_to_skb( if (gso_type && skb->network_header) { struct flow_keys_basic keys; - if (!skb->protocol) + if (!skb->protocol) { + __be16 protocol = dev_parse_header_protocol(skb); + virtio_net_hdr_set_proto(skb, hdr); + if (protocol && protocol != skb->protocol) + return -EINVAL; + } retry: if (!skb_flow_dissect_flow_keys_basic(NULL, skb, &keys, NULL, 0, 0, 0,