Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3578824pxb; Mon, 24 Jan 2022 12:41:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4MiJXnhRQ2EWQ009i+4p6s37PgDaFlRQFFN8nGdJDC6t4Bcj+D3k2Z9ykgsSbY6UywBrz X-Received: by 2002:a17:90a:aa95:: with SMTP id l21mr76351pjq.207.1643056868943; Mon, 24 Jan 2022 12:41:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643056868; cv=none; d=google.com; s=arc-20160816; b=JKZQZ+HeAPJXYjV8AjWlCEta6RIPeYsS4bK/Zxue4PY2RmZ7Co7aVW2xLe3JmQUADQ yMWF/VkxkHxjY9XqcuxWHBSz60JsbKD8U2OYUu0ivvNbWcTRv9TkoMgyJ3tSa4uiMcyf 5MP3qaYsifESZ3TeuxwdlIu5MWkHYRGmACANfmVTx6wm0ILxTsda0Ja8CrPFmgkYsr43 guV7UQAUfQ3ns5FDbUzmqeEWAbZMic7ZrEk3Y1mxqQOVV9Sl+InXhIwIKnww22QvSwVN yWH8XQuT2rWimDU7skZI/ZOG2/7zadbdc2vmB8oWtEuDRQzCRu/n+v9P2cXS3Z4a/HtZ 5nHA== 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=9mr94IPFIyTYk2NkF5kVPbWqSOk1GZKFovo7fX3H0qQ=; b=s8AiYCZPv2uS2ZVPru3MKeAeoirUXmYvxNzV6BpaQG+z+E86ytkDv5OfXZaYU/nRDP m8dVn91LNREYjQfa7nPF2peYCo+sWO++3U4N8yhyWbqReRn7OTsaFrGwb3iRvaOqRqaQ KmXMphScQiXWErOW1/r/zvtASnV4gl25LeEOu6/p2wVQuW6NsNx8PoLSO5kp+yK7TdyS cgzAOxvyY++qZ16bdUv6kfYKAFQ5vuQrAIG6T7aOSGdhxuQTwyl4IOaQIH9CvBHSDOkl SDcqt/N/F7cwL5yQOBhwXjtvb5VEE2Hs1OCIqiTROf2l9Ia3spB75uRQQr9dUXCh2Q6L vrmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0vj5Mw5A; 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 y12si13376921plp.111.2022.01.24.12.40.55; Mon, 24 Jan 2022 12:41:08 -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=0vj5Mw5A; 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 S1359013AbiAXT4J (ORCPT + 99 others); Mon, 24 Jan 2022 14:56:09 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:35146 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349781AbiAXThq (ORCPT ); Mon, 24 Jan 2022 14:37:46 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 703CA6121F; Mon, 24 Jan 2022 19:37:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31C46C340E7; Mon, 24 Jan 2022 19:37:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643053064; bh=MIGW9zqQbSvj2OlFGfCSxrMOEsdVAhrTP4QjjKHJvW8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0vj5Mw5ANtqiY38w62AUWKq9+JVFFonVMzu4duPEw436q/t47DbN1V35DDSCorICH iuhKLkG6KqGgLREWtCIJrkGayoZxTVNofY+mAURx7+1vnNVSK2OJwBgoy8Dmy28RiR t4l0peha02TlFHBts1UmmPmMzNqy5bqZWiBYE6EA= 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.4 264/320] xfrm: fix policy lookup for ipv6 gre packets Date: Mon, 24 Jan 2022 19:44:08 +0100 Message-Id: <20220124184002.961580557@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@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 @@ -743,6 +743,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 & @@ -978,6 +979,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)) @@ -1085,6 +1087,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; @@ -1530,7 +1533,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 @@ -3443,6 +3444,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);