Netfilter fixes for net
Subsystems (4)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi,
The following patchset contains Netfilter fixes for net:
1) Revalidate bridge ports, add missing NULL checks to fetch the bridge device by the port. From Florian Westphal.
2) Fix netdevice refcount leak in the error path of nft_fwd hardware offload function, also from Florian.
3) Unregister helper expectfn callback on conntrack helper module removal, otherwise dangling pointer remains in place, from Weiming Shi.
4) Fix possible pointer infoleak in getsockopt() IPT_SO_GET_ENTRIES, From Kyle Zeng.
5) Validate that device MAC header is present before nf_syslog accesses it. From Xiang Mei.
6-8) Three patches to address a possible infoleak of stale stack
data in three nf_tables expressions, due to mismatch in the _init() and _eval() function which is possible since 14fb07130c7d. From Davide Ornaghi and Florian Westphal.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-26-06-10
Thanks.
----------------------------------------------------------------
The following changes since commit 4aacf509e537a711fa71bca9f234e5eb6968850e:
net: mv643xx: fix OF node refcount (2026-06-04 18:40:31 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-26-06-10
for you to fetch changes up to c7d573551f9286100a055ef696cde6af54549677:
netfilter: nft_meta_bridge: fix stale stack leak via IIFHWADDR register (2026-06-10 18:00:32 +0200)
----------------------------------------------------------------
netfilter pull request 26-06-10
----------------------------------------------------------------
Davide Ornaghi (2):
netfilter: nft_fib: fix stale stack leak via the OIFNAME register
netfilter: nft_meta_bridge: fix stale stack leak via IIFHWADDR register
Florian Westphal (3):
netfilter: revalidate bridge ports
netfilter: nf_tables_offload: drop device refcount on error
netfilter: nft_exthdr: fix register tracking for F_PRESENT flag
Kyle Zeng (1):
netfilter: x_tables: avoid leaking percpu counter pointers
Weiming Shi (1):
netfilter: nf_conntrack: destroy stale expectfn expectations on unregister
Xiang Mei (1):
netfilter: nf_log: validate MAC header was set before dumping it
include/net/netfilter/nf_conntrack_helper.h | 1 + net/bridge/netfilter/ebt_dnat.c | 4 +- net/bridge/netfilter/ebt_redirect.c | 16 +++++--- net/bridge/netfilter/nft_meta_bridge.c | 2 + net/ipv4/netfilter/arp_tables.c | 15 +++---- net/ipv4/netfilter/ip_tables.c | 15 +++---- net/ipv4/netfilter/nf_nat_h323.c | 2 + net/ipv4/netfilter/nft_fib_ipv4.c | 2 +- net/ipv6/netfilter/ip6_tables.c | 15 +++---- net/ipv6/netfilter/nft_fib_ipv6.c | 2 +- net/netfilter/nf_conntrack_helper.c | 19 +++++++++ net/netfilter/nf_dup_netdev.c | 6 ++- net/netfilter/nf_log_syslog.c | 4 +- net/netfilter/nf_nat_core.c | 2 + net/netfilter/nf_nat_sip.c | 1 + net/netfilter/nfnetlink_log.c | 23 +++++++++-- net/netfilter/nfnetlink_queue.c | 64 +++++++++++++++++++++++++---- net/netfilter/nft_exthdr.c | 3 ++ net/netfilter/nft_fib.c | 6 +++ 19 files changed, 151 insertions(+), 51 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/8 netfilter: revalidate bridge ports
From: Florian Westphal <[email protected]>
ebt_redirect_tg() dereferences br_port_get_rcu() return without a NULL check, causing a kernel panic when the bridge port has been removed between the original hook invocation and an NFQUEUE reinject.
A mere NULL check isn't sufficient, however. As sashiko review points out userspace can not only remove the port from the bridge, it could also place the device in a different virtual device, e.g. macvlan.
If this happens, we must drop the packet, there is no way for us to reinject it into the bridge path.
Switch to _upper API, we don't need the bridge port structure. Also, this fix keeps another bug intact:
Both nfnetlink_log and nfnetlink_queue use CONFIG_BRIDGE_NETFILTER too aggressive, which prevents certain logging features when queueing in bridge family: NETFILTER_FAMILY_BRIDGE can be enabled while the old CONFIG_BRIDGE_NETFILTER cruft is off.
Fixes tag is a common ancestor, this was always broken.
--- net/bridge/netfilter/ebt_dnat.c | 4 +- net/bridge/netfilter/ebt_redirect.c | 16 +++++--- net/netfilter/nfnetlink_log.c | 23 +++++++++-- net/netfilter/nfnetlink_queue.c | 64 +++++++++++++++++++++++++---- 4 files changed, 89 insertions(+), 18 deletions(-)
net/bridge/netfilter/ebt_dnat.c +3 -1
@@ -39,7 +39,9 @@ ebt_dnat_tg(struct sk_buff *skb, const struct xt_action_param *par) dev =xt_in (par);break ;case NF_BR_PRE_ROUTING : - dev =br_port_get_rcu (xt_in (par))->br->dev; + dev =netdev_master_upper_dev_get_rcu (xt_in (par)); +if (!dev)/* bridge port removed? */ +return EBT_DROP ;break ;default : dev =NULL ;
net/bridge/netfilter/ebt_redirect.c +11 -5
@@ -24,12 +24,18 @@ ebt_redirect_tg(struct sk_buff *skb, const struct xt_action_param *par)if (skb_ensure_writable (skb,0 ))return EBT_DROP ; -if (xt_hooknum (par) !=NF_BR_BROUTING ) -/* rcu_read_lock()ed by nf_hook_thresh */ -ether_addr_copy (eth_hdr (skb)->h_dest, -br_port_get_rcu (xt_in (par))->br->dev->dev_addr); -else +if (xt_hooknum (par) !=NF_BR_BROUTING ) { +const struct net_device *dev; + + dev =netdev_master_upper_dev_get_rcu (xt_in (par)); +if (!dev) +return EBT_DROP ; + +ether_addr_copy (eth_hdr (skb)->h_dest, dev->dev_addr); + }else {ether_addr_copy (eth_hdr (skb)->h_dest,xt_in (par)->dev_addr); + } + skb->pkt_type =PACKET_HOST ;return info->target; }
net/netfilter/nfnetlink_log.c +19 -4
@@ -451,6 +451,23 @@ static int nfulnl_put_bridge(struct nfulnl_instance *inst, const struct sk_buffreturn -1 ; } +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER ) +static int nflog_put_master_ifindex (struct sk_buff *nlskb,int attr, +const struct net_device *dev) +{ +const struct net_device *upper; + +if (dev && !netif_is_bridge_port (dev)) +return 0 ; + + upper =netdev_master_upper_dev_get_rcu ((struct net_device *)dev); +if (upper &&nla_put_be32 (nlskb, attr,htonl (upper->ifindex))) +return -EMSGSIZE ; + +return 0 ; +} +#endif +/* This is an inline function, we don't really care about a long * list of arguments */ static inline int
@@ -505,8 +522,7 @@ __build_packet_message(struct nfnl_log_net *log,/* rcu_read_lock()ed by nf_hook_thresh or * nf_log_packet. */ - nla_put_be32(inst->skb, NFULA_IFINDEX_INDEV, - htonl(br_port_get_rcu(indev)->br->dev->ifindex))) + nflog_put_master_ifindex(inst->skb, NFULA_IFINDEX_INDEV, indev)) goto nla_put_failure; }else {int physinif;
@@ -542,8 +558,7 @@ __build_packet_message(struct nfnl_log_net *log,/* rcu_read_lock()ed by nf_hook_thresh or * nf_log_packet. */ - nla_put_be32(inst->skb, NFULA_IFINDEX_OUTDEV, - htonl(br_port_get_rcu(outdev)->br->dev->ifindex))) + nflog_put_master_ifindex(inst->skb, NFULA_IFINDEX_OUTDEV, outdev)) goto nla_put_failure; }else {struct net_device *physoutdev;
net/netfilter/nfnetlink_queue.c +56 -8
92 lines not on this page · raw message
Signature · 1 line
2.47.3
Re: [PATCH net 1/8] netfilter: revalidate bridge ports
This series was applied to netdev/net.git (main) by Pablo Neira Ayuso <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Pablo Neira Ayuso <[email protected]>:
Quoted 8 lines · On Wed, 10 Jun 2026 18:16:21 +0200 you wrote:
From: Florian Westphal <[email protected]>
ebt_redirect_tg()dereferencesbr_port_get_rcu()return without a NULL check, causing a kernel panic when the bridge port has been removed between the original hook invocation and an NFQUEUE reinject.[...]
Here is the summary with links:
- [net,1/8] netfilter: revalidate bridge ports
https://git.kernel.org/netdev/net/c/ccb9fd4b8753 - [net,2/8] netfilter: nf_tables_offload: drop device refcount on error https://git.kernel.org/netdev/net/c/efc542561729 - [net,3/8] netfilter: nf_conntrack: destroy stale expectfn expectations on unregister https://git.kernel.org/netdev/net/c/c3009418f9fa - [net,4/8] netfilter: x_tables: avoid leaking percpu counter pointers https://git.kernel.org/netdev/net/c/f7f2fbb0e893 - [net,5/8] netfilter: nf_log: validate MAC header was set before dumping it https://git.kernel.org/netdev/net/c/a84b6fedbc97 - [net,6/8] netfilter: nft_exthdr: fix register tracking for F_PRESENT flag https://git.kernel.org/netdev/net/c/772cecf198da - [net,7/8] netfilter: nft_fib: fix stale stack leak via the OIFNAME register https://git.kernel.org/netdev/net/c/ab185e0c4fb8 - [net,8/8] netfilter: nft_meta_bridge: fix stale stack leak via IIFHWADDR register https://git.kernel.org/netdev/net/c/c7d573551f92
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Pablo Neira Ayuso
maintainerPATCH 2/8 netfilter: nf_tables_offload: drop device refcount on error
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Reported by sashiko:
If nft_flow_action_entry_next() returns NULL, dev reference leaks.
--- net/netfilter/nf_dup_netdev.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/netfilter/nf_dup_netdev.c +4 -2
@@ -74,16 +74,18 @@ int nft_fwd_dup_netdev_offload(struct nft_offload_ctx *ctx,struct flow_action_entry *entry;struct net_device *dev; -/* nft_flow_rule_destroy() releases the reference on this device. */ dev =dev_get_by_index (ctx->net, oif);if (!dev)return -EOPNOTSUPP ; entry =nft_flow_action_entry_next (ctx, flow); -if (!entry) +if (!entry) { +dev_put (dev);return -E2BIG ; + } entry->id = id; +/* nft_flow_rule_destroy() releases the reference on this device. */ entry->dev = dev;return 0 ;
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 3/8 netfilter: nf_conntrack: destroy stale expectfn expectations on unregister
In reply to Pablo Neira AyusoFrom: Weiming Shi <[email protected]>
NAT helpers such as nf_nat_h323 store a raw pointer to module text in exp->expectfn (e.g. ip_nat_q931_expect). nf_ct_helper_expectfn_unregister() only unlinks the callback descriptor and never walks the expectation table, so an expectation pending at module removal survives with a dangling exp->expectfn into freed module text.
When the expected connection arrives, init_conntrack() invokes exp->expectfn(), now a stale pointer into the unloaded module. Reproduced on a KASAN build by loading the H.323 helpers, creating a Q.931 expectation, unloading nf_nat_h323, then connecting to the expected port:
Oops: int3: 0000 [#1] SMP KASAN NOPTI RIP: 0010:0xffffffffa06102d1 init_conntrack.isra.0 (net/netfilter/nf_conntrack_core.c:1862) nf_conntrack_in (net/netfilter/nf_conntrack_core.c:2049) ipv4_conntrack_local (net/netfilter/nf_conntrack_proto.c:223) nf_hook_slow (net/netfilter/core.c:619) __ip_local_out (net/ipv4/ip_output.c:120) __tcp_transmit_skb (net/ipv4/tcp_output.c:1715) tcp_connect (net/ipv4/tcp_output.c:4374) tcp_v4_connect (net/ipv4/tcp_ipv4.c:345) __sys_connect (net/socket.c:2167) Modules linked in: nf_conntrack_h323 [last unloaded: nf_nat_h323]
Reaching the dangling state requires CAP_SYS_MODULE in the initial user namespace to remove a NAT helper that still has live expectations, so this is a robustness fix; leaving an expectation pointing at freed text is wrong regardless.
Add nf_ct_helper_expectfn_destroy(), which walks the expectation table and drops every expectation whose ->expectfn matches the descriptor being torn down. Call it from each NAT helper's exit path after the existing RCU grace period, so no expectation outlives the code it points at and no extra synchronize_rcu() is introduced. With the fix, the same reproducer runs to completion without the Oops.
--- include/net/netfilter/nf_conntrack_helper.h | 1 + net/ipv4/netfilter/nf_nat_h323.c | 2 ++ net/netfilter/nf_conntrack_helper.c | 19 +++++++++++++++++++ net/netfilter/nf_nat_core.c | 2 ++ net/netfilter/nf_nat_sip.c | 1 + 5 files changed, 25 insertions(+)
include/net/netfilter/nf_conntrack_helper.h +1 -0
@@ -155,6 +155,7 @@ void nf_ct_helper_log(struct sk_buff *skb, const struct nf_conn *ct,void nf_ct_helper_expectfn_register (struct nf_ct_helper_expectfn *n);void nf_ct_helper_expectfn_unregister (struct nf_ct_helper_expectfn *n); +void nf_ct_helper_expectfn_destroy (const struct nf_ct_helper_expectfn *n);struct nf_ct_helper_expectfn *nf_ct_helper_expectfn_find_by_name (const char *name); struct nf_ct_helper_expectfn *
net/ipv4/netfilter/nf_nat_h323.c +2 -0
@@ -555,6 +555,8 @@ static void __exit nf_nat_h323_fini(void)nf_ct_helper_expectfn_unregister (&q931_nat);nf_ct_helper_expectfn_unregister (&callforwarding_nat);synchronize_rcu (); +nf_ct_helper_expectfn_destroy (&q931_nat); +nf_ct_helper_expectfn_destroy (&callforwarding_nat); }/****************************************************************************/
net/netfilter/nf_conntrack_helper.c +19 -0
@@ -283,6 +283,25 @@ void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n) }EXPORT_SYMBOL_GPL (nf_ct_helper_expectfn_unregister); +static bool expect_iter_expectfn (struct nf_conntrack_expect *exp,void *data) +{ +const struct nf_ct_helper_expectfn *n = data; + +/* Relies on registered expectfn descriptors having unique ->expectfn +* pointers, which holds for the in-tree NAT helpers. +*/ +return exp->expectfn == n->expectfn; +} + +/* Destroy expectations still pointing at @n->expectfn; call after the +* caller's RCU grace period so none outlives the (often modular) callback. +*/ +void nf_ct_helper_expectfn_destroy (const struct nf_ct_helper_expectfn *n) +{ +nf_ct_expect_iterate_destroy (expect_iter_expectfn, (void *)n); +} +EXPORT_SYMBOL_GPL (nf_ct_helper_expectfn_destroy); +/* Caller should hold the rcu lock */ struct nf_ct_helper_expectfn *nf_ct_helper_expectfn_find_by_name (const char *name)
net/netfilter/nf_nat_core.c +2 -0
@@ -1341,6 +1341,7 @@ static int __init nf_nat_init(void)RCU_INIT_POINTER (nf_nat_hook,NULL );nf_ct_helper_expectfn_unregister (&follow_master_nat);synchronize_net (); +nf_ct_helper_expectfn_destroy (&follow_master_nat);unregister_pernet_subsys (&nat_net_ops);kvfree (nf_nat_bysource); }
@@ -1358,6 +1359,7 @@ static void __exit nf_nat_cleanup(void)RCU_INIT_POINTER (nf_nat_hook,NULL );synchronize_net (); +nf_ct_helper_expectfn_destroy (&follow_master_nat);kvfree (nf_nat_bysource);unregister_pernet_subsys (&nat_net_ops); }
net/netfilter/nf_nat_sip.c +1 -0
@@ -655,6 +655,7 @@ static void __exit nf_nat_sip_fini(void)RCU_INIT_POINTER (nf_nat_sip_hooks,NULL );nf_ct_helper_expectfn_unregister (&sip_nat);synchronize_rcu (); +nf_ct_helper_expectfn_destroy (&sip_nat); }static const struct nf_nat_sip_hooks sip_hooks = {
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 4/8 netfilter: x_tables: avoid leaking percpu counter pointers
In reply to Pablo Neira AyusoFrom: Kyle Zeng <[email protected]>
The native and compat get-entries paths copy the fixed rule entry header from the kernelized rule blob to userspace before overwriting the entry's counter fields with a sanitized counter snapshot.
On SMP kernels, entry->counters.pcnt contains the percpu allocation address used by x_tables rule counters. A caller can provide a userspace buffer that faults during the initial fixed-header copy after pcnt has been copied but before the later sanitized counter copy runs. The syscall then returns -EFAULT while leaving the raw percpu pointer in userspace.
Copy only the fixed entry prefix before counters from the kernelized rule blob, then copy the sanitized counter snapshot into the counter field. Apply this ordering to the IPv4, IPv6, and ARP native and compat get-entries implementations so a fault cannot expose the internal percpu counter pointer.
--- net/ipv4/netfilter/arp_tables.c | 15 ++++++--------- net/ipv4/netfilter/ip_tables.c | 15 ++++++--------- net/ipv6/netfilter/ip6_tables.c | 15 ++++++--------- 3 files changed, 18 insertions(+), 27 deletions(-)
net/ipv4/netfilter/arp_tables.c +6 -9
@@ -702,14 +702,12 @@ static int copy_entries_to_user(unsigned int total_size,const struct xt_entry_target *t; e = loc_cpu_entry + off; -if (copy_to_user (userptr + off, e,sizeof (*e))) { - ret = -EFAULT ; - goto free_counters; - } -if (copy_to_user (userptr + off +if (copy_to_user (userptr + off, e, + offsetof(struct arpt_entry , counters)) || +copy_to_user (userptr + off + offsetof(struct arpt_entry , counters), &counters[num], -sizeof (counters[num])) !=0 ) { +sizeof (counters[num]))) { ret = -EFAULT ; goto free_counters; }
@@ -1327,9 +1325,8 @@ static int compat_copy_entry_to_user(struct arpt_entry *e, void __user **dstptr, origsize = *size; ce = *dstptr; -if (copy_to_user (ce, e,sizeof (struct arpt_entry )) !=0 || -copy_to_user (&ce->counters, &counters[i], -sizeof (counters[i])) !=0 ) +if (copy_to_user (ce, e, offsetof(struct compat_arpt_entry , counters)) || +copy_to_user (&ce->counters, &counters[i],sizeof (counters[i])))return -EFAULT ; *dstptr +=sizeof (struct compat_arpt_entry );
net/ipv4/netfilter/ip_tables.c +6 -9
@@ -832,14 +832,12 @@ copy_entries_to_user(unsigned int total_size,const struct xt_entry_target *t; e = loc_cpu_entry + off; -if (copy_to_user (userptr + off, e,sizeof (*e))) { - ret = -EFAULT ; - goto free_counters; - } -if (copy_to_user (userptr + off +if (copy_to_user (userptr + off, e, + offsetof(struct ipt_entry , counters)) || +copy_to_user (userptr + off + offsetof(struct ipt_entry , counters), &counters[num], -sizeof (counters[num])) !=0 ) { +sizeof (counters[num]))) { ret = -EFAULT ; goto free_counters; }
@@ -1228,9 +1226,8 @@ compat_copy_entry_to_user(struct ipt_entry *e, void __user **dstptr, origsize = *size; ce = *dstptr; -if (copy_to_user (ce, e,sizeof (struct ipt_entry )) !=0 || -copy_to_user (&ce->counters, &counters[i], -sizeof (counters[i])) !=0 ) +if (copy_to_user (ce, e, offsetof(struct compat_ipt_entry , counters)) || +copy_to_user (&ce->counters, &counters[i],sizeof (counters[i])))return -EFAULT ; *dstptr +=sizeof (struct compat_ipt_entry );
net/ipv6/netfilter/ip6_tables.c +6 -9
@@ -848,14 +848,12 @@ copy_entries_to_user(unsigned int total_size,const struct xt_entry_target *t; e = loc_cpu_entry + off; -if (copy_to_user (userptr + off, e,sizeof (*e))) { - ret = -EFAULT ; - goto free_counters; - } -if (copy_to_user (userptr + off +if (copy_to_user (userptr + off, e, + offsetof(struct ip6t_entry , counters)) || +copy_to_user (userptr + off + offsetof(struct ip6t_entry , counters), &counters[num], -sizeof (counters[num])) !=0 ) { +sizeof (counters[num]))) { ret = -EFAULT ; goto free_counters; }
@@ -1244,9 +1242,8 @@ compat_copy_entry_to_user(struct ip6t_entry *e, void __user **dstptr, origsize = *size; ce = *dstptr; -if (copy_to_user (ce, e,sizeof (struct ip6t_entry )) !=0 || -copy_to_user (&ce->counters, &counters[i], -sizeof (counters[i])) !=0 ) +if (copy_to_user (ce, e, offsetof(struct compat_ip6t_entry , counters)) || +copy_to_user (&ce->counters, &counters[i],sizeof (counters[i])))return -EFAULT ; *dstptr +=sizeof (struct compat_ip6t_entry );
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 5/8 netfilter: nf_log: validate MAC header was set before dumping it
In reply to Pablo Neira AyusoFrom: Xiang Mei <[email protected]>
The fallback path of dump_mac_header() guards the MAC header access only with "skb->mac_header != skb->network_header", without checking skb_mac_header_was_set(). When the MAC header is unset, mac_header is 0xffff, so the test passes and skb_mac_header(skb) returns skb->head + 0xffff, ~64 KiB past the buffer; the loop then reads dev->hard_header_len bytes out of bounds into the kernel log.
This is reachable via the netdev logger: nf_log_unknown_packet() calls dump_mac_header() unconditionally, and an skb sent through AF_PACKET with PACKET_QDISC_BYPASS reaches the egress hook with mac_header still unset (__dev_queue_xmit(), which would reset it, is bypassed).
Add the skb_mac_header_was_set() check the ARPHRD_ETHER path already uses, and replace the open-coded MAC header length test with skb_mac_header_len(). Only skbs with an unset MAC header are affected; valid ones are dumped as before.
BUG: KASAN: slab-out-of-bounds in dump_mac_header (net/netfilter/nf_log_syslog.c:831) Read of size 1 at addr ffff88800ea49d3f by task exploit/148 Call Trace: kasan_report (mm/kasan/report.c:595) dump_mac_header (net/netfilter/nf_log_syslog.c:831) nf_log_netdev_packet (net/netfilter/nf_log_syslog.c:938 net/netfilter/nf_log_syslog.c:963) nf_log_packet (net/netfilter/nf_log.c:260) nft_log_eval (net/netfilter/nft_log.c:60) nft_do_chain (net/netfilter/nf_tables_core.c:285) nft_do_chain_netdev (net/netfilter/nft_chain_filter.c:307) nf_hook_slow (net/netfilter/core.c:619) nf_hook_direct_egress (net/packet/af_packet.c:257) packet_xmit (net/packet/af_packet.c:280) packet_sendmsg (net/packet/af_packet.c:3114) __sys_sendto (net/socket.c:2265)
--- net/netfilter/nf_log_syslog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_log_syslog.c +2 -2
@@ -815,8 +815,8 @@ static void dump_mac_header(struct nf_log_buf *m, fallback:nf_log_buf_add (m,"MAC=" ); -if (dev->hard_header_len && - skb->mac_header != skb->network_header) { +if (dev->hard_header_len &&skb_mac_header_was_set (skb) && +skb_mac_header_len (skb) !=0 ) {const unsigned char *p =skb_mac_header (skb);unsigned int i;
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 6/8 netfilter: nft_exthdr: fix register tracking for F_PRESENT flag
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
nft_exthdr_init() passes user-controlled priv->len to nft_parse_register_store(), which marks that many bytes in the register bitmap as initialized. However, when NFT_EXTHDR_F_PRESENT is set, the eval paths write only 1 byte (nft_reg_store8) or 4 bytes (*dest = 0 on TCP/DCCP error path). When len > 4, registers beyond the first are never written, retaining uninitialized stack data from nft_regs.
Bail out if userspace requests too much data when F_PRESENT is set.
--- net/netfilter/nft_exthdr.c | 3 +++ 1 file changed, 3 insertions(+)
net/netfilter/nft_exthdr.c +3 -0
@@ -532,6 +532,9 @@ static int nft_exthdr_init(const struct nft_ctx *ctx,return err; } +if ((flags &NFT_EXTHDR_F_PRESENT ) && len !=1 ) +return -EINVAL ; + priv->type =nla_get_u8 (tb[NFTA_EXTHDR_TYPE ]); priv->offset = offset; priv->len = len;
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 7/8 netfilter: nft_fib: fix stale stack leak via the OIFNAME register
In reply to Pablo Neira AyusoFrom: Davide Ornaghi <[email protected]>
For NFT_FIB_RESULT_OIFNAME the destination register is declared with len = IFNAMSIZ (four 32-bit registers), but on the lookup-fail, RTN_LOCAL and oif-mismatch paths nft_fib{4,6}_eval() only writes one register via "*dest = 0". The remaining three registers are left as whatever was on the stack in nft_do_chain()'s struct nft_regs, and a downstream expression that loads the register span can leak that uninitialised kernel stack to userspace.
The NFTA_FIB_F_PRESENT existence check has the same shape: it is only meaningful for NFT_FIB_RESULT_OIF, yet it was accepted for any result type while the eval stores a single byte via nft_reg_store8(), leaving the rest of the declared span stale.
Fix both:
- replace the bare "*dest = 0" in the eval with nft_fib_store_result(), which strscpy_pad()s the whole IFNAMSIZ for OIFNAME (and is already used on the other early-return path), and
- restrict NFTA_FIB_F_PRESENT to NFT_FIB_RESULT_OIF and declare its destination as a single u8, so the marked span matches the one byte the eval writes.
--- net/ipv4/netfilter/nft_fib_ipv4.c | 2 +- net/ipv6/netfilter/nft_fib_ipv6.c | 2 +- net/netfilter/nft_fib.c | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-)
net/ipv4/netfilter/nft_fib_ipv4.c +1 -1
@@ -128,7 +128,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs, fl4.saddr =get_saddr (iph->daddr); } - *dest =0 ; +nft_fib_store_result (dest, priv,NULL );if (fib_lookup (nft_net (pkt), &fl4, &res,FIB_LOOKUP_IGNORE_LINKSTATE ))return ;
net/ipv6/netfilter/nft_fib_ipv6.c +1 -1
@@ -239,7 +239,7 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs, lookup_flags =nft_fib6_flowi_init (&fl6, priv, pkt, oif, iph); - *dest =0 ; +nft_fib_store_result (dest, priv,NULL ); ret =nft_fib6_lookup (nft_net (pkt), &fl6, &res, lookup_flags);if (ret || res.fib6_flags & (RTF_REJECT |RTF_ANYCAST |RTF_LOCAL ))return ;
net/netfilter/nft_fib.c +6 -0
@@ -107,6 +107,12 @@ int nft_fib_init(const struct nft_ctx *ctx, const struct nft_expr *expr,return -EINVAL ; } +if (priv->flags &NFTA_FIB_F_PRESENT ) { +if (priv->result !=NFT_FIB_RESULT_OIF ) +return -EINVAL ; + len =sizeof (u8); + } + err =nft_parse_register_store (ctx, tb[NFTA_FIB_DREG ], &priv->dreg,NULL ,NFT_DATA_VALUE , len);if (err <0 )
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 8/8 netfilter: nft_meta_bridge: fix stale stack leak via IIFHWADDR register
In reply to Pablo Neira AyusoFrom: Davide Ornaghi <[email protected]>
NFT_META_BRI_IIFHWADDR declares its destination register with len = ETH_ALEN (6 bytes), which the register-init tracking rounds up to two 32-bit registers (8 bytes). nft_meta_bridge_get_eval() then does memcpy(dest, br_dev->dev_addr, ETH_ALEN), writing only 6 bytes and leaving the upper 2 bytes of the second register as uninitialised nft_do_chain() stack. A downstream load of that register span leaks those stale bytes to userspace.
Zero the second register before the memcpy so the full declared span is written.
--- net/bridge/netfilter/nft_meta_bridge.c | 2 ++ 1 file changed, 2 insertions(+)
net/bridge/netfilter/nft_meta_bridge.c +2 -0
@@ -64,6 +64,8 @@ static void nft_meta_bridge_get_eval(const struct nft_expr *expr,if (!br_dev) goto err; +/* ETH_ALEN (6) is shorter than the destination register span (8) */ + dest[1 ] =0 ;memcpy (dest, br_dev->dev_addr,ETH_ALEN );return ;default :
Signature · 1 line
2.47.3