Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp550880imp; Thu, 21 Feb 2019 06:41:33 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ+5BNFTMg2OoRPD8000V6A1t85UGpK57izEP2eCtqwmSjtT236vF4zL3BtILlNpHWBmXwR X-Received: by 2002:a63:5f0f:: with SMTP id t15mr34722789pgb.272.1550760093216; Thu, 21 Feb 2019 06:41:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550760093; cv=none; d=google.com; s=arc-20160816; b=Xauw+HBAymRtnDwIFdWdVlEmar0JwQeNHkj8tJIsOzMbyJOGcz4zaKV2jKJbQS1c39 ePNjUJCGu9TiIvHcIH58mz9wXuWXw0kdi8xPoesL7zERnbwNW05smgkMvcyLCcOiZrIE l1AzNISOLn+qcIdD40idUzqmMwXBaQVlQD6FR6z3RW5uzWFhPQY15bPESqA6E+ZVn9mz X8+XScWHgxUmjT7wU8pPfMwD5vB3/zdRPcOHxzZvGRdYyWdis4lt47PF8d+XqalllV6k 9jv8Qxx0ufK8WCeOQN0ffStz2Joj94awpa3cONyqeAJj8NrzqvSJHrt+1AMsGUXt3rIZ Gt1Q== 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=cTtRa/TctEGv2YEQ7E6kKb5f3WeiGG1/F1bWhAN0V28=; b=Ff9rGfJfYc7TK0hfXjyHxy/7ac3vdSUVgqZ53CCVwP4MqcaP60cYbbbMQmtaOxuDmc ThWeFWW4NHHeYlGoVhEqDdArdlyGgO7cTDO4xM7iG+/+wtJyYqg7QQIp9HlTzhhDhAj1 x0SOs7Bd7wR7HwgkhkycogBLiNjjA74/1fDP74ZuJMGnetRT8/yWPpxgx4hvNWdd3MF6 FuO77k/LD6cR31rvHNSLhfUJWeBVM0eiN8q509QqP5Ik/x4SZGjbTL3Bq5ak4IyUj66U A8wt64EZTddm935e26jv4O3EuSSHezfCFtbCBRqhEop9XfHaUP4DfbLjwEmlfmydsh5y GRCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ql+f3BP9; 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 cn17si2009929plb.139.2019.02.21.06.41.17; Thu, 21 Feb 2019 06:41:33 -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=ql+f3BP9; 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 S1729005AbfBUOjr (ORCPT + 99 others); Thu, 21 Feb 2019 09:39:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:33798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728391AbfBUOjn (ORCPT ); Thu, 21 Feb 2019 09:39:43 -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 21D442080D; Thu, 21 Feb 2019 14:39:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550759982; bh=w1e8K0lkPr1Bj0rgJNWEVcBeEkHpYEuI1XkQMVDODDA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ql+f3BP965D7OIburjjWX60hbYlMbJXuKfA5DrIg9EQQJZMIbVTWLCqKBqSXH4fp8 zgoylNqayBYHUoq3u8rOgVHe5wlZojai/1c/nrHF1zDlZkrDN+SHlxrXA8rqKEyuAM AOvZa3zB8mbWThs/lbQbKed0LgcgsWB+6rwgnxzc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Willem de Bruijn , Eric Dumazet , "David S. Miller" Subject: [PATCH 4.14 13/23] net: validate untrusted gso packets without csum offload Date: Thu, 21 Feb 2019 15:35:55 +0100 Message-Id: <20190221125247.314183752@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190221125246.162644302@linuxfoundation.org> References: <20190221125246.162644302@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Willem de Bruijn [ Upstream commit d5be7f632bad0f489879eed0ff4b99bd7fe0b74c ] Syzkaller again found a path to a kernel crash through bad gso input. By building an excessively large packet to cause an skb field to wrap. If VIRTIO_NET_HDR_F_NEEDS_CSUM was set this would have been dropped in skb_partial_csum_set. GSO packets that do not set checksum offload are suspicious and rare. Most callers of virtio_net_hdr_to_skb already pass them to skb_probe_transport_header. Move that test forward, change it to detect parse failure and drop packets on failure as those cleary are not one of the legitimate VIRTIO_NET_HDR_GSO types. Fixes: bfd5f4a3d605 ("packet: Add GSO/csum offload support.") Fixes: f43798c27684 ("tun: Allow GSO using virtio_net_hdr") Reported-by: syzbot Signed-off-by: Willem de Bruijn Reviewed-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/linux/skbuff.h | 2 +- include/linux/virtio_net.h | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -2377,7 +2377,7 @@ static inline void skb_probe_transport_h return; else if (skb_flow_dissect_flow_keys(skb, &keys, 0)) skb_set_transport_header(skb, keys.control.thoff); - else + else if (offset_hint >= 0) skb_set_transport_header(skb, offset_hint); } --- a/include/linux/virtio_net.h +++ b/include/linux/virtio_net.h @@ -57,6 +57,15 @@ static inline int virtio_net_hdr_to_skb( if (!skb_partial_csum_set(skb, start, off)) return -EINVAL; + } else { + /* 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) { + skb_probe_transport_header(skb, -1); + if (!skb_transport_header_was_set(skb)) + return -EINVAL; + } } if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {