netfilter: updates for net
Subsystems (3)
Florian Westphal
maintainerv2 cover netfilter: updates for net
The following patchset contains Netfilter fixes for *net*:
Change since v1: drop patches 7-9 (ctnetlink expectation handling):
Expectation infra in conntrack has design issues wrt. rcu lifetime guarantees. No ETA on a new iteration at ths time. There are no other changes.
Due to large volume of backlogged patches its unlikely I will make the 2nd planned PR this week, so several legit fixes will be pushed back to next week. Sorry for the inconvenience but I am out of ideas and alternatives.
1) syzbot managed to add/remove devices to a flowtable, due to a bug in the flowtable netdevice notifier this gets us a double-add and eventually UaF when device is removed again (we only expect one entry, duplicate remains past net_device end-of-life). From Phil Sutter, bug added in 6.16.
2) Yiming Qian reports another nf_tables transaction handling bug:
in some cases error unwind misses to undo certain set elements, resulting in refcount underflow and use-after-free, bug added in 6.4.
3) Jenny Guanni Qu found out-of-bounds read in pipapo set type. While the value is never used, it still rightfully triggers KASAN splats. Bug exists since this set type was added in 5.6.
4) a few x_tables modules contain copypastry tcp option parsing code which can read 1 byte past the option area. This bug is ancient, fix from David Dull.
5) nfnetlink_queue leaks kernel memory if userspace provides bad NFQA_VLAN/NFQA_L2HDR attributes. From Hyunwoo Kim, bug stems from from 4.7 days.
6) nfnetlink_cthelper has incorrect loop restart logic which may result in reading one pointer past end of array. From 3.6 days, fix also from Hyunwoo Kim.
7) xt_IDLETIMER v0 extension must reject working with timers added by revision v1, else we get list corruption. Bug added in v5.7. From Yifan Wu, Juefei Pu and Yuan Tan via Xin Lu.
Please, pull these changes from:
The following changes since commit 6f1a9140ecda3baba3d945b9a6155af4268aafc4:
net: add xmit recursion limit to tunnel xmit functions (2026-03-10 13:30:30 +0100)
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git tags/nf-26-03-10
for you to fetch changes up to 329f0b9b48ee6ab59d1ab72fef55fe8c6463a6cf:
netfilter: xt_IDLETIMER: reject rev0 reuse of ALARM timer labels (2026-03-10 14:10:43 +0100)
----------------------------------------------------------------
netfilter pull request nf-26-03-10
----------------------------------------------------------------
David Dull (1):
netfilter: x_tables: guard option walkers against 1-byte tail reads
Florian Westphal (1):
netfilter: nf_tables: always walk all pending catchall elements
Hyunwoo Kim (2):
netfilter: nfnetlink_queue: fix entry leak in bridge verdict error path
netfilter: nfnetlink_cthelper: fix OOB read in nfnl_cthelper_dump_table()
Jenny Guanni Qu (1):
netfilter: nft_set_pipapo: fix stack out-of-bounds read in pipapo_drop()
Phil Sutter (1):
netfilter: nf_tables: Fix for duplicate device in netdev hooks
Yuan Tan (1):
netfilter: xt_IDLETIMER: reject rev0 reuse of ALARM timer labels
net/netfilter/nf_tables_api.c | 4 +--- net/netfilter/nfnetlink_cthelper.c | 8 ++++---- net/netfilter/nfnetlink_queue.c | 4 +++- net/netfilter/nft_chain_filter.c | 2 +- net/netfilter/nft_set_pipapo.c | 3 ++- net/netfilter/xt_IDLETIMER.c | 6 ++++++ net/netfilter/xt_dccp.c | 4 ++-- net/netfilter/xt_tcpudp.c | 6 ++++-- 8 files changed, 23 insertions(+), 14 deletions(-)
Signature · 1 line
2.52.0
Florian Westphal
maintainerPATCH v2 1/7 netfilter: nf_tables: Fix for duplicate device in netdev hooks
From: Phil Sutter <[email protected]>
When handling NETDEV_REGISTER notification, duplicate device registration must be avoided since the device may have been added by nft_netdev_hook_alloc() already when creating the hook.
--- net/netfilter/nf_tables_api.c | 2 +- net/netfilter/nft_chain_filter.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -9688,7 +9688,7 @@ static int nft_flowtable_event(unsigned long event, struct net_device *dev,break ;case NETDEV_REGISTER :/* NOP if not matching or already registered */ -if (!match || (changename && ops)) +if (!match || ops)continue ; ops = kzalloc_obj(struct nf_hook_ops,
net/netfilter/nft_chain_filter.c +1 -1
@@ -344,7 +344,7 @@ static int nft_netdev_event(unsigned long event, struct net_device *dev,break ;case NETDEV_REGISTER :/* NOP if not matching or already registered */ -if (!match || (changename && ops)) +if (!match || ops)continue ; ops = kmemdup(&basechain->ops,
Signature · 1 line
2.52.0
Re: [PATCH net v2 1/7] netfilter: nf_tables: Fix for duplicate device in netdev hooks
This series was applied to netdev/net.git (main) by Florian Westphal <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Florian Westphal <[email protected]>:
Quoted 14 lines · On Tue, 10 Mar 2026 14:20:43 +0100 you wrote:
From: Phil Sutter <[email protected]>
When handling
NETDEV_REGISTERnotification, duplicate device registration must be avoided since the device may have been added bynft_netdev_hook_alloc()already when creating the hook.Suggested-by Florian Westphal <[email protected]>Reported-by [email protected]Fixes a331b78a5525 ("netfilter: nf_tables: Respect NETDEV_REGISTER events")Tested-by Helen Koike <[email protected]>Signed-off-by Phil Sutter <[email protected]>Signed-off-by Florian Westphal <[email protected]>
Quoted 1 line
[...]
Here is the summary with links:
- [net,v2,1/7] netfilter: nf_tables: Fix for duplicate device in netdev hooks
https://git.kernel.org/netdev/net/c/b7cdc5a97d02 - [net,v2,2/7] netfilter: nf_tables: always walk all pending catchall elements https://git.kernel.org/netdev/net/c/7cb9a23d7ae4 - [net,v2,3/7] netfilter: nft_set_pipapo: fix stack out-of-bounds read in pipapo_drop() https://git.kernel.org/netdev/net/c/d6d8cd2db236 - [net,v2,4/7] netfilter: x_tables: guard option walkers against 1-byte tail reads https://git.kernel.org/netdev/net/c/cfe770220ac2 - [net,v2,5/7] netfilter: nfnetlink_queue: fix entry leak in bridge verdict error path https://git.kernel.org/netdev/net/c/f1ba83755d81 - [net,v2,6/7] netfilter: nfnetlink_cthelper: fix OOB read in nfnl_cthelper_dump_table() https://git.kernel.org/netdev/net/c/6dcee8496d53 - [net,v2,7/7] netfilter: xt_IDLETIMER: reject rev0 reuse of ALARM timer labels https://git.kernel.org/netdev/net/c/329f0b9b48ee
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Florian Westphal
maintainerPATCH v2 2/7 netfilter: nf_tables: always walk all pending catchall elements
In reply to Florian WestphalDuring transaction processing we might have more than one catchall element:
1 live catchall element and 1 pending element that is coming as part of the new batch.
If the map holding the catchall elements is also going away, its required to toggle all catchall elements and not just the first viable candidate.
Otherwise, we get:
WARNING: ./include/net/netfilter/nf_tables.h:1281 at nft_data_release+0xb7/0xe0 [nf_tables], CPU#2: nft/1404 RIP: 0010:nft_data_release+0xb7/0xe0 [nf_tables] [..] __nft_set_elem_destroy+0x106/0x380 [nf_tables] nf_tables_abort_release+0x348/0x8d0 [nf_tables] nf_tables_abort+0xcf2/0x3ac0 [nf_tables] nfnetlink_rcv_batch+0x9c9/0x20e0 [..]
--- net/netfilter/nf_tables_api.c | 2 -- 1 file changed, 2 deletions(-)
net/netfilter/nf_tables_api.c +0 -2
@@ -829,7 +829,6 @@ static void nft_map_catchall_deactivate(const struct nft_ctx *ctx,nft_set_elem_change_active (ctx->net, set, ext);nft_setelem_data_deactivate (ctx->net, set, catchall->elem); -break ; } }
@@ -5873,7 +5872,6 @@ static void nft_map_catchall_activate(const struct nft_ctx *ctx,nft_clear (ctx->net, ext);nft_setelem_data_activate (ctx->net, set, catchall->elem); -break ; } }
Signature · 1 line
2.52.0
Florian Westphal
maintainerPATCH v2 3/7 netfilter: nft_set_pipapo: fix stack out-of-bounds read in pipapo_drop()
In reply to Florian WestphalFrom: Jenny Guanni Qu <[email protected]>
pipapo_drop() passes rulemap[i + 1].n to pipapo_unmap() as the to_offset argument on every iteration, including the last one where i == m->field_count - 1. This reads one element past the end of the stack-allocated rulemap array (declared as rulemap[NFT_PIPAPO_MAX_FIELDS] with NFT_PIPAPO_MAX_FIELDS == 16).
Although pipapo_unmap() returns early when is_last is true without using the to_offset value, the argument is evaluated at the call site before the function body executes, making this a genuine out-of-bounds stack read confirmed by KASAN:
BUG: KASAN: stack-out-of-bounds in pipapo_drop+0x50c/0x57c [nf_tables] Read of size 4 at addr ffff8000810e71a4
This frame has 1 object:
[32, 160) 'rulemap'
The buggy address is at offset 164 -- exactly 4 bytes past the end of the rulemap array.
Pass 0 instead of rulemap[i + 1].n on the last iteration to avoid the out-of-bounds read.
--- net/netfilter/nft_set_pipapo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nft_set_pipapo.c +2 -1
@@ -1640,6 +1640,7 @@ static void pipapo_drop(struct nft_pipapo_match *m,int i;nft_pipapo_for_each_field (f, i, m) { +bool last = i == m->field_count -1 ;int g;for (g =0 ; g < f->groups; g++) {
@@ -1659,7 +1660,7 @@ static void pipapo_drop(struct nft_pipapo_match *m, }pipapo_unmap (f->mt, f->rules, rulemap[i].to, rulemap[i].n, - rulemap[i +1 ].n, i == m->field_count -1 ); + last ?0 : rulemap[i +1 ].n, last);if (pipapo_resize (f, f->rules, f->rules - rulemap[i].n)) {/* We can ignore this, a failure to shrink tables down * doesn't make tables invalid.
Signature · 1 line
2.52.0
Florian Westphal
maintainerPATCH v2 4/7 netfilter: x_tables: guard option walkers against 1-byte tail reads
In reply to Florian WestphalFrom: David Dull <[email protected]>
When the last byte of options is a non-single-byte option kind, walkers that advance with i += op[i + 1] ? : 1 can read op[i + 1] past the end of the option area.
Add an explicit i == optlen - 1 check before dereferencing op[i + 1] in xt_tcpudp and xt_dccp option walkers.
--- net/netfilter/xt_dccp.c | 4 ++-- net/netfilter/xt_tcpudp.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-)
net/netfilter/xt_dccp.c +2 -2
@@ -62,10 +62,10 @@ dccp_find_option(u_int8_t option,return true; } -if (op[i] <2 ) +if (op[i] <2 || i == optlen -1 ) i++;else - i += op[i+1 ]?:1 ; + i += op[i +1 ] ? :1 ; }spin_unlock_bh (&dccp_buflock);
net/netfilter/xt_tcpudp.c +4 -2
@@ -59,8 +59,10 @@ tcp_find_option(u_int8_t option,for (i =0 ; i < optlen; ) {if (op[i] == option)return !invert; -if (op[i] <2 ) i++; -else i += op[i+1 ]?:1 ; +if (op[i] <2 || i == optlen -1 ) + i++; +else + i += op[i +1 ] ? :1 ; }return invert;
Signature · 1 line
2.52.0
Florian Westphal
maintainerPATCH v2 5/7 netfilter: nfnetlink_queue: fix entry leak in bridge verdict error path
In reply to Florian WestphalFrom: Hyunwoo Kim <[email protected]>
nfqnl_recv_verdict() calls find_dequeue_entry() to remove the queue entry from the queue data structures, taking ownership of the entry. For PF_BRIDGE packets, it then calls nfqa_parse_bridge() to parse VLAN attributes. If nfqa_parse_bridge() returns an error (e.g. NFQA_VLAN present but NFQA_VLAN_TCI missing), the function returns immediately without freeing the dequeued entry or its sk_buff.
This leaks the nf_queue_entry, its associated sk_buff, and all held references (net_device refcounts, struct net refcount). Repeated triggering exhausts kernel memory.
Fix this by dropping the entry via nfqnl_reinject() with NF_DROP verdict on the error path, consistent with other error handling in this file.
--- net/netfilter/nfnetlink_queue.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/nfnetlink_queue.c +3 -1
@@ -1546,8 +1546,10 @@ static int nfqnl_recv_verdict(struct sk_buff *skb, const struct nfnl_info *info,if (entry->state.pf ==PF_BRIDGE ) { err =nfqa_parse_bridge (entry, nfqa); -if (err <0 ) +if (err <0 ) { +nfqnl_reinject (entry,NF_DROP );return err; + } }if (nfqa[NFQA_PAYLOAD ]) {
Signature · 1 line
2.52.0
Florian Westphal
maintainerPATCH v2 6/7 netfilter: nfnetlink_cthelper: fix OOB read in nfnl_cthelper_dump_table()
In reply to Florian WestphalFrom: Hyunwoo Kim <[email protected]>
nfnl_cthelper_dump_table() has a 'goto restart' that jumps to a label inside the for loop body. When the "last" helper saved in cb->args[1] is deleted between dump rounds, every entry fails the (cur != last) check, so cb->args[1] is never cleared. The for loop finishes with cb->args[0] == nf_ct_helper_hsize, and the 'goto restart' jumps back into the loop body bypassing the bounds check, causing an 8-byte out-of-bounds read on nf_ct_helper_hash[nf_ct_helper_hsize].
The 'goto restart' block was meant to re-traverse the current bucket when "last" is no longer found, but it was placed after the for loop instead of inside it. Move the block into the for loop body so that the restart only occurs while cb->args[0] is still within bounds.
BUG: KASAN: slab-out-of-bounds in nfnl_cthelper_dump_table+0x9f/0x1b0 Read of size 8 at addr ffff888104ca3000 by task poc_cthelper/131 Call Trace: nfnl_cthelper_dump_table+0x9f/0x1b0 netlink_dump+0x333/0x880 netlink_recvmsg+0x3e2/0x4b0 sock_recvmsg+0xde/0xf0 __sys_recvfrom+0x150/0x200 __x64_sys_recvfrom+0x76/0x90 do_syscall_64+0xc3/0x6e0 Allocated by task 1: __kvmalloc_node_noprof+0x21b/0x700 nf_ct_alloc_hashtable+0x65/0xd0 nf_conntrack_helper_init+0x21/0x60 nf_conntrack_init_start+0x18d/0x300 nf_conntrack_standalone_init+0x12/0xc0
--- net/netfilter/nfnetlink_cthelper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/netfilter/nfnetlink_cthelper.c +4 -4
@@ -601,10 +601,10 @@ nfnl_cthelper_dump_table(struct sk_buff *skb, struct netlink_callback *cb) goto out; } } - } -if (cb->args[1 ]) { - cb->args[1 ] =0 ; - goto restart; +if (cb->args[1 ]) { + cb->args[1 ] =0 ; + goto restart; + } } out:rcu_read_unlock ();
Signature · 1 line
2.52.0
Florian Westphal
maintainerPATCH v2 7/7 netfilter: xt_IDLETIMER: reject rev0 reuse of ALARM timer labels
In reply to Florian WestphalFrom: Yuan Tan <[email protected]>
IDLETIMER revision 0 rules reuse existing timers by label and always call mod_timer() on timer->timer.
If the label was created first by revision 1 with XT_IDLETIMER_ALARM, the object uses alarm timer semantics and timer->timer is never initialized. Reusing that object from revision 0 causes mod_timer() on an uninitialized timer_list, triggering debugobjects warnings and possible panic when panic_on_warn=1.
Fix this by rejecting revision 0 rule insertion when an existing timer with the same label is of ALARM type.
--- net/netfilter/xt_IDLETIMER.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/netfilter/xt_IDLETIMER.c +6 -0
@@ -318,6 +318,12 @@ static int idletimer_tg_checkentry(const struct xt_tgchk_param *par) info->timer =__idletimer_tg_find_by_label (info->label);if (info->timer) { +if (info->timer->timer_type &XT_IDLETIMER_ALARM ) { +pr_debug ("Adding/Replacing rule with same label and different timer type is not allowed\n" ); +mutex_unlock (&list_mutex); +return -EINVAL ; + } + info->timer->refcnt++;mod_timer (&info->timer->timer,secs_to_jiffies (info->timeout) + jiffies);
Signature · 1 line
2.52.0