Netfilter fixes for net
Subsystems (6)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi,
The following patchset contains Netfilter fixes for net, this contains fixes for a few crash, but many of the patches are trivial/correctness fixes. There is too one rework of the conntrack expectation timeout strategy to deal with a possible race when removing an expectation.
1) Fix the incorrect flowtable timeout extension for entries in hw offload, from Adrian Bente. This is correcting a defect in the functionality, no crash.
2) Hold reference to device under the fake dst in br_netfilter, from Haoze Xie. This is fixing a possible UaF if the device is removed while packet is sitting in nfqueue.
3) Reject template conntrack in xt_cluster, otherwise access to uninitialize conntrack fields are possible leading to WARN_ON due to unset layer 3 protocol. From Wyatt Feng.
4) Make sure the IPv6 tunnel header is in the linear skb data area before pulling. While at it remove incomplete NEXTHDR_DEST support. From Lorenzo Bianconi. This possibly leading to crash if IPv4 header is not linear, but GRO already guarantees this, unlikely but still possible.
5) Bail out immediately if ENOMEM is seen in a nfnetlink batch, no further processing since this will accumulate more bogus errors. From Florian Westphal. Functionally improvements under memory stress, no crash.
6) Use test_bit_acquire in ipset hash set to avoid reordering of subsequent memory access. This is addressing a LLM related report, no crash has been observed. From Jozsef Kadlecsik.
7) Use test_bit_acquire in ipset bitmap set too, for the same reason as in the previous patch, from Jozsef Kadlecsik.
8) Call kfree_rcu() after rcu_assign_pointer() to address a possible UaF, very hard to trigger. Never observed in practise, reported by LLM. Also from Jozsef Kadlecsik.
9) Use disable_delayed_work_sync() instead cancel_delayed_work_sync() to avoid that ipset GC handler re-queues work as reported by LLM. From Jozsef Kadlecsik. This is for correctness.
10) Restore the check in nft_payload for exceeding payloda offset over 2^16. From Florian Westphal. This fixes a silent truncation, not a big deal, but better be assertive and reject it.
11) Validate NFT_META_BRI_IIFHWADDR can only run from bridge prerouting. From Florian Westphal. Harmless but it could allow to read bytes from skb->cb.
12) Zero out destination hardware address during the flowtable path setup, also from Florian. This is a correctness fix, LLM points that possible infoleak can happen but topology to achieve it is not clear.
13) Skip IPv4 options if present when building the IPV4 reject reply. Otherwise bytes in the IPv4 options header can be sent back to origin where the ICMP header is being expected. Again from Florian Westphal.
14) Replace timer API for expectation by GC worker approach. This is implicitly fixing a race between nf_ct_remove_expectations() which might fail to remove the expectation due to timer_del() returning false because timer has expired and callback is being run concurrently. This fix is addressing a crash that has been already reported with a reproducer.
15) Store the master tuple in the expectation, since SLAB_TYPESAFE_BY_RCU does not guarantee that accessing exp->master under rcu read lock refer to the right master conntrack. Found by initial round of fixes for expectation by LLM also found this.
16) Check if br_vlan_get_pvid_rcu() fails to address a possible stack infoleak of 4-bytes. From Florian Westphal.
This is slightly over the 15 patch limit in batches, please, allow this round to exceed it by one.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-26-06-19
Thanks.
----------------------------------------------------------------
The following changes since commit 96e7f9122aae0ed000ee321f324b812a447906d9:
eth: fbnic: take netif_addr_lock_bh() around rx mode address programming (2026-06-18 18:36:26 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git tags/nf-26-06-19
for you to fetch changes up to 05477f7a037c127854b58441f60b34210668f5c3:
netfilter: nft_meta_bridge: fix NFT_META_BRI_IIFPVID stack leak (2026-06-19 12:27:08 +0200)
----------------------------------------------------------------
netfilter pull request 26-06-19
----------------------------------------------------------------
Adrian Bente (1):
netfilter: flowtable: fix offloaded ct timeout never being extended
Florian Westphal (6):
netfilter: nfnetlink: make OOM conditions fatal
netfilter: nft_payload: reject offsets exceeding 65535 bytes
netfilter: nft_meta_bridge: add validate callback for get operations
netfilter: nft_flow_offload: zero device address for non-ether case
netfilter: nf_reject: skip iphdr options when looking for icmp header
netfilter: nft_meta_bridge: fix NFT_META_BRI_IIFPVID stack leak
Haoze Xie (1):
netfilter: nf_queue: pin bridge device while NFQUEUE holds fake dst
Jozsef Kadlecsik (4):
netfilter: ipset: Don't use test_bit() in lockless RCU readers in hash types
netfilter: ipset: Don't use test_bit() in lockless RCU readers in bitmap types
netfilter: ipset: fix order of kfree_rcu() and rcu_assign_pointer()
netfilter: ipset: make sure gc is properly stopped
Lorenzo Bianconi (1):
netfilter: flowtable: fix and simplify IP6IP6 tunnel handling
Pablo Neira Ayuso (2):
netfilter: nf_conntrack_expect: use conntrack GC to reap expectations
netfilter: nf_conntrack_expect: store master_tuple in expectation
Wyatt Feng (1):
netfilter: xt_cluster: reject template conntracks in hash match
include/net/netfilter/nf_conntrack_expect.h | 17 ++- include/net/netfilter/nf_queue.h | 1 + include/net/netfilter/nft_meta.h | 2 + include/uapi/linux/netfilter/nf_conntrack_common.h | 1 + net/bridge/netfilter/nft_meta_bridge.c | 23 +++- net/ipv4/netfilter/nf_reject_ipv4.c | 2 +- net/ipv6/ip6_tunnel.c | 7 + net/netfilter/ipset/ip_set_bitmap_gen.h | 4 +- net/netfilter/ipset/ip_set_bitmap_ip.c | 2 +- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 2 +- net/netfilter/ipset/ip_set_bitmap_port.c | 2 +- net/netfilter/ipset/ip_set_core.c | 4 +- net/netfilter/ipset/ip_set_hash_gen.h | 12 +- net/netfilter/nf_conntrack_broadcast.c | 1 + net/netfilter/nf_conntrack_core.c | 33 ++++- net/netfilter/nf_conntrack_expect.c | 147 +++++++++++---------- net/netfilter/nf_conntrack_h323_main.c | 4 +- net/netfilter/nf_conntrack_helper.c | 10 +- net/netfilter/nf_conntrack_netlink.c | 31 ++--- net/netfilter/nf_conntrack_sip.c | 13 +- net/netfilter/nf_flow_table_core.c | 13 +- net/netfilter/nf_flow_table_ip.c | 80 +++-------- net/netfilter/nf_flow_table_path.c | 4 +- net/netfilter/nf_queue.c | 14 ++ net/netfilter/nfnetlink.c | 7 + net/netfilter/nfnetlink_queue.c | 3 + net/netfilter/nft_ct.c | 3 +- net/netfilter/nft_meta.c | 5 +- net/netfilter/nft_payload.c | 16 ++- net/netfilter/xt_cluster.c | 2 +- .../selftests/net/netfilter/nft_flowtable.sh | 8 +- 31 files changed, 268 insertions(+), 205 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/16 netfilter: flowtable: fix offloaded ct timeout never being extended
From: Adrian Bente <[email protected]>
OpenWrt has recently migrated many platforms to kernel 6.18. On the MediaTek platform, which supports hardware network offloading, WiFi connections accelerated via the WED path were observed to drop after roughly 300 seconds.
After several debugging sessions, assisted by the Claude LLM, the problem was narrowed down as follows:
nf_flow_table_extend_ct_timeout() extends ct->timeout for offloaded flows using:
cmpxchg(&ct->timeout, expires, new_timeout);
'expires' comes from nf_ct_expires(ct) and is a relative value, while ct->timeout holds an absolute timestamp. The two are never equal, so the cmpxchg always fails and the timeout is never extended.
This goes unnoticed for most flows, but a long-lived hardware (WED) offloaded flow on MediaTek MT7986 eventually has ct->timeout decay to zero, the conntrack entry is reaped and the connection breaks.
Open-code the relative value from a single READ_ONCE(ct->timeout) snapshot and compare against that same absolute snapshot in the cmpxchg, so the timeout extension actually takes effect while the datapath remains authoritative if it updates ct->timeout concurrently.
--- net/netfilter/nf_flow_table_core.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
net/netfilter/nf_flow_table_core.c +9 -4
@@ -505,8 +505,13 @@ static u32 nf_flow_table_tcp_timeout(const struct nf_conn *ct)*/ static void nf_flow_table_extend_ct_timeout (struct nf_conn *ct) { -static const u32 min_timeout =5 *60 *HZ ; -u32 expires =nf_ct_expires (ct); +static const s32 min_timeout =5 *60 *HZ ; +u32 ct_timeout =READ_ONCE (ct->timeout); +s32 expires; + + expires = ct_timeout - nfct_time_stamp; +if (expires <=0 )/* already expired */ +return ;/* normal case: large enough timeout, nothing to do. */ if (likely (expires >= min_timeout))
@@ -524,7 +529,7 @@ static void nf_flow_table_extend_ct_timeout(struct nf_conn *ct)if (nf_ct_is_confirmed (ct) &&test_bit (IPS_OFFLOAD_BIT , &ct->status)) {u8 l4proto =nf_ct_protonum (ct); -u32 new_timeout = true; +u32 new_timeout =1 ;switch (l4proto) {case IPPROTO_UDP :
@@ -549,7 +554,7 @@ static void nf_flow_table_extend_ct_timeout(struct nf_conn *ct)*/ if (new_timeout) { new_timeout += nfct_time_stamp; -cmpxchg (&ct->timeout, expires, new_timeout); +cmpxchg (&ct->timeout, ct_timeout, new_timeout); } }
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 2/16 netfilter: nf_queue: pin bridge device while NFQUEUE holds fake dst
In reply to Pablo Neira AyusoFrom: Haoze Xie <[email protected]>
The br_netfilter fake rtable is embedded in struct net_bridge and is attached to bridged packets with skb_dst_set_noref(). If such a packet is queued to NFQUEUE, __nf_queue() upgrades that fake dst with skb_dst_force().
At that point the queued skb can hold a real dst reference after bridge teardown has started. The problem is not that every bridged packet needs its own dst reference. The problem is that NFQUEUE can keep the bridge private fake dst alive after unregister begins.
Fix this by keeping the bridge fake dst model unchanged and pinning the bridge master device only while the packet sits in NFQUEUE. Record the bridge device in nf_queue_entry when the queued skb carries a bridge fake dst, take a device reference for the queue lifetime, and drop it when the queue entry is freed.
Also make sure queued entries are reaped when that bridge device goes down, and drop the redundant nf_bridge_info_exists() test from the fake dst detection.
This keeps netdev_priv(br->dev) alive until verdict completion, so the embedded fake rtable and its metrics backing storage cannot be freed out from under dst_release(). It also avoids the constant refcount bump and avoids using ipv4-specific dst helpers for IPv6 bridge traffic.
--- include/net/netfilter/nf_queue.h | 1 + net/netfilter/nf_queue.c | 14 ++++++++++++++ net/netfilter/nfnetlink_queue.c | 3 +++ 3 files changed, 18 insertions(+)
include/net/netfilter/nf_queue.h +1 -0
@@ -18,6 +18,7 @@ struct nf_queue_entry {unsigned int id;unsigned int hook_index;/* index in hook_entries->hook[] */ #if IS_ENABLED (CONFIG_BRIDGE_NETFILTER ) +struct net_device *bridge_dev;struct net_device *physin;struct net_device *physout;#endif
net/netfilter/nf_queue.c +14 -0
@@ -68,6 +68,7 @@ static void nf_queue_entry_release_refs(struct nf_queue_entry *entry)nf_queue_sock_put (state->sk);#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER ) +dev_put (entry->bridge_dev);dev_put (entry->physin);dev_put (entry->physout);#endif
@@ -84,6 +85,8 @@ static void __nf_queue_entry_init_physdevs(struct nf_queue_entry *entry) {#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )const struct sk_buff *skb = entry->skb; +struct dst_entry *dst =skb_dst (skb); +struct net_device *dev =NULL ;if (nf_bridge_info_exists (skb)) { entry->physin =nf_bridge_get_physindev (skb, entry->state.net);
@@ -92,6 +95,16 @@ static void __nf_queue_entry_init_physdevs(struct nf_queue_entry *entry) entry->physin =NULL ; entry->physout = NULL; } + +if (entry->state.pf ==NFPROTO_BRIDGE && + dst && (dst->flags &DST_FAKE_RTABLE )) + dev =dst_dev_rcu (dst); + +/* Must hold a reference on the bridge device: dst_hold() protects +* the dst itself, but the fake rtable is embedded in bridge-private +* storage that netdevice teardown can free independently. +*/ + entry->bridge_dev = dev;#endif }
@@ -108,6 +121,7 @@ bool nf_queue_entry_get_refs(struct nf_queue_entry *entry)dev_hold (state->out);#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER ) +dev_hold (entry->bridge_dev);dev_hold (entry->physin);dev_hold (entry->physout);#endif
net/netfilter/nfnetlink_queue.c +3 -0
@@ -1262,6 +1262,9 @@ dev_cmp(struct nf_queue_entry *entry, unsigned long ifindex)if (physinif == ifindex || physoutif == ifindex)return 1 ; + +if (entry->bridge_dev && entry->bridge_dev->ifindex == ifindex) +return 1 ;#endif if (entry->skb_dev && entry->skb_dev->ifindex == ifindex)return 1 ;
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 3/16 netfilter: xt_cluster: reject template conntracks in hash match
In reply to Pablo Neira AyusoFrom: Wyatt Feng <[email protected]>
xt_cluster_mt() treats any non-NULL nf_ct_get() result as a fully initialized conntrack and passes it to xt_cluster_hash().
This causes a state confusion bug when the raw table CT target attaches a template conntrack to skb->_nfct before normal conntrack processing. Templates carry IPS_TEMPLATE status but do not have a valid tuple for hashing yet, so xt_cluster_hash() can hit its WARN_ON() path on the zeroed l3num field.
Reject template conntracks before hashing them. This matches existing netfilter handling for template objects and avoids hashing incomplete conntrack state.
--- net/netfilter/xt_cluster.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_cluster.c +1 -1
@@ -107,7 +107,7 @@ xt_cluster_mt(const struct sk_buff *skb, struct xt_action_param *par) } ct =nf_ct_get (skb, &ctinfo); -if (ct ==NULL ) +if (!ct ||nf_ct_is_template (ct))return false;if (ct->master)
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 4/16 netfilter: flowtable: fix and simplify IP6IP6 tunnel handling
In reply to Pablo Neira AyusoFrom: Lorenzo Bianconi <[email protected]>
Fix nf_flow_ip6_tunnel_proto() to use pskb_may_pull() instead of skb_header_pointer() to ensure the outer IPv6 header is in the skb headroom, which is required for subsequent packet processing. Move ctx->offset update inside the IPPROTO_IPV6 conditional block since it should only be adjusted when an IP6IP6 tunnel is actually detected. Simplify the rx path by removing ipv6_skip_exthdr() and checking ip6h->nexthdr directly, as the flowtable fast path only handles simple IP6IP6 encapsulation without extension headers.
Drop the tunnel encapsulation limit destination option support from the tx path to match, since the rx path no longer handles extension headers. Remove the encap_limit parameter from nf_flow_offload_ipv6_forward(), nf_flow_tunnel_ip6ip6_push() and nf_flow_tunnel_v6_push(), along with the ipv6_tel_txoption struct and related headroom/MTU adjustments.
--- net/ipv6/ip6_tunnel.c | 7 ++ net/netfilter/nf_flow_table_ip.c | 80 +++++-------------- .../selftests/net/netfilter/nft_flowtable.sh | 8 +- 3 files changed, 30 insertions(+), 65 deletions(-)
net/ipv6/ip6_tunnel.c +7 -0
@@ -1851,6 +1851,13 @@ static int ip6_tnl_fill_forward_path(struct net_device_path_ctx *ctx,struct dst_entry *dst;int err; +if (!(t->parms.flags &IP6_TNL_F_IGN_ENCAP_LIMIT )) { +/* encaplimit option is currently not supported is +* sw-acceleration path. +*/ +return -EOPNOTSUPP ; + } + dst =ip6_route_output (dev_net (ctx->dev),NULL , &fl6);if (!dst->error) { path->type =DEV_PATH_TUN ;
net/netfilter/nf_flow_table_ip.c +19 -61
173 lines not on this page · raw message
tools/testing/selftests/net/netfilter/nft_flowtable.sh +4 -4
@@ -592,7 +592,7 @@ ip -net "$nsr1" link set tun0 up ip -net "$nsr1" addr add 192.168.100.1/24 dev tun0 ip netns exec "$nsr1" sysctl net.ipv4.conf.tun0.forwarding=1 > /dev/null -ip -net "$nsr1" link add name tun6 type ip6tnl local fee1:2::1 remote fee1:2::2 +ip -net "$nsr1" link add name tun6 type ip6tnl local fee1:2::1 remote fee1:2::2 encaplimit none ip -net "$nsr1" link set tun6 up ip -net "$nsr1" addr add fee1:3::1/64 dev tun6 nodad
@@ -601,7 +601,7 @@ ip -net "$nsr2" link set tun0 up ip -net "$nsr2" addr add 192.168.100.2/24 dev tun0 ip netns exec "$nsr2" sysctl net.ipv4.conf.tun0.forwarding=1 > /dev/null -ip -net "$nsr2" link add name tun6 type ip6tnl local fee1:2::2 remote fee1:2::1 || ret=1 +ip -net "$nsr2" link add name tun6 type ip6tnl local fee1:2::2 remote fee1:2::1 encaplimit none || ret=1 ip -net "$nsr2" link set tun6 up ip -net "$nsr2" addr add fee1:3::2/64 dev tun6 nodad
@@ -651,7 +651,7 @@ ip -net "$nsr1" route change default via 192.168.200.2 ip netns exec "$nsr1" sysctl net.ipv4.conf.tun0/10.forwarding=1 > /dev/null ip netns exec "$nsr1" nft -a insert rule inet filter forward 'meta oif tun0.10 accept' -ip -net "$nsr1" link add name tun6.10 type ip6tnl local fee1:4::1 remote fee1:4::2 +ip -net "$nsr1" link add name tun6.10 type ip6tnl local fee1:4::1 remote fee1:4::2 encaplimit none ip -net "$nsr1" link set tun6.10 up ip -net "$nsr1" addr add fee1:5::1/64 dev tun6.10 nodad ip -6 -net "$nsr1" route delete default
@@ -670,7 +670,7 @@ ip -net "$nsr2" addr add 192.168.200.2/24 dev tun0.10 ip -net "$nsr2" route change default via 192.168.200.1 ip netns exec "$nsr2" sysctl net.ipv4.conf.tun0/10.forwarding=1 > /dev/null -ip -net "$nsr2" link add name tun6.10 type ip6tnl local fee1:4::2 remote fee1:4::1 || ret=1 +ip -net "$nsr2" link add name tun6.10 type ip6tnl local fee1:4::2 remote fee1:4::1 encaplimit none || ret=1 ip -net "$nsr2" link set tun6.10 up ip -net "$nsr2" addr add fee1:5::2/64 dev tun6.10 nodad ip -6 -net "$nsr2" route delete default
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 5/16 netfilter: nfnetlink: make OOM conditions fatal
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Batch support design attempts to process the entire batch, even after a call has returned an error. The advantage is that userspace gets all errors in one go.
The disadvantages are:
1. ->call() needs to cope with bad-state-due-to-previous-error
2. One error can trigger a cascade of followup errors which can obfuscate the real problem.
Make -ENOMEM fatal, if we cannot allocate some object there is a high chance we're going to report followup errors that are nonsensical from userspace point of view.
--- net/netfilter/nfnetlink.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/netfilter/nfnetlink.c +7 -0
@@ -531,6 +531,13 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh, status |=NFNL_BATCH_REPLAY ; goto done; } + +/* No point in further processing; followup errors can +* be bogus (e.g. -ENOENT because object that next +* rule/element wants could not be inserted). +*/ +if (err == -ENOMEM ) + goto ack; } ack:if (nlh->nlmsg_flags &NLM_F_ACK || err) {
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 6/16 netfilter: ipset: Don't use test_bit() in lockless RCU readers in hash types
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Sashiko pointed out that there are a few lockless RCU readers using test_bit() which is a relaxed atomic operation and provides no memory barrier guarantees. Use test_bit_acquire() instead where the operation may run parallel with add/del/gc, i.e. is not one from the next cases
- protected by region lock
- in a set destroy phase
- in a new/temporary set creation phase
--- net/netfilter/ipset/ip_set_hash_gen.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +5 -5
@@ -689,7 +689,7 @@ mtype_resize(struct ip_set *set, bool retried)continue ; pos =smp_load_acquire (&n->pos);for (j =0 ; j < pos; j++) { -if (!test_bit (j, n->used)) +if (!test_bit_acquire (j, n->used))continue ; data =ahash_data (n, j, dsize);if (SET_ELEM_EXPIRED (set, data))
@@ -826,7 +826,7 @@ mtype_ext_size(struct ip_set *set, u32 *elements, size_t *ext_size)continue ; pos =smp_load_acquire (&n->pos);for (j =0 ; j < pos; j++) { -if (!test_bit (j, n->used)) +if (!test_bit_acquire (j, n->used))continue ; data =ahash_data (n, j, set->dsize);if (!SET_ELEM_EXPIRED (set, data))
@@ -1201,7 +1201,7 @@ mtype_test_cidrs(struct ip_set *set, struct mtype_elem *d,continue ; pos =smp_load_acquire (&n->pos);for (i =0 ; i < pos; i++) { -if (!test_bit (i, n->used)) +if (!test_bit_acquire (i, n->used))continue ; data =ahash_data (n, i, set->dsize);if (!mtype_data_equal (data, d, &multi))
@@ -1259,7 +1259,7 @@ mtype_test(struct ip_set *set, void *value, const struct ip_set_ext *ext, } pos =smp_load_acquire (&n->pos);for (i =0 ; i < pos; i++) { -if (!test_bit (i, n->used)) +if (!test_bit_acquire (i, n->used))continue ; data =ahash_data (n, i, set->dsize);if (!mtype_data_equal (data, d, &multi))
@@ -1396,7 +1396,7 @@ mtype_list(const struct ip_set *set,continue ; pos =smp_load_acquire (&n->pos);for (i =0 ; i < pos; i++) { -if (!test_bit (i, n->used)) +if (!test_bit_acquire (i, n->used))continue ; e =ahash_data (n, i, set->dsize);if (SET_ELEM_EXPIRED (set, e))
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 7/16 netfilter: ipset: Don't use test_bit() in lockless RCU readers in bitmap types
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
The pair of the patch "netfilter: ipset: Don't use test_bit() in lockless RCU readers in hash types" for the bitmap types.
--- net/netfilter/ipset/ip_set_bitmap_gen.h | 4 +++- net/netfilter/ipset/ip_set_bitmap_ip.c | 2 +- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 2 +- net/netfilter/ipset/ip_set_bitmap_port.c | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-)
net/netfilter/ipset/ip_set_bitmap_gen.h +3 -1
@@ -165,6 +165,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,ip_set_init_skbinfo (ext_skbinfo (x, set), ext);/* Activate element */ +smp_mb__before_atomic ();set_bit (e->id, map->members); set->elements++;
@@ -219,7 +220,7 @@ mtype_list(const struct ip_set *set,cond_resched_rcu (); id = cb->args[IPSET_CB_ARG0 ]; x =get_ext (set, map, id); - if (!test_bit(id, map->members) || + if (!test_bit_acquire(id, map->members) || (SET_WITH_TIMEOUT(set) && #ifdef IP_SET_BITMAP_STORED_TIMEOUT mtype_is_filled(x) &&
@@ -278,6 +279,7 @@ mtype_gc(struct timer_list *t) x =get_ext (set, map, id);if (ip_set_timeout_expired (ext_timeout (x, set))) {clear_bit (id, map->members); +smp_mb__after_atomic ();ip_set_ext_destroy (set, x); set->elements--; }
net/netfilter/ipset/ip_set_bitmap_ip.c +1 -1
@@ -67,7 +67,7 @@ static int bitmap_ip_do_test(const struct bitmap_ip_adt_elem *e, struct bitmap_ip *map, size_t dsize) { - return !!test_bit(e->id, map->members); + return !!test_bit_acquire(e->id, map->members); } static int
net/netfilter/ipset/ip_set_bitmap_ipmac.c +1 -1
@@ -86,7 +86,7 @@ bitmap_ipmac_do_test(const struct bitmap_ipmac_adt_elem *e, {const struct bitmap_ipmac_elem *elem; -if (!test_bit (e->id, map->members)) +if (!test_bit_acquire (e->id, map->members))return 0 ; elem =get_const_elem (map->extensions, e->id, dsize);if (e->add_mac && elem->filled ==MAC_FILLED )
net/netfilter/ipset/ip_set_bitmap_port.c +1 -1
@@ -58,7 +58,7 @@ static int bitmap_port_do_test(const struct bitmap_port_adt_elem *e, const struct bitmap_port *map, size_t dsize) { - return !!test_bit(e->id, map->members); + return !!test_bit_acquire(e->id, map->members); } static int
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 8/16 netfilter: ipset: fix order of kfree_rcu() and rcu_assign_pointer()
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Sashiko pointed out that kfree_rcu() was called before rcu_assign_pointer() in handling the comment extension. Fix the order so that rcu_assign_pointer() called first.
--- net/netfilter/ipset/ip_set_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/ipset/ip_set_core.c +2 -2
@@ -351,8 +351,8 @@ ip_set_init_comment(struct ip_set *set, struct ip_set_comment *comment,if (unlikely (c)) { set->ext_size -=sizeof (*c) +strlen (c->str) +1 ; -kfree_rcu (c, rcu);rcu_assign_pointer (comment->c,NULL ); +kfree_rcu (c, rcu); }if (!len)return ;
@@ -393,8 +393,8 @@ ip_set_comment_free(struct ip_set *set, void *ptr)if (unlikely (!c))return ; set->ext_size -=sizeof (*c) +strlen (c->str) +1 ; -kfree_rcu (c, rcu);rcu_assign_pointer (comment->c,NULL ); +kfree_rcu (c, rcu); }typedef void (*destroyer )(struct ip_set *,void *);
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 9/16 netfilter: ipset: make sure gc is properly stopped
In reply to Pablo Neira AyusoFrom: Jozsef Kadlecsik <[email protected]>
Sashiko noticed that when destroying a set,cancel_delayed_work_sync() was called while gc
calls queue_delayed_work() unconditionally which
can lead not to properly shutting down the gc.
--- net/netfilter/ipset/ip_set_hash_gen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipset/ip_set_hash_gen.h +1 -1
@@ -606,7 +606,7 @@ mtype_cancel_gc(struct ip_set *set)struct htype *h = set->data;if (SET_WITH_TIMEOUT (set)) -cancel_delayed_work_sync (&h->gc.dwork); +disable_delayed_work_sync (&h->gc.dwork); } static int
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 10/16 netfilter: nft_payload: reject offsets exceeding 65535 bytes
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Large offsets were rejected based on netlink policy, but blamed commit removed the policy without updating nft_payload_inner_init() to use the truncation-check helper.
Silent truncation is not a problem, but not wanted either, so add a check.
--- net/netfilter/nft_payload.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
net/netfilter/nft_payload.c +13 -3
@@ -224,11 +224,17 @@ static int nft_payload_init(const struct nft_ctx *ctx, const struct nlattr * const tb[]) {struct nft_payload *priv =nft_expr_priv (expr); +u32 offset; +int err; priv->base =ntohl (nla_get_be32 (tb[NFTA_PAYLOAD_BASE ])); - priv->offset =ntohl (nla_get_be32 (tb[NFTA_PAYLOAD_OFFSET ])); priv->len =ntohl (nla_get_be32 (tb[NFTA_PAYLOAD_LEN ])); + err =nft_parse_u32_check (tb[NFTA_PAYLOAD_OFFSET ],U16_MAX , &offset); +if (err <0 ) +return err; + priv->offset = offset; +return nft_parse_register_store (ctx, tb[NFTA_PAYLOAD_DREG ], &priv->dreg,NULL ,NFT_DATA_VALUE , priv->len);
@@ -621,7 +627,8 @@ static int nft_payload_inner_init(const struct nft_ctx *ctx, const struct nlattr * const tb[]) {struct nft_payload *priv =nft_expr_priv (expr); -u32 base; +u32 base, offset; +int err;if (!tb[NFTA_PAYLOAD_BASE ] || !tb[NFTA_PAYLOAD_OFFSET ] || !tb[NFTA_PAYLOAD_LEN ] || !tb[NFTA_PAYLOAD_DREG ])
@@ -639,8 +646,11 @@ static int nft_payload_inner_init(const struct nft_ctx *ctx, } priv->base = base; - priv->offset =ntohl (nla_get_be32 (tb[NFTA_PAYLOAD_OFFSET ])); priv->len =ntohl (nla_get_be32 (tb[NFTA_PAYLOAD_LEN ])); + err =nft_parse_u32_check (tb[NFTA_PAYLOAD_OFFSET ],U16_MAX , &offset); +if (err <0 ) +return err; + priv->offset = offset; return nft_parse_register_store(ctx, tb[NFTA_PAYLOAD_DREG], &priv->dreg, NULL, NFT_DATA_VALUE,
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 11/16 netfilter: nft_meta_bridge: add validate callback for get operations
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Blamed commit added NFT_META_BRI_IIFHWADDR to the set validate callback, yet this is a get operation.
Add a get validate callback and move the NFT_META_BRI_IIFHWADDR key there.
AFAICS this is harmless, NFT_META_BRI_IIFHWADDR can deal with a NULL input device and the set handler ignores a NFT_META_BRI_IIFHWADDR operation, but it allows to read 4 bytes off bridge skb->cb[].
--- include/net/netfilter/nft_meta.h | 2 ++ net/bridge/netfilter/nft_meta_bridge.c | 19 ++++++++++++++++++- net/netfilter/nft_meta.c | 5 +++-- 3 files changed, 23 insertions(+), 3 deletions(-)
include/net/netfilter/nft_meta.h +2 -0
@@ -40,6 +40,8 @@ void nft_meta_set_eval(const struct nft_expr *expr,void nft_meta_set_destroy (const struct nft_ctx *ctx,const struct nft_expr *expr); +int nft_meta_get_validate (const struct nft_ctx *ctx, +const struct nft_expr *expr);int nft_meta_set_validate (const struct nft_ctx *ctx,const struct nft_expr *expr);
net/bridge/netfilter/nft_meta_bridge.c +18 -1
@@ -107,12 +107,30 @@ static int nft_meta_bridge_get_init(const struct nft_ctx *ctx, NULL, NFT_DATA_VALUE, len); } +static int nft_meta_bridge_get_validate (const struct nft_ctx *ctx, +const struct nft_expr *expr) +{ +struct nft_meta *priv =nft_expr_priv (expr); +unsigned int hooks; + +switch (priv->key) { +case NFT_META_BRI_IIFHWADDR : + hooks =1 <<NF_BR_PRE_ROUTING ; +break ; +default : +return nft_meta_get_validate (ctx, expr); + } + +return nft_chain_validate_hooks (ctx->chain, hooks); +} +static struct nft_expr_type nft_meta_bridge_type;static const struct nft_expr_ops nft_meta_bridge_get_ops = { .type = &nft_meta_bridge_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_meta )), .eval = nft_meta_bridge_get_eval, .init = nft_meta_bridge_get_init, + .validate = nft_meta_bridge_get_validate, .dump = nft_meta_get_dump, };
@@ -168,7 +186,6 @@ static int nft_meta_bridge_set_validate(const struct nft_ctx *ctx,switch (priv->key) {case NFT_META_BRI_BROUTE : -case NFT_META_BRI_IIFHWADDR : hooks =1 <<NF_BR_PRE_ROUTING ;break ;default :
net/netfilter/nft_meta.c +3 -2
@@ -635,8 +635,8 @@ static int nft_meta_get_validate_xfrm(const struct nft_ctx *ctx)#endif } -static int nft_meta_get_validate (const struct nft_ctx *ctx, -const struct nft_expr *expr) +int nft_meta_get_validate (const struct nft_ctx *ctx, +const struct nft_expr *expr) {const struct nft_meta *priv =nft_expr_priv (expr);
@@ -652,6 +652,7 @@ static int nft_meta_get_validate(const struct nft_ctx *ctx,return 0 ; } +EXPORT_SYMBOL_GPL (nft_meta_get_validate);int nft_meta_set_validate (const struct nft_ctx *ctx,const struct nft_expr *expr)
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 12/16 netfilter: nft_flow_offload: zero device address for non-ether case
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
LLM points out that the skip causes unitialised stack array to propagate down into dev_fill_forward_path(). Its not clear to me that there is a guarantee that a later ctx.dev->netdev_ops->ndo_fill_forward_path() would always fix this up.
--- net/netfilter/nf_flow_table_path.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/nf_flow_table_path.c +3 -1
@@ -53,8 +53,10 @@ static int nft_dev_fill_forward_path(const struct nf_flow_route *route,struct neighbour *n;u8 nud_state; -if (!nft_is_valid_ether_device (dev)) +if (!nft_is_valid_ether_device (dev)) { +eth_zero_addr (ha); goto out; + } n =dst_neigh_lookup (dst_cache, daddr);if (!n)
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 13/16 netfilter: nf_reject: skip iphdr options when looking for icmp header
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Not a big deal but this hould have used the real ip header length and not the base header size. As-is, if there are options then nf_skb_is_icmp_unreach() result will be random.
--- net/ipv4/netfilter/nf_reject_ipv4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/netfilter/nf_reject_ipv4.c +1 -1
@@ -89,7 +89,7 @@ static bool nf_skb_is_icmp_unreach(const struct sk_buff *skb)if (iph->protocol !=IPPROTO_ICMP )return false; - thoff =skb_network_offset (skb) +sizeof (*iph); + thoff =skb_network_offset (skb) +ip_hdrlen (skb); tp = skb_header_pointer(skb, thoff + offsetof(struct icmphdr, type),
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 14/16 netfilter: nf_conntrack_expect: use conntrack GC to reap expectations
In reply to Pablo Neira AyusoThis patch replaces the timer API by GC worker approach for expectations, as it already happened in many other subsystems.
Use the existing conntrack GC worker to iterate over the local list of expectations in the master conntrack to reap expired expectations. Check IPS_HELPER_BIT to run GC for expectations, set it on for nft_ct expectation which nevers sets it. Hold the expectation spinlock while iterating over the master conntrack expectation list to synchronize with nf_ct_remove_expectations(). This also performs runtime packet path garbage collection through the expectation insertion and lookup functions while walking over one of the chains of the global expectation hashtables. Unconfirmed conntrack entries are skipped since ct->ext can be reallocated and dying are skipped since those will be gone soon. Set on IPS_HELPER_BIT if the helper ct extension is added, then the new GC worker does not need to bump the ct refcount to check if the ct->ext helper is available.
This removes the extra bump on the refcount for expectation timers, this allows to remove several nf_ct_expect_put() calls after the unlink, after this update only refcount remains at 1 while on the expectation hashes.
This patch implicitly addresses a race with the existing timer API allowing an expectation to access a stale exp->master pointer which has been already released when expectation removal loses races with an expiring timer, ie. timer_del() reporting false.
Add a new NF_CT_EXPECT_DEAD flag to reap this expectation via GC. This is needed by nf_conntrack_unexpect_related() which is called in error paths to invalidate newly created expectations that has been added into the hashes. These expectactions cannot be inmediately released as GC or nf_ct_remove_expectations() could race to make it. On expectation insert, the runtime GC reaps stale expectations before checking the expectation limit set by policy.
Set current timestamp in nf_ct_expect_alloc(), then add the expectation policy timeout (or custom timeout specified added on top of this) to specify the expectation lifetime.
--- include/net/netfilter/nf_conntrack_expect.h | 16 +- .../linux/netfilter/nf_conntrack_common.h | 1 + net/netfilter/nf_conntrack_core.c | 33 +++- net/netfilter/nf_conntrack_expect.c | 145 +++++++++--------- net/netfilter/nf_conntrack_h323_main.c | 4 +- net/netfilter/nf_conntrack_helper.c | 10 +- net/netfilter/nf_conntrack_netlink.c | 22 ++- net/netfilter/nf_conntrack_sip.c | 13 +- net/netfilter/nft_ct.c | 3 +- 9 files changed, 139 insertions(+), 108 deletions(-)
include/net/netfilter/nf_conntrack_expect.h +13 -3
@@ -54,8 +54,8 @@ struct nf_conntrack_expect {/* The conntrack of the master connection */ struct nf_conn *master; -/* Timer function; deletes the expectation. */ -struct timer_list timeout; +/* jiffies32 when this expectation expires */ +u32 timeout;#if IS_ENABLED (CONFIG_NF_NAT )union nf_inet_addr saved_addr;
@@ -69,6 +69,14 @@ struct nf_conntrack_expect {struct rcu_head rcu; }; +static inline bool nf_ct_exp_is_expired (const struct nf_conntrack_expect *exp) +{ +if (READ_ONCE (exp->flags) &NF_CT_EXPECT_DEAD ) +return true; + +return (__s32)(READ_ONCE (exp->timeout) - nfct_time_stamp) <=0 ; +} +static inline struct net *nf_ct_exp_net (struct nf_conntrack_expect *exp) {return read_pnet (&exp->net);
@@ -130,7 +138,6 @@ static inline void nf_ct_unlink_expect(struct nf_conntrack_expect *exp)void nf_ct_remove_expectations (struct nf_conn *ct);void nf_ct_unexpect_related (struct nf_conntrack_expect *exp); -bool nf_ct_remove_expect (struct nf_conntrack_expect *exp);void nf_ct_expect_iterate_destroy (bool (*iter)(struct nf_conntrack_expect *e,void *data),void *data); void nf_ct_expect_iterate_net(struct net *net,
@@ -153,5 +160,8 @@ static inline int nf_ct_expect_related(struct nf_conntrack_expect *expect, return nf_ct_expect_related_report(expect, 0, 0, flags); } +struct nf_conn_help ; +void nf_ct_expectation_gc (struct nf_conn_help *master_help); +#endif /*_NF_CONNTRACK_EXPECT_H*/
include/uapi/linux/netfilter/nf_conntrack_common.h +1 -0
@@ -160,6 +160,7 @@ enum ip_conntrack_expect_events {#define NF_CT_EXPECT_USERSPACE 0x4#ifdef __KERNEL__ +#define NF_CT_EXPECT_DEAD 0x8#define NF_CT_EXPECT_MASK (NF_CT_EXPECT_PERMANENT | NF_CT_EXPECT_INACTIVE | \ NF_CT_EXPECT_USERSPACE)#endif
net/netfilter/nf_conntrack_core.c +32 -1
@@ -1471,6 +1471,31 @@ static bool gc_worker_can_early_drop(const struct nf_conn *ct)return false; } +static void nf_ct_help_gc (struct nf_conn *ct) +{ +struct nf_conn_help *help; + +if (!refcount_inc_not_zero (&ct->ct_general.use)) +return ; + +/* load ->status after refcount increase */ +smp_acquire__after_ctrl_dep (); + +if (!nf_ct_is_confirmed (ct) ||nf_ct_is_dying (ct)) { +nf_ct_put (ct); +return ; + } + +/* re-check helper due to SLAB_TYPESAFE_BY_RCU */ +if (test_bit (IPS_HELPER_BIT , &ct->status)) { + help =nfct_help (ct); +if (help) +nf_ct_expectation_gc (help); + } + +nf_ct_put (ct); +} +static void gc_worker (struct work_struct *work) {unsigned int i, hashsz, nf_conntrack_max95 =0 ;
@@ -1543,7 +1568,13 @@ static void gc_worker(struct work_struct *work) expires = (expires - (long )next_run) / ++count; next_run += expires; -if (nf_conntrack_max95 ==0 ||gc_worker_skip_ct (tmp)) +if (gc_worker_skip_ct (tmp)) +continue ; + +if (test_bit (IPS_HELPER_BIT , &tmp->status)) +nf_ct_help_gc (tmp); + +if (nf_conntrack_max95 ==0 )continue ; net =nf_ct_net (tmp);
net/netfilter/nf_conntrack_expect.c +72 -73
293 lines not on this page · raw message
net/netfilter/nf_conntrack_h323_main.c +2 -2
@@ -1388,8 +1388,8 @@ static int process_rcf(struct sk_buff *skb, struct nf_conn *ct,"timeout to %u seconds for" , info->timeout);nf_ct_dump_tuple (&exp->tuple); -mod_timer_pending (&exp->timeout, - jiffies + info->timeout *HZ ); +WRITE_ONCE (exp->timeout, + nfct_time_stamp + (info->timeout *HZ )); }spin_unlock_bh (&nf_conntrack_expect_lock); }
net/netfilter/nf_conntrack_helper.c +4 -6
@@ -181,10 +181,10 @@ nf_ct_helper_ext_add(struct nf_conn *ct, gfp_t gfp)struct nf_conn_help *help; help =nf_ct_ext_add (ct,NF_CT_EXT_HELPER , gfp); -if (help) +if (help) { +__set_bit (IPS_HELPER_BIT , &ct->status);INIT_HLIST_HEAD (&help->expectations); -else -pr_debug ("failed to add helper extension area" ); + }return help; }EXPORT_SYMBOL_GPL (nf_ct_helper_ext_add);
@@ -203,10 +203,8 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,return 0 ; help =nfct_help (tmpl); -if (help !=NULL ) { +if (help) helper =rcu_dereference (help->helper); -set_bit (IPS_HELPER_BIT , &ct->status); - } help =nfct_help (ct);
net/netfilter/nf_conntrack_netlink.c +9 -13
@@ -3014,8 +3014,8 @@ static int ctnetlink_exp_dump_expect(struct sk_buff *skb, const struct nf_conntrack_expect *exp) { + __s32 timeout = (__s32)(READ_ONCE(exp->timeout) - nfct_time_stamp) / HZ;struct nf_conn *master = exp->master; -long timeout = ((long )exp->timeout.expires - (long )jiffies) /HZ ;struct nf_conntrack_helper *helper;#if IS_ENABLED (CONFIG_NF_NAT )struct nlattr *nest_parms;
@@ -3178,6 +3178,9 @@ ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb) restart:hlist_for_each_entry_rcu (exp, &nf_ct_expect_hash[cb->args[0 ]], hnode) { +if (nf_ct_exp_is_expired (exp)) +continue ; +if (l3proto && exp->tuple.src.l3num != l3proto)continue ;
@@ -3456,11 +3459,8 @@ static int ctnetlink_del_expect(struct sk_buff *skb, }/* after list removal, usage count == 1 */ -if (timer_delete (&exp->timeout)) { -nf_ct_unlink_expect_report (exp,NETLINK_CB (skb).portid, -nlmsg_report (info->nlh)); -nf_ct_expect_put (exp); - } +nf_ct_unlink_expect_report (exp,NETLINK_CB (skb).portid, +nlmsg_report (info->nlh));spin_unlock_bh (&nf_conntrack_expect_lock);/* have to put what we 'get' above. * after this line usage count == 0 */
@@ -3484,14 +3484,10 @@ static int ctnetlink_change_expect(struct nf_conntrack_expect *x, const struct nlattr * const cda[]) { - if (cda[CTA_EXPECT_TIMEOUT]) { - if (!timer_delete(&x->timeout)) - return -ETIME; + if (cda[CTA_EXPECT_TIMEOUT]) + WRITE_ONCE(x->timeout, nfct_time_stamp + + ntohl(nla_get_be32(cda[CTA_EXPECT_TIMEOUT])) * HZ); - x->timeout.expires = jiffies + -ntohl (nla_get_be32 (cda[CTA_EXPECT_TIMEOUT ])) *HZ ; -add_timer (&x->timeout); - }return 0 ; }
net/netfilter/nf_conntrack_sip.c +5 -8
@@ -897,11 +897,10 @@ static int refresh_signalling_expectation(struct nf_conn *ct, exp->tuple.dst.protonum != proto || exp->tuple.dst.u.udp.port != port) continue; -if (mod_timer_pending (&exp->timeout, jiffies + expires *HZ )) { - exp->flags &= ~NF_CT_EXPECT_INACTIVE ; - found =1 ; -break ; - } +WRITE_ONCE (exp->timeout, nfct_time_stamp + (expires *HZ )); +WRITE_ONCE (exp->flags, exp->flags & ~NF_CT_EXPECT_INACTIVE ); + found =1 ; +break ; }spin_unlock_bh (&nf_conntrack_expect_lock);return found;
@@ -920,8 +919,7 @@ static void flush_expectations(struct nf_conn *ct, bool media)hlist_for_each_entry_safe (exp, next, &help->expectations, lnode) {if ((exp->class !=SIP_EXPECT_SIGNALLING ) ^ media)continue ; -if (!nf_ct_remove_expect (exp)) -continue ; +nf_ct_unlink_expect (exp);if (!media)break ; }
@@ -1413,7 +1411,6 @@ static int process_register_request(struct sk_buff *skb, unsigned int protoff,nf_ct_expect_init (exp,SIP_EXPECT_SIGNALLING ,nf_ct_l3num (ct), saddr, &daddr, proto,NULL , &port); - exp->timeout.expires = sip_timeout *HZ ;rcu_assign_pointer (exp->assign_helper, helper); exp->flags =NF_CT_EXPECT_PERMANENT |NF_CT_EXPECT_INACTIVE ;
net/netfilter/nft_ct.c +1 -2
@@ -1145,7 +1145,6 @@ static void nft_ct_helper_obj_eval(struct nft_object *obj, help =nf_ct_helper_ext_add (ct,GFP_ATOMIC );if (help &&refcount_inc_not_zero (&to_assign->ct_refcnt)) {rcu_assign_pointer (help->helper, to_assign); -set_bit (IPS_HELPER_BIT , &ct->status);if ((ct->status &IPS_NAT_MASK ) && !nfct_seqadj (ct))if (!nfct_seqadj_ext_add (ct))
@@ -1326,7 +1325,7 @@ static void nft_ct_expect_obj_eval(struct nft_object *obj, &ct->tuplehash[!dir].tuple.src.u3, &ct->tuplehash[!dir].tuple.dst.u3, priv->l4proto, NULL, &priv->dport); - exp->timeout.expires = jiffies + priv->timeout *HZ ; + exp->timeout += priv->timeout *HZ ;if (nf_ct_expect_related (exp,0 ) !=0 ) regs->verdict.code =NF_DROP ;
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 15/16 netfilter: nf_conntrack_expect: store master_tuple in expectation
In reply to Pablo Neira AyusoStore master conntrack tuple in the expectation since exp->master might refer to a different conntrack when accessed from rcu read side lock area due to typesafe rcu rules.
--- include/net/netfilter/nf_conntrack_expect.h | 1 + net/netfilter/nf_conntrack_broadcast.c | 1 + net/netfilter/nf_conntrack_expect.c | 2 ++ net/netfilter/nf_conntrack_netlink.c | 9 +++------ 4 files changed, 7 insertions(+), 6 deletions(-)
include/net/netfilter/nf_conntrack_expect.h +1 -0
@@ -26,6 +26,7 @@ struct nf_conntrack_expect {possible_net_t net;/* We expect this tuple, with the following mask */ +struct nf_conntrack_tuple master_tuple;struct nf_conntrack_tuple tuple;struct nf_conntrack_tuple_mask mask;
net/netfilter/nf_conntrack_broadcast.c +1 -0
@@ -62,6 +62,7 @@ int nf_conntrack_broadcast_help(struct sk_buff *skb,if (exp ==NULL ) goto out; + exp->master_tuple = ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple; exp->tuple = ct->tuplehash[IP_CT_DIR_REPLY ].tuple; helper =rcu_dereference (help->helper);
net/netfilter/nf_conntrack_expect.c +2 -0
@@ -355,6 +355,8 @@ void nf_ct_expect_init(struct nf_conntrack_expect *exp, unsigned int class, exp->tuple.src.l3num = family; exp->tuple.dst.protonum = proto; + exp->master_tuple = ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple; +if (saddr) {memcpy (&exp->tuple.src.u3, saddr, len);if (sizeof (exp->tuple.src.u3) > len)
net/netfilter/nf_conntrack_netlink.c +3 -6
@@ -3015,7 +3015,6 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb, const struct nf_conntrack_expect *exp) {__s32 timeout = (__s32)(READ_ONCE (exp->timeout) - nfct_time_stamp) /HZ ; -struct nf_conn *master = exp->master;struct nf_conntrack_helper *helper;#if IS_ENABLED (CONFIG_NF_NAT )struct nlattr *nest_parms;
@@ -3030,9 +3029,7 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb, goto nla_put_failure;if (ctnetlink_exp_dump_mask (skb, &exp->tuple, &exp->mask) <0 ) goto nla_put_failure; -if (ctnetlink_exp_dump_tuple (skb, - &master->tuplehash[IP_CT_DIR_ORIGINAL ].tuple, -CTA_EXPECT_MASTER ) <0 ) +if (ctnetlink_exp_dump_tuple (skb, &exp->master_tuple,CTA_EXPECT_MASTER ) <0 ) goto nla_put_failure;#if IS_ENABLED (CONFIG_NF_NAT )
@@ -3045,9 +3042,9 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,if (nla_put_be32 (skb,CTA_EXPECT_NAT_DIR ,htonl (exp->dir))) goto nla_put_failure; - nat_tuple.src.l3num =nf_ct_l3num (master); + nat_tuple.src.l3num = exp->master_tuple.src.l3num; nat_tuple.src.u3 = exp->saved_addr; - nat_tuple.dst.protonum =nf_ct_protonum (master); + nat_tuple.dst.protonum = exp->master_tuple.dst.protonum; nat_tuple.src.u = exp->saved_proto; if (ctnetlink_exp_dump_tuple(skb, &nat_tuple,
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 16/16 netfilter: nft_meta_bridge: fix NFT_META_BRI_IIFPVID stack leak
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
This needs to test for nonzero retval.
--- net/bridge/netfilter/nft_meta_bridge.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/bridge/netfilter/nft_meta_bridge.c +3 -1
@@ -44,7 +44,9 @@ static void nft_meta_bridge_get_eval(const struct nft_expr *expr,if (!br_dev || !br_vlan_enabled (br_dev)) goto err; -br_vlan_get_pvid_rcu (in, &p_pvid); +if (br_vlan_get_pvid_rcu (in, &p_pvid)) + goto err; +nft_reg_store16 (dest, p_pvid);return ; }
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerHi,
Please scratch this v1 series.
I have posted a v2 for this series for the net tree.
Thanks.
Quoted 168 lines · Pablo Neira Ayuso
Hi,
The following patchset contains Netfilter fixes for net, this contains fixes for a few crash, but many of the patches are trivial/correctness fixes. There is too one rework of the conntrack expectation timeout strategy to deal with a possible race when removing an expectation.
1) Fix the incorrect flowtable timeout extension for entries in hw offload, from Adrian Bente. This is correcting a defect in the functionality, no crash.
2) Hold reference to device under the fake dst in
br_netfilter, from Haoze Xie. This is fixing a possible UaF if the device is removed while packet is sitting in nfqueue.3) Reject template conntrack in
xt_cluster, otherwise access to uninitialize conntrack fields are possible leading toWARN_ONdue to unset layer 3 protocol. From Wyatt Feng.4) Make sure the IPv6 tunnel header is in the linear skb data area before pulling. While at it remove incomplete
NEXTHDR_DESTsupport. From Lorenzo Bianconi. This possibly leading to crash if IPv4 header is not linear, but GRO already guarantees this, unlikely but still possible.5) Bail out immediately if ENOMEM is seen in a nfnetlink batch, no further processing since this will accumulate more bogus errors. From Florian Westphal. Functionally improvements under memory stress, no crash.
6) Use
test_bit_acquirein ipset hash set to avoid reordering of subsequent memory access. This is addressing a LLM related report, no crash has been observed. From Jozsef Kadlecsik.7) Use
test_bit_acquirein ipset bitmap set too, for the same reason as in the previous patch, from Jozsef Kadlecsik.8) Call
kfree_rcu()afterrcu_assign_pointer()to address a possible UaF, very hard to trigger. Never observed in practise, reported by LLM. Also from Jozsef Kadlecsik.9) Use
disable_delayed_work_sync()insteadcancel_delayed_work_sync()to avoid that ipset GC handler re-queues work as reported by LLM. From Jozsef Kadlecsik. This is for correctness.10) Restore the check in
nft_payloadfor exceeding payloda offset over 2^16. From Florian Westphal. This fixes a silent truncation, not a big deal, but better be assertive and reject it.11) Validate
NFT_META_BRI_IIFHWADDRcan only run from bridge prerouting. From Florian Westphal. Harmless but it could allow to read bytes fromskb->cb.12) Zero out destination hardware address during the flowtable path setup, also from Florian. This is a correctness fix, LLM points that possible infoleak can happen but topology to achieve it is not clear.
13) Skip IPv4 options if present when building the IPV4 reject reply. Otherwise bytes in the IPv4 options header can be sent back to origin where the ICMP header is being expected. Again from Florian Westphal.
14) Replace timer API for expectation by GC worker approach. This is implicitly fixing a race between
nf_ct_remove_expectations()which might fail to remove the expectation due totimer_del()returning false because timer has expired and callback is being run concurrently. This fix is addressing a crash that has been already reported with a reproducer.15) Store the master tuple in the expectation, since
SLAB_TYPESAFE_BY_RCUdoes not guarantee that accessingexp->masterunder rcu read lock refer to the right master conntrack. Found by initial round of fixes for expectation by LLM also found this.16) Check if
br_vlan_get_pvid_rcu()fails to address a possible stack infoleak of 4-bytes. From Florian Westphal.This is slightly over the 15 patch limit in batches, please, allow this round to exceed it by one.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.gitnf-26-06-19Thanks.
----------------------------------------------------------------
The following changes since commit
96e7f9122aae0ed000ee321f324b812a447906d9:eth: fbnic: take
netif_addr_lock_bh()around rx mode address programming (2026-06-18 18:36:26 -0700)are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.gittags/nf-26-06-19for you to fetch changes up to
05477f7a037c127854b58441f60b34210668f5c3:netfilter:
nft_meta_bridge: fixNFT_META_BRI_IIFPVIDstack leak (2026-06-19 12:27:08 +0200)----------------------------------------------------------------
netfilter pull request 26-06-19----------------------------------------------------------------
Adrian Bente (1):
netfilter: flowtable: fix offloaded ct timeout never being extendedFlorian Westphal (6):
netfilter: nfnetlink: make OOM conditions fatal
netfilter:nft_payload: reject offsets exceeding 65535 bytes
netfilter:nft_meta_bridge: add validate callback for get operations
netfilter:nft_flow_offload: zero device address for non-ether case
netfilter:nf_reject: skip iphdr options when looking for icmp header
netfilter:nft_meta_bridge: fixNFT_META_BRI_IIFPVIDstack leakHaoze Xie (1):
netfilter:nf_queue: pin bridge device while NFQUEUE holds fake dstJozsef Kadlecsik (4):
netfilter: ipset: Don't usetest_bit()in lockless RCU readers in hash types
netfilter: ipset: Don't usetest_bit()in lockless RCU readers in bitmap types
netfilter: ipset: fix order ofkfree_rcu()andrcu_assign_pointer()
netfilter: ipset: make sure gc is properly stoppedLorenzo Bianconi (1):
netfilter: flowtable: fix and simplify IP6IP6 tunnel handlingPablo Neira Ayuso (2):
netfilter:nf_conntrack_expect: use conntrack GC to reap expectations
netfilter:nf_conntrack_expect: storemaster_tuplein expectationWyatt Feng (1):
netfilter:xt_cluster: reject template conntracks in hash matchinclude/net/netfilter/nf_conntrack_expect.h | 17 ++- include/net/netfilter/nf_queue.h | 1 + include/net/netfilter/nft_meta.h | 2 + include/uapi/linux/netfilter/nf_conntrack_common.h | 1 + net/bridge/netfilter/nft_meta_bridge.c | 23 +++- net/ipv4/netfilter/nf_reject_ipv4.c | 2 +- net/ipv6/ip6_tunnel.c | 7 + net/netfilter/ipset/ip_set_bitmap_gen.h | 4 +- net/netfilter/ipset/ip_set_bitmap_ip.c | 2 +- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 2 +- net/netfilter/ipset/ip_set_bitmap_port.c | 2 +- net/netfilter/ipset/ip_set_core.c | 4 +- net/netfilter/ipset/ip_set_hash_gen.h | 12 +- net/netfilter/nf_conntrack_broadcast.c | 1 + net/netfilter/nf_conntrack_core.c | 33 ++++- net/netfilter/nf_conntrack_expect.c | 147 +++++++++++---------- net/netfilter/nf_conntrack_h323_main.c | 4 +- net/netfilter/nf_conntrack_helper.c | 10 +- net/netfilter/nf_conntrack_netlink.c | 31 ++--- net/netfilter/nf_conntrack_sip.c | 13 +- net/netfilter/nf_flow_table_core.c | 13 +- net/netfilter/nf_flow_table_ip.c | 80 +++-------- net/netfilter/nf_flow_table_path.c | 4 +- net/netfilter/nf_queue.c | 14 ++ net/netfilter/nfnetlink.c | 7 + net/netfilter/nfnetlink_queue.c | 3 + net/netfilter/nft_ct.c | 3 +- net/netfilter/nft_meta.c | 5 +- net/netfilter/nft_payload.c | 16 ++- net/netfilter/xt_cluster.c | 2 +- .../selftests/net/netfilter/nft_flowtable.sh | 8 +- 31 files changed, 268 insertions(+), 205 deletions(-)