Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2161931ioo; Mon, 23 May 2022 11:33:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxgrUCt6+3F2gPY5/XTbJvS5pKV78G//UHD1JxqSdNeUmepi/g4SdJu8SPbHD8P6bducBT X-Received: by 2002:a17:90a:eac5:b0:1df:7da8:4b19 with SMTP id ev5-20020a17090aeac500b001df7da84b19mr367080pjb.2.1653330812880; Mon, 23 May 2022 11:33:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653330812; cv=none; d=google.com; s=arc-20160816; b=xRUBK2ynkqKzZ6GL5fziFWHDAxbEazMJjLNMWvHCBDZRS5imMVu9e2LKQQeiSMaiRO wBxTk8iWQZm15umfe6PSsfpdmu5jgfSc5eby6tWrX3MGLGtqNL64lTXOzV63YKGEZwIe fnTDD77snryZ5XXVpFFICrxnPhXq35ACgkZBhKjKSSLZMCdQ3EDEX0Ge5nZUjkrAKGHx XENSvHXANVYxKMZpWBNz5MtPUFCSwIZS/zAsH6yEb+fruRlL2Eq5MPQ81RuLXouDRtlB UfuBwvop5G2y5r9gpWmXtNuyywLQVdUat3gpThHh6+bW+TRX1JuEO5A6UTTX3M9DhqnP tqOA== 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=mFlOeCkdnFJLdT6NBf8vpBkZLFgI6sqbwIePw/2h2eo=; b=OUwiuI5Ct35sMES2R27ezMHj09YjzIZXsoXmjijaWxZUv1l+MckBwi213oR4sIaIJA Zmz4VpLxVK92NpINc/BcB2eA33FYaPzAggS4kvXg5+qtauONhDGqRguRH/yrP8SjGmRp O+7lVol+jh4Y79KF2ctxw4asPZBefVXYkXiS3Gw47daC2J8f3xq1V/22W30YGuPwbKSC C+04lClJ6ToOhCg762T00y4xbafJjjzhgc/s4c1oWaA3ZcgJWkqje4IbClBg1awRNrYc zadI93Gko7Brm3M4aSh3FXu+viN+ID7Y9+w0DuG6wuT97RD4qN26gF9biZrTBdWvyj1C 1C6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o2Bvx5NS; 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 b6-20020a633406000000b003a35bcf5d49si11646605pga.763.2022.05.23.11.33.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 11:33:32 -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=o2Bvx5NS; 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 4299DEC3F7; Mon, 23 May 2022 11:31:54 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243793AbiEWSOh (ORCPT + 99 others); Mon, 23 May 2022 14:14:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243841AbiEWRvt (ORCPT ); Mon, 23 May 2022 13:51:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 144F463539; Mon, 23 May 2022 10:38:29 -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 dfw.source.kernel.org (Postfix) with ESMTPS id C424260916; Mon, 23 May 2022 17:29:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD122C385AA; Mon, 23 May 2022 17:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653326982; bh=avndaQch640ZfRGocl3/Glaq1ZfFlwbRC5EyDnOyZQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o2Bvx5NSP1bGsU8mVRPCsyGL/tncvnOEOQ6yHyku7cycy9BpydijxOQvgkDsP4YTt abyXQ81aUBwebcqS00xVL2h54JlAlr7S/RU4naUb/gQBo/63k1Qx/+ap1TN4ctQdMA e2Z6YJCBacnjpxTtTLvnECm6s6fg0qvosTNF2lTg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ritaro Takenaka , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.17 119/158] netfilter: flowtable: move dst_check to packet path Date: Mon, 23 May 2022 19:04:36 +0200 Message-Id: <20220523165850.563558597@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165830.581652127@linuxfoundation.org> References: <20220523165830.581652127@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.6 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=unavailable 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: Ritaro Takenaka [ Upstream commit 2738d9d963bd1f06d5114c2b4fa5771a95703991 ] Fixes sporadic IPv6 packet loss when flow offloading is enabled. IPv6 route GC and flowtable GC are not synchronized. When dst_cache becomes stale and a packet passes through the flow before the flowtable GC teardowns it, the packet can be dropped. So, it is necessary to check dst every time in packet path. Fixes: 227e1e4d0d6c ("netfilter: nf_flowtable: skip device lookup from interface index") Signed-off-by: Ritaro Takenaka Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_flow_table_core.c | 23 +---------------------- net/netfilter/nf_flow_table_ip.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c index de783c9094d7..9fb407084c50 100644 --- a/net/netfilter/nf_flow_table_core.c +++ b/net/netfilter/nf_flow_table_core.c @@ -415,32 +415,11 @@ nf_flow_table_iterate(struct nf_flowtable *flow_table, return err; } -static bool flow_offload_stale_dst(struct flow_offload_tuple *tuple) -{ - struct dst_entry *dst; - - if (tuple->xmit_type == FLOW_OFFLOAD_XMIT_NEIGH || - tuple->xmit_type == FLOW_OFFLOAD_XMIT_XFRM) { - dst = tuple->dst_cache; - if (!dst_check(dst, tuple->dst_cookie)) - return true; - } - - return false; -} - -static bool nf_flow_has_stale_dst(struct flow_offload *flow) -{ - return flow_offload_stale_dst(&flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].tuple) || - flow_offload_stale_dst(&flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple); -} - static void nf_flow_offload_gc_step(struct nf_flowtable *flow_table, struct flow_offload *flow, void *data) { if (nf_flow_has_expired(flow) || - nf_ct_is_dying(flow->ct) || - nf_flow_has_stale_dst(flow)) + nf_ct_is_dying(flow->ct)) flow_offload_teardown(flow); if (test_bit(NF_FLOW_TEARDOWN, &flow->flags)) { diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c index 6257d87c3a56..28026467b54c 100644 --- a/net/netfilter/nf_flow_table_ip.c +++ b/net/netfilter/nf_flow_table_ip.c @@ -227,6 +227,15 @@ static bool nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu) return true; } +static inline bool nf_flow_dst_check(struct flow_offload_tuple *tuple) +{ + if (tuple->xmit_type != FLOW_OFFLOAD_XMIT_NEIGH && + tuple->xmit_type != FLOW_OFFLOAD_XMIT_XFRM) + return true; + + return dst_check(tuple->dst_cache, tuple->dst_cookie); +} + static unsigned int nf_flow_xmit_xfrm(struct sk_buff *skb, const struct nf_hook_state *state, struct dst_entry *dst) @@ -346,6 +355,11 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, if (nf_flow_state_check(flow, iph->protocol, skb, thoff)) return NF_ACCEPT; + if (!nf_flow_dst_check(&tuplehash->tuple)) { + flow_offload_teardown(flow); + return NF_ACCEPT; + } + if (skb_try_make_writable(skb, thoff + hdrsize)) return NF_DROP; @@ -582,6 +596,11 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb, if (nf_flow_state_check(flow, ip6h->nexthdr, skb, thoff)) return NF_ACCEPT; + if (!nf_flow_dst_check(&tuplehash->tuple)) { + flow_offload_teardown(flow); + return NF_ACCEPT; + } + if (skb_try_make_writable(skb, thoff + hdrsize)) return NF_DROP; -- 2.35.1