Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp941766pxb; Wed, 6 Apr 2022 04:57:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxez223HINul0OiviJztS/rnvZsWIDMDMsTSCeLG2qpnGIknLpHxvrQ3p4b87N90zp7cr4z X-Received: by 2002:a63:e51:0:b0:399:3a4f:3794 with SMTP id 17-20020a630e51000000b003993a4f3794mr6650260pgo.554.1649246239617; Wed, 06 Apr 2022 04:57:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649246239; cv=none; d=google.com; s=arc-20160816; b=p95wVOAVIh+J1wmcfLwjYyfMrTqznFW/x8B2XWzNgwt4+MyxIkaxWYyLTnbl+/FvL9 LlqURXtJUQIQemWxHG0bI0WHQ7FRKbjrLW+VxCR8pIrLD/zIYIyRPQg6xa/4mlfpIff1 R1o3FqzaahuaVYMeTCLGvgAb3/25vZ6RjZTak5AzpNm4AekQKt0+Q8YM54VylAy7NwM2 T/2ljA42yvlZgrRb3aOLCGt4DBNmHKO7cQAHlh2cCwn4ZopEVAA4K8RkbECoA70I7w9a Aq7faaUommW1mTPBvAshYnlzPOZXfH9q51Mzuq5/X0AgBQvMCRRATPQl3sjlSPYkRCph v/1A== 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=SoxuuxEUc4J5pj9wZWOfKi9PIWsIHrvWCNMqspsqSO4=; b=CzQgA43pUjtUlBr575fA7CVrWVqTvYpmFvXAh+mFRConzdFILkb/GUlNDKHEFeNKZK fSf/sz0HdsqUvv4sckxsZweTFe1aI+S+gWp6//f+UkmJoGP1uT0c+dMInfhU38moDbV/ w7OAk6w5JWWNyqMOSQ5kffiofvmV9IkKCqavHShoDlH+ktA0bEbnDSZlC6IHLvoLbqyv WoaU+CAzSjh2+BFsRQcdmPzfeYK4OwoGzvPC4VSO60GkS7M4tCu0P6nTIEpQirZ+Ecwy 1ypvnFrsZoPqhf50sU6d8soS9V9lbQqIWtEderB1r1NDzKWsw1HmOdKLkyzcLQdtrsfQ n7Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=S9KH4zy3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u11-20020a17090341cb00b00153f7e1559dsi15816898ple.55.2022.04.06.04.57.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 04:57:19 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=S9KH4zy3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0BE8A653F13; Wed, 6 Apr 2022 03:19:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573733AbiDEWw4 (ORCPT + 99 others); Tue, 5 Apr 2022 18:52:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349264AbiDEJtb (ORCPT ); Tue, 5 Apr 2022 05:49:31 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 974591FA5C; Tue, 5 Apr 2022 02:43:23 -0700 (PDT) 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 47A8FB818F3; Tue, 5 Apr 2022 09:43:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE5B9C385A1; Tue, 5 Apr 2022 09:43:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151801; bh=ef63SUoVK6J5b3AlqYjE7V+Dbi7YliJ+HCPpNgIERHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S9KH4zy3y/eZ2AHsmGB3sfOvD9QSwhlO88Sj2ZF/fNfKctX83sTYcLLc0+Jtmbr/8 TUzCaCvY8olgWd3HAZbf6XeZPwXOfzMc6zlpE3Y05ZuIP0RdJjFmcyI3QXv9fOikfb Y0+8ga1XFxIVXjxp+y/0FwXsZXhpQpLncy80Bqps= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.15 547/913] netfilter: flowtable: Fix QinQ and pppoe support for inet table Date: Tue, 5 Apr 2022 09:26:49 +0200 Message-Id: <20220405070356.244976195@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pablo Neira Ayuso [ Upstream commit 0492d857636e1c52cd71594a723c4b26a7b31978 ] nf_flow_offload_inet_hook() does not check for 802.1q and PPPoE. Fetch inner ethertype from these encapsulation protocols. Fixes: 72efd585f714 ("netfilter: flowtable: add pppoe support") Fixes: 4cd91f7c290f ("netfilter: flowtable: add vlan support") Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- include/net/netfilter/nf_flow_table.h | 18 ++++++++++++++++++ net/netfilter/nf_flow_table_inet.c | 17 +++++++++++++++++ net/netfilter/nf_flow_table_ip.c | 18 ------------------ 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/include/net/netfilter/nf_flow_table.h b/include/net/netfilter/nf_flow_table.h index a3647fadf1cc..9f927c44087d 100644 --- a/include/net/netfilter/nf_flow_table.h +++ b/include/net/netfilter/nf_flow_table.h @@ -10,6 +10,8 @@ #include #include #include +#include +#include struct nf_flowtable; struct nf_flow_rule; @@ -313,4 +315,20 @@ int nf_flow_rule_route_ipv6(struct net *net, const struct flow_offload *flow, int nf_flow_table_offload_init(void); void nf_flow_table_offload_exit(void); +static inline __be16 nf_flow_pppoe_proto(const struct sk_buff *skb) +{ + __be16 proto; + + proto = *((__be16 *)(skb_mac_header(skb) + ETH_HLEN + + sizeof(struct pppoe_hdr))); + switch (proto) { + case htons(PPP_IP): + return htons(ETH_P_IP); + case htons(PPP_IPV6): + return htons(ETH_P_IPV6); + } + + return 0; +} + #endif /* _NF_FLOW_TABLE_H */ diff --git a/net/netfilter/nf_flow_table_inet.c b/net/netfilter/nf_flow_table_inet.c index bc4126d8ef65..280fdd32965f 100644 --- a/net/netfilter/nf_flow_table_inet.c +++ b/net/netfilter/nf_flow_table_inet.c @@ -6,12 +6,29 @@ #include #include #include +#include static unsigned int nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) { + struct vlan_ethhdr *veth; + __be16 proto; + switch (skb->protocol) { + case htons(ETH_P_8021Q): + veth = (struct vlan_ethhdr *)skb_mac_header(skb); + proto = veth->h_vlan_encapsulated_proto; + break; + case htons(ETH_P_PPP_SES): + proto = nf_flow_pppoe_proto(skb); + break; + default: + proto = skb->protocol; + break; + } + + switch (proto) { case htons(ETH_P_IP): return nf_flow_offload_ip_hook(priv, skb, state); case htons(ETH_P_IPV6): diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c index 889cf88d3dba..6257d87c3a56 100644 --- a/net/netfilter/nf_flow_table_ip.c +++ b/net/netfilter/nf_flow_table_ip.c @@ -8,8 +8,6 @@ #include #include #include -#include -#include #include #include #include @@ -239,22 +237,6 @@ static unsigned int nf_flow_xmit_xfrm(struct sk_buff *skb, return NF_STOLEN; } -static inline __be16 nf_flow_pppoe_proto(const struct sk_buff *skb) -{ - __be16 proto; - - proto = *((__be16 *)(skb_mac_header(skb) + ETH_HLEN + - sizeof(struct pppoe_hdr))); - switch (proto) { - case htons(PPP_IP): - return htons(ETH_P_IP); - case htons(PPP_IPV6): - return htons(ETH_P_IPV6); - } - - return 0; -} - static bool nf_flow_skb_encap_protocol(const struct sk_buff *skb, __be16 proto, u32 *offset) { -- 2.34.1