Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17552840rwd; Tue, 27 Jun 2023 04:49:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6lPzMCe47QVEmfhhjqoWp7KGt3R1HfxoLTzAhCi7ThthvmzIyN2F3tb8qXFYmegq0Hw8bg X-Received: by 2002:a05:6a20:3d1a:b0:126:4f3a:e180 with SMTP id y26-20020a056a203d1a00b001264f3ae180mr11178785pzi.46.1687866570960; Tue, 27 Jun 2023 04:49:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687866570; cv=none; d=google.com; s=arc-20160816; b=o7p6aQRy5b5uMK6h5TW9sehfbHyQ9Rt8f21VI5z5RoKrfsThhjagAeIxk8FaH4Y0WX zJ7j+e2b1jpy9AB+HJ8YNzq5uYjJ2eFpuwPmZ2s7fIGsSf0L8sQosuzBF88lhqolvS8d INc9gYXcUDxz1rNz9cXH84GyNy1TWCj/x/PZoCS/wPkyOgvA0r0QPCI19bQ7QxCmB9iy AoFc0faqxl2GwF6W1mBgJtIXDKNVsRhshoZKJfiQQk4vfgF57Ijsd3CuW28rwEQ3yXYm eZJHSc3tsuuoZvXTVBNmaKNuTWKA9VZCZoqxxTLUhDpWMlYpILWKwLIDFokjqfmnmRWP TLXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=GlZ9GyuGlXnTyrcWfAZl4Xh4hJrYDe59/Pl/AlZRM0o=; fh=nGxBs5+OeyP6Ut/Wnh6sbc+8LmEkp6qD5VM9dwi5mJo=; b=HIWmBwDli2mHSDMMPIoJmeY7mXjj6/0tdQUI0JncBN5v5m6+PR4yoglXj/N27W5/kq x3uemJEQT0cfsBv+Fh7mfpQ02SYVPxm4hwV14rl79eG4VLRxPkSCsfbJq3h5f8si/oPR Lzj8WmqRCdMM98YOi4kOMu3E4x/IilrvJmROcfa4CGoSjYO0J1Ta6Qc8NeVAiEtKM6Iu DpFII6NmYP2IQR1YBRFUFFlRkbgg9QPPNRGxi7cZMOpAe+4sMN1huACM/QCRIgufNiuu mnIpiaQYLKVU8fSRPEiCE65EsuoJnAQw+8tAhjHSCGUhJWPCcwFt1+uv7IWUZSrT+Gtq lDDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l11-20020a17090270cb00b001b035819d5csi6444806plt.203.2023.06.27.04.49.18; Tue, 27 Jun 2023 04:49:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231326AbjF0LNB (ORCPT + 99 others); Tue, 27 Jun 2023 07:13:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229804AbjF0LNA (ORCPT ); Tue, 27 Jun 2023 07:13:00 -0400 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:237:300::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E08181FF3; Tue, 27 Jun 2023 04:12:58 -0700 (PDT) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1qE6cq-0003Sm-6H; Tue, 27 Jun 2023 13:12:48 +0200 Date: Tue, 27 Jun 2023 13:12:48 +0200 From: Florian Westphal To: Daniel Xu Cc: daniel@iogearbox.net, edumazet@google.com, kuba@kernel.org, fw@strlen.de, pabeni@redhat.com, pablo@netfilter.org, andrii@kernel.org, davem@davemloft.net, ast@kernel.org, kadlec@netfilter.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, dsahern@kernel.org Subject: Re: [PATCH bpf-next 4/7] netfilter: bpf: Support BPF_F_NETFILTER_IP_DEFRAG in netfilter link Message-ID: <20230627111248.GH3207@breakpoint.cc> References: <242c66138bf4ec8aa26b29d736fb48242b4164ce.1687819413.git.dxu@dxuuu.xyz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <242c66138bf4ec8aa26b29d736fb48242b4164ce.1687819413.git.dxu@dxuuu.xyz> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Daniel Xu wrote: > +static int bpf_nf_enable_defrag(struct bpf_nf_link *link) > +{ > + int err; > + > + switch (link->hook_ops.pf) { > +#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4) > + case NFPROTO_IPV4: > + const struct nf_defrag_v4_hook *v4_hook; > + > + err = request_module("nf_defrag_ipv4"); > + if (err) > + return err; > + > + rcu_read_lock(); > + v4_hook = rcu_dereference(nf_defrag_v4_hook); > + err = v4_hook->enable(link->net); > + rcu_read_unlock(); I'd reverse this, first try rcu_dereference(), then modprobe if thats returned NULL. > +static void bpf_nf_disable_defrag(struct bpf_nf_link *link) > +{ > + switch (link->hook_ops.pf) { > +#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4) > + case NFPROTO_IPV4: > + const struct nf_defrag_v4_hook *v4_hook; > + > + rcu_read_lock(); > + v4_hook = rcu_dereference(nf_defrag_v4_hook); > + v4_hook->disable(link->net); > + rcu_read_unlock(); if (v4_hook) v4_hook->disable() Else we get trouble on manual 'rmmod'. > + /* make sure conntrack confirm is always last */ > + prio = attr->link_create.netfilter.priority; > + if (prio == NF_IP_PRI_FIRST) > + return -ERANGE; /* sabotage_in and other warts */ > + else if (prio == NF_IP_PRI_LAST) > + return -ERANGE; /* e.g. conntrack confirm */ > + else if ((attr->link_create.netfilter.flags & BPF_F_NETFILTER_IP_DEFRAG) && > + (prio > NF_IP_PRI_FIRST && prio <= NF_IP_PRI_CONNTRACK_DEFRAG)) > + return -ERANGE; /* cannot use defrag if prog runs before nf_defrag */ You could elide the (prio > NF_IP_PRI_FIRST, its already handled by first conditional. Otherwise this looks good to me.