KASAN: slab-out-of-bounds Read in cttimeout_net_exit
Subsystems (3)
syzbot
syzbotHello,
syzbot found the following issue on:
HEAD commit: 65a9dedc11d6 net: phy: marvell: Add errata section 5.1 for.. git tree: net-next console output: https://syzkaller.appspot.com/x/log.txt?x=16fafa9ef00000 kernel config: https://syzkaller.appspot.com/x/.config?x=c05eee2efc702eed dashboard link: https://syzkaller.appspot.com/bug?extid=92968395eedbdbd3617d compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
Unfortunately, I don't have any reproducer for this issue yet.
IMPORTANT: if you fix the issue, please add the following tag to the commit:
bond0 (unregistering): (slave bond_slave_1): Releasing backup interface bond0 (unregistering): (slave bond_slave_0): Releasing backup interface bond0 (unregistering): Released all slaves
==================================================================
BUG: KASAN: slab-out-of-bounds in __list_del_entry_valid+0xcc/0xf0 lib/list_debug.c:42 Read of size 8 at addr ffff888051af75b8 by task kworker/u4:5/1223 CPU: 1 PID: 1223 Comm: kworker/u4:5 Not tainted 5.18.0-rc6-syzkaller-01553-g65a9dedc11d6 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: netns cleanup_net Call Trace: <TASK> __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106 print_address_description.constprop.0.cold+0xeb/0x495 mm/kasan/report.c:313 print_report mm/kasan/report.c:429 [inline] kasan_report.cold+0xf4/0x1c6 mm/kasan/report.c:491 __list_del_entry_valid+0xcc/0xf0 lib/list_debug.c:42 __list_del_entry include/linux/list.h:134 [inline] list_del include/linux/list.h:148 [inline] cttimeout_net_exit+0x211/0x540 net/netfilter/nfnetlink_cttimeout.c:617 ops_exit_list+0xb0/0x170 net/core/net_namespace.c:162 cleanup_net+0x4ea/0xb00 net/core/net_namespace.c:594 process_one_work+0x996/0x1610 kernel/workqueue.c:2289 worker_thread+0x665/0x1080 kernel/workqueue.c:2436 kthread+0x2e9/0x3a0 kernel/kthread.c:376 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298 </TASK> Allocated by task 9270: kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38 kasan_set_track mm/kasan/common.c:45 [inline] set_alloc_info mm/kasan/common.c:436 [inline] ____kasan_kmalloc mm/kasan/common.c:515 [inline] ____kasan_kmalloc mm/kasan/common.c:474 [inline] __kasan_kmalloc+0xa9/0xd0 mm/kasan/common.c:524 kmalloc include/linux/slab.h:586 [inline] kzalloc include/linux/slab.h:714 [inline] cttimeout_new_timeout+0x51f/0xa50 net/netfilter/nfnetlink_cttimeout.c:156 nfnetlink_rcv_msg+0xbcd/0x13f0 net/netfilter/nfnetlink.c:297 netlink_rcv_skb+0x153/0x420 net/netlink/af_netlink.c:2501 nfnetlink_rcv+0x1ac/0x420 net/netfilter/nfnetlink.c:655 netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline] netlink_unicast+0x543/0x7f0 net/netlink/af_netlink.c:1345 netlink_sendmsg+0x917/0xe10 net/netlink/af_netlink.c:1921 sock_sendmsg_nosec net/socket.c:714 [inline] sock_sendmsg+0xcf/0x120 net/socket.c:734 ____sys_sendmsg+0x6eb/0x810 net/socket.c:2460 ___sys_sendmsg+0xf3/0x170 net/socket.c:2514 __sys_sendmsg net/socket.c:2543 [inline] __do_sys_sendmsg net/socket.c:2552 [inline] __se_sys_sendmsg net/socket.c:2550 [inline] __x64_sys_sendmsg+0x132/0x220 net/socket.c:2550 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x44/0xae The buggy address belongs to the object at ffff888051af7500 which belongs to the cache kmalloc-128 of size 128
The buggy address is located 56 bytes to the right of
128-byte region [ffff888051af7500, ffff888051af7580)
The buggy address belongs to the physical page:
page:ffffea000146bdc0 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff888051af7100 pfn:0x51af7
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 ffffea0001ed5e48 ffffea0001cf4b08 ffff888010c418c0
raw: ffff888051af7100 000000000010000b 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x112cc0(GFP_USER|__GFP_NOWARN|__GFP_NORETRY), pid 7027, tgid 7027 (cmp), ts 227162348638, free_ts 227160439771
prep_new_page mm/page_alloc.c:2441 [inline]
get_page_from_freelist+0xba2/0x3e00 mm/page_alloc.c:4182
__alloc_pages+0x1b2/0x500 mm/page_alloc.c:5408
__alloc_pages_node include/linux/gfp.h:587 [inline]
alloc_slab_page mm/slub.c:1801 [inline]
allocate_slab+0x80/0x3c0 mm/slub.c:1944
new_slab mm/slub.c:2004 [inline]
___slab_alloc+0x8df/0xf20 mm/slub.c:3005
__slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3092
slab_alloc_node mm/slub.c:3183 [inline]
__kmalloc_node+0x2cb/0x390 mm/slub.c:4458
kmalloc_array_node include/linux/slab.h:676 [inline]
kcalloc_node include/linux/slab.h:681 [inline]
memcg_alloc_slab_cgroups+0x8b/0x140 mm/memcontrol.c:2810
account_slab mm/slab.h:652 [inline]
allocate_slab+0x2c9/0x3c0 mm/slub.c:1960
new_slab mm/slub.c:2004 [inline]
___slab_alloc+0x8df/0xf20 mm/slub.c:3005
__slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3092
slab_alloc_node mm/slub.c:3183 [inline]
slab_alloc mm/slub.c:3225 [inline]
__kmem_cache_alloc_lru mm/slub.c:3232 [inline]
kmem_cache_alloc+0x360/0x3b0 mm/slub.c:3242
vm_area_dup+0x88/0x3f0 kernel/fork.c:467
__split_vma+0xa5/0x550 mm/mmap.c:2712
split_vma+0x95/0xd0 mm/mmap.c:2770
mprotect_fixup+0x72d/0x950 mm/mprotect.c:494
do_mprotect_pkey+0x532/0x980 mm/mprotect.c:650
page last free stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1356 [inline]
free_pcp_prepare+0x549/0xd20 mm/page_alloc.c:1406
free_unref_page_prepare mm/page_alloc.c:3328 [inline]
free_unref_page+0x19/0x6a0 mm/page_alloc.c:3423
__vunmap+0x85d/0xd30 mm/vmalloc.c:2667
free_work+0x58/0x70 mm/vmalloc.c:97
process_one_work+0x996/0x1610 kernel/workqueue.c:2289
worker_thread+0x665/0x1080 kernel/workqueue.c:2436
kthread+0x2e9/0x3a0 kernel/kthread.c:376
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298
Memory state around the buggy address:
ffff888051af7480: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff888051af7500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fc fc
>ffff888051af7580: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
^
ffff888051af7600: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888051af7680: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================---
This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at [email protected].
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
Florian Westphal
maintainerPATCH 1/1 netfilter: cttimeout: fix slab-out-of-bounds read in cttimeout_net_exit
syzbot reports:
BUG: KASAN: slab-out-of-bounds in __list_del_entry_valid+0xcc/0xf0 lib/list_debug.c:42 [..] list_del include/linux/list.h:148 [inline] cttimeout_net_exit+0x211/0x540 net/netfilter/nfnetlink_cttimeout.c:617
No reproducer so far. Looking at recent changes in this area its clear that the free_head must not be at the end of the structure because nf_ct_timeout structure has variable size.
--- net/netfilter/nfnetlink_cttimeout.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/netfilter/nfnetlink_cttimeout.c +3 -2
@@ -35,12 +35,13 @@ static unsigned int nfct_timeout_id __read_mostly;struct ctnl_timeout {struct list_head head; +struct list_head free_head;struct rcu_head rcu_head;refcount_t refcnt;char name[CTNL_TIMEOUT_NAME_MAX ]; -struct nf_ct_timeout timeout; -struct list_head free_head; +/* must be at the end */ +struct nf_ct_timeout timeout; };struct nfct_timeout_pernet {
Signature · 1 line
2.35.1
Re: [PATCH nf-next] netfilter: cttimeout: fix slab-out-of-bounds read in cttimeout_net_exit
Quoted 9 lines · Florian Westphal
syzbot reports:
BUG: KASAN: slab-out-of-bounds in __list_del_entry_valid+0xcc/0xf0 lib/list_debug.c:42 [..] list_del include/linux/list.h:148 [inline] cttimeout_net_exit+0x211/0x540 net/netfilter/nfnetlink_cttimeout.c:617No reproducer so far. Looking at recent changes in this area its clear that the
free_headmust not be at the end of the structure becausenf_ct_timeoutstructure has variable size.
Applied, thanks
syzbot
syzbotsyzbot has found a reproducer for the following issue on:
syzbot has found a reproducer for the following issue on:
HEAD commit: 6ac6dc746d70 Merge branch 'mlx5-next' of git://git.kernel... git tree: net-next console+strace: https://syzkaller.appspot.com/x/log.txt?x=15095107f00000 kernel config: https://syzkaller.appspot.com/x/.config?x=20ac3e0ebf0db3bd dashboard link: https://syzkaller.appspot.com/bug?extid=92968395eedbdbd3617d compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=12e777bff00000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=12613a87f00000
IMPORTANT: if you fix the issue, please add the following tag to the commit:
general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] CPU: 1 PID: 11 Comm: kworker/u4:1 Not tainted 5.19.0-rc1-syzkaller-00373-g6ac6dc746d70 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: netns cleanup_net RIP: 0010:__list_del_entry_valid+0x81/0xf0 lib/list_debug.c:51 Code: 0f 84 b5 a6 41 05 48 b8 22 01 00 00 00 00 ad de 49 39 c4 0f 84 b6 a6 41 05 48 b8 00 00 00 00 00 fc ff df 4c 89 e2 48 c1 ea 03 <80> 3c 02 00 75 51 49 8b 14 24 48 39 ea 0f 85 6a a6 41 05 49 8d 7d RSP: 0018:ffffc90000107bc0 EFLAGS: 00010246 RAX: dffffc0000000000 RBX: ffff88801759b310 RCX: 0000000000000000 RDX: 0000000000000000 RSI: ffffffff879e16e1 RDI: ffff88801759b328 RBP: ffff88801759b320 R08: 0000000000000005 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000000 R13: 0000000000000000 R14: dffffc0000000000 R15: ffff88801759b328 FS: 0000000000000000(0000) GS:ffff8880b9b00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f5555f6a01d CR3: 0000000074e46000 CR4: 00000000003506e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> __list_del_entry include/linux/list.h:134 [inline] list_del include/linux/list.h:148 [inline] cttimeout_net_exit+0x211/0x540 net/netfilter/nfnetlink_cttimeout.c:618 ops_exit_list+0xb0/0x170 net/core/net_namespace.c:162 cleanup_net+0x4ea/0xb00 net/core/net_namespace.c:594 process_one_work+0x996/0x1610 kernel/workqueue.c:2289 worker_thread+0x665/0x1080 kernel/workqueue.c:2436 kthread+0x2e9/0x3a0 kernel/kthread.c:376 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:302 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:__list_del_entry_valid+0x81/0xf0 lib/list_debug.c:51 Code: 0f 84 b5 a6 41 05 48 b8 22 01 00 00 00 00 ad de 49 39 c4 0f 84 b6 a6 41 05 48 b8 00 00 00 00 00 fc ff df 4c 89 e2 48 c1 ea 03 <80> 3c 02 00 75 51 49 8b 14 24 48 39 ea 0f 85 6a a6 41 05 49 8d 7d RSP: 0018:ffffc90000107bc0 EFLAGS: 00010246 RAX: dffffc0000000000 RBX: ffff88801759b310 RCX: 0000000000000000 RDX: 0000000000000000 RSI: ffffffff879e16e1 RDI: ffff88801759b328 RBP: ffff88801759b320 R08: 0000000000000005 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000000 R13: 0000000000000000 R14: dffffc0000000000 R15: ffff88801759b328 FS: 0000000000000000(0000) GS:ffff8880b9b00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f5555f6a01d CR3: 0000000025f1e000 CR4: 00000000003506e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 ---------------- Code disassembly (best guess): 0: 0f 84 b5 a6 41 05 je 0x541a6bb 6: 48 b8 22 01 00 00 00 movabs $0xdead000000000122,%rax d: 00 ad de 10: 49 39 c4 cmp %rax,%r12 13: 0f 84 b6 a6 41 05 je 0x541a6cf 19: 48 b8 00 00 00 00 00 movabs $0xdffffc0000000000,%rax 20: fc ff df 23: 4c 89 e2 mov %r12,%rdx 26: 48 c1 ea 03 shr $0x3,%rdx * 2a: 80 3c 02 00 cmpb $0x0,(%rdx,%rax,1) <-- trapping instruction 2e: 75 51 jne 0x81 30: 49 8b 14 24 mov (%r12),%rdx 34: 48 39 ea cmp %rbp,%rdx 37: 0f 85 6a a6 41 05 jne 0x541a6a7 3d: 49 rex.WB 3e: 8d .byte 0x8d 3f: 7d .byte 0x7d
Florian Westphal
maintainerPATCH 1/1 netfilter: cttimeout: fix slab-out-of-bounds read typo in cttimeout_net_exit
syzbot reports:
BUG: KASAN: slab-out-of-bounds in __list_del_entry_valid+0xcc/0xf0 lib/list_debug.c:42 [..] list_del include/linux/list.h:148 [inline] cttimeout_net_exit+0x211/0x540 net/netfilter/nfnetlink_cttimeout.c:617
Problem is the wrong name of the list member, so container_of yields incorrect onj address.
--- net/netfilter/nfnetlink_cttimeout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nfnetlink_cttimeout.c +1 -1
@@ -614,7 +614,7 @@ static void __net_exit cttimeout_net_exit(struct net *net)nf_ct_untimeout (net,NULL ); -list_for_each_entry_safe (cur, tmp, &pernet->nfct_timeout_freelist, head) { +list_for_each_entry_safe (cur, tmp, &pernet->nfct_timeout_freelist, free_head) {list_del (&cur->free_head);if (refcount_dec_and_test (&cur->refcnt))
Signature · 1 line
2.35.1