Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1280427pxb; Fri, 22 Jan 2021 11:21:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJw02F2T1pHSzUEsoG3V89Kq4o+GI9gPpBooWj9A0l1bxrKFZyXUs9WCv+2bKfV3nA/dZuef X-Received: by 2002:a05:6402:2289:: with SMTP id cw9mr345023edb.319.1611343262479; Fri, 22 Jan 2021 11:21:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611343262; cv=none; d=google.com; s=arc-20160816; b=vJ35NGIJ+fUunaJ6qTWSu3tU5bLeKB6FrZlY8vne0lHoOBGtRfNxJUKo29AqdkaSbb B1cYmVtPUhndHsXHXS5DOOr12gwtXHxtJuQXZ4l5HtbaQh1cJlNWS1MJDVTllcMnqoxO ZaZrJ1MXBbJ/8luPvYyBubAf0/jSrWa18+z1ZuRNOCfEnrkoNERPeMKX7q9DKWBywoAg TnfuDw9AhWEkwE1ZicwU1dIarU+pokcu0TPGuu3zzOffPknwHA9zl1uBR3kY2XnKQC6X 0BHi/acm4yKQvnXf0rQDwOXZv6O+Bp78YqKaGh6qZDuFH8Oz0AQPVj5kNevvgyA8Zht6 oE4w== 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=YpZlwEC6s1TtUEnIjFOl3VicqkNLG+ftddKmRB79LLA=; b=q9zmrXJeSSpeTqC3NHDy1mTzdNxGIl7LWlaZqBXm4orw0P8uHbgeaiNWbeV1coxHtc CAuAXvfJWskWnvfOwxTg8obr+FZFq9hxzgD4dUwvu2bGMBm2q+lpERGxxDCj1EIV08Sw b5qEqqHC3rujN/KlC3B4Nj8znVuJepZJcp6CSRcW8EU296wzd6O7qKMGciORwk1hbOc6 UI8mkYafFE+W7L5wfvP8ucthyptpEiZQURJP0NrKX4uDW7qPXT8Uru2BeOVO+ImkTG1L b6dwx9oY6tYzSlocUseIJMxMBQNEePYhOOp5KHU+RNnOhSaY7vz6rouJnU5t4LKVPpLI ZSqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HNS3eZTd; 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 b22si4048534eds.249.2021.01.22.11.20.39; Fri, 22 Jan 2021 11:21:02 -0800 (PST) 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=HNS3eZTd; 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 S1730369AbhAVSyU (ORCPT + 99 others); Fri, 22 Jan 2021 13:54:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:38994 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728523AbhAVOWB (ORCPT ); Fri, 22 Jan 2021 09:22:01 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 28FB123AFC; Fri, 22 Jan 2021 14:16:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1611324962; bh=alyDjuWVtFfP4kKunJUuzsyY+rphhSBDLfy6kkNURfs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HNS3eZTdKgSS5ehA7Rhon7LdhomsSxEG+Ch/37LJ919hcabSz9Sk4kyHaQsieXpKU dkWPjjNUKngyVaNn8BG2qYDdjNZh7YBLa4TEx18yaUCBiYFh7IMlp84nwi+coWlC8+ J3kKYON3GghmTqzj5uADPeo+keDQSRJRG5GhLCyE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aya Levin , Tariq Toukan , Jakub Kicinski Subject: [PATCH 4.19 21/22] net: ipv6: Validate GSO SKB before finish IPv6 processing Date: Fri, 22 Jan 2021 15:12:39 +0100 Message-Id: <20210122135732.753335365@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210122135731.921636245@linuxfoundation.org> References: <20210122135731.921636245@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: Aya Levin [ Upstream commit b210de4f8c97d57de051e805686248ec4c6cfc52 ] There are cases where GSO segment's length exceeds the egress MTU: - Forwarding of a TCP GRO skb, when DF flag is not set. - Forwarding of an skb that arrived on a virtualisation interface (virtio-net/vhost/tap) with TSO/GSO size set by other network stack. - Local GSO skb transmitted on an NETIF_F_TSO tunnel stacked over an interface with a smaller MTU. - Arriving GRO skb (or GSO skb in a virtualised environment) that is bridged to a NETIF_F_TSO tunnel stacked over an interface with an insufficient MTU. If so: - Consume the SKB and its segments. - Issue an ICMP packet with 'Packet Too Big' message containing the MTU, allowing the source host to reduce its Path MTU appropriately. Note: These cases are handled in the same manner in IPv4 output finish. This patch aligns the behavior of IPv6 and the one of IPv4. Fixes: 9e50849054a4 ("netfilter: ipv6: move POSTROUTING invocation before fragmentation") Signed-off-by: Aya Levin Reviewed-by: Tariq Toukan Link: https://lore.kernel.org/r/1610027418-30438-1-git-send-email-ayal@nvidia.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/ipv6/ip6_output.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -128,8 +128,42 @@ static int ip6_finish_output2(struct net return -EINVAL; } +static int +ip6_finish_output_gso_slowpath_drop(struct net *net, struct sock *sk, + struct sk_buff *skb, unsigned int mtu) +{ + struct sk_buff *segs, *nskb; + netdev_features_t features; + int ret = 0; + + /* Please see corresponding comment in ip_finish_output_gso + * describing the cases where GSO segment length exceeds the + * egress MTU. + */ + features = netif_skb_features(skb); + segs = skb_gso_segment(skb, features & ~NETIF_F_GSO_MASK); + if (IS_ERR_OR_NULL(segs)) { + kfree_skb(skb); + return -ENOMEM; + } + + consume_skb(skb); + + skb_list_walk_safe(segs, segs, nskb) { + int err; + + skb_mark_not_on_list(segs); + err = ip6_fragment(net, sk, segs, ip6_finish_output2); + if (err && ret == 0) + ret = err; + } + + return ret; +} + static int ip6_finish_output(struct net *net, struct sock *sk, struct sk_buff *skb) { + unsigned int mtu; int ret; ret = BPF_CGROUP_RUN_PROG_INET_EGRESS(sk, skb); @@ -146,7 +180,11 @@ static int ip6_finish_output(struct net } #endif - if ((skb->len > ip6_skb_dst_mtu(skb) && !skb_is_gso(skb)) || + mtu = ip6_skb_dst_mtu(skb); + if (skb_is_gso(skb) && !skb_gso_validate_network_len(skb, mtu)) + return ip6_finish_output_gso_slowpath_drop(net, sk, skb, mtu); + + if ((skb->len > mtu && !skb_is_gso(skb)) || dst_allfrag(skb_dst(skb)) || (IP6CB(skb)->frag_max_size && skb->len > IP6CB(skb)->frag_max_size)) return ip6_fragment(net, sk, skb, ip6_finish_output2);