Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3512572pxf; Mon, 15 Mar 2021 11:11:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBLJasssP6Kh7gxjaZqeK5l1YVSDEwMFrlDZVO/vxfCJqcAvVKJ+KgJnLFDEIwZibobKgE X-Received: by 2002:a05:6402:30b9:: with SMTP id df25mr32020479edb.136.1615831876105; Mon, 15 Mar 2021 11:11:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615831876; cv=none; d=google.com; s=arc-20160816; b=MnE6E0OfmWb86CsiDCXsXJEmnQLIuC/8iAjRPWuzD/XxtKKWmFW4nQnhKSQQ/mfw+I u225AJLucWHm7FakgBztcPxpmX6Q++rNq4Tn462Usp/1HyOxm/6XpUHE1wnqbKu6Flna PWlbBBZTF/CnM7jiUG1pu3O1VKXuHj46UrIiH+iIw6jD2lGaO5edI2JiItKqWHuJgvAM AvdKcs6iNd6iQDHjGci/uIEQ3pUmmdnpjTIKztHQkVSzr2PJ6Ht5510ps8fw6FgxwK7V LfrgZ6X3ZjbcNX88XmAFAjHI00yOCCdi6Ki6w+PAclkWv6mog/TjvHERu8fcLSJa9JMV 425w== 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=B6BAFGRZS7HVW7BhbNGf5shr8WSwjCt0EU+31lQBsJ0=; b=M+fMl4SzoUWiljucPzYGRbTzs71nQY6w70KpFCITtTWqy/mtIRWilysboYTARZasbo N1HFLtDmpNpvA126wiActcVnWwLfrllK5XGBwdfubh8Rug9QiPKK4UfoAeKZLy07uLgI yQHFqqpGQ5ZlkXVSY0SPNTblZ5gu3hISF3JU+wGsKL48yPYHgujhjI3vl8Ua6YbY43O/ wo69BtUsEvoy5KdBuHham4KF0Cl9yOqQtAv5i76CF6JlN8KcPtIwsq0gaPPHI1Opg1ee eC9LcIPxmC+fFCoTc/yd7kM7uiw836UpLJSlg9Pf+yhldaZKhSbyy143dhG/5BHZpcQc /rKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tdYdy8wT; 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 k7si11348085ejs.165.2021.03.15.11.10.46; Mon, 15 Mar 2021 11:11:16 -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=tdYdy8wT; 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 S235812AbhCOOLE (ORCPT + 99 others); Mon, 15 Mar 2021 10:11:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:36764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232300AbhCON6W (ORCPT ); Mon, 15 Mar 2021 09:58:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C926664DAD; Mon, 15 Mar 2021 13:58:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816700; bh=pSzsIv9mKbzUyVoUYhlP3NM70+Th+OOODsvNRQ5HNhs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tdYdy8wT3GCiIkin5iw2XKkH2RNkklxHqKtOzFKuGcxDM9ghykmL60wQ6nlwJ0dVJ DBLjw2LWFqAc/stXTi8ze0CWwleNRV+RURX5VBUhgCTPLJlKAHXhXm9skZ75MAevc/ EsU+ojJWAdTmA7IbtpNtyevMfhNEMQrXNgoBoxNs= 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 4.14 06/95] net: check if protocol extracted by virtio_net_hdr_set_proto is correct Date: Mon, 15 Mar 2021 14:56:36 +0100 Message-Id: <20210315135740.476968410@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135740.245494252@linuxfoundation.org> References: <20210315135740.245494252@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 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(skb, &keys, 0)) { /* UFO does not specify ipv4 or 6: try both */