syzbot


KASAN: use-after-free Read in gsm_cleanup_mux

Status: fixed on 2023/09/11 10:44
Reported-by: syzbot+947ecd0ac8b5b531dcc9@syzkaller.appspotmail.com
Fix commit: 31311a9a4baa tty: n_gsm: fix the UAF caused by race condition in gsm_cleanup_mux
First crash: 580d, last: 514d
Fix bisection: fixed by (bisect log) :
commit 31311a9a4baae0ad47c85e448af21b2120344ff0
Author: Yi Yang <yiyang13@huawei.com>
Date: Fri Aug 11 03:11:21 2023 +0000

  tty: n_gsm: fix the UAF caused by race condition in gsm_cleanup_mux

  
Bug presence (1)
Date Name Commit Repro Result
2023/08/30 upstream (ToT) 6c1b980a7e79 C Didn't crash
Similar bugs (2)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: use-after-free Read in gsm_cleanup_mux serial C done done 16 474d 753d 23/28 fixed on 2023/10/12 12:48
linux-5.15 KASAN: use-after-free Read in gsm_cleanup_mux C error 2 519d 545d 0/3 auto-obsoleted due to no activity on 2023/09/30 23:33
Fix bisection attempts (2)
Created Duration User Patch Repo Result
2023/09/11 04:23 3h04m bisect fix linux-6.1.y OK (1) job log
2023/06/27 14:06 1h04m bisect fix linux-6.1.y OK (0) job log log

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in gsm_cleanup_mux+0x824/0x910 drivers/tty/n_gsm.c:2491
Read of size 4 at addr ffff888016ae100c by task syz-executor292/3549

CPU: 1 PID: 3549 Comm: syz-executor292 Not tainted 6.1.35-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 05/27/2023
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1e3/0x2cb lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:284 [inline]
 print_report+0x15f/0x4f0 mm/kasan/report.c:395
 kasan_report+0x136/0x160 mm/kasan/report.c:495
 gsm_cleanup_mux+0x824/0x910 drivers/tty/n_gsm.c:2491
 gsm_config drivers/tty/n_gsm.c:2754 [inline]
 gsmld_ioctl+0xab7/0x15a0 drivers/tty/n_gsm.c:3117
 tty_ioctl+0x88e/0xbd0 drivers/tty/tty_io.c:2782
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:870 [inline]
 __se_sys_ioctl+0xf1/0x160 fs/ioctl.c:856
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f63eb2ddc69
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 11 15 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:00007f63eb26e318 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007f63eb3654d8 RCX: 00007f63eb2ddc69
RDX: 0000000020000040 RSI: 00000000404c4701 RDI: 0000000000000004
RBP: 00007f63eb3654d0 R08: 00007f63eb26e700 R09: 0000000000000000
R10: 00007f63eb26e700 R11: 0000000000000246 R12: 00007f63eb33308c
R13: 00007fffde92073f R14: 00007f63eb26e400 R15: 0000000000022000
 </TASK>

Allocated by task 3543:
 kasan_save_stack mm/kasan/common.c:45 [inline]
 kasan_set_track+0x4b/0x70 mm/kasan/common.c:52
 ____kasan_kmalloc mm/kasan/common.c:374 [inline]
 __kasan_kmalloc+0x97/0xb0 mm/kasan/common.c:383
 kmalloc include/linux/slab.h:553 [inline]
 kzalloc include/linux/slab.h:689 [inline]
 gsm_dlci_alloc+0x53/0x3a0 drivers/tty/n_gsm.c:2064
 gsm_activate_mux+0x1c/0x290 drivers/tty/n_gsm.c:2538
 gsm_config drivers/tty/n_gsm.c:2778 [inline]
 gsmld_ioctl+0xd66/0x15a0 drivers/tty/n_gsm.c:3117
 tty_ioctl+0x88e/0xbd0 drivers/tty/tty_io.c:2782
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:870 [inline]
 __se_sys_ioctl+0xf1/0x160 fs/ioctl.c:856
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 3543:
 kasan_save_stack mm/kasan/common.c:45 [inline]
 kasan_set_track+0x4b/0x70 mm/kasan/common.c:52
 kasan_save_free_info+0x27/0x40 mm/kasan/generic.c:516
 ____kasan_slab_free+0xd6/0x120 mm/kasan/common.c:236
 kasan_slab_free include/linux/kasan.h:177 [inline]
 slab_free_hook mm/slub.c:1724 [inline]
 slab_free_freelist_hook mm/slub.c:1750 [inline]
 slab_free mm/slub.c:3661 [inline]
 __kmem_cache_free+0x25c/0x3c0 mm/slub.c:3674
 dlci_put drivers/tty/n_gsm.c:2120 [inline]
 gsm_dlci_release drivers/tty/n_gsm.c:2153 [inline]
 gsm_cleanup_mux+0x57e/0x910 drivers/tty/n_gsm.c:2512
 gsm_config drivers/tty/n_gsm.c:2754 [inline]
 gsmld_ioctl+0xab7/0x15a0 drivers/tty/n_gsm.c:3117
 tty_ioctl+0x88e/0xbd0 drivers/tty/tty_io.c:2782
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:870 [inline]
 __se_sys_ioctl+0xf1/0x160 fs/ioctl.c:856
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Last potentially related work creation:
 kasan_save_stack+0x3b/0x60 mm/kasan/common.c:45
 __kasan_record_aux_stack+0xb0/0xc0 mm/kasan/generic.c:486
 call_rcu+0x163/0xa10 kernel/rcu/tree.c:2799
 netlink_release+0x1384/0x17f0 net/netlink/af_netlink.c:817
 __sock_release net/socket.c:652 [inline]
 sock_close+0xcd/0x230 net/socket.c:1370
 __fput+0x3b7/0x890 fs/file_table.c:320
 task_work_run+0x246/0x300 kernel/task_work.c:179
 resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
 exit_to_user_mode_loop+0xd9/0x100 kernel/entry/common.c:171
 exit_to_user_mode_prepare+0xb1/0x140 kernel/entry/common.c:204
 __syscall_exit_to_user_mode_work kernel/entry/common.c:286 [inline]
 syscall_exit_to_user_mode+0x60/0x270 kernel/entry/common.c:297
 do_syscall_64+0x49/0xb0 arch/x86/entry/common.c:86
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

The buggy address belongs to the object at ffff888016ae1000
 which belongs to the cache kmalloc-2k of size 2048
The buggy address is located 12 bytes inside of
 2048-byte region [ffff888016ae1000, ffff888016ae1800)

The buggy address belongs to the physical page:
page:ffffea00005ab800 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x16ae0
head:ffffea00005ab800 order:3 compound_mapcount:0 compound_pincount:0
flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000010200 dead000000000100 dead000000000122 ffff888012442000
raw: 0000000000000000 0000000000080008 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 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 1, tgid 1 (swapper/0), ts 2421548043, free_ts 0
 set_page_owner include/linux/page_owner.h:31 [inline]
 post_alloc_hook+0x18d/0x1b0 mm/page_alloc.c:2533
 prep_new_page mm/page_alloc.c:2540 [inline]
 get_page_from_freelist+0x32ed/0x3480 mm/page_alloc.c:4292
 __alloc_pages+0x28d/0x770 mm/page_alloc.c:5559
 alloc_page_interleave+0x22/0x1c0 mm/mempolicy.c:2113
 alloc_slab_page+0x6a/0x150 mm/slub.c:1794
 allocate_slab mm/slub.c:1939 [inline]
 new_slab+0x84/0x2d0 mm/slub.c:1992
 ___slab_alloc+0xa71/0x1080 mm/slub.c:3180
 __slab_alloc mm/slub.c:3279 [inline]
 slab_alloc_node mm/slub.c:3364 [inline]
 __kmem_cache_alloc_node+0x19f/0x260 mm/slub.c:3437
 kmalloc_trace+0x26/0xe0 mm/slab_common.c:1045
 kmalloc include/linux/slab.h:553 [inline]
 kzalloc include/linux/slab.h:689 [inline]
 acpi_os_allocate_zeroed include/acpi/platform/aclinuxex.h:57 [inline]
 acpi_ds_create_walk_state+0xff/0x2a0 drivers/acpi/acpica/dswstate.c:518
 acpi_ds_auto_serialize_method+0xe3/0x240 drivers/acpi/acpica/dsmethod.c:81
 acpi_ds_init_one_object+0x1b7/0x360 drivers/acpi/acpica/dsinit.c:110
 acpi_ns_walk_namespace+0x28c/0x4e0
 acpi_ds_initialize_objects+0x195/0x2a0 drivers/acpi/acpica/dsinit.c:189
 acpi_ns_load_table+0xf5/0x120 drivers/acpi/acpica/nsload.c:106
 acpi_tb_load_namespace+0x289/0x6c0 drivers/acpi/acpica/tbxfload.c:158
page_owner free stack trace missing

Memory state around the buggy address:
 ffff888016ae0f00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff888016ae0f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff888016ae1000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                      ^
 ffff888016ae1080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888016ae1100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (4):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/06/28 05:54 linux-6.1.y e84a4e368abe 4cd5bb25 .config console log report syz C [disk image] [vmlinux] [kernel image] ci2-linux-6-1-kasan KASAN: use-after-free Read in gsm_cleanup_mux
2023/05/27 23:37 linux-6.1.y a343b0dd87b4 cf184559 .config console log report syz C [disk image] [vmlinux] [kernel image] ci2-linux-6-1-kasan-arm64 KASAN: use-after-free Read in gsm_cleanup_mux
2023/05/27 23:16 linux-6.1.y a343b0dd87b4 cf184559 .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-6-1-kasan-arm64 KASAN: use-after-free Read in gsm_cleanup_mux
2023/04/23 07:39 linux-6.1.y f17b0ab65d17 2b32bd34 .config console log report info [disk image] [vmlinux] [kernel image] ci2-linux-6-1-kasan-arm64 KASAN: use-after-free Read in gsm_cleanup_mux
* Struck through repros no longer work on HEAD.