* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
@ 2025-08-25 1:10 ` Hillf Danton
2025-08-25 1:51 ` syzbot
2025-08-25 4:51 ` Hillf Danton
` (19 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Hillf Danton @ 2025-08-25 1:10 UTC (permalink / raw)
To: syzbot; +Cc: linux-kernel, syzkaller-bugs
> Date: Sun, 24 Aug 2025 12:21:23 -0700 [thread overview]
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b1c92cdf5af3 Merge branch 'net-wangxun-complete-ethtool-co..
> git tree: net-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1411b062580000
> kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
> dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
> compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14221862580000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=159fba34580000
#syz test
--- x/net/xfrm/xfrm_state.c
+++ y/net/xfrm/xfrm_state.c
@@ -615,6 +615,7 @@ static void xfrm_state_gc_destroy(struct
put_page(x->xfrag.page);
xfrm_dev_state_free(x);
security_xfrm_state_free(x);
+ xfrm_state_delete(x);
xfrm_state_free(x);
}
--
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-25 1:10 ` Hillf Danton
@ 2025-08-25 1:51 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-25 1:51 UTC (permalink / raw)
To: hdanton, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Write in __xfrm_state_delete
==================================================================
BUG: KASAN: slab-use-after-free in __hlist_del include/linux/list.h:980 [inline]
BUG: KASAN: slab-use-after-free in hlist_del_rcu include/linux/rculist.h:560 [inline]
BUG: KASAN: slab-use-after-free in __xfrm_state_delete+0x666/0xca0 net/xfrm/xfrm_state.c:831
Write of size 8 at addr ffff88805adca228 by task kworker/u8:3/49
CPU: 0 UID: 0 PID: 49 Comm: kworker/u8:3 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Workqueue: netns cleanup_net
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xca/0x240 mm/kasan/report.c:482
kasan_report+0x118/0x150 mm/kasan/report.c:595
__hlist_del include/linux/list.h:980 [inline]
hlist_del_rcu include/linux/rculist.h:560 [inline]
__xfrm_state_delete+0x666/0xca0 net/xfrm/xfrm_state.c:831
xfrm_state_delete net/xfrm/xfrm_state.c:857 [inline]
xfrm_state_flush+0x45f/0x770 net/xfrm/xfrm_state.c:940
xfrm6_tunnel_net_exit+0x3c/0x100 net/ipv6/xfrm6_tunnel.c:337
ops_exit_list net/core/net_namespace.c:198 [inline]
ops_undo_list+0x497/0x990 net/core/net_namespace.c:251
cleanup_net+0x4c5/0x800 net/core/net_namespace.c:682
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+0x70e/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>
Allocated by task 8781:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
unpoison_slab_object mm/kasan/common.c:330 [inline]
__kasan_slab_alloc+0x6c/0x80 mm/kasan/common.c:356
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
kmem_cache_alloc_noprof+0x1c1/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x2f0 net/xfrm/xfrm_state.c:734
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1834
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2354
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a3/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x205/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82c/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x21c/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 5886:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:576
poison_slab_object mm/kasan/common.c:243 [inline]
__kasan_slab_free+0x5b/0x80 mm/kasan/common.c:275
kasan_slab_free include/linux/kasan.h:233 [inline]
slab_free_hook mm/slub.c:2417 [inline]
slab_free mm/slub.c:4680 [inline]
kmem_cache_free+0x18f/0x400 mm/slub.c:4782
xfrm_state_free net/xfrm/xfrm_state.c:591 [inline]
xfrm_state_gc_destroy net/xfrm/xfrm_state.c:619 [inline]
xfrm_state_gc_task+0x549/0x6d0 net/xfrm/xfrm_state.c:635
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+0x70e/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
The buggy address belongs to the object at ffff88805adca200
which belongs to the cache xfrm_state of size 928
The buggy address is located 40 bytes inside of
freed 928-byte region [ffff88805adca200, ffff88805adca5a0)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x5adc8
head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
ksm flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff8880206d5b40 ffffea0000a56400 dead000000000003
raw: 0000000000000000 00000000000f000f 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff8880206d5b40 ffffea0000a56400 dead000000000003
head: 0000000000000000 00000000000f000f 00000000f5000000 0000000000000000
head: 00fff00000000002 ffffea00016b7201 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000004
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Unmovable, gfp_mask 0x52820(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 7652, tgid 7651 (syz.0.589), ts 110782357540, free_ts 110737724351
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3858
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5148
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2416
alloc_slab_page mm/slub.c:2487 [inline]
allocate_slab+0x8a/0x370 mm/slub.c:2655
new_slab mm/slub.c:2709 [inline]
___slab_alloc+0xbeb/0x1410 mm/slub.c:3891
__slab_alloc mm/slub.c:3981 [inline]
__slab_alloc_node mm/slub.c:4056 [inline]
slab_alloc_node mm/slub.c:4217 [inline]
kmem_cache_alloc_noprof+0x283/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x2f0 net/xfrm/xfrm_state.c:734
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1834
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2354
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a3/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x205/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82c/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
page last free pid 6376 tgid 6376 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
__free_frozen_pages+0xbc4/0xd30 mm/page_alloc.c:2895
discard_slab mm/slub.c:2753 [inline]
__put_partials+0x156/0x1a0 mm/slub.c:3218
put_cpu_partial+0x17c/0x250 mm/slub.c:3293
__slab_free+0x2d5/0x3c0 mm/slub.c:4550
qlink_free mm/kasan/quarantine.c:163 [inline]
qlist_free_all+0x97/0x140 mm/kasan/quarantine.c:179
kasan_quarantine_reduce+0x148/0x160 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x22/0x80 mm/kasan/common.c:340
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
kmem_cache_alloc_noprof+0x1c1/0x3c0 mm/slub.c:4236
getname_flags+0xb8/0x540 fs/namei.c:146
getname include/linux/fs.h:2918 [inline]
__do_sys_unlink fs/namei.c:4696 [inline]
__se_sys_unlink fs/namei.c:4694 [inline]
__x64_sys_unlink+0x3a/0x50 fs/namei.c:4694
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff88805adca100: 00 00 00 00 00 00 00 00 00 00 00 00 fc fc fc fc
ffff88805adca180: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88805adca200: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88805adca280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88805adca300: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Tested on:
commit: b1c92cdf Merge branch 'net-wangxun-complete-ethtool-co..
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=15eb1862580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=13f62ef0580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
2025-08-25 1:10 ` Hillf Danton
@ 2025-08-25 4:51 ` Hillf Danton
2025-08-25 12:33 ` syzbot
2025-08-25 12:44 ` Hillf Danton
` (18 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Hillf Danton @ 2025-08-25 4:51 UTC (permalink / raw)
To: syzbot; +Cc: linux-kernel, syzkaller-bugs
> Date: Sun, 24 Aug 2025 12:21:23 -0700 [thread overview]
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b1c92cdf5af3 Merge branch 'net-wangxun-complete-ethtool-co..
> git tree: net-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1411b062580000
> kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
> dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
> compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14221862580000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=159fba34580000
#syz test
--- x/net/xfrm/xfrm_state.c
+++ y/net/xfrm/xfrm_state.c
@@ -615,6 +615,8 @@ static void xfrm_state_gc_destroy(struct
put_page(x->xfrag.page);
xfrm_dev_state_free(x);
security_xfrm_state_free(x);
+ x->km.state++;
+ xfrm_state_delete(x);
xfrm_state_free(x);
}
--
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-25 4:51 ` Hillf Danton
@ 2025-08-25 12:33 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-25 12:33 UTC (permalink / raw)
To: hdanton, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
BUG: corrupted list in __xfrm_state_delete
non-paged memory
list_del corruption, ffff88805ae82758->next is LIST_POISON1 (dead000000000100)
------------[ cut here ]------------
kernel BUG at lib/list_debug.c:58!
Oops: invalid opcode: 0000 [#1] SMP KASAN PTI
CPU: 0 UID: 0 PID: 9 Comm: kworker/0:0 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Workqueue: events xfrm_state_gc_task
RIP: 0010:__list_del_entry_valid_or_report+0x10e/0x190 lib/list_debug.c:56
Code: 00 3a e3 8b 48 89 de e8 d0 79 57 fc 90 0f 0b 4c 89 e7 e8 f5 ff 31 fd 48 c7 c7 60 3a e3 8b 48 89 de 4c 89 e2 e8 b3 79 57 fc 90 <0f> 0b 4c 89 e7 e8 d8 ff 31 fd 48 c7 c7 c0 3a e3 8b 48 89 de 4c 89
RSP: 0018:ffffc900000e7900 EFLAGS: 00010246
RAX: 000000000000004e RBX: ffff88805ae82758 RCX: 684aa0a479b90900
RDX: 0000000000000000 RSI: 0000000000000202 RDI: 0000000000000000
RBP: dffffc0000000000 R08: 0000000000000003 R09: 0000000000000004
R10: dffffc0000000000 R11: fffffbfff1bfa1ec R12: dead000000000100
R13: dffffc0000000000 R14: dead000000000100 R15: dead000000000122
FS: 0000000000000000(0000) GS:ffff888125c18000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000562559a41950 CR3: 000000007bf98000 CR4: 00000000003526f0
Call Trace:
<TASK>
__list_del_entry_valid include/linux/list.h:124 [inline]
__list_del_entry include/linux/list.h:215 [inline]
list_del include/linux/list.h:229 [inline]
__xfrm_state_delete+0xc2/0xca0 net/xfrm/xfrm_state.c:821
xfrm_state_delete net/xfrm/xfrm_state.c:858 [inline]
xfrm_state_gc_destroy net/xfrm/xfrm_state.c:619 [inline]
xfrm_state_gc_task+0x54f/0x700 net/xfrm/xfrm_state.c:636
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+0x70e/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>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:__list_del_entry_valid_or_report+0x10e/0x190 lib/list_debug.c:56
Code: 00 3a e3 8b 48 89 de e8 d0 79 57 fc 90 0f 0b 4c 89 e7 e8 f5 ff 31 fd 48 c7 c7 60 3a e3 8b 48 89 de 4c 89 e2 e8 b3 79 57 fc 90 <0f> 0b 4c 89 e7 e8 d8 ff 31 fd 48 c7 c7 c0 3a e3 8b 48 89 de 4c 89
RSP: 0018:ffffc900000e7900 EFLAGS: 00010246
RAX: 000000000000004e RBX: ffff88805ae82758 RCX: 684aa0a479b90900
RDX: 0000000000000000 RSI: 0000000000000202 RDI: 0000000000000000
RBP: dffffc0000000000 R08: 0000000000000003 R09: 0000000000000004
R10: dffffc0000000000 R11: fffffbfff1bfa1ec R12: dead000000000100
R13: dffffc0000000000 R14: dead000000000100 R15: dead000000000122
FS: 0000000000000000(0000) GS:ffff888125c18000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000562559a41950 CR3: 000000007bf98000 CR4: 00000000003526f0
Tested on:
commit: b1c92cdf Merge branch 'net-wangxun-complete-ethtool-co..
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=15a39862580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=10077a34580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
2025-08-25 1:10 ` Hillf Danton
2025-08-25 4:51 ` Hillf Danton
@ 2025-08-25 12:44 ` Hillf Danton
2025-08-25 14:13 ` syzbot
2025-08-25 15:59 ` Sabrina Dubroca
` (17 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Hillf Danton @ 2025-08-25 12:44 UTC (permalink / raw)
To: syzbot; +Cc: linux-kernel, syzkaller-bugs
> Date: Sun, 24 Aug 2025 12:21:23 -0700 [thread overview]
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b1c92cdf5af3 Merge branch 'net-wangxun-complete-ethtool-co..
> git tree: net-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1411b062580000
> kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
> dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
> compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14221862580000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=159fba34580000
#syz test
--- x/net/xfrm/xfrm_state.c
+++ y/net/xfrm/xfrm_state.c
@@ -615,6 +615,8 @@ static void xfrm_state_gc_destroy(struct
put_page(x->xfrag.page);
xfrm_dev_state_free(x);
security_xfrm_state_free(x);
+ x->km.state++;
+ xfrm_state_delete(x);
xfrm_state_free(x);
}
@@ -816,7 +818,11 @@ int __xfrm_state_delete(struct xfrm_stat
x->km.state = XFRM_STATE_DEAD;
spin_lock(&net->xfrm.xfrm_state_lock);
- list_del(&x->km.all);
+ if (list_empty(&x->km.all)) {
+ spin_unlock(&net->xfrm.xfrm_state_lock);
+ return 0;
+ }
+ list_del_init(&x->km.all);
hlist_del_rcu(&x->bydst);
hlist_del_rcu(&x->bysrc);
if (x->km.seq)
--
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-25 12:44 ` Hillf Danton
@ 2025-08-25 14:13 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-25 14:13 UTC (permalink / raw)
To: hdanton, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Write in __xfrm_state_delete
==================================================================
BUG: KASAN: slab-use-after-free in __hlist_del include/linux/list.h:980 [inline]
BUG: KASAN: slab-use-after-free in hlist_del_rcu include/linux/rculist.h:560 [inline]
BUG: KASAN: slab-use-after-free in __xfrm_state_delete+0x5ff/0xc80 net/xfrm/xfrm_state.c:836
Write of size 8 at addr ffff888077c659a8 by task kworker/u8:3/49
CPU: 1 UID: 0 PID: 49 Comm: kworker/u8:3 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Workqueue: netns cleanup_net
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xca/0x240 mm/kasan/report.c:482
kasan_report+0x118/0x150 mm/kasan/report.c:595
__hlist_del include/linux/list.h:980 [inline]
hlist_del_rcu include/linux/rculist.h:560 [inline]
__xfrm_state_delete+0x5ff/0xc80 net/xfrm/xfrm_state.c:836
xfrm_state_delete net/xfrm/xfrm_state.c:862 [inline]
xfrm_state_flush+0x45f/0x770 net/xfrm/xfrm_state.c:945
xfrm6_tunnel_net_exit+0x3c/0x100 net/ipv6/xfrm6_tunnel.c:337
ops_exit_list net/core/net_namespace.c:198 [inline]
ops_undo_list+0x497/0x990 net/core/net_namespace.c:251
cleanup_net+0x4c5/0x800 net/core/net_namespace.c:682
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+0x70e/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>
Allocated by task 7549:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
unpoison_slab_object mm/kasan/common.c:330 [inline]
__kasan_slab_alloc+0x6c/0x80 mm/kasan/common.c:356
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
kmem_cache_alloc_noprof+0x1c1/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x2f0 net/xfrm/xfrm_state.c:735
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1839
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2359
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a0/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x205/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82c/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x21c/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 6519:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:576
poison_slab_object mm/kasan/common.c:243 [inline]
__kasan_slab_free+0x5b/0x80 mm/kasan/common.c:275
kasan_slab_free include/linux/kasan.h:233 [inline]
slab_free_hook mm/slub.c:2417 [inline]
slab_free mm/slub.c:4680 [inline]
kmem_cache_free+0x18f/0x400 mm/slub.c:4782
xfrm_state_free net/xfrm/xfrm_state.c:591 [inline]
xfrm_state_gc_destroy net/xfrm/xfrm_state.c:620 [inline]
xfrm_state_gc_task+0x566/0x700 net/xfrm/xfrm_state.c:636
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+0x70e/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
The buggy address belongs to the object at ffff888077c65980
which belongs to the cache xfrm_state of size 928
The buggy address is located 40 bytes inside of
freed 928-byte region [ffff888077c65980, ffff888077c65d20)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x77c64
head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff88801b381280 dead000000000122 0000000000000000
raw: 0000000000000000 00000000000f000f 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff88801b381280 dead000000000122 0000000000000000
head: 0000000000000000 00000000000f000f 00000000f5000000 0000000000000000
head: 00fff00000000002 ffffea0001df1901 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000004
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Unmovable, gfp_mask 0x52820(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 7529, tgid 7528 (syz.0.521), ts 196999276626, free_ts 191028336513
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3858
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5148
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2416
alloc_slab_page mm/slub.c:2487 [inline]
allocate_slab+0x8a/0x370 mm/slub.c:2655
new_slab mm/slub.c:2709 [inline]
___slab_alloc+0xbeb/0x1410 mm/slub.c:3891
__slab_alloc mm/slub.c:3981 [inline]
__slab_alloc_node mm/slub.c:4056 [inline]
slab_alloc_node mm/slub.c:4217 [inline]
kmem_cache_alloc_noprof+0x283/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x2f0 net/xfrm/xfrm_state.c:735
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1839
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2359
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a0/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x205/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82c/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
page last free pid 6212 tgid 6212 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
__free_frozen_pages+0xbc4/0xd30 mm/page_alloc.c:2895
__slab_free+0x303/0x3c0 mm/slub.c:4591
qlink_free mm/kasan/quarantine.c:163 [inline]
qlist_free_all+0x97/0x140 mm/kasan/quarantine.c:179
kasan_quarantine_reduce+0x148/0x160 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x22/0x80 mm/kasan/common.c:340
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
kmem_cache_alloc_noprof+0x1c1/0x3c0 mm/slub.c:4236
getname_flags+0xb8/0x540 fs/namei.c:146
getname include/linux/fs.h:2918 [inline]
getname_maybe_null include/linux/fs.h:2925 [inline]
vfs_fstatat+0x43/0x170 fs/stat.c:370
__do_sys_newfstatat fs/stat.c:542 [inline]
__se_sys_newfstatat fs/stat.c:536 [inline]
__x64_sys_newfstatat+0x116/0x190 fs/stat.c:536
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff888077c65880: 00 00 00 00 00 00 00 00 00 00 00 00 fc fc fc fc
ffff888077c65900: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff888077c65980: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888077c65a00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888077c65a80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Tested on:
commit: b1c92cdf Merge branch 'net-wangxun-complete-ethtool-co..
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=148baef0580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=12b26862580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (2 preceding siblings ...)
2025-08-25 12:44 ` Hillf Danton
@ 2025-08-25 15:59 ` Sabrina Dubroca
2025-08-26 3:27 ` Hillf Danton
` (16 subsequent siblings)
20 siblings, 0 replies; 44+ messages in thread
From: Sabrina Dubroca @ 2025-08-25 15:59 UTC (permalink / raw)
To: syzbot, Aakash Kumar S, steffen.klassert, herbert
Cc: davem, edumazet, horms, kuba, linux-kernel, netdev, pabeni,
syzkaller-bugs
2025-08-24, 12:21:23 -0700, syzbot wrote:
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b1c92cdf5af3 Merge branch 'net-wangxun-complete-ethtool-co..
> git tree: net-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1411b062580000
> kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
> dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
> compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14221862580000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=159fba34580000
This splat seems to be caused by commit 94f39804d891 ("xfrm: Duplicate
SPI Handling"), which removed the "newspi != 0" check before inserting
the state on the byspi list. But __xfrm_state_delete will only remove
states (in this case, when they expire) from the byspi list if
x->id.spi != 0.
So maybe something like this?
-------- 8< --------
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 78fcbb89cf32..d213ca3653a8 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -2583,6 +2583,8 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high,
for (h = 0; h < range; h++) {
u32 spi = (low == high) ? low : get_random_u32_inclusive(low, high);
+ if (spi == 0)
+ goto next;
newspi = htonl(spi);
spin_lock_bh(&net->xfrm.xfrm_state_lock);
@@ -2598,6 +2600,7 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high,
xfrm_state_put(x0);
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
+next:
if (signal_pending(current)) {
err = -ERESTARTSYS;
goto unlock;
--
Sabrina
^ permalink raw reply related [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (3 preceding siblings ...)
2025-08-25 15:59 ` Sabrina Dubroca
@ 2025-08-26 3:27 ` Hillf Danton
2025-08-26 3:53 ` syzbot
2025-08-26 4:16 ` Hillf Danton
` (15 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Hillf Danton @ 2025-08-26 3:27 UTC (permalink / raw)
To: syzbot; +Cc: linux-kernel, syzkaller-bugs
> Date: Sun, 24 Aug 2025 12:21:23 -0700 [thread overview]
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b1c92cdf5af3 Merge branch 'net-wangxun-complete-ethtool-co..
> git tree: net-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1411b062580000
> kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
> dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
> compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14221862580000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=159fba34580000
#syz test
--- x/net/xfrm/xfrm_state.c
+++ y/net/xfrm/xfrm_state.c
@@ -798,6 +798,7 @@ void xfrm_dev_state_free(struct xfrm_sta
void __xfrm_state_destroy(struct xfrm_state *x)
{
WARN_ON(x->km.state != XFRM_STATE_DEAD);
+ WARN_ON(!hlist_unhashed(&x->bydst));
spin_lock_bh(&xfrm_state_gc_lock);
hlist_add_head(&x->gclist, &xfrm_state_gc_list);
--
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-26 3:27 ` Hillf Danton
@ 2025-08-26 3:53 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-26 3:53 UTC (permalink / raw)
To: hdanton, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in __xfrm_state_destroy
------------[ cut here ]------------
WARNING: CPU: 1 PID: 1107 at net/xfrm/xfrm_state.c:801 __xfrm_state_destroy+0x15f/0x190 net/xfrm/xfrm_state.c:801
Modules linked in:
CPU: 1 UID: 0 PID: 1107 Comm: kworker/u8:5 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Workqueue: netns cleanup_net
RIP: 0010:__xfrm_state_destroy+0x15f/0x190 net/xfrm/xfrm_state.c:801
Code: 48 c7 c2 00 34 63 8f 5b 41 5c 41 5d 41 5e 41 5f 5d e9 25 89 69 f7 e8 70 33 9f f7 90 0f 0b 90 e9 00 ff ff ff e8 62 33 9f f7 90 <0f> 0b 90 e9 20 ff ff ff 44 89 f1 80 e1 07 38 c1 0f 8c c6 fe ff ff
RSP: 0018:ffffc90003aaf7f0 EFLAGS: 00010293
RAX: ffffffff8a2077ce RBX: ffff88806bb13308 RCX: ffff888026b2bc00
RDX: 0000000000000000 RSI: 0000000000000005 RDI: 0000000000000005
RBP: 0000000000000005 R08: ffff88806bb1336b R09: 1ffff1100d76266d
R10: dffffc0000000000 R11: ffffed100d76266e R12: dffffc0000000000
R13: 1ffff1100d762662 R14: ffff88806bb13310 R15: dffffc0000000000
FS: 0000000000000000(0000) GS:ffff888125d18000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f3a61070008 CR3: 00000000777e6000 CR4: 00000000003526f0
Call Trace:
<TASK>
xfrm_state_put include/net/xfrm.h:928 [inline]
xfrm_state_flush+0x4ab/0x630 net/xfrm/xfrm_state.c:943
xfrm6_tunnel_net_exit+0x3c/0x100 net/ipv6/xfrm6_tunnel.c:337
ops_exit_list net/core/net_namespace.c:198 [inline]
ops_undo_list+0x49a/0x990 net/core/net_namespace.c:251
cleanup_net+0x4c5/0x800 net/core/net_namespace.c:682
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+0x70e/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>
Tested on:
commit: df534e75 net: phylink: remove stale an_enabled from doc
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=17488634580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=1660c462580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (4 preceding siblings ...)
2025-08-26 3:27 ` Hillf Danton
@ 2025-08-26 4:16 ` Hillf Danton
2025-08-26 5:12 ` syzbot
2025-08-26 7:31 ` Hillf Danton
` (14 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Hillf Danton @ 2025-08-26 4:16 UTC (permalink / raw)
To: syzbot; +Cc: linux-kernel, syzkaller-bugs
> Date: Sun, 24 Aug 2025 12:21:23 -0700 [thread overview]
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b1c92cdf5af3 Merge branch 'net-wangxun-complete-ethtool-co..
> git tree: net-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1411b062580000
> kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
> dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
> compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14221862580000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=159fba34580000
#syz test
--- x/net/xfrm/xfrm_state.c
+++ y/net/xfrm/xfrm_state.c
@@ -798,6 +798,7 @@ void xfrm_dev_state_free(struct xfrm_sta
void __xfrm_state_destroy(struct xfrm_state *x)
{
WARN_ON(x->km.state != XFRM_STATE_DEAD);
+ WARN_ON(!hlist_unhashed(&x->bydst));
spin_lock_bh(&xfrm_state_gc_lock);
hlist_add_head(&x->gclist, &xfrm_state_gc_list);
@@ -934,14 +935,15 @@ restart:
if (!xfrm_state_kern(x) &&
xfrm_id_proto_match(x->id.proto, proto)) {
xfrm_state_hold(x);
+ if (x->km.state == XFRM_STATE_DEAD)
+ x->km.state++;
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
err = xfrm_state_delete(x);
xfrm_audit_state_delete(x, err ? 0 : 1,
task_valid);
xfrm_state_put(x);
- if (!err)
- cnt++;
+ cnt++;
spin_lock_bh(&net->xfrm.xfrm_state_lock);
goto restart;
--
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-26 4:16 ` Hillf Danton
@ 2025-08-26 5:12 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-26 5:12 UTC (permalink / raw)
To: hdanton, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in __xfrm_state_destroy
------------[ cut here ]------------
WARNING: CPU: 1 PID: 36 at net/xfrm/xfrm_state.c:801 __xfrm_state_destroy+0x15f/0x190 net/xfrm/xfrm_state.c:801
Modules linked in:
CPU: 1 UID: 0 PID: 36 Comm: kworker/u8:2 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Workqueue: netns cleanup_net
RIP: 0010:__xfrm_state_destroy+0x15f/0x190 net/xfrm/xfrm_state.c:801
Code: 48 c7 c2 00 34 63 8f 5b 41 5c 41 5d 41 5e 41 5f 5d e9 25 89 69 f7 e8 70 33 9f f7 90 0f 0b 90 e9 00 ff ff ff e8 62 33 9f f7 90 <0f> 0b 90 e9 20 ff ff ff 44 89 f1 80 e1 07 38 c1 0f 8c c6 fe ff ff
RSP: 0018:ffffc90000ac77f0 EFLAGS: 00010293
RAX: ffffffff8a2077ce RBX: ffff88807cc9c008 RCX: ffff8881404e1e00
RDX: 0000000000000000 RSI: 0000000000000005 RDI: 0000000000000005
RBP: 0000000000000005 R08: ffff88807cc9c06b R09: 1ffff1100f99380d
R10: dffffc0000000000 R11: ffffed100f99380e R12: dffffc0000000000
R13: 1ffff1100f993802 R14: ffff88807cc9c010 R15: dffffc0000000000
FS: 0000000000000000(0000) GS:ffff888125d18000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000055eb8c9a1008 CR3: 0000000027f28000 CR4: 00000000003526f0
Call Trace:
<TASK>
xfrm_state_put include/net/xfrm.h:928 [inline]
xfrm_state_flush+0x4fd/0x6c0 net/xfrm/xfrm_state.c:945
xfrm6_tunnel_net_exit+0x3c/0x100 net/ipv6/xfrm6_tunnel.c:337
ops_exit_list net/core/net_namespace.c:198 [inline]
ops_undo_list+0x49a/0x990 net/core/net_namespace.c:251
cleanup_net+0x4c5/0x800 net/core/net_namespace.c:682
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+0x70e/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>
Tested on:
commit: df534e75 net: phylink: remove stale an_enabled from doc
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=13d69c42580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=10aaeef0580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (5 preceding siblings ...)
2025-08-26 4:16 ` Hillf Danton
@ 2025-08-26 7:31 ` Hillf Danton
2025-08-26 11:11 ` syzbot
2025-08-26 9:41 ` Edward Adam Davis
` (13 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Hillf Danton @ 2025-08-26 7:31 UTC (permalink / raw)
To: syzbot; +Cc: linux-kernel, syzkaller-bugs
> Date: Sun, 24 Aug 2025 12:21:23 -0700 [thread overview]
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b1c92cdf5af3 Merge branch 'net-wangxun-complete-ethtool-co..
> git tree: net-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1411b062580000
> kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
> dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
> compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14221862580000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=159fba34580000
#syz test
--- x/net/xfrm/xfrm_state.c
+++ y/net/xfrm/xfrm_state.c
@@ -618,6 +618,8 @@ static void xfrm_state_gc_destroy(struct
xfrm_state_free(x);
}
+static DEFINE_MUTEX(notify_mutex);
+
static void xfrm_state_gc_task(struct work_struct *work)
{
struct xfrm_state *x;
@@ -630,8 +632,10 @@ static void xfrm_state_gc_task(struct wo
synchronize_rcu();
+ mutex_lock(¬ify_mutex);
hlist_for_each_entry_safe(x, tmp, &gc_list, gclist)
xfrm_state_gc_destroy(x);
+ mutex_unlock(¬ify_mutex);
}
static enum hrtimer_restart xfrm_timer_handler(struct hrtimer *me)
@@ -921,6 +925,7 @@ int xfrm_state_flush(struct net *net, u8
{
int i, err = 0, cnt = 0;
+ mutex_lock(¬ify_mutex);
spin_lock_bh(&net->xfrm.xfrm_state_lock);
err = xfrm_state_flush_secctx_check(net, proto, task_valid);
if (err)
@@ -950,6 +955,7 @@ restart:
}
out:
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
+ mutex_unlock(¬ify_mutex);
if (cnt)
err = 0;
--
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-26 7:31 ` Hillf Danton
@ 2025-08-26 11:11 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-26 11:11 UTC (permalink / raw)
To: hdanton, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Read in xfrm_alloc_spi
==================================================================
BUG: KASAN: slab-use-after-free in xfrm_state_lookup_spi_proto net/xfrm/xfrm_state.c:1714 [inline]
BUG: KASAN: slab-use-after-free in xfrm_alloc_spi+0x570/0xf30 net/xfrm/xfrm_state.c:2595
Read of size 4 at addr ffff88807bb0cd84 by task syz-executor246/14912
CPU: 0 UID: 0 PID: 14912 Comm: syz-executor246 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xca/0x240 mm/kasan/report.c:482
kasan_report+0x118/0x150 mm/kasan/report.c:595
xfrm_state_lookup_spi_proto net/xfrm/xfrm_state.c:1714 [inline]
xfrm_alloc_spi+0x570/0xf30 net/xfrm/xfrm_state.c:2595
xfrm_alloc_userspi+0x70b/0xc90 net/xfrm/xfrm_user.c:1873
xfrm_user_rcv_msg+0x7a0/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x219/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f06f4e4ba79
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 c1 17 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd8ce44c18 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f06f4e4ba79
RDX: 0000000000000000 RSI: 0000200000000440 RDI: 0000000000000003
RBP: 000000000007a151 R08: 0000000000000006 R09: 0000000000000006
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffd8ce44c2c
R13: 431bde82d7b634db R14: 0000000000000001 R15: 0000000000000001
</TASK>
Allocated by task 12219:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
unpoison_slab_object mm/kasan/common.c:330 [inline]
__kasan_slab_alloc+0x6c/0x80 mm/kasan/common.c:356
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
kmem_cache_alloc_noprof+0x1c1/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x2f0 net/xfrm/xfrm_state.c:737
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1839
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2359
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a0/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x219/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 43:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:576
poison_slab_object mm/kasan/common.c:243 [inline]
__kasan_slab_free+0x5b/0x80 mm/kasan/common.c:275
kasan_slab_free include/linux/kasan.h:233 [inline]
slab_free_hook mm/slub.c:2417 [inline]
slab_free mm/slub.c:4680 [inline]
kmem_cache_free+0x18f/0x400 mm/slub.c:4782
xfrm_state_free net/xfrm/xfrm_state.c:591 [inline]
xfrm_state_gc_destroy net/xfrm/xfrm_state.c:618 [inline]
xfrm_state_gc_task+0x53b/0x6d0 net/xfrm/xfrm_state.c:637
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+0x70e/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
The buggy address belongs to the object at ffff88807bb0ccc0
which belongs to the cache xfrm_state of size 928
The buggy address is located 196 bytes inside of
freed 928-byte region [ffff88807bb0ccc0, ffff88807bb0d060)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7bb0c
head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff888140aa6640 dead000000000122 0000000000000000
raw: 0000000000000000 00000000000f000f 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff888140aa6640 dead000000000122 0000000000000000
head: 0000000000000000 00000000000f000f 00000000f5000000 0000000000000000
head: 00fff00000000002 ffffea0001eec301 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000004
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Unmovable, gfp_mask 0x52820(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 12205, tgid 12205 (syz-executor246), ts 469927494442, free_ts 450521370354
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3858
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5148
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2416
alloc_slab_page mm/slub.c:2487 [inline]
allocate_slab+0x8a/0x370 mm/slub.c:2655
new_slab mm/slub.c:2709 [inline]
___slab_alloc+0xbeb/0x1410 mm/slub.c:3891
__slab_alloc mm/slub.c:3981 [inline]
__slab_alloc_node mm/slub.c:4056 [inline]
slab_alloc_node mm/slub.c:4217 [inline]
kmem_cache_alloc_noprof+0x283/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x2f0 net/xfrm/xfrm_state.c:737
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1839
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2359
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a0/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
page last free pid 10426 tgid 10426 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
__free_frozen_pages+0xbc4/0xd30 mm/page_alloc.c:2895
__folio_put+0x21b/0x2c0 mm/swap.c:112
page_to_skb+0x738/0x930 drivers/net/virtio_net.c:941
receive_mergeable drivers/net/virtio_net.c:2496 [inline]
receive_buf+0x45f/0x15e0 drivers/net/virtio_net.c:2634
virtnet_receive_packets drivers/net/virtio_net.c:2992 [inline]
virtnet_receive drivers/net/virtio_net.c:3016 [inline]
virtnet_poll+0x1fbc/0x2d80 drivers/net/virtio_net.c:3110
__napi_poll+0xc7/0x360 net/core/dev.c:7506
napi_poll net/core/dev.c:7569 [inline]
net_rx_action+0x707/0xe30 net/core/dev.c:7696
handle_softirqs+0x283/0x870 kernel/softirq.c:579
do_softirq+0xec/0x180 kernel/softirq.c:480
__local_bh_enable_ip+0x17d/0x1c0 kernel/softirq.c:407
spin_unlock_bh include/linux/spinlock.h:396 [inline]
xfrm_alloc_spi+0xae6/0xf30 net/xfrm/xfrm_state.c:2620
xfrm_alloc_userspi+0x70b/0xc90 net/xfrm/xfrm_user.c:1873
xfrm_user_rcv_msg+0x7a0/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
Memory state around the buggy address:
ffff88807bb0cc80: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb
ffff88807bb0cd00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88807bb0cd80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88807bb0ce00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88807bb0ce80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Tested on:
commit: 3c149179 ibmvnic: Increase max subcrq indirect entries..
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=12d9f862580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=130deef0580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (6 preceding siblings ...)
2025-08-26 7:31 ` Hillf Danton
@ 2025-08-26 9:41 ` Edward Adam Davis
2025-08-26 11:34 ` syzbot
2025-08-26 13:22 ` Hillf Danton
` (12 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Edward Adam Davis @ 2025-08-26 9:41 UTC (permalink / raw)
To: syzbot+a25ee9d20d31e483ba7b; +Cc: linux-kernel, syzkaller-bugs
#syz test
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 78fcbb89cf32..b8b4843f9c6d 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -932,7 +932,8 @@ int xfrm_state_flush(struct net *net, u8 proto, bool task_valid)
restart:
hlist_for_each_entry(x, net->xfrm.state_bydst+i, bydst) {
if (!xfrm_state_kern(x) &&
- xfrm_id_proto_match(x->id.proto, proto)) {
+ xfrm_id_proto_match(x->id.proto, proto) &&
+ x->km.state != XFRM_STATE_DEAD) {
xfrm_state_hold(x);
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
^ permalink raw reply related [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-26 9:41 ` Edward Adam Davis
@ 2025-08-26 11:34 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-26 11:34 UTC (permalink / raw)
To: eadavis, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Write in __xfrm_state_delete
==================================================================
BUG: KASAN: slab-use-after-free in __hlist_del include/linux/list.h:980 [inline]
BUG: KASAN: slab-use-after-free in hlist_del_rcu include/linux/rculist.h:560 [inline]
BUG: KASAN: slab-use-after-free in __xfrm_state_delete+0x666/0xca0 net/xfrm/xfrm_state.c:830
Write of size 8 at addr ffff888042050ce8 by task kworker/u8:4/74
CPU: 1 UID: 0 PID: 74 Comm: kworker/u8:4 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Workqueue: netns cleanup_net
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xca/0x240 mm/kasan/report.c:482
kasan_report+0x118/0x150 mm/kasan/report.c:595
__hlist_del include/linux/list.h:980 [inline]
hlist_del_rcu include/linux/rculist.h:560 [inline]
__xfrm_state_delete+0x666/0xca0 net/xfrm/xfrm_state.c:830
xfrm_state_delete net/xfrm/xfrm_state.c:856 [inline]
xfrm_state_flush+0x497/0x7d0 net/xfrm/xfrm_state.c:940
xfrm6_tunnel_net_exit+0x3c/0x100 net/ipv6/xfrm6_tunnel.c:337
ops_exit_list net/core/net_namespace.c:198 [inline]
ops_undo_list+0x49a/0x990 net/core/net_namespace.c:251
cleanup_net+0x4c5/0x800 net/core/net_namespace.c:682
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+0x70e/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>
Allocated by task 7535:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
unpoison_slab_object mm/kasan/common.c:330 [inline]
__kasan_slab_alloc+0x6c/0x80 mm/kasan/common.c:356
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
kmem_cache_alloc_noprof+0x1c1/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x2f0 net/xfrm/xfrm_state.c:733
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1834
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2354
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a3/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x219/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 9:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:576
poison_slab_object mm/kasan/common.c:243 [inline]
__kasan_slab_free+0x5b/0x80 mm/kasan/common.c:275
kasan_slab_free include/linux/kasan.h:233 [inline]
slab_free_hook mm/slub.c:2417 [inline]
slab_free mm/slub.c:4680 [inline]
kmem_cache_free+0x18f/0x400 mm/slub.c:4782
xfrm_state_free net/xfrm/xfrm_state.c:591 [inline]
xfrm_state_gc_destroy net/xfrm/xfrm_state.c:618 [inline]
xfrm_state_gc_task+0x52d/0x6b0 net/xfrm/xfrm_state.c:634
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+0x70e/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
The buggy address belongs to the object at ffff888042050cc0
which belongs to the cache xfrm_state of size 928
The buggy address is located 40 bytes inside of
freed 928-byte region [ffff888042050cc0, ffff888042051060)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x42050
head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff88802229adc0 dead000000000122 0000000000000000
raw: 0000000000000000 00000000000f000f 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff88802229adc0 dead000000000122 0000000000000000
head: 0000000000000000 00000000000f000f 00000000f5000000 0000000000000000
head: 00fff00000000002 ffffea0001081401 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000004
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Unmovable, gfp_mask 0x52820(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 7523, tgid 7522 (syz.0.524), ts 112083797676, free_ts 111991511473
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3858
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5148
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2416
alloc_slab_page mm/slub.c:2487 [inline]
allocate_slab+0x8a/0x370 mm/slub.c:2655
new_slab mm/slub.c:2709 [inline]
___slab_alloc+0xbeb/0x1410 mm/slub.c:3891
__slab_alloc mm/slub.c:3981 [inline]
__slab_alloc_node mm/slub.c:4056 [inline]
slab_alloc_node mm/slub.c:4217 [inline]
kmem_cache_alloc_noprof+0x283/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x2f0 net/xfrm/xfrm_state.c:733
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1834
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2354
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a3/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
page last free pid 49 tgid 49 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
__free_frozen_pages+0xbc4/0xd30 mm/page_alloc.c:2895
stack_depot_save_flags+0x436/0x860 lib/stackdepot.c:727
kasan_save_stack mm/kasan/common.c:48 [inline]
kasan_save_track+0x4f/0x80 mm/kasan/common.c:68
unpoison_slab_object mm/kasan/common.c:330 [inline]
__kasan_slab_alloc+0x6c/0x80 mm/kasan/common.c:356
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
kmem_cache_alloc_noprof+0x1c1/0x3c0 mm/slub.c:4236
mempool_alloc_noprof+0x1a4/0x510 mm/mempool.c:406
bio_alloc_bioset+0x241/0x1110 block/bio.c:555
bio_alloc_clone block/bio.c:866 [inline]
bio_split+0x110/0x4a0 block/bio.c:1687
bio_submit_split+0x96/0x5e0 block/blk-merge.c:115
__bio_split_to_limits block/blk.h:402 [inline]
blk_mq_submit_bio+0x166a/0x2520 block/blk-mq.c:3164
__submit_bio+0x207/0x5a0 block/blk-core.c:635
__submit_bio_noacct_mq block/blk-core.c:722 [inline]
submit_bio_noacct_nocheck+0x505/0xb50 block/blk-core.c:751
ext4_io_submit+0xe0/0x150 fs/ext4/page-io.c:404
ext4_do_writepages+0xbba/0x4610 fs/ext4/inode.c:2881
ext4_writepages+0x205/0x350 fs/ext4/inode.c:3025
do_writepages+0x32e/0x550 mm/page-writeback.c:2634
Memory state around the buggy address:
ffff888042050b80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888042050c00: fb fb fb fb fc fc fc fc fc fc fc fc fc fc fc fc
>ffff888042050c80: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb
^
ffff888042050d00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888042050d80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Tested on:
commit: 3c149179 ibmvnic: Increase max subcrq indirect entries..
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=17fae462580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=10e79c42580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (7 preceding siblings ...)
2025-08-26 9:41 ` Edward Adam Davis
@ 2025-08-26 13:22 ` Hillf Danton
2025-08-26 19:54 ` syzbot
2025-08-27 0:40 ` Hillf Danton
` (11 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Hillf Danton @ 2025-08-26 13:22 UTC (permalink / raw)
To: syzbot; +Cc: linux-kernel, syzkaller-bugs
> Date: Sun, 24 Aug 2025 12:21:23 -0700 [thread overview]
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b1c92cdf5af3 Merge branch 'net-wangxun-complete-ethtool-co..
> git tree: net-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1411b062580000
> kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
> dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
> compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14221862580000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=159fba34580000
#syz test
--- x/net/xfrm/xfrm_state.c
+++ y/net/xfrm/xfrm_state.c
@@ -618,6 +618,8 @@ static void xfrm_state_gc_destroy(struct
xfrm_state_free(x);
}
+static DEFINE_MUTEX(notify_mutex);
+
static void xfrm_state_gc_task(struct work_struct *work)
{
struct xfrm_state *x;
@@ -630,8 +632,10 @@ static void xfrm_state_gc_task(struct wo
synchronize_rcu();
+ mutex_lock(¬ify_mutex);
hlist_for_each_entry_safe(x, tmp, &gc_list, gclist)
xfrm_state_gc_destroy(x);
+ mutex_unlock(¬ify_mutex);
}
static enum hrtimer_restart xfrm_timer_handler(struct hrtimer *me)
@@ -921,6 +925,7 @@ int xfrm_state_flush(struct net *net, u8
{
int i, err = 0, cnt = 0;
+ mutex_lock(¬ify_mutex);
spin_lock_bh(&net->xfrm.xfrm_state_lock);
err = xfrm_state_flush_secctx_check(net, proto, task_valid);
if (err)
@@ -950,6 +955,7 @@ restart:
}
out:
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
+ mutex_unlock(¬ify_mutex);
if (cnt)
err = 0;
@@ -2569,6 +2575,8 @@ int xfrm_alloc_spi(struct xfrm_state *x,
u32 range = high - low + 1;
__be32 newspi = 0;
+ if (!mutex_trylock(¬ify_mutex))
+ return err;
spin_lock_bh(&x->lock);
if (x->km.state == XFRM_STATE_DEAD) {
NL_SET_ERR_MSG(extack, "Target ACQUIRE is in DEAD state");
@@ -2612,6 +2620,7 @@ int xfrm_alloc_spi(struct xfrm_state *x,
unlock:
spin_unlock_bh(&x->lock);
+ mutex_unlock(¬ify_mutex);
return err;
}
--
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-26 13:22 ` Hillf Danton
@ 2025-08-26 19:54 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-26 19:54 UTC (permalink / raw)
To: hdanton, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Read in xfrm_alloc_spi
==================================================================
BUG: KASAN: slab-use-after-free in xfrm_state_lookup_spi_proto net/xfrm/xfrm_state.c:1714 [inline]
BUG: KASAN: slab-use-after-free in xfrm_alloc_spi+0x5b5/0xf80 net/xfrm/xfrm_state.c:2597
Read of size 4 at addr ffff88807d2351c4 by task syz-executor207/14761
CPU: 0 UID: 0 PID: 14761 Comm: syz-executor207 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xca/0x240 mm/kasan/report.c:482
kasan_report+0x118/0x150 mm/kasan/report.c:595
xfrm_state_lookup_spi_proto net/xfrm/xfrm_state.c:1714 [inline]
xfrm_alloc_spi+0x5b5/0xf80 net/xfrm/xfrm_state.c:2597
xfrm_alloc_userspi+0x70b/0xc90 net/xfrm/xfrm_user.c:1873
xfrm_user_rcv_msg+0x7a0/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x219/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f14cde8fa79
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 c1 17 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffe635fb118 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f14cde8fa79
RDX: 0000000000000000 RSI: 0000200000000440 RDI: 0000000000000003
RBP: 000000000007b5da R08: 0000000000000006 R09: 0000000000000006
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffe635fb12c
R13: 431bde82d7b634db R14: 0000000000000001 R15: 0000000000000001
</TASK>
Allocated by task 12087:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
unpoison_slab_object mm/kasan/common.c:330 [inline]
__kasan_slab_alloc+0x6c/0x80 mm/kasan/common.c:356
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
kmem_cache_alloc_noprof+0x1c1/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x2f0 net/xfrm/xfrm_state.c:737
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1839
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2359
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a0/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x219/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 5885:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:576
poison_slab_object mm/kasan/common.c:243 [inline]
__kasan_slab_free+0x5b/0x80 mm/kasan/common.c:275
kasan_slab_free include/linux/kasan.h:233 [inline]
slab_free_hook mm/slub.c:2417 [inline]
slab_free mm/slub.c:4680 [inline]
kmem_cache_free+0x18f/0x400 mm/slub.c:4782
xfrm_state_free net/xfrm/xfrm_state.c:591 [inline]
xfrm_state_gc_destroy net/xfrm/xfrm_state.c:618 [inline]
xfrm_state_gc_task+0x53b/0x6d0 net/xfrm/xfrm_state.c:637
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+0x70e/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
The buggy address belongs to the object at ffff88807d235100
which belongs to the cache xfrm_state of size 928
The buggy address is located 196 bytes inside of
freed 928-byte region [ffff88807d235100, ffff88807d2354a0)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7d234
head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff88801a500b40 dead000000000122 0000000000000000
raw: 0000000000000000 00000000000f000f 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff88801a500b40 dead000000000122 0000000000000000
head: 0000000000000000 00000000000f000f 00000000f5000000 0000000000000000
head: 00fff00000000002 ffffea0001f48d01 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000004
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Unmovable, gfp_mask 0x52820(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 12083, tgid 12083 (syz-executor207), ts 475296018136, free_ts 442896950351
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3858
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5148
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2416
alloc_slab_page mm/slub.c:2487 [inline]
allocate_slab+0x8a/0x370 mm/slub.c:2655
new_slab mm/slub.c:2709 [inline]
___slab_alloc+0xbeb/0x1410 mm/slub.c:3891
__slab_alloc mm/slub.c:3981 [inline]
__slab_alloc_node mm/slub.c:4056 [inline]
slab_alloc_node mm/slub.c:4217 [inline]
kmem_cache_alloc_noprof+0x283/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x2f0 net/xfrm/xfrm_state.c:737
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1839
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2359
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a0/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
page last free pid 9292 tgid 9292 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
__free_frozen_pages+0xbc4/0xd30 mm/page_alloc.c:2895
__slab_free+0x303/0x3c0 mm/slub.c:4591
qlink_free mm/kasan/quarantine.c:163 [inline]
qlist_free_all+0x97/0x140 mm/kasan/quarantine.c:179
kasan_quarantine_reduce+0x148/0x160 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x22/0x80 mm/kasan/common.c:340
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
kmem_cache_alloc_noprof+0x1c1/0x3c0 mm/slub.c:4236
getname_flags+0xb8/0x540 fs/namei.c:146
getname include/linux/fs.h:2918 [inline]
do_sys_openat2+0xbc/0x1c0 fs/open.c:1429
do_sys_open fs/open.c:1450 [inline]
__do_sys_openat fs/open.c:1466 [inline]
__se_sys_openat fs/open.c:1461 [inline]
__x64_sys_openat+0x138/0x170 fs/open.c:1461
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff88807d235080: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff88807d235100: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88807d235180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88807d235200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88807d235280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Tested on:
commit: 3c149179 ibmvnic: Increase max subcrq indirect entries..
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=10a62462580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=16378634580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (8 preceding siblings ...)
2025-08-26 13:22 ` Hillf Danton
@ 2025-08-27 0:40 ` Hillf Danton
2025-08-27 2:44 ` syzbot
2025-08-27 1:30 ` Edward Adam Davis
` (10 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Hillf Danton @ 2025-08-27 0:40 UTC (permalink / raw)
To: syzbot; +Cc: linux-kernel, syzkaller-bugs
> Date: Sun, 24 Aug 2025 12:21:23 -0700 [thread overview]
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b1c92cdf5af3 Merge branch 'net-wangxun-complete-ethtool-co..
> git tree: net-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1411b062580000
> kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
> dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
> compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14221862580000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=159fba34580000
#syz test
--- x/include/net/xfrm.h
+++ y/include/net/xfrm.h
@@ -202,6 +202,7 @@ struct xfrm_state {
refcount_t refcnt;
spinlock_t lock;
+ int deleted;
u32 pcpu_num;
struct xfrm_id id;
--- x/net/xfrm/xfrm_state.c
+++ y/net/xfrm/xfrm_state.c
@@ -615,6 +615,7 @@ static void xfrm_state_gc_destroy(struct
put_page(x->xfrag.page);
xfrm_dev_state_free(x);
security_xfrm_state_free(x);
+ xfrm_state_delete(x);
xfrm_state_free(x);
}
@@ -812,10 +813,16 @@ int __xfrm_state_delete(struct xfrm_stat
struct net *net = xs_net(x);
int err = -ESRCH;
- if (x->km.state != XFRM_STATE_DEAD) {
- x->km.state = XFRM_STATE_DEAD;
+ for (;;) {
+ if (x->km.state != XFRM_STATE_DEAD)
+ x->km.state = XFRM_STATE_DEAD;
spin_lock(&net->xfrm.xfrm_state_lock);
+ if (x->deleted) {
+ spin_unlock(&net->xfrm.xfrm_state_lock);
+ return 0;
+ }
+ x->deleted++;
list_del(&x->km.all);
hlist_del_rcu(&x->bydst);
hlist_del_rcu(&x->bysrc);
--
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-27 0:40 ` Hillf Danton
@ 2025-08-27 2:44 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-27 2:44 UTC (permalink / raw)
To: hdanton, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Write in __xfrm_state_delete
==================================================================
BUG: KASAN: slab-use-after-free in __hlist_del include/linux/list.h:980 [inline]
BUG: KASAN: slab-use-after-free in hlist_del_rcu include/linux/rculist.h:560 [inline]
BUG: KASAN: slab-use-after-free in __xfrm_state_delete+0x76e/0xde0 net/xfrm/xfrm_state.c:837
Write of size 8 at addr ffff8880627eb768 by task kworker/u8:3/49
CPU: 0 UID: 0 PID: 49 Comm: kworker/u8:3 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Workqueue: netns cleanup_net
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xca/0x240 mm/kasan/report.c:482
kasan_report+0x118/0x150 mm/kasan/report.c:595
__hlist_del include/linux/list.h:980 [inline]
hlist_del_rcu include/linux/rculist.h:560 [inline]
__xfrm_state_delete+0x76e/0xde0 net/xfrm/xfrm_state.c:837
xfrm_state_delete net/xfrm/xfrm_state.c:863 [inline]
xfrm_state_flush+0x44a/0x750 net/xfrm/xfrm_state.c:946
xfrm6_tunnel_net_exit+0x3c/0x100 net/ipv6/xfrm6_tunnel.c:337
ops_exit_list net/core/net_namespace.c:198 [inline]
ops_undo_list+0x49a/0x990 net/core/net_namespace.c:251
cleanup_net+0x4c5/0x800 net/core/net_namespace.c:682
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+0x70e/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>
Allocated by task 10050:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
unpoison_slab_object mm/kasan/common.c:330 [inline]
__kasan_slab_alloc+0x6c/0x80 mm/kasan/common.c:356
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
kmem_cache_alloc_noprof+0x1c1/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x2f0 net/xfrm/xfrm_state.c:734
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1840
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2360
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a3/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x219/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 6028:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:576
poison_slab_object mm/kasan/common.c:243 [inline]
__kasan_slab_free+0x5b/0x80 mm/kasan/common.c:275
kasan_slab_free include/linux/kasan.h:233 [inline]
slab_free_hook mm/slub.c:2417 [inline]
slab_free mm/slub.c:4680 [inline]
kmem_cache_free+0x18f/0x400 mm/slub.c:4782
xfrm_state_free net/xfrm/xfrm_state.c:591 [inline]
xfrm_state_gc_destroy net/xfrm/xfrm_state.c:619 [inline]
xfrm_state_gc_task+0x549/0x6d0 net/xfrm/xfrm_state.c:635
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+0x70e/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
The buggy address belongs to the object at ffff8880627eb740
which belongs to the cache xfrm_state of size 936
The buggy address is located 40 bytes inside of
freed 936-byte region [ffff8880627eb740, ffff8880627ebae8)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x627e8
head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff88801b3c9280 dead000000000100 dead000000000122
raw: 0000000000000000 00000000000f000f 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff88801b3c9280 dead000000000100 dead000000000122
head: 0000000000000000 00000000000f000f 00000000f5000000 0000000000000000
head: 00fff00000000002 ffffea000189fa01 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000004
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Unmovable, gfp_mask 0x52820(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 8688, tgid 8687 (syz.0.1073), ts 121523868095, free_ts 121487674016
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3858
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5148
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2416
alloc_slab_page mm/slub.c:2487 [inline]
allocate_slab+0x8a/0x370 mm/slub.c:2655
new_slab mm/slub.c:2709 [inline]
___slab_alloc+0xbeb/0x1410 mm/slub.c:3891
__slab_alloc mm/slub.c:3981 [inline]
__slab_alloc_node mm/slub.c:4056 [inline]
slab_alloc_node mm/slub.c:4217 [inline]
kmem_cache_alloc_noprof+0x283/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x2f0 net/xfrm/xfrm_state.c:734
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1840
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2360
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a3/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
page last free pid 8685 tgid 8685 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
__free_frozen_pages+0xbc4/0xd30 mm/page_alloc.c:2895
__slab_free+0x303/0x3c0 mm/slub.c:4591
qlink_free mm/kasan/quarantine.c:163 [inline]
qlist_free_all+0x97/0x140 mm/kasan/quarantine.c:179
kasan_quarantine_reduce+0x148/0x160 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x22/0x80 mm/kasan/common.c:340
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
kmem_cache_alloc_noprof+0x1c1/0x3c0 mm/slub.c:4236
getname_flags+0xb8/0x540 fs/namei.c:146
getname include/linux/fs.h:2918 [inline]
__do_sys_symlinkat fs/namei.c:4772 [inline]
__se_sys_symlinkat fs/namei.c:4769 [inline]
__x64_sys_symlinkat+0x7a/0xb0 fs/namei.c:4769
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff8880627eb600: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffff8880627eb680: 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc fc
>ffff8880627eb700: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb
^
ffff8880627eb780: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880627eb800: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Tested on:
commit: 24204116 Merge branch 'ipv6-sr-simplify-and-optimize-h..
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=14fa9ef0580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=137977bc580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (9 preceding siblings ...)
2025-08-27 0:40 ` Hillf Danton
@ 2025-08-27 1:30 ` Edward Adam Davis
2025-08-27 3:03 ` syzbot
2025-08-27 4:51 ` Hillf Danton
` (9 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Edward Adam Davis @ 2025-08-27 1:30 UTC (permalink / raw)
To: syzbot+a25ee9d20d31e483ba7b; +Cc: linux-kernel, syzkaller-bugs
#syz test
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 78fcbb89cf32..137b5b660683 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -929,10 +929,10 @@ int xfrm_state_flush(struct net *net, u8 proto, bool task_valid)
err = -ESRCH;
for (i = 0; i <= net->xfrm.state_hmask; i++) {
struct xfrm_state *x;
-restart:
hlist_for_each_entry(x, net->xfrm.state_bydst+i, bydst) {
if (!xfrm_state_kern(x) &&
- xfrm_id_proto_match(x->id.proto, proto)) {
+ xfrm_id_proto_match(x->id.proto, proto) &&
+ x->km.state != XFRM_STATE_DEAD) {
xfrm_state_hold(x);
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
@@ -940,11 +940,9 @@ int xfrm_state_flush(struct net *net, u8 proto, bool task_valid)
xfrm_audit_state_delete(x, err ? 0 : 1,
task_valid);
xfrm_state_put(x);
- if (!err)
- cnt++;
+ cnt++;
spin_lock_bh(&net->xfrm.xfrm_state_lock);
- goto restart;
}
}
}
^ permalink raw reply related [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-27 1:30 ` Edward Adam Davis
@ 2025-08-27 3:03 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-27 3:03 UTC (permalink / raw)
To: eadavis, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in xfrm_state_fini
------------[ cut here ]------------
WARNING: CPU: 1 PID: 3658 at net/xfrm/xfrm_state.c:3301 xfrm_state_fini+0x26d/0x2f0 net/xfrm/xfrm_state.c:3301
Modules linked in:
CPU: 1 UID: 0 PID: 3658 Comm: kworker/u8:14 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Workqueue: netns cleanup_net
RIP: 0010:xfrm_state_fini+0x26d/0x2f0 net/xfrm/xfrm_state.c:3301
Code: c1 e8 03 42 80 3c 28 00 74 08 48 89 df e8 6b b2 00 f8 48 8b 3b 5b 41 5c 41 5d 41 5e 41 5f 5d e9 29 73 e1 f7 e8 84 46 9d f7 90 <0f> 0b 90 e9 fd fd ff ff e8 76 46 9d f7 90 0f 0b 90 e9 60 fe ff ff
RSP: 0018:ffffc9000c5c7898 EFLAGS: 00010293
RAX: ffffffff8a2264ac RBX: ffff888033aa8000 RCX: ffff888030f70000
RDX: 0000000000000000 RSI: ffffffff8be33660 RDI: ffffffff84d05cc3
RBP: ffffc9000c5c79b0 R08: ffffffff8fa38437 R09: 1ffffffff1f47086
R10: dffffc0000000000 R11: fffffbfff1f47087 R12: ffffffff8f631480
R13: 1ffff920018b8f40 R14: ffff888033aa9480 R15: dffffc0000000000
FS: 0000000000000000(0000) GS:ffff888125d1a000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f67e456d480 CR3: 0000000079c90000 CR4: 00000000003526f0
Call Trace:
<TASK>
xfrm_net_exit+0x2d/0x70 net/xfrm/xfrm_policy.c:4354
ops_exit_list net/core/net_namespace.c:198 [inline]
ops_undo_list+0x49a/0x990 net/core/net_namespace.c:251
cleanup_net+0x4c5/0x800 net/core/net_namespace.c:682
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+0x70e/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>
Tested on:
commit: 24204116 Merge branch 'ipv6-sr-simplify-and-optimize-h..
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=15d69ef0580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=142d77bc580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (10 preceding siblings ...)
2025-08-27 1:30 ` Edward Adam Davis
@ 2025-08-27 4:51 ` Hillf Danton
2025-08-27 6:27 ` syzbot
2025-08-27 5:18 ` Hillf Danton
` (8 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Hillf Danton @ 2025-08-27 4:51 UTC (permalink / raw)
To: syzbot; +Cc: linux-kernel, syzkaller-bugs
> Date: Sun, 24 Aug 2025 12:21:23 -0700 [thread overview]
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b1c92cdf5af3 Merge branch 'net-wangxun-complete-ethtool-co..
> git tree: net-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1411b062580000
> kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
> dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
> compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14221862580000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=159fba34580000
#syz test
--- x/include/net/xfrm.h
+++ y/include/net/xfrm.h
@@ -202,6 +202,7 @@ struct xfrm_state {
refcount_t refcnt;
spinlock_t lock;
+ int deleted;
u32 pcpu_num;
struct xfrm_id id;
--- x/net/xfrm/xfrm_state.c
+++ y/net/xfrm/xfrm_state.c
@@ -615,6 +615,7 @@ static void xfrm_state_gc_destroy(struct
put_page(x->xfrag.page);
xfrm_dev_state_free(x);
security_xfrm_state_free(x);
+ xfrm_state_delete(x);
xfrm_state_free(x);
}
@@ -812,10 +813,16 @@ int __xfrm_state_delete(struct xfrm_stat
struct net *net = xs_net(x);
int err = -ESRCH;
- if (x->km.state != XFRM_STATE_DEAD) {
- x->km.state = XFRM_STATE_DEAD;
+ for (;;) {
+ if (x->km.state != XFRM_STATE_DEAD)
+ x->km.state = XFRM_STATE_DEAD;
spin_lock(&net->xfrm.xfrm_state_lock);
+ if (x->deleted) {
+ spin_unlock(&net->xfrm.xfrm_state_lock);
+ return 0;
+ }
+ x->deleted++;
list_del(&x->km.all);
hlist_del_rcu(&x->bydst);
hlist_del_rcu(&x->bysrc);
@@ -931,15 +938,16 @@ int xfrm_state_flush(struct net *net, u8
struct xfrm_state *x;
restart:
hlist_for_each_entry(x, net->xfrm.state_bydst+i, bydst) {
- if (!xfrm_state_kern(x) &&
+ if (!xfrm_state_kern(x) && x->km.state != XFRM_STATE_DEAD &&
xfrm_id_proto_match(x->id.proto, proto)) {
xfrm_state_hold(x);
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
- err = xfrm_state_delete(x);
+ err = 0;
xfrm_audit_state_delete(x, err ? 0 : 1,
task_valid);
xfrm_state_put(x);
+ xfrm_state_put(x);
if (!err)
cnt++;
--
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-27 4:51 ` Hillf Danton
@ 2025-08-27 6:27 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-27 6:27 UTC (permalink / raw)
To: hdanton, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in xfrm_state_flush
------------[ cut here ]------------
WARNING: CPU: 1 PID: 13 at net/xfrm/xfrm_state.c:801 __xfrm_state_destroy net/xfrm/xfrm_state.c:801 [inline]
WARNING: CPU: 1 PID: 13 at net/xfrm/xfrm_state.c:801 xfrm_state_put include/net/xfrm.h:929 [inline]
WARNING: CPU: 1 PID: 13 at net/xfrm/xfrm_state.c:801 xfrm_state_flush+0x7d9/0x910 net/xfrm/xfrm_state.c:950
Modules linked in:
CPU: 1 UID: 0 PID: 13 Comm: kworker/u8:1 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Workqueue: netns cleanup_net
RIP: 0010:__xfrm_state_destroy net/xfrm/xfrm_state.c:801 [inline]
RIP: 0010:xfrm_state_put include/net/xfrm.h:929 [inline]
RIP: 0010:xfrm_state_flush+0x7d9/0x910 net/xfrm/xfrm_state.c:950
Code: bd 1d 9f f7 90 0f 0b 90 e9 33 fd ff ff e8 af 1d 9f f7 4c 89 e7 be 03 00 00 00 e8 32 6d a7 fa e9 01 fe ff ff e8 98 1d 9f f7 90 <0f> 0b 90 e9 50 fe ff ff e8 8a 1d 9f f7 4c 89 e7 be 03 00 00 00 e8
RSP: 0018:ffffc90000127820 EFLAGS: 00010293
RAX: ffffffff8a208d98 RBX: ffff88807a6fddc0 RCX: ffff88801cec8000
RDX: 0000000000000000 RSI: 0000000000000001 RDI: 0000000000000005
RBP: 0000000000000001 R08: ffff88807a6fde2b R09: 1ffff1100f4dfbc5
R10: dffffc0000000000 R11: ffffed100f4dfbc6 R12: ffff88807a6fde28
R13: ffff88807a6fdef0 R14: dffffc0000000000 R15: 0000000000000001
FS: 0000000000000000(0000) GS:ffff888125d1a000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f1ca06d5e9c CR3: 0000000074866000 CR4: 00000000003526f0
Call Trace:
<TASK>
xfrm6_tunnel_net_exit+0x3c/0x100 net/ipv6/xfrm6_tunnel.c:337
ops_exit_list net/core/net_namespace.c:198 [inline]
ops_undo_list+0x49a/0x990 net/core/net_namespace.c:251
cleanup_net+0x4c5/0x800 net/core/net_namespace.c:682
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+0x70e/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>
Tested on:
commit: 24204116 Merge branch 'ipv6-sr-simplify-and-optimize-h..
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=13939ef0580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=150ca462580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (11 preceding siblings ...)
2025-08-27 4:51 ` Hillf Danton
@ 2025-08-27 5:18 ` Hillf Danton
2025-08-27 6:44 ` syzbot
2025-08-27 5:49 ` Edward Adam Davis
` (7 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Hillf Danton @ 2025-08-27 5:18 UTC (permalink / raw)
To: syzbot; +Cc: linux-kernel, syzkaller-bugs
> Date: Sun, 24 Aug 2025 12:21:23 -0700 [thread overview]
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b1c92cdf5af3 Merge branch 'net-wangxun-complete-ethtool-co..
> git tree: net-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1411b062580000
> kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
> dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
> compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14221862580000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=159fba34580000
#syz test
--- x/include/net/xfrm.h
+++ y/include/net/xfrm.h
@@ -202,6 +202,7 @@ struct xfrm_state {
refcount_t refcnt;
spinlock_t lock;
+ int deleted;
u32 pcpu_num;
struct xfrm_id id;
--- x/net/xfrm/xfrm_state.c
+++ y/net/xfrm/xfrm_state.c
@@ -615,6 +615,7 @@ static void xfrm_state_gc_destroy(struct
put_page(x->xfrag.page);
xfrm_dev_state_free(x);
security_xfrm_state_free(x);
+ xfrm_state_delete(x);
xfrm_state_free(x);
}
@@ -812,10 +813,16 @@ int __xfrm_state_delete(struct xfrm_stat
struct net *net = xs_net(x);
int err = -ESRCH;
- if (x->km.state != XFRM_STATE_DEAD) {
- x->km.state = XFRM_STATE_DEAD;
+ for (;;) {
+ if (x->km.state != XFRM_STATE_DEAD)
+ x->km.state = XFRM_STATE_DEAD;
spin_lock(&net->xfrm.xfrm_state_lock);
+ if (x->deleted) {
+ spin_unlock(&net->xfrm.xfrm_state_lock);
+ return 0;
+ }
+ x->deleted++;
list_del(&x->km.all);
hlist_del_rcu(&x->bydst);
hlist_del_rcu(&x->bysrc);
@@ -929,22 +936,28 @@ int xfrm_state_flush(struct net *net, u8
err = -ESRCH;
for (i = 0; i <= net->xfrm.state_hmask; i++) {
struct xfrm_state *x;
+ bool dead;
restart:
hlist_for_each_entry(x, net->xfrm.state_bydst+i, bydst) {
if (!xfrm_state_kern(x) &&
xfrm_id_proto_match(x->id.proto, proto)) {
- xfrm_state_hold(x);
+ dead = x->km.state == XFRM_STATE_DEAD;
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
- err = xfrm_state_delete(x);
+ if (dead) {
+ flush:
+ schedule_work(&xfrm_state_gc_work);
+ flush_work(&xfrm_state_gc_work);
+ spin_lock_bh(&net->xfrm.xfrm_state_lock);
+ goto restart;
+ }
+ err = 0;
xfrm_audit_state_delete(x, err ? 0 : 1,
task_valid);
xfrm_state_put(x);
if (!err)
cnt++;
-
- spin_lock_bh(&net->xfrm.xfrm_state_lock);
- goto restart;
+ goto flush;
}
}
}
--
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-27 5:18 ` Hillf Danton
@ 2025-08-27 6:44 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-27 6:44 UTC (permalink / raw)
To: hdanton, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in xfrm_state_flush
------------[ cut here ]------------
WARNING: CPU: 0 PID: 49 at net/xfrm/xfrm_state.c:801 __xfrm_state_destroy net/xfrm/xfrm_state.c:801 [inline]
WARNING: CPU: 0 PID: 49 at net/xfrm/xfrm_state.c:801 xfrm_state_put include/net/xfrm.h:929 [inline]
WARNING: CPU: 0 PID: 49 at net/xfrm/xfrm_state.c:801 xfrm_state_flush+0x627/0x740 net/xfrm/xfrm_state.c:957
Modules linked in:
CPU: 0 UID: 0 PID: 49 Comm: kworker/u8:3 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Workqueue: netns cleanup_net
RIP: 0010:__xfrm_state_destroy net/xfrm/xfrm_state.c:801 [inline]
RIP: 0010:xfrm_state_put include/net/xfrm.h:929 [inline]
RIP: 0010:xfrm_state_flush+0x627/0x740 net/xfrm/xfrm_state.c:957
Code: 3f 8b 02 f8 48 8b 2b 48 85 ed 0f 84 dd 00 00 00 48 83 c5 f8 0f 84 d3 00 00 00 e8 54 1f 9f f7 e9 b3 fc ff ff e8 4a 1f 9f f7 90 <0f> 0b 90 e9 68 fe ff ff e8 3c 1f 9f f7 48 8b 7c 24 20 be 03 00 00
RSP: 0018:ffffc90000b97820 EFLAGS: 00010293
RAX: ffffffff8a208be6 RBX: 0000000000000001 RCX: ffff888022abbc00
RDX: 0000000000000000 RSI: 0000000000000001 RDI: 0000000000000005
RBP: ffff888029974440 R08: ffff8880299744ab R09: 1ffff1100532e895
R10: dffffc0000000000 R11: ffffed100532e896 R12: 0000000000000001
R13: 0000000000000000 R14: 0000000000000000 R15: dffffc0000000000
FS: 0000000000000000(0000) GS:ffff888125c1a000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f50d6d1d440 CR3: 000000004dc26000 CR4: 00000000003526f0
Call Trace:
<TASK>
xfrm6_tunnel_net_exit+0x3c/0x100 net/ipv6/xfrm6_tunnel.c:337
ops_exit_list net/core/net_namespace.c:198 [inline]
ops_undo_list+0x49a/0x990 net/core/net_namespace.c:251
cleanup_net+0x4c5/0x800 net/core/net_namespace.c:682
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+0x70e/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>
Tested on:
commit: 24204116 Merge branch 'ipv6-sr-simplify-and-optimize-h..
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=13f39ef0580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=1519dc42580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (12 preceding siblings ...)
2025-08-27 5:18 ` Hillf Danton
@ 2025-08-27 5:49 ` Edward Adam Davis
2025-08-27 6:44 ` syzbot
2025-08-27 6:56 ` Edward Adam Davis
` (6 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Edward Adam Davis @ 2025-08-27 5:49 UTC (permalink / raw)
To: syzbot+a25ee9d20d31e483ba7b; +Cc: linux-kernel, syzkaller-bugs
#syz test
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 78fcbb89cf32..137b5b660683 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -929,10 +929,10 @@ int xfrm_state_flush(struct net *net, u8 proto, bool task_valid)
err = -ESRCH;
for (i = 0; i <= net->xfrm.state_hmask; i++) {
struct xfrm_state *x;
-restart:
hlist_for_each_entry(x, net->xfrm.state_bydst+i, bydst) {
if (!xfrm_state_kern(x) &&
- xfrm_id_proto_match(x->id.proto, proto)) {
+ xfrm_id_proto_match(x->id.proto, proto) &&
+ x->km.state != XFRM_STATE_DEAD) {
xfrm_state_hold(x);
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
@@ -940,11 +940,9 @@ int xfrm_state_flush(struct net *net, u8 proto, bool task_valid)
xfrm_audit_state_delete(x, err ? 0 : 1,
task_valid);
xfrm_state_put(x);
- if (!err)
- cnt++;
+ cnt++;
spin_lock_bh(&net->xfrm.xfrm_state_lock);
- goto restart;
}
}
}
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 78fcbb89cf32..3de1ac70019f 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -929,10 +929,10 @@ int xfrm_state_flush(struct net *net, u8 proto, bool task_valid)
err = -ESRCH;
for (i = 0; i <= net->xfrm.state_hmask; i++) {
struct xfrm_state *x;
-restart:
hlist_for_each_entry(x, net->xfrm.state_bydst+i, bydst) {
if (!xfrm_state_kern(x) &&
- xfrm_id_proto_match(x->id.proto, proto)) {
+ xfrm_id_proto_match(x->id.proto, proto) &&
+ x->km.state != XFRM_STATE_DEAD) {
xfrm_state_hold(x);
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
@@ -940,11 +940,9 @@ int xfrm_state_flush(struct net *net, u8 proto, bool task_valid)
xfrm_audit_state_delete(x, err ? 0 : 1,
task_valid);
xfrm_state_put(x);
- if (!err)
- cnt++;
+ cnt++;
spin_lock_bh(&net->xfrm.xfrm_state_lock);
- goto restart;
}
}
}
@@ -1557,6 +1555,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,
#endif
if (km_query(x, tmpl, pol) == 0) {
spin_lock_bh(&net->xfrm.xfrm_state_lock);
+ BUG_ON(x->km.state == XFRM_STATE_DEAD);
x->km.state = XFRM_STATE_ACQ;
x->dir = XFRM_SA_DIR_OUT;
list_add(&x->km.all, &net->xfrm.state_all);
@@ -1722,6 +1721,7 @@ static void __xfrm_state_insert(struct xfrm_state *x)
struct net *net = xs_net(x);
unsigned int h;
+ BUG_ON(x->km.state == XFRM_STATE_DEAD);
list_add(&x->km.all, &net->xfrm.state_all);
/* Sanitize mark before store */
^ permalink raw reply related [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (13 preceding siblings ...)
2025-08-27 5:49 ` Edward Adam Davis
@ 2025-08-27 6:56 ` Edward Adam Davis
2025-08-27 7:26 ` syzbot
2025-08-27 7:57 ` Hillf Danton
` (5 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Edward Adam Davis @ 2025-08-27 6:56 UTC (permalink / raw)
To: syzbot+a25ee9d20d31e483ba7b; +Cc: linux-kernel, syzkaller-bugs
#syz test
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 78fcbb89cf3..3de1ac70019 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -929,10 +929,10 @@ int xfrm_state_flush(struct net *net, u8 proto, bool task_valid)
err = -ESRCH;
for (i = 0; i <= net->xfrm.state_hmask; i++) {
struct xfrm_state *x;
-restart:
hlist_for_each_entry(x, net->xfrm.state_bydst+i, bydst) {
if (!xfrm_state_kern(x) &&
- xfrm_id_proto_match(x->id.proto, proto)) {
+ xfrm_id_proto_match(x->id.proto, proto) &&
+ x->km.state != XFRM_STATE_DEAD) {
xfrm_state_hold(x);
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
@@ -940,11 +940,9 @@ int xfrm_state_flush(struct net *net, u8 proto, bool task_valid)
xfrm_audit_state_delete(x, err ? 0 : 1,
task_valid);
xfrm_state_put(x);
- if (!err)
- cnt++;
+ cnt++;
spin_lock_bh(&net->xfrm.xfrm_state_lock);
- goto restart;
}
}
}
@@ -1557,6 +1555,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,
#endif
if (km_query(x, tmpl, pol) == 0) {
spin_lock_bh(&net->xfrm.xfrm_state_lock);
+ BUG_ON(x->km.state == XFRM_STATE_DEAD);
x->km.state = XFRM_STATE_ACQ;
x->dir = XFRM_SA_DIR_OUT;
list_add(&x->km.all, &net->xfrm.state_all);
@@ -1722,6 +1721,7 @@ static void __xfrm_state_insert(struct xfrm_state *x)
struct net *net = xs_net(x);
unsigned int h;
+ BUG_ON(x->km.state == XFRM_STATE_DEAD);
list_add(&x->km.all, &net->xfrm.state_all);
/* Sanitize mark before store */
^ permalink raw reply related [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-27 6:56 ` Edward Adam Davis
@ 2025-08-27 7:26 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-27 7:26 UTC (permalink / raw)
To: eadavis, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in xfrm_state_fini
------------[ cut here ]------------
WARNING: CPU: 0 PID: 2132 at net/xfrm/xfrm_state.c:3303 xfrm_state_fini+0x26d/0x2f0 net/xfrm/xfrm_state.c:3303
Modules linked in:
CPU: 0 UID: 0 PID: 2132 Comm: kworker/u8:7 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Workqueue: netns cleanup_net
RIP: 0010:xfrm_state_fini+0x26d/0x2f0 net/xfrm/xfrm_state.c:3303
Code: c1 e8 03 42 80 3c 28 00 74 08 48 89 df e8 fb b1 00 f8 48 8b 3b 5b 41 5c 41 5d 41 5e 41 5f 5d e9 b9 72 e1 f7 e8 14 46 9d f7 90 <0f> 0b 90 e9 fd fd ff ff e8 06 46 9d f7 90 0f 0b 90 e9 60 fe ff ff
RSP: 0000:ffffc90004827898 EFLAGS: 00010293
RAX: ffffffff8a22651c RBX: ffff888023d54880 RCX: ffff888029618000
RDX: 0000000000000000 RSI: ffffffff8be33660 RDI: ffff888029618000
RBP: ffffc900048279b0 R08: ffffffff8fa38437 R09: 1ffffffff1f47086
R10: dffffc0000000000 R11: fffffbfff1f47087 R12: ffffffff8f631480
R13: 1ffff92000904f40 R14: ffff888023d55d00 R15: dffffc0000000000
FS: 0000000000000000(0000) GS:ffff888125c1a000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000055be456ece28 CR3: 000000007da92000 CR4: 00000000003526f0
Call Trace:
<TASK>
xfrm_net_exit+0x2d/0x70 net/xfrm/xfrm_policy.c:4354
ops_exit_list net/core/net_namespace.c:198 [inline]
ops_undo_list+0x49a/0x990 net/core/net_namespace.c:251
cleanup_net+0x4c5/0x800 net/core/net_namespace.c:682
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+0x70e/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>
Tested on:
commit: 24204116 Merge branch 'ipv6-sr-simplify-and-optimize-h..
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=11279ef0580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=10eb9ef0580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (14 preceding siblings ...)
2025-08-27 6:56 ` Edward Adam Davis
@ 2025-08-27 7:57 ` Hillf Danton
2025-08-27 8:22 ` syzbot
2025-08-27 8:10 ` Edward Adam Davis
` (4 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Hillf Danton @ 2025-08-27 7:57 UTC (permalink / raw)
To: syzbot; +Cc: linux-kernel, syzkaller-bugs
> Date: Sun, 24 Aug 2025 12:21:23 -0700 [thread overview]
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b1c92cdf5af3 Merge branch 'net-wangxun-complete-ethtool-co..
> git tree: net-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1411b062580000
> kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
> dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
> compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14221862580000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=159fba34580000
#syz test
--- x/include/net/xfrm.h
+++ y/include/net/xfrm.h
@@ -202,6 +202,7 @@ struct xfrm_state {
refcount_t refcnt;
spinlock_t lock;
+ int deleted;
u32 pcpu_num;
struct xfrm_id id;
--- x/net/xfrm/xfrm_state.c
+++ y/net/xfrm/xfrm_state.c
@@ -615,6 +615,7 @@ static void xfrm_state_gc_destroy(struct
put_page(x->xfrag.page);
xfrm_dev_state_free(x);
security_xfrm_state_free(x);
+ xfrm_state_delete(x);
xfrm_state_free(x);
}
@@ -812,10 +813,16 @@ int __xfrm_state_delete(struct xfrm_stat
struct net *net = xs_net(x);
int err = -ESRCH;
- if (x->km.state != XFRM_STATE_DEAD) {
- x->km.state = XFRM_STATE_DEAD;
+ for (;;) {
+ if (x->km.state != XFRM_STATE_DEAD)
+ x->km.state = XFRM_STATE_DEAD;
spin_lock(&net->xfrm.xfrm_state_lock);
+ if (x->deleted) {
+ spin_unlock(&net->xfrm.xfrm_state_lock);
+ return 0;
+ }
+ x->deleted++;
list_del(&x->km.all);
hlist_del_rcu(&x->bydst);
hlist_del_rcu(&x->bysrc);
@@ -929,22 +936,29 @@ int xfrm_state_flush(struct net *net, u8
err = -ESRCH;
for (i = 0; i <= net->xfrm.state_hmask; i++) {
struct xfrm_state *x;
+ bool dead;
restart:
hlist_for_each_entry(x, net->xfrm.state_bydst+i, bydst) {
if (!xfrm_state_kern(x) &&
xfrm_id_proto_match(x->id.proto, proto)) {
- xfrm_state_hold(x);
+ dead = x->km.state == XFRM_STATE_DEAD;
+ x->km.state = XFRM_STATE_DEAD;
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
- err = xfrm_state_delete(x);
+ if (dead) {
+ flush:
+ schedule_work(&xfrm_state_gc_work);
+ flush_work(&xfrm_state_gc_work);
+ spin_lock_bh(&net->xfrm.xfrm_state_lock);
+ goto restart;
+ }
+ err = 0;
xfrm_audit_state_delete(x, err ? 0 : 1,
task_valid);
xfrm_state_put(x);
if (!err)
cnt++;
-
- spin_lock_bh(&net->xfrm.xfrm_state_lock);
- goto restart;
+ goto flush;
}
}
}
--
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-27 7:57 ` Hillf Danton
@ 2025-08-27 8:22 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-27 8:22 UTC (permalink / raw)
To: hdanton, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING: refcount bug in __xfrm_state_delete
------------[ cut here ]------------
refcount_t: underflow; use-after-free.
WARNING: CPU: 1 PID: 24 at lib/refcount.c:28 refcount_warn_saturate+0x11a/0x1d0 lib/refcount.c:28
Modules linked in:
CPU: 1 UID: 0 PID: 24 Comm: kworker/1:0 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Workqueue: events xfrm_state_gc_task
RIP: 0010:refcount_warn_saturate+0x11a/0x1d0 lib/refcount.c:28
Code: 80 b1 e2 8b e8 77 4e bb fc 90 0f 0b 90 90 eb d7 e8 6b af f7 fc c6 05 81 7b c5 0a 01 90 48 c7 c7 e0 b1 e2 8b e8 57 4e bb fc 90 <0f> 0b 90 90 eb b7 e8 4b af f7 fc c6 05 5e 7b c5 0a 01 90 48 c7 c7
RSP: 0018:ffffc900001e7888 EFLAGS: 00010246
RAX: 516864998ccbad00 RBX: 0000000000000003 RCX: ffff88801d680000
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000002
RBP: 0000000000000000 R08: ffffc900001e75a7 R09: 1ffff9200003ceb4
R10: dffffc0000000000 R11: fffff5200003ceb5 R12: dffffc0000000000
R13: ffff88802f119aa0 R14: ffff88802f1199e8 R15: ffff88802f119b90
FS: 0000000000000000(0000) GS:ffff888125d1a000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000055809cc3f950 CR3: 000000007eb98000 CR4: 00000000003526f0
Call Trace:
<TASK>
__refcount_sub_and_test include/linux/refcount.h:400 [inline]
__refcount_dec_and_test include/linux/refcount.h:432 [inline]
refcount_dec_and_test include/linux/refcount.h:450 [inline]
xfrm_state_put include/net/xfrm.h:928 [inline]
__xfrm_state_delete+0xc73/0xde0 net/xfrm/xfrm_state.c:850
xfrm_state_delete net/xfrm/xfrm_state.c:863 [inline]
xfrm_state_gc_destroy net/xfrm/xfrm_state.c:618 [inline]
xfrm_state_gc_task+0x532/0x6d0 net/xfrm/xfrm_state.c:635
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+0x70e/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>
Tested on:
commit: 24204116 Merge branch 'ipv6-sr-simplify-and-optimize-h..
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=13749462580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=11c49462580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (15 preceding siblings ...)
2025-08-27 7:57 ` Hillf Danton
@ 2025-08-27 8:10 ` Edward Adam Davis
2025-08-27 9:14 ` syzbot
2025-08-27 8:39 ` Hillf Danton
` (3 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Edward Adam Davis @ 2025-08-27 8:10 UTC (permalink / raw)
To: syzbot+a25ee9d20d31e483ba7b; +Cc: linux-kernel, syzkaller-bugs
#syz test
diff --git a/net/ipv6/xfrm6_tunnel.c b/net/ipv6/xfrm6_tunnel.c
index 0a0eeaed0591..5120a763da0d 100644
--- a/net/ipv6/xfrm6_tunnel.c
+++ b/net/ipv6/xfrm6_tunnel.c
@@ -334,7 +334,7 @@ static void __net_exit xfrm6_tunnel_net_exit(struct net *net)
struct xfrm6_tunnel_net *xfrm6_tn = xfrm6_tunnel_pernet(net);
unsigned int i;
- xfrm_state_flush(net, 0, false);
+ xfrm_state_flush(net, IPSEC_PROTO_ANY, false);
xfrm_flush_gc();
for (i = 0; i < XFRM6_TUNNEL_SPI_BYADDR_HSIZE; i++)
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 78fcbb89cf32..77db3b5fe4ac 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -3297,7 +3297,7 @@ void xfrm_state_fini(struct net *net)
unsigned int sz;
flush_work(&net->xfrm.state_hash_work);
- xfrm_state_flush(net, 0, false);
+ xfrm_state_flush(net, IPSEC_PROTO_ANY, false);
flush_work(&xfrm_state_gc_work);
WARN_ON(!list_empty(&net->xfrm.state_all));
^ permalink raw reply related [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-27 8:10 ` Edward Adam Davis
@ 2025-08-27 9:14 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-27 9:14 UTC (permalink / raw)
To: eadavis, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Write in __xfrm_state_delete
==================================================================
BUG: KASAN: slab-use-after-free in __hlist_del include/linux/list.h:980 [inline]
BUG: KASAN: slab-use-after-free in hlist_del_rcu include/linux/rculist.h:560 [inline]
BUG: KASAN: slab-use-after-free in __xfrm_state_delete+0x666/0xca0 net/xfrm/xfrm_state.c:830
Write of size 8 at addr ffff88805af9bba8 by task kworker/u8:6/1110
CPU: 0 UID: 0 PID: 1110 Comm: kworker/u8:6 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Workqueue: netns cleanup_net
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xca/0x240 mm/kasan/report.c:482
kasan_report+0x118/0x150 mm/kasan/report.c:595
__hlist_del include/linux/list.h:980 [inline]
hlist_del_rcu include/linux/rculist.h:560 [inline]
__xfrm_state_delete+0x666/0xca0 net/xfrm/xfrm_state.c:830
xfrm_state_delete net/xfrm/xfrm_state.c:856 [inline]
xfrm_state_flush+0x45f/0x770 net/xfrm/xfrm_state.c:939
xfrm6_tunnel_net_exit+0x3f/0x100 net/ipv6/xfrm6_tunnel.c:337
ops_exit_list net/core/net_namespace.c:198 [inline]
ops_undo_list+0x49a/0x990 net/core/net_namespace.c:251
cleanup_net+0x4c5/0x800 net/core/net_namespace.c:682
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+0x70e/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>
Allocated by task 7551:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
unpoison_slab_object mm/kasan/common.c:330 [inline]
__kasan_slab_alloc+0x6c/0x80 mm/kasan/common.c:356
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
kmem_cache_alloc_noprof+0x1c1/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x2f0 net/xfrm/xfrm_state.c:733
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1833
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2353
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a0/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x219/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 10:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:576
poison_slab_object mm/kasan/common.c:243 [inline]
__kasan_slab_free+0x5b/0x80 mm/kasan/common.c:275
kasan_slab_free include/linux/kasan.h:233 [inline]
slab_free_hook mm/slub.c:2417 [inline]
slab_free mm/slub.c:4680 [inline]
kmem_cache_free+0x18f/0x400 mm/slub.c:4782
xfrm_state_free net/xfrm/xfrm_state.c:591 [inline]
xfrm_state_gc_destroy net/xfrm/xfrm_state.c:618 [inline]
xfrm_state_gc_task+0x52d/0x6b0 net/xfrm/xfrm_state.c:634
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+0x70e/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
The buggy address belongs to the object at ffff88805af9bb80
which belongs to the cache xfrm_state of size 928
The buggy address is located 40 bytes inside of
freed 928-byte region [ffff88805af9bb80, ffff88805af9bf20)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x5af98
head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff88801b325140 dead000000000122 0000000000000000
raw: 0000000000000000 00000000000f000f 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff88801b325140 dead000000000122 0000000000000000
head: 0000000000000000 00000000000f000f 00000000f5000000 0000000000000000
head: 00fff00000000002 ffffea00016be601 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000004
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Unmovable, gfp_mask 0x52820(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 7495, tgid 7494 (syz.0.502), ts 107639354526, free_ts 107636640273
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3858
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5148
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2416
alloc_slab_page mm/slub.c:2487 [inline]
allocate_slab+0x8a/0x370 mm/slub.c:2655
new_slab mm/slub.c:2709 [inline]
___slab_alloc+0xbeb/0x1410 mm/slub.c:3891
__slab_alloc mm/slub.c:3981 [inline]
__slab_alloc_node mm/slub.c:4056 [inline]
slab_alloc_node mm/slub.c:4217 [inline]
kmem_cache_alloc_noprof+0x283/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x2f0 net/xfrm/xfrm_state.c:733
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1833
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2353
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a0/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
page last free pid 6353 tgid 6353 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
__free_frozen_pages+0xbc4/0xd30 mm/page_alloc.c:2895
__slab_free+0x303/0x3c0 mm/slub.c:4591
qlink_free mm/kasan/quarantine.c:163 [inline]
qlist_free_all+0x97/0x140 mm/kasan/quarantine.c:179
kasan_quarantine_reduce+0x148/0x160 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x22/0x80 mm/kasan/common.c:340
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
kmem_cache_alloc_noprof+0x1c1/0x3c0 mm/slub.c:4236
anon_vma_alloc mm/rmap.c:94 [inline]
anon_vma_fork+0xde/0x500 mm/rmap.c:360
dup_mmap+0x9eb/0x1ac0 mm/mmap.c:1797
dup_mm kernel/fork.c:1485 [inline]
copy_mm+0x13c/0x4b0 kernel/fork.c:1537
copy_process+0x1706/0x3c00 kernel/fork.c:2175
kernel_clone+0x21e/0x840 kernel/fork.c:2605
__do_sys_clone kernel/fork.c:2748 [inline]
__se_sys_clone kernel/fork.c:2732 [inline]
__x64_sys_clone+0x18b/0x1e0 kernel/fork.c:2732
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff88805af9ba80: fb fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
ffff88805af9bb00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88805af9bb80: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88805af9bc00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88805af9bc80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Tested on:
commit: 24204116 Merge branch 'ipv6-sr-simplify-and-optimize-h..
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=14a85ef0580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=17949462580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (16 preceding siblings ...)
2025-08-27 8:10 ` Edward Adam Davis
@ 2025-08-27 8:39 ` Hillf Danton
2025-08-27 9:31 ` syzbot
2025-08-27 9:35 ` Edward Adam Davis
` (2 subsequent siblings)
20 siblings, 1 reply; 44+ messages in thread
From: Hillf Danton @ 2025-08-27 8:39 UTC (permalink / raw)
To: syzbot; +Cc: linux-kernel, syzkaller-bugs
> Date: Sun, 24 Aug 2025 12:21:23 -0700 [thread overview]
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b1c92cdf5af3 Merge branch 'net-wangxun-complete-ethtool-co..
> git tree: net-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1411b062580000
> kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
> dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
> compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14221862580000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=159fba34580000
#syz test
--- x/include/net/xfrm.h
+++ y/include/net/xfrm.h
@@ -202,6 +202,7 @@ struct xfrm_state {
refcount_t refcnt;
spinlock_t lock;
+ int deleted;
u32 pcpu_num;
struct xfrm_id id;
--- x/net/xfrm/xfrm_state.c
+++ y/net/xfrm/xfrm_state.c
@@ -615,6 +615,7 @@ static void xfrm_state_gc_destroy(struct
put_page(x->xfrag.page);
xfrm_dev_state_free(x);
security_xfrm_state_free(x);
+ xfrm_state_delete(x);
xfrm_state_free(x);
}
@@ -812,10 +813,16 @@ int __xfrm_state_delete(struct xfrm_stat
struct net *net = xs_net(x);
int err = -ESRCH;
- if (x->km.state != XFRM_STATE_DEAD) {
- x->km.state = XFRM_STATE_DEAD;
+ for (;;) {
+ if (x->km.state != XFRM_STATE_DEAD)
+ x->km.state = XFRM_STATE_DEAD;
spin_lock(&net->xfrm.xfrm_state_lock);
+ if (x->deleted) {
+ spin_unlock(&net->xfrm.xfrm_state_lock);
+ return 0;
+ }
+ x->deleted++;
list_del(&x->km.all);
hlist_del_rcu(&x->bydst);
hlist_del_rcu(&x->bysrc);
@@ -833,14 +840,7 @@ int __xfrm_state_delete(struct xfrm_stat
spin_unlock(&net->xfrm.xfrm_state_lock);
xfrm_dev_state_delete(x);
-
xfrm_state_delete_tunnel(x);
-
- /* All xfrm_state objects are created by xfrm_state_alloc.
- * The xfrm_state_alloc call gives a reference, and that
- * is what we are dropping here.
- */
- xfrm_state_put(x);
err = 0;
}
@@ -929,22 +929,29 @@ int xfrm_state_flush(struct net *net, u8
err = -ESRCH;
for (i = 0; i <= net->xfrm.state_hmask; i++) {
struct xfrm_state *x;
+ bool dead;
restart:
hlist_for_each_entry(x, net->xfrm.state_bydst+i, bydst) {
if (!xfrm_state_kern(x) &&
xfrm_id_proto_match(x->id.proto, proto)) {
- xfrm_state_hold(x);
+ dead = x->km.state == XFRM_STATE_DEAD;
+ x->km.state = XFRM_STATE_DEAD;
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
- err = xfrm_state_delete(x);
+ if (dead) {
+ flush:
+ schedule_work(&xfrm_state_gc_work);
+ flush_work(&xfrm_state_gc_work);
+ spin_lock_bh(&net->xfrm.xfrm_state_lock);
+ goto restart;
+ }
+ err = 0;
xfrm_audit_state_delete(x, err ? 0 : 1,
task_valid);
xfrm_state_put(x);
if (!err)
cnt++;
-
- spin_lock_bh(&net->xfrm.xfrm_state_lock);
- goto restart;
+ goto flush;
}
}
}
--
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-27 8:39 ` Hillf Danton
@ 2025-08-27 9:31 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-27 9:31 UTC (permalink / raw)
To: hdanton, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Read in xfrm_state_flush
==================================================================
BUG: KASAN: slab-use-after-free in instrument_atomic_read include/linux/instrumented.h:68 [inline]
BUG: KASAN: slab-use-after-free in atomic_read include/linux/atomic/atomic-instrumented.h:32 [inline]
BUG: KASAN: slab-use-after-free in xfrm_state_kern include/net/xfrm.h:1534 [inline]
BUG: KASAN: slab-use-after-free in xfrm_state_flush+0x2e8/0x770 net/xfrm/xfrm_state.c:935
Read of size 4 at addr ffff88805b356418 by task kworker/u8:4/59
CPU: 0 UID: 0 PID: 59 Comm: kworker/u8:4 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Workqueue: netns cleanup_net
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xca/0x240 mm/kasan/report.c:482
kasan_report+0x118/0x150 mm/kasan/report.c:595
check_region_inline mm/kasan/generic.c:-1 [inline]
kasan_check_range+0x2b0/0x2c0 mm/kasan/generic.c:189
instrument_atomic_read include/linux/instrumented.h:68 [inline]
atomic_read include/linux/atomic/atomic-instrumented.h:32 [inline]
xfrm_state_kern include/net/xfrm.h:1534 [inline]
xfrm_state_flush+0x2e8/0x770 net/xfrm/xfrm_state.c:935
xfrm6_tunnel_net_exit+0x3c/0x100 net/ipv6/xfrm6_tunnel.c:337
ops_exit_list net/core/net_namespace.c:198 [inline]
ops_undo_list+0x49a/0x990 net/core/net_namespace.c:251
cleanup_net+0x4c5/0x800 net/core/net_namespace.c:682
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+0x70e/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>
Allocated by task 7705:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
unpoison_slab_object mm/kasan/common.c:330 [inline]
__kasan_slab_alloc+0x6c/0x80 mm/kasan/common.c:356
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
kmem_cache_alloc_noprof+0x1c1/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x2f0 net/xfrm/xfrm_state.c:734
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1840
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2360
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a0/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x219/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 10:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:576
poison_slab_object mm/kasan/common.c:243 [inline]
__kasan_slab_free+0x5b/0x80 mm/kasan/common.c:275
kasan_slab_free include/linux/kasan.h:233 [inline]
slab_free_hook mm/slub.c:2417 [inline]
slab_free mm/slub.c:4680 [inline]
kmem_cache_free+0x18f/0x400 mm/slub.c:4782
xfrm_state_free net/xfrm/xfrm_state.c:591 [inline]
xfrm_state_gc_destroy net/xfrm/xfrm_state.c:619 [inline]
xfrm_state_gc_task+0x549/0x6d0 net/xfrm/xfrm_state.c:635
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+0x70e/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
The buggy address belongs to the object at ffff88805b356200
which belongs to the cache xfrm_state of size 936
The buggy address is located 536 bytes inside of
freed 936-byte region [ffff88805b356200, ffff88805b3565a8)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x5b354
head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff888144e94500 dead000000000122 0000000000000000
raw: 0000000000000000 00000000800f000f 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff888144e94500 dead000000000122 0000000000000000
head: 0000000000000000 00000000800f000f 00000000f5000000 0000000000000000
head: 00fff00000000002 ffffea00016cd501 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000004
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Unmovable, gfp_mask 0x52820(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 7675, tgid 7674 (syz.0.601), ts 110112755349, free_ts 102648833516
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3858
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5148
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2416
alloc_slab_page mm/slub.c:2487 [inline]
allocate_slab+0x8a/0x370 mm/slub.c:2655
new_slab mm/slub.c:2709 [inline]
___slab_alloc+0xbeb/0x1410 mm/slub.c:3891
__slab_alloc mm/slub.c:3981 [inline]
__slab_alloc_node mm/slub.c:4056 [inline]
slab_alloc_node mm/slub.c:4217 [inline]
kmem_cache_alloc_noprof+0x283/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x2f0 net/xfrm/xfrm_state.c:734
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1840
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2360
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a0/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
page last free pid 6809 tgid 6809 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
__free_frozen_pages+0xbc4/0xd30 mm/page_alloc.c:2895
discard_slab mm/slub.c:2753 [inline]
__put_partials+0x156/0x1a0 mm/slub.c:3218
put_cpu_partial+0x17c/0x250 mm/slub.c:3293
__slab_free+0x2d5/0x3c0 mm/slub.c:4550
qlink_free mm/kasan/quarantine.c:163 [inline]
qlist_free_all+0x97/0x140 mm/kasan/quarantine.c:179
kasan_quarantine_reduce+0x148/0x160 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x22/0x80 mm/kasan/common.c:340
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
__do_kmalloc_node mm/slub.c:4364 [inline]
__kmalloc_noprof+0x224/0x4f0 mm/slub.c:4377
kmalloc_noprof include/linux/slab.h:909 [inline]
kmalloc_array_noprof include/linux/slab.h:948 [inline]
security_inode_init_security+0x107/0x3f0 security/security.c:1829
shmem_symlink+0xd9/0x510 mm/shmem.c:4163
vfs_symlink+0x143/0x2f0 fs/namei.c:4730
do_symlinkat+0x1b1/0x3f0 fs/namei.c:4756
__do_sys_symlinkat fs/namei.c:4772 [inline]
__se_sys_symlinkat fs/namei.c:4769 [inline]
__x64_sys_symlinkat+0x95/0xb0 fs/namei.c:4769
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff88805b356300: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88805b356380: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88805b356400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88805b356480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88805b356500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Tested on:
commit: 24204116 Merge branch 'ipv6-sr-simplify-and-optimize-h..
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=17406c62580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=1399a462580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (17 preceding siblings ...)
2025-08-27 8:39 ` Hillf Danton
@ 2025-08-27 9:35 ` Edward Adam Davis
2025-08-27 10:23 ` syzbot
2025-08-27 10:07 ` Hillf Danton
2025-08-27 11:00 ` Hillf Danton
20 siblings, 1 reply; 44+ messages in thread
From: Edward Adam Davis @ 2025-08-27 9:35 UTC (permalink / raw)
To: syzbot+a25ee9d20d31e483ba7b; +Cc: linux-kernel, syzkaller-bugs
#syz test
diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index f3014e4f54fc..a1d5acd1f2ad 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -229,6 +229,7 @@ struct xfrm_state {
int trailer_len;
u32 extra_flags;
struct xfrm_mark smark;
+ u8 alive;
} props;
struct xfrm_lifetime_cfg lft;
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 78fcbb89cf32..d66adf7ee6a2 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -755,6 +755,7 @@ struct xfrm_state *xfrm_state_alloc(struct net *net)
x->pcpu_num = UINT_MAX;
spin_lock_init(&x->lock);
x->mode_data = NULL;
+ x->props.alive = 1;
}
return x;
}
@@ -830,6 +831,7 @@ int __xfrm_state_delete(struct xfrm_state *x)
hlist_del_rcu(&x->byspi);
net->xfrm.state_num--;
xfrm_nat_keepalive_state_updated(x);
+ x->props.alive = 0;
spin_unlock(&net->xfrm.xfrm_state_lock);
xfrm_dev_state_delete(x);
@@ -932,7 +934,8 @@ int xfrm_state_flush(struct net *net, u8 proto, bool task_valid)
restart:
hlist_for_each_entry(x, net->xfrm.state_bydst+i, bydst) {
if (!xfrm_state_kern(x) &&
- xfrm_id_proto_match(x->id.proto, proto)) {
+ xfrm_id_proto_match(x->id.proto, proto) &&
+ x->props.alive) {
xfrm_state_hold(x);
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
^ permalink raw reply related [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-27 9:35 ` Edward Adam Davis
@ 2025-08-27 10:23 ` syzbot
0 siblings, 0 replies; 44+ messages in thread
From: syzbot @ 2025-08-27 10:23 UTC (permalink / raw)
To: eadavis, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Write in __xfrm_state_delete
==================================================================
BUG: KASAN: slab-use-after-free in __hlist_del include/linux/list.h:980 [inline]
BUG: KASAN: slab-use-after-free in hlist_del_rcu include/linux/rculist.h:560 [inline]
BUG: KASAN: slab-use-after-free in __xfrm_state_delete+0x666/0xcd0 net/xfrm/xfrm_state.c:831
Write of size 8 at addr ffff8880285bd9a8 by task kworker/u8:7/3075
CPU: 1 UID: 0 PID: 3075 Comm: kworker/u8:7 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
Workqueue: netns cleanup_net
Call Trace:
<TASK>
dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xca/0x240 mm/kasan/report.c:482
kasan_report+0x118/0x150 mm/kasan/report.c:595
__hlist_del include/linux/list.h:980 [inline]
hlist_del_rcu include/linux/rculist.h:560 [inline]
__xfrm_state_delete+0x666/0xcd0 net/xfrm/xfrm_state.c:831
xfrm_state_delete net/xfrm/xfrm_state.c:858 [inline]
xfrm_state_flush+0x487/0x7c0 net/xfrm/xfrm_state.c:942
xfrm6_tunnel_net_exit+0x3c/0x100 net/ipv6/xfrm6_tunnel.c:337
ops_exit_list net/core/net_namespace.c:198 [inline]
ops_undo_list+0x49a/0x990 net/core/net_namespace.c:251
cleanup_net+0x4c5/0x800 net/core/net_namespace.c:682
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+0x70e/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>
Allocated by task 10077:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
unpoison_slab_object mm/kasan/common.c:330 [inline]
__kasan_slab_alloc+0x6c/0x80 mm/kasan/common.c:356
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
kmem_cache_alloc_noprof+0x1c1/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x320 net/xfrm/xfrm_state.c:733
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1836
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2356
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a3/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x219/0x270 net/socket.c:729
____sys_sendmsg+0x505/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmsg net/socket.c:2700 [inline]
__do_sys_sendmsg net/socket.c:2705 [inline]
__se_sys_sendmsg net/socket.c:2703 [inline]
__x64_sys_sendmsg+0x19b/0x260 net/socket.c:2703
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 24:
kasan_save_stack mm/kasan/common.c:47 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:68
kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:576
poison_slab_object mm/kasan/common.c:243 [inline]
__kasan_slab_free+0x5b/0x80 mm/kasan/common.c:275
kasan_slab_free include/linux/kasan.h:233 [inline]
slab_free_hook mm/slub.c:2417 [inline]
slab_free mm/slub.c:4680 [inline]
kmem_cache_free+0x18f/0x400 mm/slub.c:4782
xfrm_state_free net/xfrm/xfrm_state.c:591 [inline]
xfrm_state_gc_destroy net/xfrm/xfrm_state.c:618 [inline]
xfrm_state_gc_task+0x52d/0x6b0 net/xfrm/xfrm_state.c:634
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+0x70e/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
The buggy address belongs to the object at ffff8880285bd980
which belongs to the cache xfrm_state of size 928
The buggy address is located 40 bytes inside of
freed 928-byte region [ffff8880285bd980, ffff8880285bdd20)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x285bc
head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff88801fef0640 dead000000000100 dead000000000122
raw: 0000000000000000 00000000000f000f 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff88801fef0640 dead000000000100 dead000000000122
head: 0000000000000000 00000000000f000f 00000000f5000000 0000000000000000
head: 00fff00000000002 ffffea0000a16f01 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000004
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Unmovable, gfp_mask 0x52820(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 6998, tgid 6997 (syz.0.241), ts 106338851731, free_ts 105263132831
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x21e4/0x22c0 mm/page_alloc.c:3858
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5148
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2416
alloc_slab_page mm/slub.c:2487 [inline]
allocate_slab+0x8a/0x370 mm/slub.c:2655
new_slab mm/slub.c:2709 [inline]
___slab_alloc+0xbeb/0x1410 mm/slub.c:3891
__slab_alloc mm/slub.c:3981 [inline]
__slab_alloc_node mm/slub.c:4056 [inline]
slab_alloc_node mm/slub.c:4217 [inline]
kmem_cache_alloc_noprof+0x283/0x3c0 mm/slub.c:4236
xfrm_state_alloc+0x24/0x320 net/xfrm/xfrm_state.c:733
__find_acq_core+0x8a7/0x1c00 net/xfrm/xfrm_state.c:1836
xfrm_find_acq+0x78/0xa0 net/xfrm/xfrm_state.c:2356
xfrm_alloc_userspi+0x6b3/0xc90 net/xfrm/xfrm_user.c:1863
xfrm_user_rcv_msg+0x7a3/0xab0 net/xfrm/xfrm_user.c:3501
netlink_rcv_skb+0x208/0x470 net/netlink/af_netlink.c:2552
xfrm_netlink_rcv+0x79/0x90 net/xfrm/xfrm_user.c:3523
netlink_unicast_kernel net/netlink/af_netlink.c:1320 [inline]
netlink_unicast+0x82f/0x9e0 net/netlink/af_netlink.c:1346
netlink_sendmsg+0x805/0xb30 net/netlink/af_netlink.c:1896
page last free pid 6867 tgid 6867 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
__free_frozen_pages+0xbc4/0xd30 mm/page_alloc.c:2895
discard_slab mm/slub.c:2753 [inline]
__put_partials+0x156/0x1a0 mm/slub.c:3218
put_cpu_partial+0x17c/0x250 mm/slub.c:3293
__slab_free+0x2d5/0x3c0 mm/slub.c:4550
qlink_free mm/kasan/quarantine.c:163 [inline]
qlist_free_all+0x97/0x140 mm/kasan/quarantine.c:179
kasan_quarantine_reduce+0x148/0x160 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x22/0x80 mm/kasan/common.c:340
kasan_slab_alloc include/linux/kasan.h:250 [inline]
slab_post_alloc_hook mm/slub.c:4180 [inline]
slab_alloc_node mm/slub.c:4229 [inline]
__do_kmalloc_node mm/slub.c:4364 [inline]
__kmalloc_noprof+0x224/0x4f0 mm/slub.c:4377
kmalloc_noprof include/linux/slab.h:909 [inline]
kzalloc_noprof include/linux/slab.h:1039 [inline]
tomoyo_encode2 security/tomoyo/realpath.c:45 [inline]
tomoyo_encode+0x28b/0x550 security/tomoyo/realpath.c:80
tomoyo_path_perm+0x2b3/0x4b0 security/tomoyo/file.c:831
tomoyo_path_symlink+0xa3/0xe0 security/tomoyo/tomoyo.c:212
security_path_symlink+0x177/0x380 security/security.c:1984
do_symlinkat+0x107/0x3f0 fs/namei.c:4754
__do_sys_symlinkat fs/namei.c:4772 [inline]
__se_sys_symlinkat fs/namei.c:4769 [inline]
__x64_sys_symlinkat+0x95/0xb0 fs/namei.c:4769
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff8880285bd880: 00 00 00 00 00 00 00 00 00 00 00 00 fc fc fc fc
ffff8880285bd900: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8880285bd980: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8880285bda00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8880285bda80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Tested on:
commit: 24204116 Merge branch 'ipv6-sr-simplify-and-optimize-h..
git tree: net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=13069462580000
kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=10e03c42580000
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (18 preceding siblings ...)
2025-08-27 9:35 ` Edward Adam Davis
@ 2025-08-27 10:07 ` Hillf Danton
2025-08-27 10:41 ` syzbot
2025-08-27 11:00 ` Hillf Danton
20 siblings, 1 reply; 44+ messages in thread
From: Hillf Danton @ 2025-08-27 10:07 UTC (permalink / raw)
To: syzbot; +Cc: linux-kernel, syzkaller-bugs
> Date: Sun, 24 Aug 2025 12:21:23 -0700 [thread overview]
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b1c92cdf5af3 Merge branch 'net-wangxun-complete-ethtool-co..
> git tree: net-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1411b062580000
> kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
> dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
> compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14221862580000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=159fba34580000
#syz test
--- x/include/net/xfrm.h
+++ y/include/net/xfrm.h
@@ -202,6 +202,7 @@ struct xfrm_state {
refcount_t refcnt;
spinlock_t lock;
+ int deleted;
u32 pcpu_num;
struct xfrm_id id;
--- x/net/xfrm/xfrm_state.c
+++ y/net/xfrm/xfrm_state.c
@@ -615,6 +615,7 @@ static void xfrm_state_gc_destroy(struct
put_page(x->xfrag.page);
xfrm_dev_state_free(x);
security_xfrm_state_free(x);
+ xfrm_state_delete(x);
xfrm_state_free(x);
}
@@ -812,10 +813,16 @@ int __xfrm_state_delete(struct xfrm_stat
struct net *net = xs_net(x);
int err = -ESRCH;
- if (x->km.state != XFRM_STATE_DEAD) {
- x->km.state = XFRM_STATE_DEAD;
+ for (;;) {
+ if (x->km.state != XFRM_STATE_DEAD)
+ x->km.state = XFRM_STATE_DEAD;
spin_lock(&net->xfrm.xfrm_state_lock);
+ if (x->deleted) {
+ spin_unlock(&net->xfrm.xfrm_state_lock);
+ return 0;
+ }
+ x->deleted++;
list_del(&x->km.all);
hlist_del_rcu(&x->bydst);
hlist_del_rcu(&x->bysrc);
@@ -833,14 +840,7 @@ int __xfrm_state_delete(struct xfrm_stat
spin_unlock(&net->xfrm.xfrm_state_lock);
xfrm_dev_state_delete(x);
-
xfrm_state_delete_tunnel(x);
-
- /* All xfrm_state objects are created by xfrm_state_alloc.
- * The xfrm_state_alloc call gives a reference, and that
- * is what we are dropping here.
- */
- xfrm_state_put(x);
err = 0;
}
@@ -929,22 +929,29 @@ int xfrm_state_flush(struct net *net, u8
err = -ESRCH;
for (i = 0; i <= net->xfrm.state_hmask; i++) {
struct xfrm_state *x;
+ bool dead;
restart:
hlist_for_each_entry(x, net->xfrm.state_bydst+i, bydst) {
if (!xfrm_state_kern(x) &&
xfrm_id_proto_match(x->id.proto, proto)) {
- xfrm_state_hold(x);
+ dead = x->km.state == XFRM_STATE_DEAD;
+ x->km.state = XFRM_STATE_DEAD;
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
- err = xfrm_state_delete(x);
+ if (dead) {
+ flush:
+ schedule_work(&xfrm_state_gc_work);
+ flush_work(&xfrm_state_gc_work);
+ spin_lock_bh(&net->xfrm.xfrm_state_lock);
+ goto restart;
+ }
+ err = 0;
xfrm_audit_state_delete(x, err ? 0 : 1,
task_valid);
xfrm_state_put(x);
if (!err)
cnt++;
-
- spin_lock_bh(&net->xfrm.xfrm_state_lock);
- goto restart;
+ goto flush;
}
}
}
@@ -1863,6 +1870,7 @@ static struct xfrm_state *__find_acq_cor
x->mark.m = m->m;
x->lft.hard_add_expires_seconds = net->xfrm.sysctl_acq_expires;
xfrm_state_hold(x);
+ xfrm_state_hold(x);
hrtimer_start(&x->mtimer,
ktime_set(net->xfrm.sysctl_acq_expires, 0),
HRTIMER_MODE_REL_SOFT);
--
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [syzbot] [net?] KASAN: slab-use-after-free Write in __xfrm_state_delete
2025-08-24 19:21 ` syzbot
` (19 preceding siblings ...)
2025-08-27 10:07 ` Hillf Danton
@ 2025-08-27 11:00 ` Hillf Danton
2025-08-27 11:48 ` syzbot
20 siblings, 1 reply; 44+ messages in thread
From: Hillf Danton @ 2025-08-27 11:00 UTC (permalink / raw)
To: syzbot; +Cc: linux-kernel, syzkaller-bugs
> Date: Sun, 24 Aug 2025 12:21:23 -0700 [thread overview]
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: b1c92cdf5af3 Merge branch 'net-wangxun-complete-ethtool-co..
> git tree: net-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1411b062580000
> kernel config: https://syzkaller.appspot.com/x/.config?x=67b99ceb67d33475
> dashboard link: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b
> compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14221862580000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=159fba34580000
#syz test
--- x/net/xfrm/xfrm_state.c
+++ y/net/xfrm/xfrm_state.c
@@ -1863,6 +1863,7 @@ static struct xfrm_state *__find_acq_cor
x->mark.m = m->m;
x->lft.hard_add_expires_seconds = net->xfrm.sysctl_acq_expires;
xfrm_state_hold(x);
+ xfrm_state_hold(x);
hrtimer_start(&x->mtimer,
ktime_set(net->xfrm.sysctl_acq_expires, 0),
HRTIMER_MODE_REL_SOFT);
--
^ permalink raw reply [flat|nested] 44+ messages in thread