From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netdev-bot+sinfo@kernel.org
Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net,
netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com,
edumazet@kernel.org, horms@kernel.org, fw@strlen.de, ja@ssi.bg
Subject: Re: [PATCH net-next 01/15] netfilter: conntrack: prevent nf_conntrack_buckets race condition
Date: Mon, 23 Nov 2026 15:17:19 +0100 [thread overview]
Message-ID: <awRK74KlQb4lAxWD@chamomile> (raw)
In-Reply-To: <179544257400.3294.16481017816141150879@kernel.org>
Hi,
On Mon, Nov 23, 2026 at 02:02:54PM +0000, netdev-bot+sinfo@kernel.org wrote:
> Hi!
>
> This is an automated message. This series looks like a fix, but its
> commit messages seem to be missing some information:
>
> - How the issue was discovered, e.g. hit in production, hit during
> development, syzbot report, manual code inspection, LLM or static
> analysis tool scan.
>
> - Whether the issue was actually triggered, or is only theoretical
> (e.g. found by LLM and not proven at runtime). If it was triggered
> please include the symptoms, like the stack trace or kernel messages.
These are LLM findings, proved in runtime by PoC, not hit in production.
Issues are not theoretical, but not so easy to trigger. Plus one found
by syzkaller in the nft_synproxy code.
For the conntrack series, you need a misconfiguration in place (packet
mangling after conntrack already exists + use of conntrack
timeout/helpers).
For ipset, you can trigger the bugs if you try a bit hard on purpose.
The conntrack bucket sysctl race, again you have to search to hit this
race bug too.
Then, the synproxy issue was found by syzkaller.
TL;AI; Here comes a fashionable lengthy LLM generated summary (now
that generating text is cheap :), I have used the shortened version in
the pull request summary, because I think this is what a human would
like to read, I presume.
(1) Fix race condition in the nf_conntrack_buckets sysctl handler, from
Fernando Fernandez Mancera. A single global variable was used as
temporary parse buffer; since sysctl handlers are not serialized, a
concurrent reader/writer can clobber it between parse and resize,
e.g. a monitoring daemon reading while an orchestrator writes. The
global state is gone, a local stack variable is used instead and
serialization is delegated to nf_conntrack_hash_resize().
(2) Validate skb->_nfct against the packet headers. Loopback skbs
already come with a conntrack attached, act_ct may attach one too,
and clsact/pedit may rewrite headers, so a TCP nf_conn can end up on
a UDP packet. Revalidate that the skb matches its l3/l4 headers
and, if not, drop the stale reference and let nf_conntrack_in()
re-lookup the entry.
(3) Refactor the helper call logic in nf_confirm() into
nf_confirm_get_protoff() and nf_ct_call_helper(), no functional
change intended, except that NF_CT_STAT_INC_ATOMIC() is now
incremented on any NF_DROP, it was elided in some cases before,
which looks like a bug. Preparation for the stricter checks in the
followup patches.
(4) Verify the L4 protocol number matches helper->l4proto before
calling a helper. Helpers could be invoked on packets they were not
designed for, e.g. related ICMP(v6) errors in the original direction
or conntrack attached via TC/act_ct and the ip protocol later munged
by pedit. IPv4 explicitly skips fragments (conntrack normally
depends on defrag, but that is not guaranteed for ovs/tc) and the
helper is skipped when the packet carries no payload. nft_ct.c sets
l4proto on the helper it allocates to not trip the new guard.
(5) Replace the open-coded helper invocation sites by the new
nf_ct_call_helper() helper, no functional change intended besides
the extra checks.
(6) Complete the hardening of the helper invocation sequence: extract
the *current* tuple from the packet and verify it against the
conntrack entry, so helpers are not run on packets munged after the
lookup (act_ct -> pedit) and not on ICMP(v6) PMTU errors, and add a
full/sane TCP header check for TCP traffic. Also adds the missing
nhoff to ipv6_skip_exthdr(), which is needed for conntrack over
bridge.
Patches (8) to (12) are a single hardening series for the helper
invocation path, they should be kept together.
(7) Validate the timeout object protocol in nft_ct before attaching it.
nft_ct_timeout_obj_eval() only compared the object protocol against
packet metadata, which does not necessarily describe the entry since
the header may be modified after conntrack attached it. Timeout
objects carry protocol specific arrays, so attaching an object with
fewer timeout states to an entry with more of them lets the tracker
read beyond the object. Require the object protocol to match the
conntrack tuple protocol, as named timeout policies and the ct
helper objects already do. Based on a patch from Kyle Zeng.
(8) Handle only pure SYN and pure ACK packets in nft_synproxy, from
Nguyen Ngoc Thang. Any segment with SYN was taken as the client
initial SYN and any segment with ACK as the client final ACK, so a
SYN-ACK was answered with a fresh SYN-ACK cookie; when that reply is
routed back to the same host (e.g. a peer address on lo) it re-enters
input, it is answered again and never stops, until NET_RX softirq
keeps the CPU busy and memory fills with skbs and rtable entries and
the machine OOMs. Use the same flags as ip(6)t_SYNPROXY: SYN
without ACK/FIN/RST is the initial SYN, ACK without SYN/FIN/RST is
the client ACK, anything else falls through. Two syzbot reports.
(9) Validate hook and priority for the ct zone set expression.
nft_ct_set_zone_eval() attaches the shared per-cpu template conntrack
to the skb so that defrag and nf_conntrack_in() pick up the requested
zone, so this only makes sense before the real conntrack hook: NAT
chain types are nonsensical since the eval becomes a no-op. Add a
.validate callback that restricts the expression to
PREROUTING/OUTPUT, to priorities before conntrack, to non-NAT chain
types and to the families where that hook/priority namespace is
meaningful (ip, ip6, inet, bridge), mirroring the classic xtables CT
target restriction to the raw table; bridge is further limited to
prerouting since locally originating traffic is already tracked at
the IP layer, other families are rejected. Without this, the
unconfirmed per-cpu template can reach the confirm hook on paths
where no conntrack hook runs afterwards and get inserted into the
global hash table as if it were a genuine connection.
(10) Add rhashtable_flush_and_free() and its rhltable counterpart, from
Herbert Xu. ipset needs to flush a live set while readers are in
flight, so the table briefly becomes NULL to quiesce insertions on
the old table, then in-flight insertions/removals are waited for,
rehashes are cancelled, ht->nelems is reset to zero and the new
table is installed. Walkers are detached from the old table and the
dying flag replaces the rcu_head_after_call_rcu() check in
rhashtable_walk_stop(). The rest of rhashtable is updated to cope
with a NULL ht->tbl, and the self-rearming of the deferred worker
moves inside the mutex so rehashes are fully disabled during the
flush.
(11) Add the rhashtable boilerplate stubs to ipset: the hashtable is
allocated, initialised and destroyed, but no element is inserted
yet. This patch is meant to be devoid of side effects, it is kept
separate only to reduce the size of the conversion patch.
(12) Replace the ipset internal hash table implementation with
rhashtable, joint work with Jozsef Kadlecsik. Notes on the
behavioural changes:
- Forced GC on insertion into a full set is removed, it is too
expensive from the packet path; users can enable FORCEADD or
reduce the GC frequency.
- FORCEADD and the MULTI hash type (hash:net,iface) are dropped here
and added back in patches (5) and (6) of this same series to keep
the diff size reasonable.
- initval, bucketsize and hashtable bits options are still accepted
for backward compatibility, but they are not used anymore.
- Automatic shrinking stays disabled: ipset hash types only grow,
and shrinking would also make the dump walker hit -EAGAIN during
resize, which results in duplicated or omitted elements in a few
ipset test cases.
- Left-overs from the old implementation are intentionally kept to
avoid growing this diff any further (data_next stubs, region
locking, resize callback and the resize checks in the ipset core);
they will be removed in a followup series.
(13) Report the size of the dynamically allocated cidr storage in the
memory usage reported to userspace, this accounting was lost in
8e5fd2a55e24 ("netfilter: ipset: rework cidr bookkeeping").
(14) Re-add IP_SET_HASH_WITH_MULTI support, i.e. the hash:net,iface set
type, on top of rhashtable. A net/cidr/physdev key maps to one
struct mtype_group which owns a small RCU-protected list of the
elements sharing that key, each element holding one distinct
interface/wildcard value. An rhltable was tried first, but
hash:net,iface requires control over the insertion order.
mtype_group_find()/mtype_group_test() give exact elements priority
over wildcard ones via the mtype_data_isexact() hook, independently
of the list order, so that:
- mtype_del() does not remove a wildcard element instead of the
specific element named in the request,
- mtype_test()/mtype_test_cidrs() do not shadow an earlier, more
specific (e.g. nomatch) element,
- mtype_add() with IPSET_FLAG_EXIST does not tear down an unrelated
wildcard element while refreshing a specific element that shares
its key.
The element count is tracked explicitly through htype->nelems since
the rhashtable only counts the group heads. The new
IPSET_GROUP_MAX_ENTRIES limit bounds the group list length; this is
not a new restriction, the old implementation provided the same
implicit upper bound through AHASH_MAX_TUNED (64), and it is kept
explicit because the list walk becomes expensive as it grows.
(15) Re-add forceadd support that the conversion in (3) removed. New
mtype_remove_random() helper looks up a random key slot, a group for
IP_SET_HASH_WITH_MULTI sets or a plain element otherwise, and evicts
it so the new element can be added, as it used to be before the
rhashtable conversion.
Thanks.
next prev parent reply other threads:[~2026-11-23 14:17 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 13:57 [PATCH net-next,v2 00/15] Netfilter updates for net-next Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 01/15] netfilter: conntrack: prevent nf_conntrack_buckets race condition Pablo Neira Ayuso
2026-11-23 14:02 ` netdev-bot+sinfo
2026-11-23 14:17 ` Pablo Neira Ayuso [this message]
2026-11-23 13:57 ` [PATCH net-next 02/15] netfilter: conntrack: validate skb->_nfct and packet headers Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 03/15] netfilter: conntrack: refactor helper call logic in nf_confirm() Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 04/15] netfilter: conntrack: verify L4 protocol before calling helper Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 05/15] netfilter: conntrack: replace open-coded helper invocation Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 06/15] netfilter: conntrack: harden helper invocation with tuple revalidation Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 07/15] netfilter: nft_ct: validate timeout object protocol Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 08/15] netfilter: nft_synproxy: only handle pure SYN and ACK packets Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 09/15] netfilter: nft_ct: validate hook and priority for ct zone set Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 10/15] rhashtable: Add rhashtable_flush_and_free helper Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 11/15] netfilter: ipset: add rhashtable boilerplate stubs Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 12/15] netfilter: ipset: replace internal hash table with rhashtable Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 13/15] netfilter: ipset: also report mem size for cidr storage to userspace Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 14/15] netfilter: ipset: re-add IP_SET_HASH_WITH_MULTI support Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 15/15] netfilter: ipset: re-add forceadd support Pablo Neira Ayuso
-- strict thread matches above, loose matches on Subject: below --
2026-11-23 13:54 [PATCH net-next 00/15] Netfilter updates for net-next Pablo Neira Ayuso
2026-11-23 13:54 ` [PATCH net-next 01/15] netfilter: conntrack: prevent nf_conntrack_buckets race condition Pablo Neira Ayuso
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=awRK74KlQb4lAxWD@chamomile \
--to=pablo@netfilter.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=ja@ssi.bg \
--cc=kuba@kernel.org \
--cc=netdev-bot+sinfo@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox