From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31F08C433E1 for ; Fri, 5 Jun 2020 12:28:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 121162075B for ; Fri, 5 Jun 2020 12:28:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591360088; bh=Su/O2RoRLBYVT3L32u3RsbBqgvAsUO4tHWmK6D+9YvM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=PyI+HVtmvQXqtvYdC3sPvRXMuRrlgWb/lgIMGtc0lbZ70iZYgbpspjL0OEspTo1F7 1AKRFmgMSNRyu0Djyhbufqeu0ndu8sGar1Yn6V+UN4lLaDh2uFNo005u7EqsqJhazZ BUHUegqchLl2LPBSCxiimcrK5DyKgQOoaRR+ozpM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728082AbgFEM2H (ORCPT ); Fri, 5 Jun 2020 08:28:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:58348 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727110AbgFEM0O (ORCPT ); Fri, 5 Jun 2020 08:26:14 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F08A920899; Fri, 5 Jun 2020 12:26:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591359973; bh=Su/O2RoRLBYVT3L32u3RsbBqgvAsUO4tHWmK6D+9YvM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2KZLTp0/PDKbX5vyj2SG+gJNfsxBV0OWnHHEEbKjulvKtsz/Jgd6is1joSBCT33bV jRWs8zmc4Y/dtuYM7SBNmJAOBLbu8pyqagwtl9S4SnAFTVgh44F3wUAMqJ5Kny4HEc pcxyCpHhx9YLZ3KOtOU+2XCD1018PGbLAzWqG1lM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Willem de Bruijn , syzbot , "David S . Miller" , Sasha Levin , virtualization@lists.linux-foundation.org Subject: [PATCH AUTOSEL 4.14 3/8] net: check untrusted gso_size at kernel entry Date: Fri, 5 Jun 2020 08:26:04 -0400 Message-Id: <20200605122609.2882841-3-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605122609.2882841-1-sashal@kernel.org> References: <20200605122609.2882841-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Willem de Bruijn [ Upstream commit 6dd912f82680761d8fb6b1bb274a69d4c7010988 ] Syzkaller again found a path to a kernel crash through bad gso input: a packet with gso size exceeding len. These packets are dropped in tcp_gso_segment and udp[46]_ufo_fragment. But they may affect gso size calculations earlier in the path. Now that we have thlen as of commit 9274124f023b ("net: stricter validation of untrusted gso packets"), check gso_size at entry too. Fixes: bfd5f4a3d605 ("packet: Add GSO/csum offload support.") Reported-by: syzbot Signed-off-by: Willem de Bruijn Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- include/linux/virtio_net.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h index 44e20c4b5141..a16e0bdf7751 100644 --- a/include/linux/virtio_net.h +++ b/include/linux/virtio_net.h @@ -31,6 +31,7 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb, { unsigned int gso_type = 0; unsigned int thlen = 0; + unsigned int p_off = 0; unsigned int ip_proto; if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) { @@ -68,7 +69,8 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb, if (!skb_partial_csum_set(skb, start, off)) return -EINVAL; - if (skb_transport_offset(skb) + thlen > skb_headlen(skb)) + p_off = skb_transport_offset(skb) + thlen; + if (p_off > skb_headlen(skb)) return -EINVAL; } else { /* gso packets without NEEDS_CSUM do not set transport_offset. @@ -90,17 +92,25 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb, return -EINVAL; } - if (keys.control.thoff + thlen > skb_headlen(skb) || + p_off = keys.control.thoff + thlen; + if (p_off > skb_headlen(skb) || keys.basic.ip_proto != ip_proto) return -EINVAL; skb_set_transport_header(skb, keys.control.thoff); + } else if (gso_type) { + p_off = thlen; + if (p_off > skb_headlen(skb)) + return -EINVAL; } } if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) { u16 gso_size = __virtio16_to_cpu(little_endian, hdr->gso_size); + if (skb->len - p_off <= gso_size) + return -EINVAL; + skb_shinfo(skb)->gso_size = gso_size; skb_shinfo(skb)->gso_type = gso_type; -- 2.25.1