syzbot


KASAN: use-after-free Read in tty_write_room

Status: upstream: reported on 2021/12/20 06:24
Reported-by: syzbot+f1c7696a5552d2b56ca4@syzkaller.appspotmail.com
First crash: 359d, last: 97d

Sample crash report:
ieee802154 phy0 wpan0: encryption failed: -22
ieee802154 phy1 wpan1: encryption failed: -22
==================================================================
BUG: KASAN: use-after-free in tty_write_room+0x76/0x80 drivers/tty/tty_ioctl.c:78
Read of size 8 at addr ffff8880319c7018 by task aoe_tx0/1229

CPU: 0 PID: 1229 Comm: aoe_tx0 Not tainted 6.0.0-rc3-syzkaller-00328-g42cf58c272ee #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/26/2022
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:317 [inline]
 print_report.cold+0x2ba/0x719 mm/kasan/report.c:433
 kasan_report+0xb1/0x1e0 mm/kasan/report.c:495
 tty_write_room+0x76/0x80 drivers/tty/tty_ioctl.c:78
 handle_tx+0x159/0x610 drivers/net/caif/caif_serial.c:226
 __netdev_start_xmit include/linux/netdevice.h:4819 [inline]
 netdev_start_xmit include/linux/netdevice.h:4833 [inline]
 xmit_one net/core/dev.c:3590 [inline]
 dev_hard_start_xmit+0x183/0x880 net/core/dev.c:3606
 __dev_queue_xmit+0x2c31/0x3ad0 net/core/dev.c:4256
 dev_queue_xmit include/linux/netdevice.h:3008 [inline]
 tx+0x6a/0xc0 drivers/block/aoe/aoenet.c:63
 kthread+0x1e7/0x3b0 drivers/block/aoe/aoecmd.c:1229
 kthread+0x2e4/0x3a0 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306
 </TASK>

Allocated by task 26412:
 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:437 [inline]
 ____kasan_kmalloc mm/kasan/common.c:516 [inline]
 ____kasan_kmalloc mm/kasan/common.c:475 [inline]
 __kasan_kmalloc+0xa9/0xd0 mm/kasan/common.c:525
 kmalloc include/linux/slab.h:600 [inline]
 kzalloc include/linux/slab.h:733 [inline]
 alloc_tty_struct+0x94/0x920 drivers/tty/tty_io.c:3091
 tty_init_dev.part.0+0x20/0x610 drivers/tty/tty_io.c:1412
 tty_init_dev include/linux/err.h:36 [inline]
 tty_open_by_driver drivers/tty/tty_io.c:2086 [inline]
 tty_open+0xb07/0xff0 drivers/tty/tty_io.c:2133
 chrdev_open+0x266/0x770 fs/char_dev.c:414
 do_dentry_open+0x4a4/0x13a0 fs/open.c:878
 do_open fs/namei.c:3557 [inline]
 path_openat+0x1c92/0x28f0 fs/namei.c:3691
 do_filp_open+0x1b6/0x400 fs/namei.c:3718
 do_sys_openat2+0x16d/0x4c0 fs/open.c:1311
 do_sys_open fs/open.c:1327 [inline]
 __do_sys_openat fs/open.c:1343 [inline]
 __se_sys_openat fs/open.c:1338 [inline]
 __x64_sys_openat+0x13f/0x1f0 fs/open.c:1338
 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+0x63/0xcd

Freed by task 18950:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 kasan_set_track+0x21/0x30 mm/kasan/common.c:45
 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:370
 ____kasan_slab_free mm/kasan/common.c:367 [inline]
 ____kasan_slab_free+0x166/0x1c0 mm/kasan/common.c:329
 kasan_slab_free include/linux/kasan.h:200 [inline]
 slab_free_hook mm/slub.c:1754 [inline]
 slab_free_freelist_hook+0x8b/0x1c0 mm/slub.c:1780
 slab_free mm/slub.c:3534 [inline]
 kfree+0xe2/0x580 mm/slub.c:4562
 process_one_work+0x991/0x1610 kernel/workqueue.c:2289
 worker_thread+0x665/0x1080 kernel/workqueue.c:2436
 kthread+0x2e4/0x3a0 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306

Last potentially related work creation:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 __kasan_record_aux_stack+0xbe/0xd0 mm/kasan/generic.c:348
 insert_work+0x48/0x350 kernel/workqueue.c:1358
 __queue_work+0x625/0x1210 kernel/workqueue.c:1517
 queue_work_on+0xee/0x110 kernel/workqueue.c:1545
 kref_put include/linux/kref.h:65 [inline]
 tty_kref_put drivers/tty/tty_io.c:1570 [inline]
 release_tty+0x4e9/0x610 drivers/tty/tty_io.c:1606
 tty_release_struct+0xb4/0xe0 drivers/tty/tty_io.c:1705
 tty_release+0xc70/0x1200 drivers/tty/tty_io.c:1865
 __fput+0x277/0x9d0 fs/file_table.c:320
 task_work_run+0xdd/0x1a0 kernel/task_work.c:177
 exit_task_work include/linux/task_work.h:38 [inline]
 do_exit+0xad5/0x29b0 kernel/exit.c:795
 do_group_exit+0xd2/0x2f0 kernel/exit.c:925
 get_signal+0x238c/0x2610 kernel/signal.c:2857
 arch_do_signal_or_restart+0x82/0x2300 arch/x86/kernel/signal.c:869
 exit_to_user_mode_loop kernel/entry/common.c:166 [inline]
 exit_to_user_mode_prepare+0x15f/0x250 kernel/entry/common.c:201
 __syscall_exit_to_user_mode_work kernel/entry/common.c:283 [inline]
 syscall_exit_to_user_mode+0x19/0x50 kernel/entry/common.c:294
 do_syscall_64+0x42/0xb0 arch/x86/entry/common.c:86
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Second to last potentially related work creation:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 __kasan_record_aux_stack+0xbe/0xd0 mm/kasan/generic.c:348
 insert_work+0x48/0x350 kernel/workqueue.c:1358
 __queue_work+0x625/0x1210 kernel/workqueue.c:1517
 queue_work_on+0xee/0x110 kernel/workqueue.c:1545
 kref_put include/linux/kref.h:65 [inline]
 tty_kref_put drivers/tty/tty_io.c:1570 [inline]
 release_tty+0x4e9/0x610 drivers/tty/tty_io.c:1606
 tty_release_struct+0xb4/0xe0 drivers/tty/tty_io.c:1705
 tty_release+0xc70/0x1200 drivers/tty/tty_io.c:1865
 __fput+0x277/0x9d0 fs/file_table.c:320
 task_work_run+0xdd/0x1a0 kernel/task_work.c:177
 exit_task_work include/linux/task_work.h:38 [inline]
 do_exit+0xad5/0x29b0 kernel/exit.c:795
 do_group_exit+0xd2/0x2f0 kernel/exit.c:925
 get_signal+0x238c/0x2610 kernel/signal.c:2857
 arch_do_signal_or_restart+0x82/0x2300 arch/x86/kernel/signal.c:869
 exit_to_user_mode_loop kernel/entry/common.c:166 [inline]
 exit_to_user_mode_prepare+0x15f/0x250 kernel/entry/common.c:201
 __syscall_exit_to_user_mode_work kernel/entry/common.c:283 [inline]
 syscall_exit_to_user_mode+0x19/0x50 kernel/entry/common.c:294
 do_syscall_64+0x42/0xb0 arch/x86/entry/common.c:86
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

The buggy address belongs to the object at ffff8880319c7000
 which belongs to the cache kmalloc-cg-2k of size 2048
The buggy address is located 24 bytes inside of
 2048-byte region [ffff8880319c7000, ffff8880319c7800)

The buggy address belongs to the physical page:
page:ffffea0000c67000 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x319c0
head:ffffea0000c67000 order:3 compound_mapcount:0 compound_pincount:0
memcg:ffff88807e204c01
flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000010200 dead000000000100 dead000000000122 ffff88801184c140
raw: 0000000000000000 0000000000080008 00000001ffffffff ffff88807e204c01
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 3641, tgid 3641 (syz-executor.3), ts 184466341870, free_ts 0
 prep_new_page mm/page_alloc.c:2532 [inline]
 get_page_from_freelist+0x109b/0x2ce0 mm/page_alloc.c:4283
 __alloc_pages+0x1c7/0x510 mm/page_alloc.c:5515
 alloc_pages+0x1a6/0x270 mm/mempolicy.c:2270
 alloc_slab_page mm/slub.c:1824 [inline]
 allocate_slab+0x27e/0x3d0 mm/slub.c:1969
 new_slab mm/slub.c:2029 [inline]
 ___slab_alloc+0x7f1/0xe10 mm/slub.c:3031
 __slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3118
 slab_alloc_node mm/slub.c:3209 [inline]
 slab_alloc mm/slub.c:3251 [inline]
 __kmalloc+0x32b/0x340 mm/slub.c:4420
 kmalloc include/linux/slab.h:605 [inline]
 kzalloc include/linux/slab.h:733 [inline]
 __register_sysctl_table+0x112/0x10a0 fs/proc/proc_sysctl.c:1344
 __devinet_sysctl_register+0x156/0x280 net/ipv4/devinet.c:2586
 devinet_sysctl_register net/ipv4/devinet.c:2626 [inline]
 devinet_sysctl_register+0x160/0x230 net/ipv4/devinet.c:2616
 inetdev_event+0xe8e/0x1610 net/ipv4/devinet.c:1611
 notifier_call_chain+0xb5/0x200 kernel/notifier.c:87
 call_netdevice_notifiers_info+0xb5/0x130 net/core/dev.c:1945
 call_netdevice_notifiers_extack net/core/dev.c:1983 [inline]
 call_netdevice_notifiers net/core/dev.c:1997 [inline]
 dev_change_name+0x571/0x820 net/core/dev.c:1226
 do_setlink+0x19a9/0x3bb0 net/core/rtnetlink.c:2760
 __rtnl_newlink+0xd6a/0x17e0 net/core/rtnetlink.c:3546
page_owner free stack trace missing

Memory state around the buggy address:
 ffff8880319c6f00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff8880319c6f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8880319c7000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                            ^
 ffff8880319c7080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8880319c7100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (12):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-upstream-kasan-gce-root 2022/09/03 23:02 upstream 42cf58c272ee 28811d0a .config log report info KASAN: use-after-free Read in tty_write_room
ci-upstream-kasan-gce-selinux-root 2022/08/26 08:54 upstream 4c612826bec1 15195ea3 .config log report info KASAN: use-after-free Read in tty_write_room
ci-upstream-kasan-gce-root 2022/08/19 19:10 upstream 4c2d0b039c5c 26a13b38 .config log report info KASAN: use-after-free Read in tty_write_room
ci-upstream-kasan-gce-selinux-root 2022/01/25 17:41 upstream a08b41ab9e2e 2cbffd88 .config log report info KASAN: use-after-free Read in tty_write_room
ci-qemu-upstream 2022/01/10 01:49 upstream df0cc57e057f 2ca0d385 .config log report info KASAN: use-after-free Read in tty_write_room
ci-qemu-upstream 2022/01/09 14:27 upstream 4634129ad9fd 2ca0d385 .config log report info KASAN: use-after-free Read in tty_write_room
ci-upstream-kasan-gce-root 2021/12/15 12:45 upstream 5472f14a3742 f752fb53 .config log report info KASAN: use-after-free Read in tty_write_room
ci-qemu-upstream-386 2022/05/20 02:09 upstream b015dcd62b86 cb1ac2e7 .config log report info KASAN: use-after-free Read in tty_write_room
ci-qemu-upstream-386 2022/01/29 03:20 upstream 8157f4707360 495e00c5 .config log report info KASAN: use-after-free Read in tty_write_room
ci-qemu-upstream-386 2021/12/21 04:50 upstream 86085fe79e3c 62bd192b .config log report info KASAN: use-after-free Read in tty_write_room
ci-upstream-linux-next-kasan-gce-root 2022/03/20 04:33 linux-next 91265a6da44d e2d91b1d .config log report info KASAN: use-after-free Read in tty_write_room
ci-upstream-linux-next-kasan-gce-root 2022/01/11 18:00 linux-next a70bf4a85b43 1884f55a .config log report info KASAN: use-after-free Read in tty_write_room
* Struck through repros no longer work on HEAD.