Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3664431pxb; Mon, 24 Jan 2022 14:48:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwGyv7MCGPqOTpC63g4HplLPhvLN4qZlAODkFJtiGweVn23sb0c6FSd0n/rvEkg2mIK0L9K X-Received: by 2002:a17:90b:3908:: with SMTP id ob8mr453868pjb.47.1643064536562; Mon, 24 Jan 2022 14:48:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643064536; cv=none; d=google.com; s=arc-20160816; b=lpVkcOp2+4Y1Oqej8j+TQcAvdvV69BmMbKdy8UmYr5nFSmiMAwddHmH3nrSdYGXiwk b/B4YW15Ht7F0kP5mFXz4uS7M39Tfep7qSB3GzGYCALk8wFq4oYkDvs0MN+IJjgH4xae vMBAUeBqc8FmQZFni7CSRn7i7Zth3LPKlU67Wn9q3BqXI/9jRBIliF8MnrUYHZA+1mxS K32nR/YJJeMU+rvKxzce23AiYasVY5GwhBoF/1uGBze7Dksm8UExm4Dtd2wZJ60d45nA Z1CMhmgkQKKarQh0ygO5SIolWw08TcjLk4fltGMeno0SGetFDDqjQqgZLqSN6fYYiVfl 002Q== 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=j98YI1ndjl7cmCwFPD3UlPR9rDehJmTnYCkanwXLmmc=; b=H4Hbd9endBXGWAwsKK7uUlD6USdWRePRhtfObViqg2GsQW5tn50LXwIUFdZhXKPH3F gmH3G2XJbNBIfdNu1bcpFZ+sUbtKA/ZiHTscqHA3YXHPcwSLFapGci/5aRej+TufyrUU ZOqlogijcGEWAK6UNQ3/t5f3FTNj3R8PxkxfG3be40ABRMsuVsZ57cGzDMShif8BALZ5 WfGC/IvFSaNkoxW3+akLKKFDEdv5NbIplYOtbHXMZEzUoIuUEKrRAF7j6PhLd7yLkm4s UjzII5+/FB8O2Zi4knUCDNaNBPNxCFHEQ/NmFvGFkgFtjmTlbWUP0q+Uhdw6h30PrO/f viqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eY+3F2vH; 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 138si14946199pgc.498.2022.01.24.14.48.45; Mon, 24 Jan 2022 14:48:56 -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=eY+3F2vH; 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 S1838683AbiAXWrG (ORCPT + 99 others); Mon, 24 Jan 2022 17:47:06 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:48390 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349372AbiAXVhK (ORCPT ); Mon, 24 Jan 2022 16:37:10 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 55ADBB811A9; Mon, 24 Jan 2022 21:37:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DC4CC340E4; Mon, 24 Jan 2022 21:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643060226; bh=bO33B91w8GdPLiN34Gv8tmv6269wB+3MTPbgMjpdAfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eY+3F2vHOjLYwVc+nox2cFZhesR5D435CZYk+sAKZpWsXwxQI1OrvnEea39/Lv0mm T+Ryi4/BjxV9Peg9vbkyKYHhxGo7H2zBvbu/ftCLVb3pivAJjiLkfsos+KgbyUt4uD 6pRypY0zEbyWkvffZwRyFm230vb9LKgo1DycVp0I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ghalem Boudour , Nicolas Dichtel , Steffen Klassert Subject: [PATCH 5.16 0880/1039] xfrm: fix policy lookup for ipv6 gre packets Date: Mon, 24 Jan 2022 19:44:29 +0100 Message-Id: <20220124184154.879723129@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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: Ghalem Boudour commit bcf141b2eb551b3477b24997ebc09c65f117a803 upstream. On egress side, xfrm lookup is called from __gre6_xmit() with the fl6_gre_key field not initialized leading to policies selectors check failure. Consequently, gre packets are sent without encryption. On ingress side, INET6_PROTO_NOPOLICY was set, thus packets were not checked against xfrm policies. Like for egress side, fl6_gre_key should be correctly set, this is now done in decode_session6(). Fixes: c12b395a4664 ("gre: Support GRE over IPv6") Cc: stable@vger.kernel.org Signed-off-by: Ghalem Boudour Signed-off-by: Nicolas Dichtel Signed-off-by: Steffen Klassert Signed-off-by: Greg Kroah-Hartman --- net/ipv6/ip6_gre.c | 5 ++++- net/xfrm/xfrm_policy.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -755,6 +755,7 @@ static netdev_tx_t __gre6_xmit(struct sk fl6->daddr = key->u.ipv6.dst; fl6->flowlabel = key->label; fl6->flowi6_uid = sock_net_uid(dev_net(dev), NULL); + fl6->fl6_gre_key = tunnel_id_to_key32(key->tun_id); dsfield = key->tos; flags = key->tun_flags & @@ -990,6 +991,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit fl6.daddr = key->u.ipv6.dst; fl6.flowlabel = key->label; fl6.flowi6_uid = sock_net_uid(dev_net(dev), NULL); + fl6.fl6_gre_key = tunnel_id_to_key32(key->tun_id); dsfield = key->tos; if (!(tun_info->key.tun_flags & TUNNEL_ERSPAN_OPT)) @@ -1098,6 +1100,7 @@ static void ip6gre_tnl_link_config_commo fl6->flowi6_oif = p->link; fl6->flowlabel = 0; fl6->flowi6_proto = IPPROTO_GRE; + fl6->fl6_gre_key = t->parms.o_key; if (!(p->flags&IP6_TNL_F_USE_ORIG_TCLASS)) fl6->flowlabel |= IPV6_TCLASS_MASK & p->flowinfo; @@ -1544,7 +1547,7 @@ static void ip6gre_fb_tunnel_init(struct static struct inet6_protocol ip6gre_protocol __read_mostly = { .handler = gre_rcv, .err_handler = ip6gre_err, - .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL, + .flags = INET6_PROTO_FINAL, }; static void ip6gre_destroy_tunnels(struct net *net, struct list_head *head) --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -33,6 +33,7 @@ #include #include #include +#include #if IS_ENABLED(CONFIG_IPV6_MIP6) #include #endif @@ -3422,6 +3423,26 @@ decode_session6(struct sk_buff *skb, str } fl6->flowi6_proto = nexthdr; return; + case IPPROTO_GRE: + if (!onlyproto && + (nh + offset + 12 < skb->data || + pskb_may_pull(skb, nh + offset + 12 - skb->data))) { + struct gre_base_hdr *gre_hdr; + __be32 *gre_key; + + nh = skb_network_header(skb); + gre_hdr = (struct gre_base_hdr *)(nh + offset); + gre_key = (__be32 *)(gre_hdr + 1); + + if (gre_hdr->flags & GRE_KEY) { + if (gre_hdr->flags & GRE_CSUM) + gre_key++; + fl6->fl6_gre_key = *gre_key; + } + } + fl6->flowi6_proto = nexthdr; + return; + #if IS_ENABLED(CONFIG_IPV6_MIP6) case IPPROTO_MH: offset += ipv6_optlen(exthdr);