yshigeru / linux-devel

Linux kernel source tree
Other
0 stars 0 forks source link

KASAN: use-after-free Read in ntfs_fill_super #1

Closed yshigeru closed 8 months ago

yshigeru commented 10 months ago
ntfs3: loop5: RAW NTFS volume: Filesystem size 8192.00 Gb > volume size 0.00 Gb. Mount in read-only.
ntfs3: loop5: NTFS 8192.00 Gb is too big to use 32 bits per cluster.
==================================================================
BUG: KASAN: use-after-free in memcmp+0x172/0x1c0 lib/string.c:681
Read of size 8 at addr ffff88802c54a002 by task syz-executor.5/32560

CPU: 0 PID: 32560 Comm: syz-executor.5 Not tainted 6.5.0-rc5 #2
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-1.fc38 04/01/2014
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xd3/0x1b0 lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:364 [inline]
 print_report+0xc4/0x630 mm/kasan/report.c:475
 kasan_report+0xda/0x110 mm/kasan/report.c:588
 memcmp+0x172/0x1c0 lib/string.c:681
 ntfs_init_from_boot fs/ntfs3/super.c:860 [inline]
 ntfs_fill_super+0x722/0x43a0 fs/ntfs3/super.c:1141
 get_tree_bdev+0x43e/0x7d0 fs/super.c:1318
 vfs_get_tree+0x88/0x350 fs/super.c:1519
 do_new_mount fs/namespace.c:3335 [inline]
 path_mount+0x69f/0x1ec0 fs/namespace.c:3662
 do_mount fs/namespace.c:3675 [inline]
 __do_sys_mount fs/namespace.c:3884 [inline]
 __se_sys_mount fs/namespace.c:3861 [inline]
 __x64_sys_mount+0x293/0x310 fs/namespace.c:3861
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x45b39e
Code: 48 c7 c0 ff ff ff ff eb aa e8 1e 0a 00 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 f3 0f 1e fa 49 89 ca b8 a5 00 00 00 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:00007f6b1ad4def8 EFLAGS: 00000202 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 00007f6b1ad4df90 RCX: 000000000045b39e
RDX: 0000000020000080 RSI: 00000000200000c0 RDI: 00007f6b1ad4df50
RBP: 0000000020000080 R08: 00007f6b1ad4df90 R09: 0000000000000040
R10: 0000000000000040 R11: 0000000000000202 R12: 00000000200000c0
R13: 00007f6b1ad4df50 R14: 000000000001f36d R15: 0000000020000040
 </TASK>

The buggy address belongs to the physical page:
page:ffffea0000b15280 refcount:0 mapcount:-128 mapping:0000000000000000 index:0x1 pfn:0x2c54a
flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xffffff7f(buddy)
raw: 00fff00000000000 ffffea0000b0df08 ffffea00006cac88 0000000000000000
raw: 0000000000000001 0000000000000001 00000000ffffff7f 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as freed
page last allocated via order 0, migratetype Movable, gfp_mask 0x140cca(GFP_HIGHUSER_MOVABLE|__GFP_COMP), pid 32291, tgid 32282 (syz-executor.7), ts 431324166165, free_ts 431399471939
 set_page_owner include/linux/page_owner.h:31 [inline]
 post_alloc_hook+0x2eb/0x350 mm/page_alloc.c:1570
 prep_new_page mm/page_alloc.c:1577 [inline]
 get_page_from_freelist+0x915/0x3990 mm/page_alloc.c:3221
 __alloc_pages+0x1d0/0x4a0 mm/page_alloc.c:4477
 __folio_alloc+0x16/0x40 mm/page_alloc.c:4509
 vma_alloc_folio+0x156/0x890 mm/mempolicy.c:2253
 shmem_alloc_folio+0x10a/0x1d0 mm/shmem.c:1579
 shmem_alloc_and_acct_folio+0x168/0x5e0 mm/shmem.c:1603
 shmem_get_folio_gfp+0xcee/0x1bb0 mm/shmem.c:1948
 shmem_get_folio mm/shmem.c:2079 [inline]
 shmem_write_begin+0x15c/0x390 mm/shmem.c:2573
 generic_perform_write+0x278/0x5f0 mm/filemap.c:3923
 __generic_file_write_iter+0x1f9/0x240 mm/filemap.c:4018
 generic_file_write_iter+0xe3/0x350 mm/filemap.c:4044
 call_write_iter include/linux/fs.h:1877 [inline]
 new_sync_write fs/read_write.c:491 [inline]
 vfs_write+0x650/0xe40 fs/read_write.c:584
 ksys_write+0x12f/0x250 fs/read_write.c:637
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1161 [inline]
 free_unref_page_prepare+0x55f/0xbd0 mm/page_alloc.c:2348
 free_unref_page_list+0xe6/0xb30 mm/page_alloc.c:2489
 release_pages+0x32d/0x1450 mm/swap.c:1042
 __folio_batch_release+0x77/0xe0 mm/swap.c:1062
 folio_batch_release include/linux/pagevec.h:83 [inline]
 shmem_undo_range+0x5e0/0x1060 mm/shmem.c:954
 shmem_truncate_range mm/shmem.c:1049 [inline]
 shmem_evict_inode+0x331/0xb40 mm/shmem.c:1164
 evict+0x2ed/0x6c0 fs/inode.c:665
 iput_final fs/inode.c:1791 [inline]
 iput.part.0+0x559/0x7a0 fs/inode.c:1817
 iput+0x5c/0x80 fs/inode.c:1807
 dentry_unlink_inode+0x292/0x430 fs/dcache.c:401
 __dentry_kill+0x3b8/0x640 fs/dcache.c:607
 dentry_kill fs/dcache.c:733 [inline]
 dput+0x8e0/0xfd0 fs/dcache.c:913
 __fput+0x536/0xac0 fs/file_table.c:392
 task_work_run+0x14d/0x240 kernel/task_work.c:179
 resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
 exit_to_user_mode_loop kernel/entry/common.c:171 [inline]
 exit_to_user_mode_prepare+0x210/0x240 kernel/entry/common.c:204
 __syscall_exit_to_user_mode_work kernel/entry/common.c:286 [inline]
 syscall_exit_to_user_mode+0x1d/0x50 kernel/entry/common.c:297

Memory state around the buggy address:
 ffff88802c549f00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 ffff88802c549f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffff88802c54a000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
                   ^
 ffff88802c54a080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff88802c54a100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
==================================================================
yshigeru commented 10 months ago

repro.cprog.gz

yshigeru commented 10 months ago

0001-fs-ntfs3-Fix-potential-use-after-free-in-ntfs_init_f.patch.gz

yshigeru commented 10 months ago

Sent the patch: https://lore.kernel.org/all/20230812154736.975753-1-syoshida@redhat.com/

yshigeru commented 8 months ago

No response from the maintainer.