syzbot


KASAN: slab-use-after-free Read in ptp_poll

Status: fixed on 2023/12/21 03:45
Subsystems: net
[Documentation on labels]
Fix commit: b714ca2ccf6a ptp: ptp_read should not release queue
First crash: 109d, last: 109d

Sample crash report:
==================================================================
BUG: KASAN: slab-use-after-free in queue_cnt drivers/ptp/ptp_private.h:89 [inline]
BUG: KASAN: slab-use-after-free in ptp_poll+0x13f/0x160 drivers/ptp/ptp_chardev.c:515
Read of size 4 at addr ffff888036545004 by task syz-executor.0/8043

CPU: 0 PID: 8043 Comm: syz-executor.0 Not tainted 6.6.0-syzkaller-15029-gbe3ca57cfb77 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1e7/0x2d0 lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:364 [inline]
 print_report+0x163/0x540 mm/kasan/report.c:475
 kasan_report+0x142/0x170 mm/kasan/report.c:588
 queue_cnt drivers/ptp/ptp_private.h:89 [inline]
 ptp_poll+0x13f/0x160 drivers/ptp/ptp_chardev.c:515
 posix_clock_poll+0xf5/0x130 kernel/time/posix-clock.c:68
 vfs_poll include/linux/poll.h:88 [inline]
 ep_item_poll fs/eventpoll.c:892 [inline]
 ep_insert+0x106a/0x19f0 fs/eventpoll.c:1561
 do_epoll_ctl+0x8e7/0xf90 fs/eventpoll.c:2219
 __do_sys_epoll_ctl fs/eventpoll.c:2276 [inline]
 __se_sys_epoll_ctl fs/eventpoll.c:2267 [inline]
 __x64_sys_epoll_ctl+0x161/0x1a0 fs/eventpoll.c:2267
 do_syscall_x64 arch/x86/entry/common.c:51 [inline]
 do_syscall_64+0x44/0x110 arch/x86/entry/common.c:82
 entry_SYSCALL_64_after_hwframe+0x63/0x6b
RIP: 0033:0x7f2129c7cae9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 e1 20 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 b0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f21287fe0c8 EFLAGS: 00000246 ORIG_RAX: 00000000000000e9
RAX: ffffffffffffffda RBX: 00007f2129d9c050 RCX: 00007f2129c7cae9
RDX: 0000000000000003 RSI: 0000000000000001 RDI: 0000000000000004
RBP: 00007f2129cc847a R08: 0000000000000000 R09: 0000000000000000
R10: 0000000020000040 R11: 0000000000000246 R12: 0000000000000000
R13: 000000000000000b R14: 00007f2129d9c050 R15: 00007ffcabf3f6c8
 </TASK>

Allocated by task 8042:
 kasan_save_stack mm/kasan/common.c:45 [inline]
 kasan_set_track+0x4f/0x70 mm/kasan/common.c:52
 ____kasan_kmalloc mm/kasan/common.c:374 [inline]
 __kasan_kmalloc+0x98/0xb0 mm/kasan/common.c:383
 kmalloc include/linux/slab.h:600 [inline]
 kzalloc include/linux/slab.h:721 [inline]
 ptp_open+0xd9/0x430 drivers/ptp/ptp_chardev.c:112
 posix_clock_open+0x155/0x1f0 kernel/time/posix-clock.c:134
 chrdev_open+0x5ab/0x630 fs/char_dev.c:414
 do_dentry_open+0x8fd/0x1590 fs/open.c:948
 do_open fs/namei.c:3622 [inline]
 path_openat+0x2845/0x3280 fs/namei.c:3779
 do_filp_open+0x234/0x490 fs/namei.c:3809
 do_sys_openat2+0x13e/0x1d0 fs/open.c:1440
 do_sys_open fs/open.c:1455 [inline]
 __do_sys_openat fs/open.c:1471 [inline]
 __se_sys_openat fs/open.c:1466 [inline]
 __x64_sys_openat+0x247/0x290 fs/open.c:1466
 do_syscall_x64 arch/x86/entry/common.c:51 [inline]
 do_syscall_64+0x44/0x110 arch/x86/entry/common.c:82
 entry_SYSCALL_64_after_hwframe+0x63/0x6b

Freed by task 8042:
 kasan_save_stack mm/kasan/common.c:45 [inline]
 kasan_set_track+0x4f/0x70 mm/kasan/common.c:52
 kasan_save_free_info+0x28/0x40 mm/kasan/generic.c:522
 ____kasan_slab_free+0xd6/0x120 mm/kasan/common.c:236
 kasan_slab_free include/linux/kasan.h:164 [inline]
 slab_free_hook mm/slub.c:1800 [inline]
 slab_free_freelist_hook mm/slub.c:1826 [inline]
 slab_free mm/slub.c:3809 [inline]
 __kmem_cache_free+0x263/0x3a0 mm/slub.c:3822
 ptp_release+0x1ce/0x1e0 drivers/ptp/ptp_chardev.c:150
 ptp_read+0x17f/0x820 drivers/ptp/ptp_chardev.c:589
 posix_clock_read+0x12f/0x190 kernel/time/posix-clock.c:51
 vfs_read+0x289/0xb00 fs/read_write.c:468
 ksys_read+0x1a0/0x2c0 fs/read_write.c:613
 do_syscall_x64 arch/x86/entry/common.c:51 [inline]
 do_syscall_64+0x44/0x110 arch/x86/entry/common.c:82
 entry_SYSCALL_64_after_hwframe+0x63/0x6b

Last potentially related work creation:
 kasan_save_stack+0x3f/0x60 mm/kasan/common.c:45
 __kasan_record_aux_stack+0xad/0xc0 mm/kasan/generic.c:492
 insert_work+0x3e/0x320 kernel/workqueue.c:1647
 __queue_work+0xc06/0x1010 kernel/workqueue.c:1799
 queue_work_on+0x14f/0x250 kernel/workqueue.c:1834
 queue_work include/linux/workqueue.h:562 [inline]
 schedule_work include/linux/workqueue.h:623 [inline]
 f2fs_handle_critical_error+0x7cb/0x9d0 fs/f2fs/super.c:4178
 f2fs_write_end_io+0x7da/0xb00 fs/f2fs/data.c:366
 __submit_merged_bio+0x28e/0x6c0 fs/f2fs/data.c:589
 __f2fs_submit_merged_write fs/f2fs/data.c:682 [inline]
 __submit_merged_write_cond fs/f2fs/data.c:704 [inline]
 f2fs_submit_merged_write_cond+0x28a/0x360 fs/f2fs/data.c:721
 f2fs_write_cache_pages fs/f2fs/data.c:3296 [inline]
 __f2fs_write_data_pages fs/f2fs/data.c:3381 [inline]
 f2fs_write_data_pages+0x302e/0x3ab0 fs/f2fs/data.c:3408
 do_writepages+0x3a6/0x670 mm/page-writeback.c:2553
 filemap_fdatawrite_wbc+0x125/0x180 mm/filemap.c:387
 __filemap_fdatawrite_range mm/filemap.c:420 [inline]
 __filemap_fdatawrite mm/filemap.c:426 [inline]
 filemap_fdatawrite+0x143/0x1b0 mm/filemap.c:431
 f2fs_sync_dirty_inodes+0x337/0x840 fs/f2fs/checkpoint.c:1107
 block_operations fs/f2fs/checkpoint.c:1240 [inline]
 f2fs_write_checkpoint+0xb6d/0x1fa0 fs/f2fs/checkpoint.c:1648
 f2fs_issue_checkpoint+0x2e6/0x4d0 fs/f2fs/checkpoint.c:1855
 f2fs_create+0x441/0x530 fs/f2fs/namei.c:387
 lookup_open fs/namei.c:3477 [inline]
 open_last_lookups fs/namei.c:3546 [inline]
 path_openat+0x13fa/0x3280 fs/namei.c:3776
 do_filp_open+0x234/0x490 fs/namei.c:3809
 do_sys_openat2+0x13e/0x1d0 fs/open.c:1440
 do_sys_open fs/open.c:1455 [inline]
 __do_sys_openat fs/open.c:1471 [inline]
 __se_sys_openat fs/open.c:1466 [inline]
 __x64_sys_openat+0x247/0x290 fs/open.c:1466
 do_syscall_x64 arch/x86/entry/common.c:51 [inline]
 do_syscall_64+0x44/0x110 arch/x86/entry/common.c:82
 entry_SYSCALL_64_after_hwframe+0x63/0x6b

Second to last potentially related work creation:
 kasan_save_stack+0x3f/0x60 mm/kasan/common.c:45
 __kasan_record_aux_stack+0xad/0xc0 mm/kasan/generic.c:492
 insert_work+0x3e/0x320 kernel/workqueue.c:1647
 __queue_work+0xc06/0x1010 kernel/workqueue.c:1799
 queue_work_on+0x14f/0x250 kernel/workqueue.c:1834
 queue_work include/linux/workqueue.h:562 [inline]
 schedule_work include/linux/workqueue.h:623 [inline]
 f2fs_handle_critical_error+0x7cb/0x9d0 fs/f2fs/super.c:4178
 f2fs_write_end_io+0x7da/0xb00 fs/f2fs/data.c:366
 __submit_merged_bio+0x28e/0x6c0 fs/f2fs/data.c:589
 __f2fs_submit_merged_write fs/f2fs/data.c:682 [inline]
 __submit_merged_write_cond fs/f2fs/data.c:704 [inline]
 f2fs_submit_merged_write_cond+0x28a/0x360 fs/f2fs/data.c:721
 f2fs_write_cache_pages fs/f2fs/data.c:3296 [inline]
 __f2fs_write_data_pages fs/f2fs/data.c:3381 [inline]
 f2fs_write_data_pages+0x302e/0x3ab0 fs/f2fs/data.c:3408
 do_writepages+0x3a6/0x670 mm/page-writeback.c:2553
 filemap_fdatawrite_wbc+0x125/0x180 mm/filemap.c:387
 __filemap_fdatawrite_range mm/filemap.c:420 [inline]
 __filemap_fdatawrite mm/filemap.c:426 [inline]
 filemap_fdatawrite+0x143/0x1b0 mm/filemap.c:431
 f2fs_sync_dirty_inodes+0x337/0x840 fs/f2fs/checkpoint.c:1107
 block_operations fs/f2fs/checkpoint.c:1240 [inline]
 f2fs_write_checkpoint+0xb6d/0x1fa0 fs/f2fs/checkpoint.c:1648
 f2fs_issue_checkpoint+0x2e6/0x4d0 fs/f2fs/checkpoint.c:1855
 f2fs_create+0x441/0x530 fs/f2fs/namei.c:387
 lookup_open fs/namei.c:3477 [inline]
 open_last_lookups fs/namei.c:3546 [inline]
 path_openat+0x13fa/0x3280 fs/namei.c:3776
 do_filp_open+0x234/0x490 fs/namei.c:3809
 do_sys_openat2+0x13e/0x1d0 fs/open.c:1440
 do_sys_open fs/open.c:1455 [inline]
 __do_sys_openat fs/open.c:1471 [inline]
 __se_sys_openat fs/open.c:1466 [inline]
 __x64_sys_openat+0x247/0x290 fs/open.c:1466
 do_syscall_x64 arch/x86/entry/common.c:51 [inline]
 do_syscall_64+0x44/0x110 arch/x86/entry/common.c:82
 entry_SYSCALL_64_after_hwframe+0x63/0x6b

The buggy address belongs to the object at ffff888036544000
 which belongs to the cache kmalloc-8k of size 8192
The buggy address is located 4100 bytes inside of
 freed 8192-byte region [ffff888036544000, ffff888036546000)

The buggy address belongs to the physical page:
page:ffffea0000d95000 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x36540
head:ffffea0000d95000 order:3 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000840(slab|head|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffffff()
raw: 00fff00000000840 ffff888012c42280 ffffea0001f43600 dead000000000004
raw: 0000000000000000 0000000080020002 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 0x1d2040(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC|__GFP_HARDWALL), pid 5441, tgid 5441 (udevd), ts 192668701906, free_ts 192667387419
 set_page_owner include/linux/page_owner.h:31 [inline]
 post_alloc_hook+0x1e6/0x210 mm/page_alloc.c:1537
 prep_new_page mm/page_alloc.c:1544 [inline]
 get_page_from_freelist+0x339a/0x3530 mm/page_alloc.c:3312
 __alloc_pages+0x255/0x670 mm/page_alloc.c:4568
 alloc_pages_mpol+0x3de/0x640 mm/mempolicy.c:2133
 alloc_slab_page+0x6a/0x160 mm/slub.c:1870
 allocate_slab mm/slub.c:2017 [inline]
 new_slab+0x84/0x2f0 mm/slub.c:2070
 ___slab_alloc+0xc85/0x1310 mm/slub.c:3223
 __slab_alloc mm/slub.c:3322 [inline]
 __slab_alloc_node mm/slub.c:3375 [inline]
 slab_alloc_node mm/slub.c:3468 [inline]
 __kmem_cache_alloc_node+0x21d/0x300 mm/slub.c:3517
 kmalloc_trace+0x2a/0xe0 mm/slab_common.c:1098
 kmalloc include/linux/slab.h:600 [inline]
 kzalloc include/linux/slab.h:721 [inline]
 tomoyo_print_bprm security/tomoyo/audit.c:26 [inline]
 tomoyo_init_log+0x11cd/0x2040 security/tomoyo/audit.c:264
 tomoyo_supervisor+0x386/0x11f0 security/tomoyo/common.c:2089
 tomoyo_audit_env_log security/tomoyo/environ.c:36 [inline]
 tomoyo_env_perm+0x178/0x210 security/tomoyo/environ.c:63
 tomoyo_environ security/tomoyo/domain.c:672 [inline]
 tomoyo_find_next_domain+0x1383/0x1cf0 security/tomoyo/domain.c:878
 tomoyo_bprm_check_security+0x114/0x170 security/tomoyo/tomoyo.c:101
 security_bprm_check+0x63/0xa0 security/security.c:1103
 search_binary_handler fs/exec.c:1725 [inline]
 exec_binprm fs/exec.c:1779 [inline]
 bprm_execve+0x95f/0x18a0 fs/exec.c:1854
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1137 [inline]
 free_unref_page_prepare+0x92a/0xa50 mm/page_alloc.c:2347
 free_unref_page+0x37/0x3f0 mm/page_alloc.c:2487
 discard_slab mm/slub.c:2116 [inline]
 __unfreeze_partials+0x1dc/0x220 mm/slub.c:2655
 put_cpu_partial+0x17b/0x250 mm/slub.c:2731
 __slab_free+0x2b6/0x390 mm/slub.c:3679
 qlink_free mm/kasan/quarantine.c:168 [inline]
 qlist_free_all+0x75/0xe0 mm/kasan/quarantine.c:187
 kasan_quarantine_reduce+0x14b/0x160 mm/kasan/quarantine.c:294
 __kasan_slab_alloc+0x23/0x70 mm/kasan/common.c:305
 kasan_slab_alloc include/linux/kasan.h:188 [inline]
 slab_post_alloc_hook+0x6c/0x3c0 mm/slab.h:763
 slab_alloc_node mm/slub.c:3478 [inline]
 __kmem_cache_alloc_node+0x1d0/0x300 mm/slub.c:3517
 __do_kmalloc_node mm/slab_common.c:1006 [inline]
 __kmalloc+0xa8/0x230 mm/slab_common.c:1020
 kmalloc include/linux/slab.h:604 [inline]
 tomoyo_add_entry security/tomoyo/common.c:2023 [inline]
 tomoyo_supervisor+0xe06/0x11f0 security/tomoyo/common.c:2095
 tomoyo_audit_env_log security/tomoyo/environ.c:36 [inline]
 tomoyo_env_perm+0x178/0x210 security/tomoyo/environ.c:63
 tomoyo_environ security/tomoyo/domain.c:672 [inline]
 tomoyo_find_next_domain+0x1383/0x1cf0 security/tomoyo/domain.c:878
 tomoyo_bprm_check_security+0x114/0x170 security/tomoyo/tomoyo.c:101
 security_bprm_check+0x63/0xa0 security/security.c:1103

Memory state around the buggy address:
 ffff888036544f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888036544f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888036545000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                   ^
 ffff888036545080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888036545100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/11/07 08:43 upstream be3ca57cfb77 83211397 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs KASAN: slab-use-after-free Read in ptp_poll
* Struck through repros no longer work on HEAD.