netfilter: nf_reject: don't leak dst refcount for loopback packets
Subsystems (3)
Florian Westphal
maintainerPATCH 1/1 netfilter: nf_reject: don't leak dst refcount for loopback packets
recent patches to add a WARN() when replacing skb dst entry found an old bug:
WARNING: include/linux/skbuff.h:1165 skb_dst_check_unset include/linux/skbuff.h:1164 [inline] WARNING: include/linux/skbuff.h:1165 skb_dst_set include/linux/skbuff.h:1210 [inline] WARNING: include/linux/skbuff.h:1165 nf_reject_fill_skb_dst+0x2a4/0x330 net/ipv4/netfilter/nf_reject_ipv4.c:234 [..] Call Trace: nf_send_unreach+0x17b/0x6e0 net/ipv4/netfilter/nf_reject_ipv4.c:325 nft_reject_inet_eval+0x4bc/0x690 net/netfilter/nft_reject_inet.c:27 expr_call_ops_eval net/netfilter/nf_tables_core.c:237 [inline] ..
This is because blamed commit forgot about loopback packets. Such packets already have a dst_entry attached, even at PRE_ROUTING stage.
Instead of checking hook just check if the skb already has a route attached to it.
---
Sending this instead of a pull request. the only other two candidates for -net are still under review.
Let me know if you prefer a normal pull request even in this case. Thanks!
net/ipv4/netfilter/nf_reject_ipv4.c | 6 ++---- net/ipv6/netfilter/nf_reject_ipv6.c | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-)
net/ipv4/netfilter/nf_reject_ipv4.c +2 -4
@@ -247,8 +247,7 @@ void nf_send_reset(struct net *net, struct sock *sk, struct sk_buff *oldskb,if (!oth)return ; -if ((hook ==NF_INET_PRE_ROUTING || hook ==NF_INET_INGRESS ) && -nf_reject_fill_skb_dst (oldskb) <0 ) +if (!skb_dst (oldskb) &&nf_reject_fill_skb_dst (oldskb) <0 )return ;if (skb_rtable (oldskb)->rt_flags & (RTCF_BROADCAST |RTCF_MULTICAST ))
@@ -321,8 +320,7 @@ void nf_send_unreach(struct sk_buff *skb_in, int code, int hook)if (iph->frag_off &htons (IP_OFFSET ))return ; -if ((hook ==NF_INET_PRE_ROUTING || hook ==NF_INET_INGRESS ) && -nf_reject_fill_skb_dst (skb_in) <0 ) +if (!skb_dst (skb_in) &&nf_reject_fill_skb_dst (skb_in) <0 )return ; if (skb_csum_unnecessary(skb_in) ||
net/ipv6/netfilter/nf_reject_ipv6.c +2 -3
@@ -293,7 +293,7 @@ void nf_send_reset6(struct net *net, struct sock *sk, struct sk_buff *oldskb, fl6.fl6_sport = otcph->dest; fl6.fl6_dport = otcph->source; -if (hook ==NF_INET_PRE_ROUTING || hook ==NF_INET_INGRESS ) { +if (!skb_dst (oldskb)) {nf_ip6_route (net, &dst,flowi6_to_flowi (&fl6), false);if (!dst)return ;
@@ -397,8 +397,7 @@ void nf_send_unreach6(struct net *net, struct sk_buff *skb_in,if (hooknum ==NF_INET_LOCAL_OUT && skb_in->dev ==NULL ) skb_in->dev = net->loopback_dev; -if ((hooknum ==NF_INET_PRE_ROUTING || hooknum ==NF_INET_INGRESS ) && -nf_reject6_fill_skb_dst (skb_in) <0 ) +if (!skb_dst (skb_in) &&nf_reject6_fill_skb_dst (skb_in) <0 )return ;icmpv6_send (skb_in,ICMPV6_DEST_UNREACH , code,0 );
Signature · 1 line
2.49.1
Pablo Neira Ayuso
maintainerHi Florian,
Quoted 13 lines · Florian Westphal
recent patches to add a
WARN()when replacing skb dst entry found an old bug:WARNING: include/linux/skbuff.h:1165 skb_dst_check_unset include/linux/skbuff.h:1164 [inline] WARNING: include/linux/skbuff.h:1165 skb_dst_set include/linux/skbuff.h:1210 [inline] WARNING: include/linux/skbuff.h:1165 nf_reject_fill_skb_dst+0x2a4/0x330 net/ipv4/netfilter/nf_reject_ipv4.c:234 [..] Call Trace: nf_send_unreach+0x17b/0x6e0 net/ipv4/netfilter/nf_reject_ipv4.c:325 nft_reject_inet_eval+0x4bc/0x690 net/netfilter/nft_reject_inet.c:27 expr_call_ops_eval net/netfilter/nf_tables_core.c:237 [inline] ..
Quoted 5 lines
This is because blamed commit forgot about loopback packets. Such packets already have a
dst_entryattached, even atPRE_ROUTINGstage.Instead of checking hook just check if the skb already has a route attached to it.
Quick question: does inconditional route lookup work for br_netfilter?
Quoted 63 lines
Fixes f53b9b0bdc59 ("netfilter: introduce support for reject at prerouting stage")Signed-off-by Florian Westphal <[email protected]>---
Sending this instead of a pull request. the only other two candidates for -net are still under review.Let me know if you prefer a normal pull request even in this case. Thanks!
net/ipv4/netfilter/nf_reject_ipv4.c | 6 ++---- net/ipv6/netfilter/nf_reject_ipv6.c | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-)net/ipv4/netfilter/nf_reject_ipv4.c +2
-4@@ -247,8 +247,7 @@ void nf_send_reset(struct net *net, struct sock *sk, struct sk_buff *oldskb,if (!oth)return ; -if ((hook ==NF_INET_PRE_ROUTING || hook ==NF_INET_INGRESS ) && -nf_reject_fill_skb_dst (oldskb) <0 ) +if (!skb_dst (oldskb) &&nf_reject_fill_skb_dst (oldskb) <0 )return ;if (skb_rtable (oldskb)->rt_flags & (RTCF_BROADCAST |RTCF_MULTICAST ))@@ -321,8 +320,7 @@ void nf_send_unreach(struct sk_buff *skb_in, int code, int hook)if (iph->frag_off &htons (IP_OFFSET ))return ; -if ((hook ==NF_INET_PRE_ROUTING || hook ==NF_INET_INGRESS ) && -nf_reject_fill_skb_dst (skb_in) <0 ) +if (!skb_dst (skb_in) &&nf_reject_fill_skb_dst (skb_in) <0 )return ; if (skb_csum_unnecessary(skb_in) ||net/ipv6/netfilter/nf_reject_ipv6.c +2
-3@@ -293,7 +293,7 @@ void nf_send_reset6(struct net *net, struct sock *sk, struct sk_buff *oldskb, fl6.fl6_sport = otcph->dest; fl6.fl6_dport = otcph->source; -if (hook ==NF_INET_PRE_ROUTING || hook ==NF_INET_INGRESS ) { +if (!skb_dst (oldskb)) {nf_ip6_route (net, &dst,flowi6_to_flowi (&fl6), false);if (!dst)return ;@@ -397,8 +397,7 @@ void nf_send_unreach6(struct net *net, struct sk_buff *skb_in,if (hooknum ==NF_INET_LOCAL_OUT && skb_in->dev ==NULL ) skb_in->dev = net->loopback_dev; -if ((hooknum ==NF_INET_PRE_ROUTING || hooknum ==NF_INET_INGRESS ) && -nf_reject6_fill_skb_dst (skb_in) <0 ) +if (!skb_dst (skb_in) &&nf_reject6_fill_skb_dst (skb_in) <0 )return ;icmpv6_send (skb_in,ICMPV6_DEST_UNREACH , code,0 );Signature · 1 line
2.49.1
Pablo Neira Ayuso
maintainerQuoted 16 lines · Pablo Neira Ayuso
Hi Florian,
Quoted 13 lines · Florian Westphal
recent patches to add a
WARN()when replacing skb dst entry found an old bug:WARNING: include/linux/skbuff.h:1165 skb_dst_check_unset include/linux/skbuff.h:1164 [inline] WARNING: include/linux/skbuff.h:1165 skb_dst_set include/linux/skbuff.h:1210 [inline] WARNING: include/linux/skbuff.h:1165 nf_reject_fill_skb_dst+0x2a4/0x330 net/ipv4/netfilter/nf_reject_ipv4.c:234 [..] Call Trace: nf_send_unreach+0x17b/0x6e0 net/ipv4/netfilter/nf_reject_ipv4.c:325 nft_reject_inet_eval+0x4bc/0x690 net/netfilter/nft_reject_inet.c:27 expr_call_ops_eval net/netfilter/nf_tables_core.c:237 [inline] ..
Quoted 7 lines
Quoted 5 lines
This is because blamed commit forgot about loopback packets. Such packets already have a
dst_entryattached, even atPRE_ROUTINGstage.Instead of checking hook just check if the skb already has a route attached to it.
Quick question: does inconditional route lookup work for
br_netfilter?
Never mind, it should be fine, the fake dst get attached to the skb.
Florian Westphal
maintainerQuoted 6 lines · Pablo Neira Ayuso
Quoted 4 lines
Quoted 2 lines
Instead of checking hook just check if the skb already has a route attached to it.
Quick question: does inconditional route lookup work for
br_netfilter?Never mind, it should be fine, the fake dst get attached to the skb.
Good point, this changes behaviour for br_netfilter case, we no longer call nf_reject_fill_skb_dst() then due to the fake dst.
I don't think br_netfilter is supposed to do anything (iptables -j REJECT doesn't work in PRE_ROUTING), and we should not encourage use of br_netfilter with nftables.
What about adding a followup patch, targetting nf, that adds:
if (hook == NF_INET_PRE_ROUTING && nf_bridge_info_exists(oldskb))
return;
?
After all, there is no guarantee that we have the needed routing info on a bridge in the first place.
Jakub Kicinski
maintainerQuoted 13 lines · On Wed, 20 Aug 2025 16:04:47 +0200 Florian Westphal wrote:
Quoted 3 lines
Quoted 1 line
Quick question: does inconditional route lookup work for
br_netfilter?Never mind, it should be fine, the fake dst get attached to the skb.
Good point, this changes behaviour for
br_netfiltercase, we no longer callnf_reject_fill_skb_dst()then due to the fake dst.I don't think
br_netfilteris supposed to do anything (iptables -j REJECT doesn't work inPRE_ROUTING), and we should not encourage use ofbr_netfilterwith nftables.What about adding a followup patch, targetting nf, that adds:
Quoted 7 lines
if (hook ==
NF_INET_PRE_ROUTING&&nf_bridge_info_exists(oldskb))return;?
After all, there is no guarantee that we have the needed routing info on a bridge in the first place.
Pablo, are you okay with that plan? Would be great to ship this to Linus and therefore net-next today, given the checks recently added there..
Quoted 20 lines · Florian Westphal
recent patches to add a
WARN()when replacing skb dst entry found an old bug:WARNING: include/linux/skbuff.h:1165 skb_dst_check_unset include/linux/skbuff.h:1164 [inline] WARNING: include/linux/skbuff.h:1165 skb_dst_set include/linux/skbuff.h:1210 [inline] WARNING: include/linux/skbuff.h:1165 nf_reject_fill_skb_dst+0x2a4/0x330 net/ipv4/netfilter/nf_reject_ipv4.c:234 [..] Call Trace: nf_send_unreach+0x17b/0x6e0 net/ipv4/netfilter/nf_reject_ipv4.c:325 nft_reject_inet_eval+0x4bc/0x690 net/netfilter/nft_reject_inet.c:27 expr_call_ops_eval net/netfilter/nf_tables_core.c:237 [inline] ..This is because blamed commit forgot about loopback packets. Such packets already have a
dst_entryattached, even atPRE_ROUTINGstage.Instead of checking hook just check if the skb already has a route attached to it.
Quoted 9 lines
Fixes f53b9b0bdc59 ("netfilter: introduce support for reject at prerouting stage")Signed-off-by Florian Westphal <[email protected]>---
Sending this instead of a pull request. the only other two candidates for -net are still under review.Let me know if you prefer a normal pull request even in this case. Thanks!
Great, I was looking at an internal syzbot report with this exact issue.
WARNING: CPU: 1 PID: 5922 at ./include/linux/skbuff.h:1165 skb_dst_check_unset include/linux/skbuff.h:1164 [inline] WARNING: CPU: 1 PID: 5922 at ./include/linux/skbuff.h:1165 skb_dst_set include/linux/skbuff.h:1211 [inline] WARNING: CPU: 1 PID: 5922 at ./include/linux/skbuff.h:1165 nf_reject6_fill_skb_dst net/ipv6/netfilter/nf_reject_ipv6.c:264 [inline] WARNING: CPU: 1 PID: 5922 at ./include/linux/skbuff.h:1165 nf_send_unreach6+0x828/0xa20 net/ipv6/netfilter/nf_reject_ipv6.c:401 Modules linked in: CPU: 1 UID: 0 PID: 5922 Comm: kworker/1:3 Not tainted syzkaller #0 PREEMPT(full) Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025 Workqueue: wg-crypt-wg0 wg_packet_tx_worker RIP: 0010:skb_dst_check_unset include/linux/skbuff.h:1164 [inline] RIP: 0010:skb_dst_set include/linux/skbuff.h:1211 [inline] RIP: 0010:nf_reject6_fill_skb_dst net/ipv6/netfilter/nf_reject_ipv6.c:264 [inline] RIP: 0010:nf_send_unreach6+0x828/0xa20 net/ipv6/netfilter/nf_reject_ipv6.c:401 Code: 85 f6 74 0a e8 a9 6c 7a f7 e9 c8 fc ff ff e8 9f 6c 7a f7 4c 8b
7c 24 18 e9 34 fa ff ff e8 90 6c 7a f7 eb 9b e8 89 6c 7a f7 90 <0f> 0b 90 e9 c7 fb ff ff 48 85 db 0f 84 81 00 00 00 4c 8d a4 24 20
RSP: 0018:ffffc90000a083c0 EFLAGS: 00010246
RAX: ffffffff8a453fa7 RBX: ffff88802e6888c0 RCX: ffff88802fc3da00
RDX: 0000000000000100 RSI: 0000000000000000 RDI: 0000000000000000
RBP: ffffc90000a08568 R08: ffff888078550b83 R09: 1ffff1100f0aa170
R10: dffffc0000000000 R11: ffffed100f0aa171 R12: ffff888079bb4101
R13: dffffc0000000001 R14: 1ffff11005cd1123 R15: 0000000000000000
FS: 0000000000000000(0000) GS:ffff888125d1b000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fd4758e56c0 CR3: 00000000776ca000 CR4: 00000000003526f0
Call Trace: <IRQ> nft_reject_inet_eval+0x441/0x690 net/netfilter/nft_reject_inet.c:44 expr_call_ops_eval net/netfilter/nf_tables_core.c:237 [inline] nft_do_chain+0x40c/0x1920 net/netfilter/nf_tables_core.c:285 nft_do_chain_inet+0x25d/0x340 net/netfilter/nft_chain_filter.c:161 nf_hook_entry_hookfn include/linux/netfilter.h:158 [inline] nf_hook_slow+0xc5/0x220 net/netfilter/core.c:623 nf_hook include/linux/netfilter.h:273 [inline] NF_HOOK+0x206/0x3a0 include/linux/netfilter.h:316 __netif_receive_skb_one_core net/core/dev.c:5979 [inline] __netif_receive_skb+0xd3/0x380 net/core/dev.c:6092 process_backlog+0x60e/0x14f0 net/core/dev.c:6444 __napi_poll+0xc7/0x360 net/core/dev.c:7494 napi_poll net/core/dev.c:7557 [inline] net_rx_action+0x707/0xe30 net/core/dev.c:7684 handle_softirqs+0x283/0x870 kernel/softirq.c:579 do_softirq+0xec/0x180 kernel/softirq.c:480 </IRQ> <TASK> __local_bh_enable_ip+0x17d/0x1c0 kernel/softirq.c:407 wg_socket_send_skb_to_peer+0x16b/0x1d0 drivers/net/wireguard/socket.c:184 wg_packet_create_data_done drivers/net/wireguard/send.c:251 [inline] wg_packet_tx_worker+0x1c8/0x7c0 drivers/net/wireguard/send.c:276 process_one_work kernel/workqueue.c:3236 [inline] process_scheduled_works+0xae1/0x17b0 kernel/workqueue.c:3319 worker_thread+0x8a0/0xda0 kernel/workqueue.c:3400 kthread+0x711/0x8a0 kernel/kthread.c:463 ret_from_fork+0x3f9/0x770 arch/x86/kernel/process.c:148 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245 </TASK>
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 13 lines · On Wed, 20 Aug 2025 14:37:07 +0200 you wrote:
recent patches to add a
WARN()when replacing skb dst entry found an old bug:WARNING: include/linux/skbuff.h:1165 skb_dst_check_unset include/linux/skbuff.h:1164 [inline] WARNING: include/linux/skbuff.h:1165 skb_dst_set include/linux/skbuff.h:1210 [inline] WARNING: include/linux/skbuff.h:1165 nf_reject_fill_skb_dst+0x2a4/0x330 net/ipv4/netfilter/nf_reject_ipv4.c:234 [..] Call Trace: nf_send_unreach+0x17b/0x6e0 net/ipv4/netfilter/nf_reject_ipv4.c:325 nft_reject_inet_eval+0x4bc/0x690 net/netfilter/nft_reject_inet.c:27 expr_call_ops_eval net/netfilter/nf_tables_core.c:237 [inline] ..
Quoted 1 line
[...]
Here is the summary with links:
- [net] netfilter: nf_reject: don't leak dst refcount for loopback packets
https://git.kernel.org/netdev/net/c/91a79b792204
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html