* [nf-next PATCH] netfilter: conntrack: Relax helper auto-assignment warning for nftables
@ 2022-02-19 13:20 Phil Sutter
2022-02-19 13:25 ` Florian Westphal
0 siblings, 1 reply; 5+ messages in thread
From: Phil Sutter @ 2022-02-19 13:20 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: Florian Westphal, netfilter-devel
With nftables, no template is being used and instead helper assignment
happens after conntrack initialization. With helper auto assignment
being disabled by default, this leads to this spurious kernel log
suggesting to use iptables CT target.
To avoid the bogus and confusing message, check helper's refcount: It is
initialized to 1 by nf_conntrack_helper_register() and incremented by
nf_conntrack_helper_try_module_get() during nft_ct_helper_obj_init(). So
if its value is larger than 1, it must be in use *somewhere*.
This approach is not perfect since there is no guarantee the helper will
actually be assigned to the packet's flow. Yet it should still cover the
intended use-case of merely loading the module.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
net/netfilter/nf_conntrack_helper.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
index ae4488a13c70c..828957f1802d8 100644
--- a/net/netfilter/nf_conntrack_helper.c
+++ b/net/netfilter/nf_conntrack_helper.c
@@ -213,11 +213,13 @@ static struct nf_conntrack_helper *
nf_ct_lookup_helper(struct nf_conn *ct, struct net *net)
{
struct nf_conntrack_net *cnet = nf_ct_pernet(net);
+ struct nf_conntrack_helper *helper =
+ __nf_ct_helper_find(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
if (!cnet->sysctl_auto_assign_helper) {
if (cnet->auto_assign_helper_warned)
return NULL;
- if (!__nf_ct_helper_find(&ct->tuplehash[IP_CT_DIR_REPLY].tuple))
+ if (!helper || refcount_read(&helper->refcnt) > 1)
return NULL;
pr_info("nf_conntrack: default automatic helper assignment "
"has been turned off for security reasons and CT-based "
@@ -227,7 +229,7 @@ nf_ct_lookup_helper(struct nf_conn *ct, struct net *net)
return NULL;
}
- return __nf_ct_helper_find(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
+ return helper;
}
int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [nf-next PATCH] netfilter: conntrack: Relax helper auto-assignment warning for nftables
2022-02-19 13:20 [nf-next PATCH] netfilter: conntrack: Relax helper auto-assignment warning for nftables Phil Sutter
@ 2022-02-19 13:25 ` Florian Westphal
2022-02-19 13:32 ` Phil Sutter
0 siblings, 1 reply; 5+ messages in thread
From: Florian Westphal @ 2022-02-19 13:25 UTC (permalink / raw)
To: Phil Sutter; +Cc: Pablo Neira Ayuso, Florian Westphal, netfilter-devel
Phil Sutter <phil@nwl.cc> wrote:
> With nftables, no template is being used and instead helper assignment
> happens after conntrack initialization. With helper auto assignment
> being disabled by default, this leads to this spurious kernel log
> suggesting to use iptables CT target.
>
> To avoid the bogus and confusing message, check helper's refcount: It is
> initialized to 1 by nf_conntrack_helper_register() and incremented by
> nf_conntrack_helper_try_module_get() during nft_ct_helper_obj_init(). So
> if its value is larger than 1, it must be in use *somewhere*.
Why not set cnet->auto_assign_helper_warned = true; from nft_ct.c?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [nf-next PATCH] netfilter: conntrack: Relax helper auto-assignment warning for nftables
2022-02-19 13:25 ` Florian Westphal
@ 2022-02-19 13:32 ` Phil Sutter
2022-02-19 13:41 ` Florian Westphal
0 siblings, 1 reply; 5+ messages in thread
From: Phil Sutter @ 2022-02-19 13:32 UTC (permalink / raw)
To: Florian Westphal; +Cc: Pablo Neira Ayuso, netfilter-devel
Hi,
On Sat, Feb 19, 2022 at 02:25:47PM +0100, Florian Westphal wrote:
> Phil Sutter <phil@nwl.cc> wrote:
> > With nftables, no template is being used and instead helper assignment
> > happens after conntrack initialization. With helper auto assignment
> > being disabled by default, this leads to this spurious kernel log
> > suggesting to use iptables CT target.
> >
> > To avoid the bogus and confusing message, check helper's refcount: It is
> > initialized to 1 by nf_conntrack_helper_register() and incremented by
> > nf_conntrack_helper_try_module_get() during nft_ct_helper_obj_init(). So
> > if its value is larger than 1, it must be in use *somewhere*.
>
> Why not set cnet->auto_assign_helper_warned = true; from nft_ct.c?
I tried, but nf_ct_pernet() is not usable from module context, or
actually symbol nf_conntrack_net_id. So I had to introduce a routine to
set the value. On the other hand I didn't like the fact that it would
permanently disable the warning even after 'nft flush ruleset'
(nit-picking).
I can recover that approach and send a v2 if you think (re-)using refcnt
is a bad idea here.
Thanks, Phil
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [nf-next PATCH] netfilter: conntrack: Relax helper auto-assignment warning for nftables
2022-02-19 13:32 ` Phil Sutter
@ 2022-02-19 13:41 ` Florian Westphal
2022-02-19 14:02 ` Phil Sutter
0 siblings, 1 reply; 5+ messages in thread
From: Florian Westphal @ 2022-02-19 13:41 UTC (permalink / raw)
To: Phil Sutter, Florian Westphal, Pablo Neira Ayuso, netfilter-devel
Phil Sutter <phil@nwl.cc> wrote:
> I tried, but nf_ct_pernet() is not usable from module context, or
> actually symbol nf_conntrack_net_id. So I had to introduce a routine to
> set the value. On the other hand I didn't like the fact that it would
> permanently disable the warning even after 'nft flush ruleset'
> (nit-picking).
> I can recover that approach and send a v2 if you think (re-)using refcnt
> is a bad idea here.
I think its a good idea to add a helper function disable the warning.
We can also call it from xt_CT.c.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [nf-next PATCH] netfilter: conntrack: Relax helper auto-assignment warning for nftables
2022-02-19 13:41 ` Florian Westphal
@ 2022-02-19 14:02 ` Phil Sutter
0 siblings, 0 replies; 5+ messages in thread
From: Phil Sutter @ 2022-02-19 14:02 UTC (permalink / raw)
To: Florian Westphal; +Cc: Pablo Neira Ayuso, netfilter-devel
On Sat, Feb 19, 2022 at 02:41:59PM +0100, Florian Westphal wrote:
> Phil Sutter <phil@nwl.cc> wrote:
> > I tried, but nf_ct_pernet() is not usable from module context, or
> > actually symbol nf_conntrack_net_id. So I had to introduce a routine to
> > set the value. On the other hand I didn't like the fact that it would
> > permanently disable the warning even after 'nft flush ruleset'
> > (nit-picking).
> > I can recover that approach and send a v2 if you think (re-)using refcnt
> > is a bad idea here.
>
> I think its a good idea to add a helper function disable the warning.
>
> We can also call it from xt_CT.c.
OK, I'll prepare a v2. Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-02-19 14:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-19 13:20 [nf-next PATCH] netfilter: conntrack: Relax helper auto-assignment warning for nftables Phil Sutter
2022-02-19 13:25 ` Florian Westphal
2022-02-19 13:32 ` Phil Sutter
2022-02-19 13:41 ` Florian Westphal
2022-02-19 14:02 ` Phil Sutter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).