2024-06-07 00:49:27

by Ubisectech Sirius

[permalink] [raw]
Subject: KASAN: slab-use-after-free Read in lock_sock_nested


Hello.
We are Ubisectech Sirius Team, the vulnerability lab of China ValiantSec. Recently, our team has discovered a issue in Linux kernel 6.8. Attached to the email were a PoC file of the issue.

Stack dump:
==================================================================
BUG: KASAN: slab-use-after-free in __lock_acquire+0x30a9/0x3bc0 kernel/locking/lockdep.c:5005
Read of size 8 at addr ffff888020d030b0 by task kworker/u7:2/8097

CPU: 1 PID: 8097 Comm: kworker/u7:2 Not tainted 6.8.0 #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
Workqueue: hci0 hci_rx_work
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xd9/0x150 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:377 [inline]
print_report+0xc1/0x5e0 mm/kasan/report.c:488
kasan_report+0xbe/0xf0 mm/kasan/report.c:601
__lock_acquire+0x30a9/0x3bc0 kernel/locking/lockdep.c:5005
lock_acquire kernel/locking/lockdep.c:5754 [inline]
lock_acquire+0x1b1/0x530 kernel/locking/lockdep.c:5719
__raw_spin_lock_bh include/linux/spinlock_api_smp.h:126 [inline]
_raw_spin_lock_bh+0x33/0x40 kernel/locking/spinlock.c:178
spin_lock_bh include/linux/spinlock.h:356 [inline]
lock_sock_nested+0x5f/0xf0 net/core/sock.c:3526
lock_sock include/net/sock.h:1691 [inline]
l2cap_sock_recv_cb+0x53/0x1f0 net/bluetooth/l2cap_sock.c:1480
l2cap_conless_channel net/bluetooth/l2cap_core.c:7771 [inline]
l2cap_recv_frame+0x817/0x9110 net/bluetooth/l2cap_core.c:7824
l2cap_recv_acldata+0xa7d/0xbf0 net/bluetooth/l2cap_core.c:8536
hci_acldata_packet net/bluetooth/hci_core.c:3876 [inline]
hci_rx_work+0x6d0/0x1560 net/bluetooth/hci_core.c:4111
process_one_work+0x87b/0x15c0 kernel/workqueue.c:2633
process_scheduled_works kernel/workqueue.c:2706 [inline]
worker_thread+0x855/0x1200 kernel/workqueue.c:2787
kthread+0x2cc/0x3b0 kernel/kthread.c:388
ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x1b/0x30 arch/x86/entry/entry_64.S:243
</TASK>

Allocated by task 21267:
kasan_save_stack+0x24/0x50 mm/kasan/common.c:47
kasan_save_track+0x14/0x30 mm/kasan/common.c:68
poison_kmalloc_redzone mm/kasan/common.c:370 [inline]
__kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:387
kasan_kmalloc include/linux/kasan.h:211 [inline]
__do_kmalloc_node mm/slub.c:3981 [inline]
__kmalloc+0x1f3/0x480 mm/slub.c:3994
kmalloc include/linux/slab.h:594 [inline]
sk_prot_alloc+0x155/0x290 net/core/sock.c:2078
sk_alloc+0x36/0xb80 net/core/sock.c:2131
bt_sock_alloc+0x3a/0x3b0 net/bluetooth/af_bluetooth.c:148
l2cap_sock_alloc net/bluetooth/l2cap_sock.c:1842 [inline]
l2cap_sock_create+0x132/0x2d0 net/bluetooth/l2cap_sock.c:1880
bt_sock_create+0x182/0x350 net/bluetooth/af_bluetooth.c:132
__sock_create+0x37b/0x850 net/socket.c:1571
sock_create net/socket.c:1622 [inline]
__sys_socket_create net/socket.c:1659 [inline]
__sys_socket_create net/socket.c:1644 [inline]
__sys_socket+0x148/0x260 net/socket.c:1706
__do_sys_socket net/socket.c:1720 [inline]
__se_sys_socket net/socket.c:1718 [inline]
__x64_sys_socket+0x72/0xb0 net/socket.c:1718
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xd5/0x270 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x6f/0x77

Freed by task 21266:
kasan_save_stack+0x24/0x50 mm/kasan/common.c:47
kasan_save_track+0x14/0x30 mm/kasan/common.c:68
kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:589
poison_slab_object mm/kasan/common.c:240 [inline]
poison_slab_object+0x102/0x190 mm/kasan/common.c:211
__kasan_slab_free+0x33/0x50 mm/kasan/common.c:256
kasan_slab_free include/linux/kasan.h:184 [inline]
slab_free_hook mm/slub.c:2121 [inline]
slab_free mm/slub.c:4299 [inline]
kfree+0x129/0x380 mm/slub.c:4409
sk_prot_free net/core/sock.c:2114 [inline]
__sk_destruct+0x5e4/0x740 net/core/sock.c:2206
sk_destruct+0xc1/0xe0 net/core/sock.c:2221
__sk_free+0xf2/0x3e0 net/core/sock.c:2232
sk_free+0x7c/0xa0 net/core/sock.c:2243
sock_put include/net/sock.h:1961 [inline]
l2cap_sock_kill net/bluetooth/l2cap_sock.c:1239 [inline]
l2cap_sock_kill+0x1fe/0x240 net/bluetooth/l2cap_sock.c:1228
l2cap_sock_release+0x18f/0x210 net/bluetooth/l2cap_sock.c:1410
__sock_release+0xb0/0x270 net/socket.c:659
sock_close+0x1c/0x30 net/socket.c:1421
__fput+0x282/0xbc0 fs/file_table.c:376
__fput_sync+0x45/0x50 fs/file_table.c:461
__do_sys_close fs/open.c:1554 [inline]
__se_sys_close fs/open.c:1539 [inline]
__x64_sys_close+0x8b/0x120 fs/open.c:1539
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xd5/0x270 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x6f/0x77

The buggy address belongs to the object at ffff888020d03000
which belongs to the cache kmalloc-2k of size 2048
The buggy address is located 176 bytes inside of
freed 2048-byte region [ffff888020d03000, ffff888020d03800)

The buggy address belongs to the physical page:
page:ffffea0000834000 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x20d00
head:ffffea0000834000 order:3 entire_mapcount:0 nr_pages_mapped:0 pincount:0
anon flags: 0xfff00000000840(slab|head|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 00fff00000000840 ffff888014842000 0000000000000000 dead000000000001
raw: 0000000000000000 0000000080080008 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0x1d2820(GFP_ATOMIC|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC|__GFP_HARDWALL), pid 14627, tgid 14627 (syz-executor.2), ts 225339630885, free_ts 223639522034
set_page_owner include/linux/page_owner.h:31 [inline]
post_alloc_hook+0x2dd/0x350 mm/page_alloc.c:1533
prep_new_page mm/page_alloc.c:1540 [inline]
get_page_from_freelist+0xd38/0x3040 mm/page_alloc.c:3311
__alloc_pages+0x215/0x21b0 mm/page_alloc.c:4569
__alloc_pages_node include/linux/gfp.h:238 [inline]
alloc_pages_node include/linux/gfp.h:261 [inline]
alloc_slab_page mm/slub.c:2190 [inline]
allocate_slab mm/slub.c:2354 [inline]
new_slab+0xd3/0x3b0 mm/slub.c:2407
___slab_alloc+0xc39/0x18c0 mm/slub.c:3540
__slab_alloc.constprop.0+0x56/0xb0 mm/slub.c:3625
__slab_alloc_node mm/slub.c:3678 [inline]
slab_alloc_node mm/slub.c:3850 [inline]
__do_kmalloc_node mm/slub.c:3980 [inline]
__kmalloc_node_track_caller+0x359/0x4a0 mm/slub.c:4001
kmalloc_reserve+0xed/0x260 net/core/skbuff.c:582
__alloc_skb+0x129/0x330 net/core/skbuff.c:651
alloc_skb include/linux/skbuff.h:1296 [inline]
nlmsg_new include/net/netlink.h:1010 [inline]
inet6_ifinfo_notify+0x7b/0x160 net/ipv6/addrconf.c:6115
addrconf_notify+0x3fc/0x1980 net/ipv6/addrconf.c:3718
notifier_call_chain+0xba/0x3e0 kernel/notifier.c:93
call_netdevice_notifiers_info+0xbe/0x140 net/core/dev.c:1966
call_netdevice_notifiers_extack net/core/dev.c:2004 [inline]
call_netdevice_notifiers net/core/dev.c:2018 [inline]
__dev_notify_flags+0x12d/0x2e0 net/core/dev.c:8687
dev_change_flags+0x109/0x170 net/core/dev.c:8725
do_setlink+0x94c/0x3b40 net/core/rtnetlink.c:2906
page last free pid 15917 tgid 15916 stack trace:
reset_page_owner include/linux/page_owner.h:24 [inline]
free_pages_prepare mm/page_alloc.c:1140 [inline]
free_unref_page_prepare+0x516/0xb10 mm/page_alloc.c:2346
free_unref_page+0x33/0x3e0 mm/page_alloc.c:2486
kasan_depopulate_vmalloc_pte+0x60/0x80 mm/kasan/shadow.c:415
apply_to_pte_range mm/memory.c:2619 [inline]
apply_to_pmd_range mm/memory.c:2663 [inline]
apply_to_pud_range mm/memory.c:2699 [inline]
apply_to_p4d_range mm/memory.c:2735 [inline]
__apply_to_page_range+0x5d2/0xf00 mm/memory.c:2769
kasan_release_vmalloc+0xab/0xc0 mm/kasan/shadow.c:532
__purge_vmap_area_lazy+0x884/0x1e40 mm/vmalloc.c:1770
_vm_unmap_aliases+0x117/0x9b0 mm/vmalloc.c:2306
change_page_attr_set_clr+0x228/0x470 arch/x86/mm/pat/set_memory.c:1842
change_page_attr_clear arch/x86/mm/pat/set_memory.c:1890 [inline]
set_memory_ro+0x7c/0xb0 arch/x86/mm/pat/set_memory.c:2076
bpf_prog_lock_ro include/linux/filter.h:889 [inline]
bpf_prog_select_runtime+0x50c/0x650 kernel/bpf/core.c:2395
bpf_prog_load+0x1721/0x23a0 kernel/bpf/syscall.c:2773
__sys_bpf+0x12ce/0x5020 kernel/bpf/syscall.c:5457
__do_sys_bpf kernel/bpf/syscall.c:5561 [inline]
__se_sys_bpf kernel/bpf/syscall.c:5559 [inline]
__x64_sys_bpf+0x78/0xc0 kernel/bpf/syscall.c:5559
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xd5/0x270 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x6f/0x77

Memory state around the buggy address:
ffff888020d02f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff888020d03000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888020d03080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888020d03100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888020d03180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Thank you for taking the time to read this email and we look forward to working with you further.








Attachments:
poc.c (83.10 kB)