From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Phil Sutter <phil@nwl.cc>
Cc: Florian Westphal <fw@strlen.de>,
netfilter-devel@vger.kernel.org, Paolo Abeni <pabeni@redhat.com>
Subject: Re: [nf-next PATCH 2/4] netfilter: nfnetlink_hook: Deref hook entry using READ_ONCE()
Date: Thu, 9 Jul 2026 14:07:44 +0200 [thread overview]
Message-ID: <ak-PECbcevqjy91_@chamomile> (raw)
In-Reply-To: <20260708161940.1477671-3-phil@nwl.cc>
Hi Phil,
On Wed, Jul 08, 2026 at 06:19:38PM +0200, Phil Sutter wrote:
> Writer (nf_remove_net_hook) assigns to the field value using
> WRITE_ONCE(), appropriately call READ_ONCE() to make sure reader
> (nfnl_hook_dump) sees either the old or new value, not both.
A bit broader question here:
Are we sure net/netfilter/core.c is safe to be walked over rcu in its
current state? Could the dummy_ops be exposed through nfnetlink_hook?
Maybe net/netfilter/core.c needs a revisited to use
rcu_assign_pointer() to assign the hook_ops to the blob, then
nfnetlink_hook uses rcu_dereference() instead of READ_ONCE.
Then the RCU semantics of the hooks would exposed in a better way?
That would made double use of RCU, one from the blob and then for the
hook_ops.
The hooks are now released using kfree_rcu(), at least in the recent
nf_nat core updates they are.
> Fixes: b010e2a4a9ac ("netfilter: nfnetlink_hook: Dump nat type chains")
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
> net/netfilter/nfnetlink_hook.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/net/netfilter/nfnetlink_hook.c b/net/netfilter/nfnetlink_hook.c
> index e47a2add4d5b..efc674fc5adf 100644
> --- a/net/netfilter/nfnetlink_hook.c
> +++ b/net/netfilter/nfnetlink_hook.c
> @@ -390,10 +390,12 @@ static int nfnl_hook_dump(struct sk_buff *nlskb,
> ops = nf_hook_entries_get_hook_ops(e);
>
> for (; i < e->num_hook_entries; i++) {
> - if (ops[i]->hook_ops_type == NF_HOOK_OP_NAT)
> - err = nfnl_hook_dump_nat(nlskb, cb, ops[i], family);
> + struct nf_hook_ops *cur = READ_ONCE(ops[i]);
> +
> + if (cur->hook_ops_type == NF_HOOK_OP_NAT)
> + err = nfnl_hook_dump_nat(nlskb, cb, cur, family);
> else
> - err = nfnl_hook_dump_one(nlskb, ctx, ops[i],
> + err = nfnl_hook_dump_one(nlskb, ctx, cur,
> ops[i]->priority, family,
> cb->nlh->nlmsg_seq);
> if (err)
> --
> 2.54.0
>
next prev parent reply other threads:[~2026-07-09 12:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 16:19 [nf-next PATCH 0/4] Address Sashiko review of NAT hook dump code Phil Sutter
2026-07-08 16:19 ` [nf-next PATCH 1/4] netfilter: nfnetlink_hook: Pass cb object to nfnl_hook_dump_nat() Phil Sutter
2026-07-08 16:19 ` [nf-next PATCH 2/4] netfilter: nfnetlink_hook: Deref hook entry using READ_ONCE() Phil Sutter
2026-07-09 12:07 ` Pablo Neira Ayuso [this message]
2026-07-09 12:36 ` Florian Westphal
2026-07-09 17:04 ` Pablo Neira Ayuso
2026-07-08 16:19 ` [nf-next PATCH 3/4] netfilter: nfnetlink_hook: Handle multipart NAT hook dumps Phil Sutter
2026-07-08 16:19 ` [nf-next PATCH 4/4] netfilter: nfnetlink_hook: Fix for concurrent NAT hooks dump and change Phil Sutter
2026-07-09 11:28 ` Phil Sutter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ak-PECbcevqjy91_@chamomile \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=phil@nwl.cc \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.