syzbot


KASAN: slab-use-after-free Read in __fput (2)

Status: fixed on 2024/05/22 23:16
Subsystems: fs
[Documentation on labels]
Reported-by: syzbot+5d4cb6b4409edfd18646@syzkaller.appspotmail.com
Fix commit: 4efaa5acf0a1 epoll: be better about file lifetimes
First crash: 240d, last: 218d
Cause bisection: introduced by (bisect log) :
commit ff2d23843f7fb4f13055be5a4a9a20ddd04e6e9c
Author: Michel DΓ€nzer <mdaenzer@redhat.com>
Date: Fri Jul 23 07:58:57 2021 +0000

  dma-buf/poll: Get a file reference for outstanding fence callbacks

Crash: general protection fault in __fput (log)
Repro: C syz .config
  
Discussions (2)
Title Replies (including bot) Last reply
[syzbot] [fs?] KASAN: slab-use-after-free Read in __fput (2) 2 (5) 2024/05/18 18:19
[PATCH] [RFC] dma-buf: fix race condition between poll and close 11 (11) 2024/05/07 15:02
Similar bugs (1)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: slab-use-after-free Read in __fput fs 2 499d 496d 0/28 auto-obsoleted due to no activity on 2023/09/21 08:39
Last patch testing requests (3)
Created Duration User Patch Repo Result
2024/05/12 22:35 23m hdanton@sina.com https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master OK log
2024/05/12 22:21 23m retest repro upstream OK log
2024/05/12 21:51 23m retest repro upstream OK log

Sample crash report:
==================================================================
BUG: KASAN: slab-use-after-free in d_inode include/linux/dcache.h:520 [inline]
BUG: KASAN: slab-use-after-free in fsnotify_parent include/linux/fsnotify.h:66 [inline]
BUG: KASAN: slab-use-after-free in fsnotify_file include/linux/fsnotify.h:106 [inline]
BUG: KASAN: slab-use-after-free in fsnotify_close include/linux/fsnotify.h:387 [inline]
BUG: KASAN: slab-use-after-free in __fput+0x1b8/0x8a0 fs/file_table.c:408
Read of size 8 at addr ffff88807e236c28 by task syz-executor273/5120

CPU: 0 PID: 5120 Comm: syz-executor273 Not tainted 6.9.0-rc5-syzkaller-00296-g5eb4573ea63d #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x241/0x360 lib/dump_stack.c:114
 print_address_description mm/kasan/report.c:377 [inline]
 print_report+0x169/0x550 mm/kasan/report.c:488
 kasan_report+0x143/0x180 mm/kasan/report.c:601
 d_inode include/linux/dcache.h:520 [inline]
 fsnotify_parent include/linux/fsnotify.h:66 [inline]
 fsnotify_file include/linux/fsnotify.h:106 [inline]
 fsnotify_close include/linux/fsnotify.h:387 [inline]
 __fput+0x1b8/0x8a0 fs/file_table.c:408
 task_work_run+0x24f/0x310 kernel/task_work.c:180
 resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
 exit_to_user_mode_loop kernel/entry/common.c:114 [inline]
 exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
 __syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline]
 syscall_exit_to_user_mode+0x168/0x370 kernel/entry/common.c:218
 do_syscall_64+0x102/0x240 arch/x86/entry/common.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f85a1f60599
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 51 18 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:00007f85a1f1b218 EFLAGS: 00000246 ORIG_RAX: 00000000000000e8
RAX: 0000000000000001 RBX: 00007f85a1fea348 RCX: 00007f85a1f60599
RDX: 0000000000000002 RSI: 00000000200000c0 RDI: 0000000000000005
RBP: 00007f85a1fea340 R08: 0000000000000000 R09: 0000000000000000
R10: 00000000000000fa R11: 0000000000000246 R12: 00007f85a1fb718c
R13: 00007f85a1fb7078 R14: 00667562616d6475 R15: 6d64752f7665642f
 </TASK>

Allocated by task 5128:
 kasan_save_stack mm/kasan/common.c:47 [inline]
 kasan_save_track+0x3f/0x80 mm/kasan/common.c:68
 unpoison_slab_object mm/kasan/common.c:312 [inline]
 __kasan_slab_alloc+0x66/0x80 mm/kasan/common.c:338
 kasan_slab_alloc include/linux/kasan.h:201 [inline]
 slab_post_alloc_hook mm/slub.c:3798 [inline]
 slab_alloc_node mm/slub.c:3845 [inline]
 kmem_cache_alloc_lru+0x178/0x350 mm/slub.c:3864
 __d_alloc+0x31/0x700 fs/dcache.c:1624
 d_alloc_pseudo+0x1f/0xb0 fs/dcache.c:1756
 alloc_path_pseudo fs/file_table.c:330 [inline]
 alloc_file_pseudo+0x123/0x290 fs/file_table.c:346
 dma_buf_getfile drivers/dma-buf/dma-buf.c:547 [inline]
 dma_buf_export+0x3dd/0x990 drivers/dma-buf/dma-buf.c:632
 udmabuf_create+0x78e/0xa10 drivers/dma-buf/udmabuf.c:272
 udmabuf_ioctl_create drivers/dma-buf/udmabuf.c:309 [inline]
 udmabuf_ioctl+0x304/0x4f0 drivers/dma-buf/udmabuf.c:340
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:904 [inline]
 __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:890
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Freed by task 5128:
 kasan_save_stack mm/kasan/common.c:47 [inline]
 kasan_save_track+0x3f/0x80 mm/kasan/common.c:68
 kasan_save_free_info+0x40/0x50 mm/kasan/generic.c:579
 poison_slab_object+0xa6/0xe0 mm/kasan/common.c:240
 __kasan_slab_free+0x37/0x60 mm/kasan/common.c:256
 kasan_slab_free include/linux/kasan.h:184 [inline]
 slab_free_hook mm/slub.c:2106 [inline]
 slab_free mm/slub.c:4280 [inline]
 kmem_cache_free+0x10b/0x2c0 mm/slub.c:4344
 __dentry_kill+0x497/0x630 fs/dcache.c:622
 dput+0x19f/0x2b0 fs/dcache.c:845
 __fput+0x678/0x8a0 fs/file_table.c:430
 task_work_run+0x24f/0x310 kernel/task_work.c:180
 resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
 exit_to_user_mode_loop kernel/entry/common.c:114 [inline]
 exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
 __syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline]
 syscall_exit_to_user_mode+0x168/0x370 kernel/entry/common.c:218
 do_syscall_64+0x102/0x240 arch/x86/entry/common.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

The buggy address belongs to the object at ffff88807e236bc0
 which belongs to the cache dentry of size 312
The buggy address is located 104 bytes inside of
 freed 312-byte region [ffff88807e236bc0, ffff88807e236cf8)

The buggy address belongs to the physical page:
page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7e236
head: order:1 entire_mapcount:0 nr_pages_mapped:0 pincount:0
ksm flags: 0xfff80000000840(slab|head|node=0|zone=1|lastcpupid=0xfff)
page_type: 0xffffffff()
raw: 00fff80000000840 ffff888015eeb8c0 ffffea0001f89100 dead000000000003
raw: 0000000000000000 0000000000150015 00000001ffffffff 0000000000000000
head: 00fff80000000840 ffff888015eeb8c0 ffffea0001f89100 dead000000000003
head: 0000000000000000 0000000000150015 00000001ffffffff 0000000000000000
head: 00fff80000000001 ffffea0001f88d81 dead000000000122 00000000ffffffff
head: 0000000200000000 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 1, migratetype Reclaimable, gfp_mask 0xd20d0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC|__GFP_RECLAIMABLE), pid 4540, tgid -1281857381 (udevd), ts 4540, free_ts 14990488689
 set_page_owner include/linux/page_owner.h:32 [inline]
 post_alloc_hook+0x1ea/0x210 mm/page_alloc.c:1534
 prep_new_page mm/page_alloc.c:1541 [inline]
 get_page_from_freelist+0x3410/0x35b0 mm/page_alloc.c:3317
 __alloc_pages+0x256/0x6c0 mm/page_alloc.c:4575
 __alloc_pages_node include/linux/gfp.h:238 [inline]
 alloc_pages_node include/linux/gfp.h:261 [inline]
 alloc_slab_page+0x5f/0x160 mm/slub.c:2175
 allocate_slab mm/slub.c:2338 [inline]
 new_slab+0x84/0x2f0 mm/slub.c:2391
 ___slab_alloc+0xc73/0x1260 mm/slub.c:3525
 __slab_alloc mm/slub.c:3610 [inline]
 __slab_alloc_node mm/slub.c:3663 [inline]
 slab_alloc_node mm/slub.c:3835 [inline]
 kmem_cache_alloc_lru+0x253/0x350 mm/slub.c:3864
 __d_alloc+0x31/0x700 fs/dcache.c:1624
 d_alloc+0x4b/0x190 fs/dcache.c:1704
 lookup_one_qstr_excl+0xce/0x260 fs/namei.c:1603
 filename_create+0x297/0x540 fs/namei.c:3893
 do_symlinkat+0xf9/0x3a0 fs/namei.c:4500
 __do_sys_symlink fs/namei.c:4528 [inline]
 __se_sys_symlink fs/namei.c:4526 [inline]
 __x64_sys_symlink+0x7e/0x90 fs/namei.c:4526
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 1 tgid 1 stack trace:
 reset_page_owner include/linux/page_owner.h:25 [inline]
 free_pages_prepare mm/page_alloc.c:1141 [inline]
 free_unref_page_prepare+0x986/0xab0 mm/page_alloc.c:2347
 free_unref_page+0x37/0x3f0 mm/page_alloc.c:2487
 free_contig_range+0x9e/0x160 mm/page_alloc.c:6572
 destroy_args+0x8a/0x890 mm/debug_vm_pgtable.c:1036
 debug_vm_pgtable+0x4be/0x550 mm/debug_vm_pgtable.c:1416
 do_one_initcall+0x248/0x880 init/main.c:1245
 do_initcall_level+0x157/0x210 init/main.c:1307
 do_initcalls+0x3f/0x80 init/main.c:1323
 kernel_init_freeable+0x435/0x5d0 init/main.c:1555
 kernel_init+0x1d/0x2b0 init/main.c:1444
 ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244

Memory state around the buggy address:
 ffff88807e236b00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 ffff88807e236b80: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb
>ffff88807e236c00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                  ^
 ffff88807e236c80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fc
 ffff88807e236d00: fc fc fc fc fc fc fc 00 00 00 00 00 00 00 00 00
==================================================================

Crashes (6):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2024/04/27 04:40 upstream 5eb4573ea63d 07b455f9 .config console log report syz C [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce KASAN: slab-use-after-free Read in __fput
2024/04/23 11:37 upstream 4d2008430ce8 21339d7b .config strace log report syz C [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-selinux-root general protection fault in __fput
2024/04/25 23:08 upstream e33c4963bf53 8bdc0f22 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-smack-root KASAN: slab-use-after-free Read in __fput
2024/04/23 07:44 upstream 4d2008430ce8 21339d7b .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-selinux-root KASAN: slab-use-after-free Read in __fput
2024/04/07 17:44 upstream 480e035fc4c7 ca620dd8 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce KASAN: slab-use-after-free Read in __fput
2024/04/28 21:50 linux-next bb7a2467e6be 07b455f9 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root KASAN: slab-use-after-free Read in __fput
* Struck through repros no longer work on HEAD.