Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4920680imc; Mon, 25 Feb 2019 13:40:12 -0800 (PST) X-Google-Smtp-Source: AHgI3IaVlCBIQKZNMjw7caF3H/LUBC5dwM/FssYUjfrvHIi3FX7KPnkFcEkWar4umcql23C8aPfs X-Received: by 2002:a17:902:8a91:: with SMTP id p17mr22517602plo.316.1551130812761; Mon, 25 Feb 2019 13:40:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551130812; cv=none; d=google.com; s=arc-20160816; b=F8PXrEQ6k8aCrCT/wFn6QfuHDSTsGx0KjhftzObxqfD8Zedh7OD1d1xdpzyV9PVoKe EatX2oxMSmP8z+SAjSo0MWU94Cmi9Hc4punT1WsM4zQ5MZYDPlisHH+2qiGOx805pYgr dteMCFYg32YptVlleI/TUtdF89s6WKyRXECrDNw2MF2DjflDXHLZUR/PTiFwrw6su62e tlP419afCvvnXUU9DsGq3MtGDZGgt9EZqdR8tWr9Q5ZyJOZr9LY/97gSrWF7APEY5PjE FHvAw1fAN3wRnAiuo2/s07v7A6oXOIx3d/tODiXUdjqewzhI0T8o2D39NfpqcFMJxXUa 1WCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=N2lAotXFCq2TkQN/IxZn+ivJghcvVJrVFGncbe/NOGM=; b=F4HeHdt5saee+iMIaaZKQoHjgcEVDxUC1tMCRaqX3K0FxRonmCkJ8CcmYojPtwdPBU PBTLbk9qANibWTmhWGeMurq4EfqBD0kN1RIYHOeniXk/OFD91Dc4nlSjJSTYGbDMxniC eW+QxwfrqNhkKtEennzMG0sE7+pBYbwpXbPvT0IPsQBY+DiImTVa7TxDCU44IBCWYqky SwaE+VWIFAZCBjPviJXQ0ZlM9oSMq10Dd2ahakrRDfUB+0dkVGoJ7NeBsFMhv5ZzI7o2 mPSjb3M2HvloFyTZouKRpGVPYMmPcJTElPny4KZyjA3zwWRfpn90X7cf/Mg3kr0UzhrB DdNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Be+BvCch; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 130si10974057pfy.262.2019.02.25.13.39.57; Mon, 25 Feb 2019 13:40:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Be+BvCch; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733201AbfBYVgg (ORCPT + 99 others); Mon, 25 Feb 2019 16:36:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:43612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732760AbfBYVgd (ORCPT ); Mon, 25 Feb 2019 16:36:33 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8B1902184E; Mon, 25 Feb 2019 21:36:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551130593; bh=pbuCiey77CUQhBpIiKiSp3qhd6AHi7qSX8Y42FI1hGc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Be+BvCchRXMPrN4l95SJuM3JESIHDmKWeVG66DLTIRDHJG1c7pHZ54y1/aBCxmPz4 Yel8e5qA9SfF8n4XhITcPtGfqDOWLLqn8ZA5Xp/x9r94c9ZlU/36FEXIE6Tv3+SULH bEBZGUfGGyceEs/Us8/2MpRTSf5VvLd+/premXzE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Willem de Bruijn , "David S. Miller" Subject: [PATCH 4.20 169/183] net: avoid false positives in untrusted gso validation Date: Mon, 25 Feb 2019 22:12:22 +0100 Message-Id: <20190225195123.648041193@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190225195054.748060397@linuxfoundation.org> References: <20190225195054.748060397@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Willem de Bruijn commit 9e8db5913264d3967b93c765a6a9e464d9c473db upstream. GSO packets with vnet_hdr must conform to a small set of gso_types. The below commit uses flow dissection to drop packets that do not. But it has false positives when the skb is not fully initialized. Dissection needs skb->protocol and skb->network_header. Infer skb->protocol from gso_type as the two must agree. SKB_GSO_UDP can use both ipv4 and ipv6, so try both. Exclude callers for which network header offset is not known. Fixes: d5be7f632bad ("net: validate untrusted gso packets without csum offload") Signed-off-by: Willem de Bruijn Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/linux/virtio_net.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) --- a/include/linux/virtio_net.h +++ b/include/linux/virtio_net.h @@ -61,10 +61,20 @@ static inline int virtio_net_hdr_to_skb( /* gso packets without NEEDS_CSUM do not set transport_offset. * probe and drop if does not match one of the above types. */ - if (gso_type) { + if (gso_type && skb->network_header) { + if (!skb->protocol) + virtio_net_hdr_set_proto(skb, hdr); +retry: skb_probe_transport_header(skb, -1); - if (!skb_transport_header_was_set(skb)) + if (!skb_transport_header_was_set(skb)) { + /* UFO does not specify ipv4 or 6: try both */ + if (gso_type & SKB_GSO_UDP && + skb->protocol == htons(ETH_P_IP)) { + skb->protocol = htons(ETH_P_IPV6); + goto retry; + } return -EINVAL; + } } }