public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance
@ 2024-09-20 14:26 syzbot
  2024-09-20 17:14 ` Jeongjun Park
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: syzbot @ 2024-09-20 14:26 UTC (permalink / raw)
  To: brauner, dhowells, jlayton, linux-fsdevel, linux-kernel,
	linux-trace-kernel, mathieu.desnoyers, mhiramat, netfs, rostedt,
	syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    a430d95c5efa Merge tag 'lsm-pr-20240911' of git://git.kern..
git tree:       upstream
console+strace: https://syzkaller.appspot.com/x/log.txt?x=15b24427980000
kernel config:  https://syzkaller.appspot.com/x/.config?x=d85e1e571a820894
dashboard link: https://syzkaller.appspot.com/bug?extid=7c48153a9d788824044b
compiler:       gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=1511a607980000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=10c7d69f980000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/4faaa939b3a4/disk-a430d95c.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/83c722076440/vmlinux-a430d95c.xz
kernel image: https://storage.googleapis.com/syzbot-assets/24c938d49c40/bzImage-a430d95c.xz

The issue was bisected to:

commit 983cdcf8fe141b0ce16bc71959a5dc55bcb0764d
Author: David Howells <dhowells@redhat.com>
Date:   Thu Jun 6 06:48:55 2024 +0000

    netfs: Simplify the writeback code

bisection log:  https://syzkaller.appspot.com/x/bisect.txt?x=1087bb00580000
final oops:     https://syzkaller.appspot.com/x/report.txt?x=1287bb00580000
console output: https://syzkaller.appspot.com/x/log.txt?x=1487bb00580000

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+7c48153a9d788824044b@syzkaller.appspotmail.com
Fixes: 983cdcf8fe14 ("netfs: Simplify the writeback code")

==================================================================
BUG: KASAN: slab-use-after-free in iov_iter_folioq_advance lib/iov_iter.c:540 [inline]
BUG: KASAN: slab-use-after-free in iov_iter_advance+0x677/0x6c0 lib/iov_iter.c:576
Read of size 8 at addr ffff88802a63dd20 by task syz-executor341/5249

CPU: 1 UID: 0 PID: 5249 Comm: syz-executor341 Not tainted 6.11.0-syzkaller-02574-ga430d95c5efa #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:93 [inline]
 dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:119
 print_address_description mm/kasan/report.c:377 [inline]
 print_report+0xc3/0x620 mm/kasan/report.c:488
 kasan_report+0xd9/0x110 mm/kasan/report.c:601
 iov_iter_folioq_advance lib/iov_iter.c:540 [inline]
 iov_iter_advance+0x677/0x6c0 lib/iov_iter.c:576
 netfs_write_folio+0x745/0x18f0 fs/netfs/write_issue.c:481
 netfs_writepages+0x2ba/0xb90 fs/netfs/write_issue.c:541
 do_writepages+0x1a6/0x7f0 mm/page-writeback.c:2683
 filemap_fdatawrite_wbc mm/filemap.c:397 [inline]
 filemap_fdatawrite_wbc+0x148/0x1c0 mm/filemap.c:387
 __filemap_fdatawrite_range+0xba/0x100 mm/filemap.c:430
 v9fs_dir_release+0x429/0x590 fs/9p/vfs_dir.c:219
 __fput+0x3f9/0xb60 fs/file_table.c:431
 task_work_run+0x151/0x250 kernel/task_work.c:228
 exit_task_work include/linux/task_work.h:40 [inline]
 do_exit+0xaa3/0x2bb0 kernel/exit.c:882
 do_group_exit+0xd3/0x2a0 kernel/exit.c:1031
 __do_sys_exit_group kernel/exit.c:1042 [inline]
 __se_sys_exit_group kernel/exit.c:1040 [inline]
 __x64_sys_exit_group+0x3e/0x50 kernel/exit.c:1040
 x64_sys_call+0x14a9/0x16a0 arch/x86/include/generated/asm/syscalls_64.h:232
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7ff0e2c14089
Code: Unable to access opcode bytes at 0x7ff0e2c1405f.
RSP: 002b:00007ffe69e64ba8 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007ff0e2c14089
RDX: 000000000000003c RSI: 00000000000000e7 RDI: 0000000000000000
RBP: 00007ff0e2c8f390 R08: ffffffffffffffb8 R09: 0000000000000006
R10: 000000007ffff000 R11: 0000000000000246 R12: 00007ff0e2c8f390
R13: 0000000000000000 R14: 00007ff0e2c8fde0 R15: 00007ff0e2be5070
 </TASK>

Allocated by task 5249:
 kasan_save_stack+0x33/0x60 mm/kasan/common.c:47
 kasan_save_track+0x14/0x30 mm/kasan/common.c:68
 poison_kmalloc_redzone mm/kasan/common.c:370 [inline]
 __kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:387
 kmalloc_noprof include/linux/slab.h:690 [inline]
 netfs_buffer_append_folio+0x181/0x750 fs/netfs/misc.c:25
 netfs_write_folio+0x542/0x18f0 fs/netfs/write_issue.c:421
 netfs_writepages+0x2ba/0xb90 fs/netfs/write_issue.c:541
 do_writepages+0x1a6/0x7f0 mm/page-writeback.c:2683
 filemap_fdatawrite_wbc mm/filemap.c:397 [inline]
 filemap_fdatawrite_wbc+0x148/0x1c0 mm/filemap.c:387
 __filemap_fdatawrite_range+0xba/0x100 mm/filemap.c:430
 v9fs_dir_release+0x429/0x590 fs/9p/vfs_dir.c:219
 __fput+0x3f9/0xb60 fs/file_table.c:431
 task_work_run+0x151/0x250 kernel/task_work.c:228
 exit_task_work include/linux/task_work.h:40 [inline]
 do_exit+0xaa3/0x2bb0 kernel/exit.c:882
 do_group_exit+0xd3/0x2a0 kernel/exit.c:1031
 __do_sys_exit_group kernel/exit.c:1042 [inline]
 __se_sys_exit_group kernel/exit.c:1040 [inline]
 __x64_sys_exit_group+0x3e/0x50 kernel/exit.c:1040
 x64_sys_call+0x14a9/0x16a0 arch/x86/include/generated/asm/syscalls_64.h:232
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Freed by task 12:
 kasan_save_stack+0x33/0x60 mm/kasan/common.c:47
 kasan_save_track+0x14/0x30 mm/kasan/common.c:68
 kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:579
 poison_slab_object+0xf7/0x160 mm/kasan/common.c:240
 __kasan_slab_free+0x32/0x50 mm/kasan/common.c:256
 kasan_slab_free include/linux/kasan.h:184 [inline]
 slab_free_hook mm/slub.c:2250 [inline]
 slab_free mm/slub.c:4474 [inline]
 kfree+0x12a/0x3b0 mm/slub.c:4595
 netfs_delete_buffer_head+0xa6/0x100 fs/netfs/misc.c:59
 netfs_writeback_unlock_folios fs/netfs/write_collect.c:139 [inline]
 netfs_collect_write_results fs/netfs/write_collect.c:493 [inline]
 netfs_write_collection_worker+0x20f9/0x4f80 fs/netfs/write_collect.c:551
 process_one_work+0x9c8/0x1b40 kernel/workqueue.c:3231
 process_scheduled_works kernel/workqueue.c:3312 [inline]
 worker_thread+0x6c8/0xf00 kernel/workqueue.c:3393
 kthread+0x2c4/0x3a0 kernel/kthread.c:389
 ret_from_fork+0x48/0x80 arch/x86/kernel/process.c:147
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244

The buggy address belongs to the object at ffff88802a63dc00
 which belongs to the cache kmalloc-512 of size 512
The buggy address is located 288 bytes inside of
 freed 512-byte region [ffff88802a63dc00, ffff88802a63de00)

The buggy address belongs to the physical page:
page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x2a63c
head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xfdffffff(slab)
raw: 00fff00000000040 ffff88801ac41c80 dead000000000122 0000000000000000
raw: 0000000000000000 0000000080100010 00000001fdffffff 0000000000000000
head: 00fff00000000040 ffff88801ac41c80 dead000000000122 0000000000000000
head: 0000000000000000 0000000080100010 00000001fdffffff 0000000000000000
head: 00fff00000000002 ffffea0000a98f01 ffffffffffffffff 0000000000000000
head: 0000000000000004 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Unmovable, gfp_mask 0xd2040(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 5249, tgid 5249 (syz-executor341), ts 139218928620, free_ts 130646507944
 set_page_owner include/linux/page_owner.h:32 [inline]
 post_alloc_hook+0x2d1/0x350 mm/page_alloc.c:1500
 prep_new_page mm/page_alloc.c:1508 [inline]
 get_page_from_freelist+0x1351/0x2e50 mm/page_alloc.c:3446
 __alloc_pages_noprof+0x22b/0x2460 mm/page_alloc.c:4702
 __alloc_pages_node_noprof include/linux/gfp.h:269 [inline]
 alloc_pages_node_noprof include/linux/gfp.h:296 [inline]
 alloc_slab_page+0x4e/0xf0 mm/slub.c:2319
 allocate_slab mm/slub.c:2482 [inline]
 new_slab+0x84/0x260 mm/slub.c:2535
 ___slab_alloc+0xdac/0x1870 mm/slub.c:3721
 __slab_alloc.constprop.0+0x56/0xb0 mm/slub.c:3811
 __slab_alloc_node mm/slub.c:3864 [inline]
 slab_alloc_node mm/slub.c:4026 [inline]
 __kmalloc_cache_noprof+0x2b4/0x300 mm/slub.c:4185
 kmalloc_noprof include/linux/slab.h:690 [inline]
 netfs_buffer_append_folio+0x181/0x750 fs/netfs/misc.c:25
 netfs_write_folio+0x542/0x18f0 fs/netfs/write_issue.c:421
 netfs_writepages+0x2ba/0xb90 fs/netfs/write_issue.c:541
 do_writepages+0x1a6/0x7f0 mm/page-writeback.c:2683
 filemap_fdatawrite_wbc mm/filemap.c:397 [inline]
 filemap_fdatawrite_wbc+0x148/0x1c0 mm/filemap.c:387
 __filemap_fdatawrite_range+0xba/0x100 mm/filemap.c:430
 v9fs_dir_release+0x429/0x590 fs/9p/vfs_dir.c:219
 __fput+0x3f9/0xb60 fs/file_table.c:431
page last free pid 4682 tgid 4682 stack trace:
 reset_page_owner include/linux/page_owner.h:25 [inline]
 free_pages_prepare mm/page_alloc.c:1101 [inline]
 free_unref_page+0x64a/0xe40 mm/page_alloc.c:2619
 __put_partials+0x14c/0x170 mm/slub.c:3049
 qlink_free mm/kasan/quarantine.c:163 [inline]
 qlist_free_all+0x4e/0x140 mm/kasan/quarantine.c:179
 kasan_quarantine_reduce+0x192/0x1e0 mm/kasan/quarantine.c:286
 __kasan_slab_alloc+0x69/0x90 mm/kasan/common.c:322
 kasan_slab_alloc include/linux/kasan.h:201 [inline]
 slab_post_alloc_hook mm/slub.c:3989 [inline]
 slab_alloc_node mm/slub.c:4038 [inline]
 kmem_cache_alloc_noprof+0x121/0x2f0 mm/slub.c:4045
 getname_flags.part.0+0x4c/0x550 fs/namei.c:139
 getname_flags+0x93/0xf0 include/linux/audit.h:322
 vfs_fstatat+0x86/0x160 fs/stat.c:340
 __do_sys_newfstatat+0xa2/0x130 fs/stat.c:505
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Memory state around the buggy address:
 ffff88802a63dc00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88802a63dc80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88802a63dd00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                               ^
 ffff88802a63dd80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88802a63de00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================
==================================================================
BUG: KASAN: slab-use-after-free in iov_iter_folioq_advance lib/iov_iter.c:540 [inline]
BUG: KASAN: slab-use-after-free in iov_iter_advance+0x677/0x6c0 lib/iov_iter.c:576
Read of size 8 at addr ffff88802a63f520 by task syz-executor341/5249

CPU: 1 UID: 0 PID: 5249 Comm: syz-executor341 Tainted: G    B              6.11.0-syzkaller-02574-ga430d95c5efa #0
Tainted: [B]=BAD_PAGE
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:93 [inline]
 dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:119
 print_address_description mm/kasan/report.c:377 [inline]
 print_report+0xc3/0x620 mm/kasan/report.c:488
 kasan_report+0xd9/0x110 mm/kasan/report.c:601
 iov_iter_folioq_advance lib/iov_iter.c:540 [inline]
 iov_iter_advance+0x677/0x6c0 lib/iov_iter.c:576
 netfs_write_folio+0x745/0x18f0 fs/netfs/write_issue.c:481
 netfs_writepages+0x2ba/0xb90 fs/netfs/write_issue.c:541
 do_writepages+0x1a6/0x7f0 mm/page-writeback.c:2683
 filemap_fdatawrite_wbc mm/filemap.c:397 [inline]
 filemap_fdatawrite_wbc+0x148/0x1c0 mm/filemap.c:387
 __filemap_fdatawrite_range+0xba/0x100 mm/filemap.c:430
 v9fs_dir_release+0x429/0x590 fs/9p/vfs_dir.c:219
 __fput+0x3f9/0xb60 fs/file_table.c:431
 task_work_run+0x151/0x250 kernel/task_work.c:228
 exit_task_work include/linux/task_work.h:40 [inline]
 do_exit+0xaa3/0x2bb0 kernel/exit.c:882
 do_group_exit+0xd3/0x2a0 kernel/exit.c:1031
 __do_sys_exit_group kernel/exit.c:1042 [inline]
 __se_sys_exit_group kernel/exit.c:1040 [inline]
 __x64_sys_exit_group+0x3e/0x50 kernel/exit.c:1040
 x64_sys_call+0x14a9/0x16a0 arch/x86/include/generated/asm/syscalls_64.h:232
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7ff0e2c14089
Code: Unable to access opcode bytes at 0x7ff0e2c1405f.
RSP: 002b:00007ffe69e64ba8 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007ff0e2c14089
RDX: 000000000000003c RSI: 00000000000000e7 RDI: 0000000000000000
RBP: 00007ff0e2c8f390 R08: ffffffffffffffb8 R09: 0000000000000006
R10: 000000007ffff000 R11: 0000000000000246 R12: 00007ff0e2c8f390
R13: 0000000000000000 R14: 00007ff0e2c8fde0 R15: 00007ff0e2be5070
 </TASK>

Allocated by task 5249:
 kasan_save_stack+0x33/0x60 mm/kasan/common.c:47
 kasan_save_track+0x14/0x30 mm/kasan/common.c:68
 poison_kmalloc_redzone mm/kasan/common.c:370 [inline]
 __kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:387
 kmalloc_noprof include/linux/slab.h:690 [inline]
 netfs_buffer_append_folio+0x181/0x750 fs/netfs/misc.c:25
 netfs_write_folio+0x542/0x18f0 fs/netfs/write_issue.c:421
 netfs_writepages+0x2ba/0xb90 fs/netfs/write_issue.c:541
 do_writepages+0x1a6/0x7f0 mm/page-writeback.c:2683
 filemap_fdatawrite_wbc mm/filemap.c:397 [inline]
 filemap_fdatawrite_wbc+0x148/0x1c0 mm/filemap.c:387
 __filemap_fdatawrite_range+0xba/0x100 mm/filemap.c:430
 v9fs_dir_release+0x429/0x590 fs/9p/vfs_dir.c:219
 __fput+0x3f9/0xb60 fs/file_table.c:431
 task_work_run+0x151/0x250 kernel/task_work.c:228
 exit_task_work include/linux/task_work.h:40 [inline]
 do_exit+0xaa3/0x2bb0 kernel/exit.c:882
 do_group_exit+0xd3/0x2a0 kernel/exit.c:1031
 __do_sys_exit_group kernel/exit.c:1042 [inline]
 __se_sys_exit_group kernel/exit.c:1040 [inline]
 __x64_sys_exit_group+0x3e/0x50 kernel/exit.c:1040
 x64_sys_call+0x14a9/0x16a0 arch/x86/include/generated/asm/syscalls_64.h:232
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Freed by task 12:
 kasan_save_stack+0x33/0x60 mm/kasan/common.c:47
 kasan_save_track+0x14/0x30 mm/kasan/common.c:68
 kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:579
 poison_slab_object+0xf7/0x160 mm/kasan/common.c:240
 __kasan_slab_free+0x32/0x50 mm/kasan/common.c:256
 kasan_slab_free include/linux/kasan.h:184 [inline]
 slab_free_hook mm/slub.c:2250 [inline]
 slab_free mm/slub.c:4474 [inline]
 kfree+0x12a/0x3b0 mm/slub.c:4595
 netfs_delete_buffer_head+0xa6/0x100 fs/netfs/misc.c:59
 netfs_writeback_unlock_folios fs/netfs/write_collect.c:139 [inline]
 netfs_collect_write_results fs/netfs/write_collect.c:493 [inline]
 netfs_write_collection_worker+0x20f9/0x4f80 fs/netfs/write_collect.c:551
 process_one_work+0x9c8/0x1b40 kernel/workqueue.c:3231
 process_scheduled_works kernel/workqueue.c:3312 [inline]
 worker_thread+0x6c8/0xf00 kernel/workqueue.c:3393
 kthread+0x2c4/0x3a0 kernel/kthread.c:389
 ret_from_fork+0x48/0x80 arch/x86/kernel/process.c:147
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244

The buggy address belongs to the object at ffff88802a63f400
 which belongs to the cache kmalloc-512 of size 512
The buggy address is located 288 bytes inside of
 freed 512-byte region [ffff88802a63f400, ffff88802a63f600)

The buggy address belongs to the physical page:
page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x2a63c
head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xfdffffff(slab)
raw: 00fff00000000040 ffff88801ac41c80 dead000000000122 0000000000000000
raw: 0000000000000000 0000000080100010 00000001fdffffff 0000000000000000
head: 00fff00000000040 ffff88801ac41c80 dead000000000122 0000000000000000
head: 0000000000000000 0000000080100010 00000001fdffffff 0000000000000000
head: 00fff00000000002 ffffea0000a98f01 ffffffffffffffff 0000000000000000
head: 0000000000000004 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Unmovable, gfp_mask 0xd2040(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 5249, tgid 5249 (syz-executor341), ts 139218928620, free_ts 130646507944
 set_page_owner include/linux/page_owner.h:32 [inline]
 post_alloc_hook+0x2d1/0x350 mm/page_alloc.c:1500
 prep_new_page mm/page_alloc.c:1508 [inline]
 get_page_from_freelist+0x1351/0x2e50 mm/page_alloc.c:3446
 __alloc_pages_noprof+0x22b/0x2460 mm/page_alloc.c:4702
 __alloc_pages_node_noprof include/linux/gfp.h:269 [inline]
 alloc_pages_node_noprof include/linux/gfp.h:296 [inline]
 alloc_slab_page+0x4e/0xf0 mm/slub.c:2319
 allocate_slab mm/slub.c:2482 [inline]
 new_slab+0x84/0x260 mm/slub.c:2535
 ___slab_alloc+0xdac/0x1870 mm/slub.c:3721
 __slab_alloc.constprop.0+0x56/0xb0 mm/slub.c:3811
 __slab_alloc_node mm/slub.c:3864 [inline]
 slab_alloc_node mm/slub.c:4026 [inline]
 __kmalloc_cache_noprof+0x2b4/0x300 mm/slub.c:4185
 kmalloc_noprof include/linux/slab.h:690 [inline]
 netfs_buffer_append_folio+0x181/0x750 fs/netfs/misc.c:25
 netfs_write_folio+0x542/0x18f0 fs/netfs/write_issue.c:421
 netfs_writepages+0x2ba/0xb90 fs/netfs/write_issue.c:541
 do_writepages+0x1a6/0x7f0 mm/page-writeback.c:2683
 filemap_fdatawrite_wbc mm/filemap.c:397 [inline]
 filemap_fdatawrite_wbc+0x148/0x1c0 mm/filemap.c:387
 __filemap_fdatawrite_range+0xba/0x100 mm/filemap.c:430
 v9fs_dir_release+0x429/0x590 fs/9p/vfs_dir.c:219
 __fput+0x3f9/0xb60 fs/file_table.c:431
page last free pid 4682 tgid 4682 stack trace:
 reset_page_owner include/linux/page_owner.h:25 [inline]
 free_pages_prepare mm/page_alloc.c:1101 [inline]
 free_unref_page+0x64a/0xe40 mm/page_alloc.c:2619
 __put_partials+0x14c/0x170 mm/slub.c:3049
 qlink_free mm/kasan/quarantine.c:163 [inline]
 qlist_free_all+0x4e/0x140 mm/kasan/quarantine.c:179
 kasan_quarantine_reduce+0x192/0x1e0 mm/kasan/quarantine.c:286
 __kasan_slab_alloc+0x69/0x90 mm/kasan/common.c:322
 kasan_slab_alloc include/linux/kasan.h:201 [inline]
 slab_post_alloc_hook mm/slub.c:3989 [inline]
 slab_alloc_node mm/slub.c:4038 [inline]
 kmem_cache_alloc_noprof+0x121/0x2f0 mm/slub.c:4045
 getname_flags.part.0+0x4c/0x550 fs/namei.c:139
 getname_flags+0x93/0xf0 include/linux/audit.h:322
 vfs_fstatat+0x86/0x160 fs/stat.c:340
 __do_sys_newfstatat+0xa2/0x130 fs/stat.c:505
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Memory state around the buggy address:
 ffff88802a63f400: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88802a63f480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88802a63f500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                               ^
 ffff88802a63f580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88802a63f600: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================
==================================================================
BUG: KASAN: slab-use-after-free in iov_iter_folioq_advance lib/iov_iter.c:540 [inline]
BUG: KASAN: slab-use-after-free in iov_iter_advance+0x677/0x6c0 lib/iov_iter.c:576
Read of size 8 at addr ffff88802c8aad20 by task syz-executor341/5249

CPU: 1 UID: 0 PID: 5249 Comm: syz-executor341 Tainted: G    B              6.11.0-syzkaller-02574-ga430d95c5efa #0
Tainted: [B]=BAD_PAGE
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:93 [inline]
 dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:119
 print_address_description mm/kasan/report.c:377 [inline]
 print_report+0xc3/0x620 mm/kasan/report.c:488
 kasan_report+0xd9/0x110 mm/kasan/report.c:601
 iov_iter_folioq_advance lib/iov_iter.c:540 [inline]
 iov_iter_advance+0x677/0x6c0 lib/iov_iter.c:576
 netfs_write_folio+0x745/0x18f0 fs/netfs/write_issue.c:481
 netfs_writepages+0x2ba/0xb90 fs/netfs/write_issue.c:541
 do_writepages+0x1a6/0x7f0 mm/page-writeback.c:2683
 filemap_fdatawrite_wbc mm/filemap.c:397 [inline]
 filemap_fdatawrite_wbc+0x148/0x1c0 mm/filemap.c:387
 __filemap_fdatawrite_range+0xba/0x100 mm/filemap.c:430
 v9fs_dir_release+0x429/0x590 fs/9p/vfs_dir.c:219
 __fput+0x3f9/0xb60 fs/file_table.c:431
 task_work_run+0x151/0x250 kernel/task_work.c:228
 exit_task_work include/linux/task_work.h:40 [inline]
 do_exit+0xaa3/0x2bb0 kernel/exit.c:882
 do_group_exit+0xd3/0x2a0 kernel/exit.c:1031
 __do_sys_exit_group kernel/exit.c:1042 [inline]
 __se_sys_exit_group kernel/exit.c:1040 [inline]
 __x64_sys_exit_group+0x3e/0x50 kernel/exit.c:1040
 x64_sys_call+0x14a9/0x16a0 arch/x86/include/generated/asm/syscalls_64.h:232
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7ff0e2c14089
Code: Unable to access opcode bytes at 0x7ff0e2c1405f.
RSP: 002b:00007ffe69e64ba8 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007ff0e2c14089
RDX: 000000000000003c RSI: 00000000000000e7 RDI: 0000000000000000
RBP: 00007ff0e2c8f390 R08: ffffffffffffffb8 R09: 0000000000000006
R10: 000000007ffff000 R11: 0000000000000246 R12: 00007ff0e2c8f390
R13: 0000000000000000 R14: 00007ff0e2c8fde0 R15: 00007ff0e2be5070
 </TASK>

Allocated by task 5249:
 kasan_save_stack+0x33/0x60 mm/kasan/common.c:47
 kasan_save_track+0x14/0x30 mm/kasan/common.c:68
 poison_kmalloc_redzone mm/kasan/common.c:370 [inline]
 __kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:387
 kmalloc_noprof include/linux/slab.h:690 [inline]
 netfs_buffer_append_folio+0x181/0x750 fs/netfs/misc.c:25
 netfs_write_folio+0x542/0x18f0 fs/netfs/write_issue.c:421
 netfs_writepages+0x2ba/0xb90 fs/netfs/write_issue.c:541
 do_writepages+0x1a6/0x7f0 mm/page-writeback.c:2683
 filemap_fdatawrite_wbc mm/filemap.c:397 [inline]
 filemap_fdatawrite_wbc+0x148/0x1c0 mm/filemap.c:387
 __filemap_fdatawrite_range+0xba/0x100 mm/filemap.c:430
 v9fs_dir_release+0x429/0x590 fs/9p/vfs_dir.c:219
 __fput+0x3f9/0xb60 fs/file_table.c:431
 task_work_run+0x151/0x250 kernel/task_work.c:228
 exit_task_work include/linux/task_work.h:40 [inline]
 do_exit+0xaa3/0x2bb0 kernel/exit.c:882
 do_group_exit+0xd3/0x2a0 kernel/exit.c:1031
 __do_sys_exit_group kernel/exit.c:1042 [inline]
 __se_sys_exit_group kernel/exit.c:1040 [inline]
 __x64_sys_exit_group+0x3e/0x50 kernel/exit.c:1040
 x64_sys_call+0x14a9/0x16a0 arch/x86/include/generated/asm/syscalls_64.h:232
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Freed by task 11:
 kasan_save_stack+0x33/0x60 mm/kasan/common.c:47
 kasan_save_track+0x14/0x30 mm/kasan/common.c:68
 kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:579
 poison_slab_object+0xf7/0x160 mm/kasan/common.c:240
 __kasan_slab_free+0x32/0x50 mm/kasan/common.c:256
 kasan_slab_free include/linux/kasan.h:184 [inline]
 slab_free_hook mm/slub.c:2250 [inline]
 slab_free mm/slub.c:4474 [inline]
 kfree+0x12a/0x3b0 mm/slub.c:4595
 netfs_delete_buffer_head+0xa6/0x100 fs/netfs/misc.c:59
 netfs_writeback_unlock_folios fs/netfs/write_collect.c:139 [inline]
 netfs_collect_write_results fs/netfs/write_collect.c:493 [inline]
 netfs_write_collection_worker+0x20f9/0x4f80 fs/netfs/write_collect.c:551
 process_one_work+0x9c8/0x1b40 kernel/workqueue.c:3231
 process_scheduled_works kernel/workqueue.c:3312 [inline]
 worker_thread+0x6c8/0xf00 kernel/workqueue.c:3393
 kthread+0x2c4/0x3a0 kernel/kthread.c:389
 ret_from_fork+0x48/0x80 arch/x86/kernel/process.c:147
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244

The buggy address belongs to the object at ffff88802c8aac00
 which belongs to the cache kmalloc-512 of size 512
The buggy address is located 288 bytes inside of
 freed 512-byte region [ffff88802c8aac00, ffff88802c8aae00)

The buggy address belongs to the physical page:
page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x2c8a8
head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0xfdffffff(slab)
raw: 00fff00000000040 ffff88801ac41c80 dead000000000122 0000000000000000
raw: 0000000000000000 0000000080100010 00000001fdffffff 0000000000000000
head: 00fff00000000040 ffff88801ac41c80 dead000000000122 0000000000000000
head: 0000000000000000 0000000080100010 00000001fdffffff 0000000000000000
head: 00fff00000000002 ffffea0000b22a01 ffffffffffffffff 0000000000000000
head: 0000000000000004 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Unmovable, gfp_mask 0xd2040(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 5249, tgid 5249 (syz-executor341), ts 141121433556, free_ts 130792291213
 set_page_owner include/linux/page_owner.h:32 [inline]
 post_alloc_hook+0x2d1/0x350 mm/page_alloc.c:1500
 prep_new_page mm/page_alloc.c:1508 [inline]
 get_page_from_freelist+0x1351/0x2e50 mm/page_alloc.c:3446
 __alloc_pages_noprof+0x22b/0x2460 mm/page_alloc.c:4702
 __alloc_pages_node_noprof include/linux/gfp.h:269 [inline]
 alloc_pages_node_noprof include/linux/gfp.h:296 [inline]
 alloc_slab_page+0x4e/0xf0 mm/slub.c:2319
 allocate_slab mm/slub.c:2482 [inline]
 new_slab+0x84/0x260 mm/slub.c:2535
 ___slab_alloc+0xdac/0x1870 mm/slub.c:3721
 __slab_alloc.constprop.0+0x56/0xb0 mm/slub.c:3811
 __slab_alloc_node mm/slub.c:3864 [inline]
 slab_alloc_node mm/slub.c:4026 [inline]
 __kmalloc_cache_noprof+0x2b4/0x300 mm/slub.c:4185
 kmalloc_noprof include/linux/slab.h:690 [inline]
 netfs_buffer_append_folio+0x181/0x750 fs/netfs/misc.c:25
 netfs_write_folio+0x542/0x18f0 fs/netfs/write_issue.c:421
 netfs_writepages+0x2ba/0xb90 fs/netfs/write_issue.c:541
 do_writepages+0x1a6/0x7f0 mm/page-writeback.c:2683
 filemap_fdatawrite_wbc mm/filemap.c:397 [inline]
 filemap_fdatawrite_wbc+0x148/0x1c0 mm/filemap.c:387
 __filemap_fdatawrite_range+0xba/0x100 mm/filemap.c:430
 v9fs_dir_release+0x429/0x590 fs/9p/vfs_dir.c:219
 __fput+0x3f9/0xb60 fs/file_table.c:431
page last free pid 5243 tgid 5243 stack trace:
 reset_page_owner include/linux/page_owner.h:25 [inline]
 free_pages_prepare mm/page_alloc.c:1101 [inline]
 free_unref_page+0x64a/0xe40 mm/page_alloc.c:2619
 __put_partials+0x14c/0x170 mm/slub.c:3049
 qlink_free mm/kasan/quarantine.c:163 [inline]
 qlist_free_all+0x4e/0x140 mm/kasan/quarantine.c:179
 kasan_quarantine_reduce+0x192/0x1e0 mm/kasan/quarantine.c:286
 __kasan_slab_alloc+0x69/0x90 mm/kasan/common.c:322
 kasan_slab_alloc include/linux/kasan.h:201 [inline]
 slab_post_alloc_hook mm/slub.c:3989 [inline]
 slab_alloc_node mm/slub.c:4038 [inline]
 __kmalloc_cache_noprof+0x11e/0x300 mm/slub.c:4185
 kmalloc_noprof include/linux/slab.h:690 [inline]
 kzalloc_noprof include/linux/slab.h:816 [inline]
 p9_fd_open net/9p/trans_fd.c:828 [inline]
 p9_fd_create+0x164/0x490 net/9p/trans_fd.c:1102
 p9_client_create+0x879/0x1210 net/9p/client.c:1015
 v9fs_session_init+0x1f8/0x1a80 fs/9p/v9fs.c:410
 v9fs_mount+0xc6/0xa50 fs/9p/vfs_super.c:122
 legacy_get_tree+0x10c/0x220 fs/fs_context.c:662
 vfs_get_tree+0x92/0x380 fs/super.c:1800
 do_new_mount fs/namespace.c:3507 [inline]
 path_mount+0x14e6/0x1f20 fs/namespace.c:3834
 do_mount fs/namespace.c:3847 [inline]
 __do_sys_mount fs/namespace.c:4055 [inline]
 __se_sys_mount fs/namespace.c:4032 [inline]
 __x64_sys_mount+0x294/0x320 fs/namespace.c:4032
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Memory state around the buggy address:
 ffff88802c8aac00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88802c8aac80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88802c8aad00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                               ^
 ffff88802c8aad80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88802c8aae00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
For information about bisection process see: https://goo.gl/tpsmEJ#bisection

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance
  2024-09-20 14:26 [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance syzbot
@ 2024-09-20 17:14 ` Jeongjun Park
  2024-09-20 17:35   ` syzbot
  2024-09-20 23:54 ` Hillf Danton
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Jeongjun Park @ 2024-09-20 17:14 UTC (permalink / raw)
  To: syzbot+7c48153a9d788824044b; +Cc: syzkaller-bugs, linux-kernel

#syz test git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ master

---
 fs/netfs/write_issue.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c
index 04e66d587f77..8e708d1f7c9d 100644
--- a/fs/netfs/write_issue.c
+++ b/fs/netfs/write_issue.c
@@ -427,6 +427,8 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
 	 * Also skip uploading for data that's been read and just needs copying
 	 * to the cache.
 	 */
+	
+	spin_lock(&wreq->lock);
 	for (int s = 0; s < NR_IO_STREAMS; s++) {
 		stream = &wreq->io_streams[s];
 		stream->submit_off = foff;
@@ -488,6 +490,7 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
 		for (int s = 0; s < NR_IO_STREAMS; s++)
 			netfs_issue_write(wreq, &wreq->io_streams[s]);
 
+	spin_unlock(&wreq->lock);
 	_leave(" = 0");
 	return 0;
 }
--

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance
  2024-09-20 17:14 ` Jeongjun Park
@ 2024-09-20 17:35   ` syzbot
  0 siblings, 0 replies; 12+ messages in thread
From: syzbot @ 2024-09-20 17:35 UTC (permalink / raw)
  To: aha310510, linux-kernel, syzkaller-bugs

Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
BUG: sleeping function called from invalid context in mempool_alloc_noprof

BUG: sleeping function called from invalid context at include/linux/sched/mm.h:337
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 6020, name: syz.0.15
preempt_count: 1, expected: 0
RCU nest depth: 0, expected: 0
2 locks held by syz.0.15/6020:
 #0: ffff888071360500 (&ctx->wb_lock){+.+.}-{3:3}, at: netfs_writepages+0xb8/0xb90 fs/netfs/write_issue.c:509
 #1: ffff888143aea528 (&rreq->lock){+.+.}-{2:2}, at: spin_lock include/linux/spinlock.h:351 [inline]
 #1: ffff888143aea528 (&rreq->lock){+.+.}-{2:2}, at: netfs_write_folio+0x5a9/0x19b0 fs/netfs/write_issue.c:431
Preemption disabled at:
[<0000000000000000>] 0x0
CPU: 0 UID: 0 PID: 6020 Comm: syz.0.15 Not tainted 6.11.0-syzkaller-07341-gbaeb9a7d8b60-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:93 [inline]
 dump_stack_lvl+0x16c/0x1f0 lib/dump_stack.c:119
 __might_resched+0x3c0/0x5e0 kernel/sched/core.c:8547
 might_alloc include/linux/sched/mm.h:337 [inline]
 mempool_alloc_noprof+0x1e8/0x390 mm/mempool.c:392
 netfs_alloc_subrequest+0xc1/0x3c0 fs/netfs/objects.c:186
 netfs_prepare_write fs/netfs/write_issue.c:157 [inline]
 netfs_advance_write fs/netfs/write_issue.c:279 [inline]
 netfs_advance_write+0x3b0/0xbd0 fs/netfs/write_issue.c:259
 netfs_write_folio+0xb62/0x19b0 fs/netfs/write_issue.c:471
 netfs_writepages+0x2ba/0xb90 fs/netfs/write_issue.c:544
 do_writepages+0x1a6/0x7f0 mm/page-writeback.c:2683
 filemap_fdatawrite_wbc mm/filemap.c:397 [inline]
 filemap_fdatawrite_wbc+0x148/0x1c0 mm/filemap.c:387
 __filemap_fdatawrite_range+0xba/0x100 mm/filemap.c:430
 v9fs_dir_release+0x429/0x590 fs/9p/vfs_dir.c:219
 __fput+0x3f9/0xb60 fs/file_table.c:431
 task_work_run+0x151/0x250 kernel/task_work.c:228
 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+0x27b/0x2a0 kernel/entry/common.c:218
 do_syscall_64+0xda/0x250 arch/x86/entry/common.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fbfe037def9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffc8aec11f8 EFLAGS: 00000246 ORIG_RAX: 00000000000001b4
RAX: 0000000000000000 RBX: 00007fbfe0537a80 RCX: 00007fbfe037def9
RDX: 0000000000000000 RSI: 000000000000001e RDI: 0000000000000003
RBP: 00007fbfe0537a80 R08: 0000000000000000 R09: 00007ffc8aec14ef
R10: 000000000003fd88 R11: 0000000000000246 R12: 00000000000239d8
R13: 00007ffc8aec1300 R14: 0000000000000032 R15: ffffffffffffffff
 </TASK>

============================================
WARNING: possible recursive locking detected
6.11.0-syzkaller-07341-gbaeb9a7d8b60-dirty #0 Tainted: G        W         
--------------------------------------------
syz.0.15/6020 is trying to acquire lock:
ffff888143aea528 (&rreq->lock){+.+.}-{2:2}, at: spin_lock_bh include/linux/spinlock.h:356 [inline]
ffff888143aea528 (&rreq->lock){+.+.}-{2:2}, at: netfs_prepare_write fs/netfs/write_issue.c:191 [inline]
ffff888143aea528 (&rreq->lock){+.+.}-{2:2}, at: netfs_advance_write fs/netfs/write_issue.c:279 [inline]
ffff888143aea528 (&rreq->lock){+.+.}-{2:2}, at: netfs_advance_write+0x6c8/0xbd0 fs/netfs/write_issue.c:259

but task is already holding lock:
ffff888143aea528 (&rreq->lock){+.+.}-{2:2}, at: spin_lock include/linux/spinlock.h:351 [inline]
ffff888143aea528 (&rreq->lock){+.+.}-{2:2}, at: netfs_write_folio+0x5a9/0x19b0 fs/netfs/write_issue.c:431

other info that might help us debug this:
 Possible unsafe locking scenario:

       CPU0
       ----
  lock(&rreq->lock);
  lock(&rreq->lock);

 *** DEADLOCK ***

 May be due to missing lock nesting notation

2 locks held by syz.0.15/6020:
 #0: ffff888071360500 (&ctx->wb_lock){+.+.}-{3:3}, at: netfs_writepages+0xb8/0xb90 fs/netfs/write_issue.c:509
 #1: ffff888143aea528 (&rreq->lock){+.+.}-{2:2}, at: spin_lock include/linux/spinlock.h:351 [inline]
 #1: ffff888143aea528 (&rreq->lock){+.+.}-{2:2}, at: netfs_write_folio+0x5a9/0x19b0 fs/netfs/write_issue.c:431

stack backtrace:
CPU: 0 UID: 0 PID: 6020 Comm: syz.0.15 Tainted: G        W          6.11.0-syzkaller-07341-gbaeb9a7d8b60-dirty #0
Tainted: [W]=WARN
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:93 [inline]
 dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:119
 print_deadlock_bug+0x2e3/0x410 kernel/locking/lockdep.c:3034
 check_deadlock kernel/locking/lockdep.c:3086 [inline]
 validate_chain kernel/locking/lockdep.c:3888 [inline]
 __lock_acquire+0x2185/0x3ce0 kernel/locking/lockdep.c:5199
 lock_acquire kernel/locking/lockdep.c:5822 [inline]
 lock_acquire+0x1b1/0x560 kernel/locking/lockdep.c:5787
 __raw_spin_lock_bh include/linux/spinlock_api_smp.h:126 [inline]
 _raw_spin_lock_bh+0x33/0x40 kernel/locking/spinlock.c:178
 spin_lock_bh include/linux/spinlock.h:356 [inline]
 netfs_prepare_write fs/netfs/write_issue.c:191 [inline]
 netfs_advance_write fs/netfs/write_issue.c:279 [inline]
 netfs_advance_write+0x6c8/0xbd0 fs/netfs/write_issue.c:259
 netfs_write_folio+0xb62/0x19b0 fs/netfs/write_issue.c:471
 netfs_writepages+0x2ba/0xb90 fs/netfs/write_issue.c:544
 do_writepages+0x1a6/0x7f0 mm/page-writeback.c:2683
 filemap_fdatawrite_wbc mm/filemap.c:397 [inline]
 filemap_fdatawrite_wbc+0x148/0x1c0 mm/filemap.c:387
 __filemap_fdatawrite_range+0xba/0x100 mm/filemap.c:430
 v9fs_dir_release+0x429/0x590 fs/9p/vfs_dir.c:219
 __fput+0x3f9/0xb60 fs/file_table.c:431
 task_work_run+0x151/0x250 kernel/task_work.c:228
 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+0x27b/0x2a0 kernel/entry/common.c:218
 do_syscall_64+0xda/0x250 arch/x86/entry/common.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fbfe037def9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 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 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffc8aec11f8 EFLAGS: 00000246 ORIG_RAX: 00000000000001b4
RAX: 0000000000000000 RBX: 00007fbfe0537a80 RCX: 00007fbfe037def9
RDX: 0000000000000000 RSI: 000000000000001e RDI: 0000000000000003
RBP: 00007fbfe0537a80 R08: 0000000000000000 R09: 00007ffc8aec14ef
R10: 000000000003fd88 R11: 0000000000000246 R12: 00000000000239d8
R13: 00007ffc8aec1300 R14: 0000000000000032 R15: ffffffffffffffff
 </TASK>


Tested on:

commit:         baeb9a7d Merge tag 'sched-rt-2024-09-17' of git://git...
git tree:       git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ master
console output: https://syzkaller.appspot.com/x/log.txt?x=10b0a427980000
kernel config:  https://syzkaller.appspot.com/x/.config?x=5a0a1caedf9d578f
dashboard link: https://syzkaller.appspot.com/bug?extid=7c48153a9d788824044b
compiler:       gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch:          https://syzkaller.appspot.com/x/patch.diff?x=1499bf00580000


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance
  2024-09-20 14:26 [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance syzbot
  2024-09-20 17:14 ` Jeongjun Park
@ 2024-09-20 23:54 ` Hillf Danton
  2024-09-21  0:18   ` syzbot
  2024-09-21  2:06 ` Hillf Danton
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Hillf Danton @ 2024-09-20 23:54 UTC (permalink / raw)
  To: syzbot; +Cc: linux-kernel, syzkaller-bugs

On Fri, 20 Sep 2024 07:26:34 -0700
> syzbot found the following issue on:
> 
> HEAD commit:    a430d95c5efa Merge tag 'lsm-pr-20240911' of git://git.kern..
> git tree:       upstream
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=10c7d69f980000

#syz test

--- x/fs/netfs/write_collect.c
+++ y/fs/netfs/write_collect.c
@@ -548,7 +548,9 @@ void netfs_write_collection_worker(struc
 		return;
 	}
 
+	mutex_lock(&ictx->wb_lock);
 	netfs_collect_write_results(wreq);
+	mutex_unlock(&ictx->wb_lock);
 
 	/* We're done when the app thread has finished posting subreqs and all
 	 * the queues in all the streams are empty.
--

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance
  2024-09-20 23:54 ` Hillf Danton
@ 2024-09-21  0:18   ` syzbot
  0 siblings, 0 replies; 12+ messages in thread
From: syzbot @ 2024-09-21  0:18 UTC (permalink / raw)
  To: hdanton, linux-kernel, syzkaller-bugs

Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in p9_client_create

------------[ cut here ]------------
kmem_cache of name '9p-fcall-cache' already exists
WARNING: CPU: 0 PID: 7251 at mm/slab_common.c:107 kmem_cache_sanity_check mm/slab_common.c:107 [inline]
WARNING: CPU: 0 PID: 7251 at mm/slab_common.c:107 __kmem_cache_create_args+0xb0/0x3c0 mm/slab_common.c:294
Modules linked in:
CPU: 0 UID: 0 PID: 7251 Comm: syz-executor103 Not tainted 6.11.0-syzkaller-07341-gbaeb9a7d8b60-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
RIP: 0010:kmem_cache_sanity_check mm/slab_common.c:107 [inline]
RIP: 0010:__kmem_cache_create_args+0xb0/0x3c0 mm/slab_common.c:294
Code: 98 48 3d d0 de 11 8e 74 25 48 8b 7b 60 48 89 ee e8 35 ae 3c 09 85 c0 75 e0 90 48 c7 c7 58 bb 59 8d 48 89 ee e8 01 38 80 ff 90 <0f> 0b 90 90 be 20 00 00 00 48 89 ef e8 bf af 3c 09 48 85 c0 0f 85
RSP: 0018:ffffc90008aaf900 EFLAGS: 00010282
RAX: 0000000000000000 RBX: ffff888030f54780 RCX: ffffffff814e16a9
RDX: ffff888027479e00 RSI: ffffffff814e16b6 RDI: 0000000000000001
RBP: ffffffff8ca2e820 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000000 R12: 0000000000000000
R13: 0000000000008004 R14: ffffc90008aaf9f0 R15: 0000000000020018
FS:  0000555587ca4380(0000) GS:ffff8880b8800000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000555587ca4ca8 CR3: 000000005152e000 CR4: 0000000000350ef0
Call Trace:
 <TASK>
 kmem_cache_create_usercopy include/linux/slab.h:361 [inline]
 p9_client_create+0xebd/0x11b0 net/9p/client.c:1042
 v9fs_session_init+0x1f8/0x1a80 fs/9p/v9fs.c:410
 v9fs_mount+0xc6/0xa50 fs/9p/vfs_super.c:122
 legacy_get_tree+0x10c/0x220 fs/fs_context.c:662
 vfs_get_tree+0x92/0x380 fs/super.c:1800
 do_new_mount fs/namespace.c:3507 [inline]
 path_mount+0x14e6/0x1f20 fs/namespace.c:3834
 do_mount fs/namespace.c:3847 [inline]
 __do_sys_mount fs/namespace.c:4055 [inline]
 __se_sys_mount fs/namespace.c:4032 [inline]
 __x64_sys_mount+0x294/0x320 fs/namespace.c:4032
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f2f88775f39
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 c1 17 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:00007ffeb6e17418 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 0030656c69662f2e RCX: 00007f2f88775f39
RDX: 0000000020000040 RSI: 0000000020000000 RDI: 0000000000000000
RBP: 00007f2f887bf04e R08: 0000000020000300 R09: 0000000000000006
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffeb6e1742c
R13: 431bde82d7b634db R14: 0000000000000001 R15: 0000000000000001
 </TASK>


Tested on:

commit:         baeb9a7d Merge tag 'sched-rt-2024-09-17' of git://git...
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=13556e9f980000
kernel config:  https://syzkaller.appspot.com/x/.config?x=5a0a1caedf9d578f
dashboard link: https://syzkaller.appspot.com/bug?extid=7c48153a9d788824044b
compiler:       gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch:          https://syzkaller.appspot.com/x/patch.diff?x=10a17607980000


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance
  2024-09-20 14:26 [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance syzbot
  2024-09-20 17:14 ` Jeongjun Park
  2024-09-20 23:54 ` Hillf Danton
@ 2024-09-21  2:06 ` Hillf Danton
  2024-09-21  2:50   ` syzbot
  2024-09-21  8:09 ` Hillf Danton
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Hillf Danton @ 2024-09-21  2:06 UTC (permalink / raw)
  To: syzbot; +Cc: linux-kernel, syzkaller-bugs

On Fri, 20 Sep 2024 07:26:34 -0700
> syzbot found the following issue on:
> 
> HEAD commit:    a430d95c5efa Merge tag 'lsm-pr-20240911' of git://git.kern..
> git tree:       upstream
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=10c7d69f980000

#syz test

--- x/fs/netfs/write_collect.c
+++ y/fs/netfs/write_collect.c
@@ -548,7 +548,9 @@ void netfs_write_collection_worker(struc
 		return;
 	}
 
+	mutex_lock(&ictx->wb_lock);
 	netfs_collect_write_results(wreq);
+	mutex_unlock(&ictx->wb_lock);
 
 	/* We're done when the app thread has finished posting subreqs and all
 	 * the queues in all the streams are empty.
--- l/net/9p/client.c
+++ c/net/9p/client.c
@@ -1039,7 +1039,7 @@ struct p9_client *p9_client_create(const
 	 * followed by data accessed from userspace by read
 	 */
 	clnt->fcall_cache =
-		kmem_cache_create_usercopy("9p-fcall-cache", clnt->msize,
+		kmem_cache_create_usercopy(client_id, clnt->msize,
 					   0, 0, P9_HDRSZ + 4,
 					   clnt->msize - (P9_HDRSZ + 4),
 					   NULL);
--

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance
  2024-09-21  2:06 ` Hillf Danton
@ 2024-09-21  2:50   ` syzbot
  0 siblings, 0 replies; 12+ messages in thread
From: syzbot @ 2024-09-21  2:50 UTC (permalink / raw)
  To: hdanton, linux-kernel, syzkaller-bugs

Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in p9_client_create

------------[ cut here ]------------
kmem_cache of name 'syzkaller' already exists
WARNING: CPU: 1 PID: 7290 at mm/slab_common.c:107 kmem_cache_sanity_check mm/slab_common.c:107 [inline]
WARNING: CPU: 1 PID: 7290 at mm/slab_common.c:107 __kmem_cache_create_args+0xb0/0x3c0 mm/slab_common.c:294
Modules linked in:
CPU: 1 UID: 0 PID: 7290 Comm: syz-executor302 Not tainted 6.11.0-syzkaller-07341-gbaeb9a7d8b60-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/06/2024
RIP: 0010:kmem_cache_sanity_check mm/slab_common.c:107 [inline]
RIP: 0010:__kmem_cache_create_args+0xb0/0x3c0 mm/slab_common.c:294
Code: 98 48 3d d0 de 11 8e 74 25 48 8b 7b 60 48 89 ee e8 35 ae 3c 09 85 c0 75 e0 90 48 c7 c7 18 bb 59 8d 48 89 ee e8 01 38 80 ff 90 <0f> 0b 90 90 be 20 00 00 00 48 89 ef e8 bf af 3c 09 48 85 c0 0f 85
RSP: 0018:ffffc90002fef8f0 EFLAGS: 00010286
RAX: 0000000000000000 RBX: ffff8880289cec80 RCX: ffffffff814e16a9
RDX: ffff88806be39e00 RSI: ffffffff814e16b6 RDI: 0000000000000001
RBP: ffffffff9023f4c1 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000000 R12: 0000000000000000
R13: 0000000000008004 R14: ffffc90002fef9f0 R15: 0000000000020018
FS:  000055558975d380(0000) GS:ffff8880b8900000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f479381ae40 CR3: 00000000794e6000 CR4: 0000000000350ef0
Call Trace:
 <TASK>
 kmem_cache_create_usercopy include/linux/slab.h:361 [inline]
 p9_client_create+0xec8/0x11c0 net/9p/client.c:1042
 v9fs_session_init+0x1f8/0x1a80 fs/9p/v9fs.c:410
 v9fs_mount+0xc6/0xa50 fs/9p/vfs_super.c:122
 legacy_get_tree+0x10c/0x220 fs/fs_context.c:662
 vfs_get_tree+0x92/0x380 fs/super.c:1800
 do_new_mount fs/namespace.c:3507 [inline]
 path_mount+0x14e6/0x1f20 fs/namespace.c:3834
 do_mount fs/namespace.c:3847 [inline]
 __do_sys_mount fs/namespace.c:4055 [inline]
 __se_sys_mount fs/namespace.c:4032 [inline]
 __x64_sys_mount+0x294/0x320 fs/namespace.c:4032
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f47937e7f39
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 c1 17 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:00007ffdc8834e28 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 0030656c69662f2e RCX: 00007f47937e7f39
RDX: 0000000020000040 RSI: 0000000020000000 RDI: 0000000000000000
RBP: 00007f479383104e R08: 0000000020000300 R09: 0000000000000006
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffdc8834e3c
R13: 431bde82d7b634db R14: 0000000000000001 R15: 0000000000000001
 </TASK>


Tested on:

commit:         baeb9a7d Merge tag 'sched-rt-2024-09-17' of git://git...
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=14a8ff00580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=5a0a1caedf9d578f
dashboard link: https://syzkaller.appspot.com/bug?extid=7c48153a9d788824044b
compiler:       gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch:          https://syzkaller.appspot.com/x/patch.diff?x=16402ca9980000


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance
  2024-09-20 14:26 [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance syzbot
                   ` (2 preceding siblings ...)
  2024-09-21  2:06 ` Hillf Danton
@ 2024-09-21  8:09 ` Hillf Danton
  2024-09-21  9:04   ` syzbot
  2024-09-21  9:25 ` Hillf Danton
  2024-10-29  8:15 ` syzbot
  5 siblings, 1 reply; 12+ messages in thread
From: Hillf Danton @ 2024-09-21  8:09 UTC (permalink / raw)
  To: syzbot; +Cc: linux-kernel, syzkaller-bugs

On Fri, 20 Sep 2024 07:26:34 -0700
> syzbot found the following issue on:
> 
> HEAD commit:    a430d95c5efa Merge tag 'lsm-pr-20240911' of git://git.kern..
> git tree:       upstream
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=10c7d69f980000

#syz test

--- x/fs/netfs/write_collect.c
+++ y/fs/netfs/write_collect.c
@@ -548,7 +548,9 @@ void netfs_write_collection_worker(struc
 		return;
 	}
 
+	mutex_lock(&ictx->wb_lock);
 	netfs_collect_write_results(wreq);
+	mutex_unlock(&ictx->wb_lock);
 
 	/* We're done when the app thread has finished posting subreqs and all
 	 * the queues in all the streams are empty.
--- l/net/9p/client.c
+++ c/net/9p/client.c
@@ -8,6 +8,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/sprintf.h>
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/fs.h>
@@ -979,6 +980,7 @@ struct p9_client *p9_client_create(const
 	int err;
 	struct p9_client *clnt;
 	char *client_id;
+	static int fcc = 0;
 
 	clnt = kmalloc(sizeof(*clnt), GFP_KERNEL);
 	if (!clnt)
@@ -991,6 +993,11 @@ struct p9_client *p9_client_create(const
 	client_id = utsname()->nodename;
 	memcpy(clnt->name, client_id, strlen(client_id) + 1);
 
+	clnt->name[__NEW_UTS_LEN] = 0;
+	if (__NEW_UTS_LEN <= snprintf(clnt->name, __NEW_UTS_LEN, "9pfcc%d", ++fcc)) {
+		kfree(clnt);
+		return ERR_PTR(-ENOMEM);
+	}
 	spin_lock_init(&clnt->lock);
 	idr_init(&clnt->fids);
 	idr_init(&clnt->reqs);
@@ -1039,7 +1046,7 @@ struct p9_client *p9_client_create(const
 	 * followed by data accessed from userspace by read
 	 */
 	clnt->fcall_cache =
-		kmem_cache_create_usercopy("9p-fcall-cache", clnt->msize,
+		kmem_cache_create_usercopy(clnt->name, clnt->msize,
 					   0, 0, P9_HDRSZ + 4,
 					   clnt->msize - (P9_HDRSZ + 4),
 					   NULL);
--

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance
  2024-09-21  8:09 ` Hillf Danton
@ 2024-09-21  9:04   ` syzbot
  0 siblings, 0 replies; 12+ messages in thread
From: syzbot @ 2024-09-21  9:04 UTC (permalink / raw)
  To: hdanton, linux-kernel, syzkaller-bugs

Hello,

syzbot tried to test the proposed patch but the build/boot failed:

./include/linux/sprintf.h:11:54: error: unknown type name 'va_list'
./include/linux/sprintf.h:13:71: error: unknown type name 'va_list'
./include/linux/sprintf.h:15:72: error: unknown type name 'va_list'
./include/linux/sprintf.h:17:70: error: unknown type name 'va_list'
./include/linux/sprintf.h:18:73: error: unknown type name 'va_list'
./include/linux/sprintf.h:21:55: error: unknown type name 'va_list'
./include/linux/fs.h:2666:9: error: implicit declaration of function 'vsnprintf' [-Werror=implicit-function-declaration]


Tested on:

commit:         1868f9d0 Merge tag 'for-linux-6.12-ofs1' of git://git...
git tree:       upstream
kernel config:  https://syzkaller.appspot.com/x/.config?x=d85e1e571a820894
dashboard link: https://syzkaller.appspot.com/bug?extid=7c48153a9d788824044b
compiler:       gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch:          https://syzkaller.appspot.com/x/patch.diff?x=165bee9f980000


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance
  2024-09-20 14:26 [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance syzbot
                   ` (3 preceding siblings ...)
  2024-09-21  8:09 ` Hillf Danton
@ 2024-09-21  9:25 ` Hillf Danton
  2024-09-21 10:10   ` syzbot
  2024-10-29  8:15 ` syzbot
  5 siblings, 1 reply; 12+ messages in thread
From: Hillf Danton @ 2024-09-21  9:25 UTC (permalink / raw)
  To: syzbot; +Cc: linux-kernel, syzkaller-bugs

On Fri, 20 Sep 2024 07:26:34 -0700
> syzbot found the following issue on:
> 
> HEAD commit:    a430d95c5efa Merge tag 'lsm-pr-20240911' of git://git.kern..
> git tree:       upstream
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=10c7d69f980000

#syz test

--- x/fs/netfs/write_collect.c
+++ y/fs/netfs/write_collect.c
@@ -548,7 +548,9 @@ void netfs_write_collection_worker(struc
 		return;
 	}
 
+	mutex_lock(&ictx->wb_lock);
 	netfs_collect_write_results(wreq);
+	mutex_unlock(&ictx->wb_lock);
 
 	/* We're done when the app thread has finished posting subreqs and all
 	 * the queues in all the streams are empty.
--- l/net/9p/client.c
+++ c/net/9p/client.c
@@ -979,6 +979,7 @@ struct p9_client *p9_client_create(const
 	int err;
 	struct p9_client *clnt;
 	char *client_id;
+	static int fcc = 0;
 
 	clnt = kmalloc(sizeof(*clnt), GFP_KERNEL);
 	if (!clnt)
@@ -991,6 +992,11 @@ struct p9_client *p9_client_create(const
 	client_id = utsname()->nodename;
 	memcpy(clnt->name, client_id, strlen(client_id) + 1);
 
+	clnt->name[__NEW_UTS_LEN] = 0;
+	if (__NEW_UTS_LEN <= snprintf(clnt->name, __NEW_UTS_LEN, "9pfcc%d", ++fcc)) {
+		kfree(clnt);
+		return ERR_PTR(-ENOMEM);
+	}
 	spin_lock_init(&clnt->lock);
 	idr_init(&clnt->fids);
 	idr_init(&clnt->reqs);
@@ -1039,7 +1045,7 @@ struct p9_client *p9_client_create(const
 	 * followed by data accessed from userspace by read
 	 */
 	clnt->fcall_cache =
-		kmem_cache_create_usercopy("9p-fcall-cache", clnt->msize,
+		kmem_cache_create_usercopy(clnt->name, clnt->msize,
 					   0, 0, P9_HDRSZ + 4,
 					   clnt->msize - (P9_HDRSZ + 4),
 					   NULL);
--

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance
  2024-09-21  9:25 ` Hillf Danton
@ 2024-09-21 10:10   ` syzbot
  0 siblings, 0 replies; 12+ messages in thread
From: syzbot @ 2024-09-21 10:10 UTC (permalink / raw)
  To: hdanton, linux-kernel, syzkaller-bugs

Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-by: syzbot+7c48153a9d788824044b@syzkaller.appspotmail.com
Tested-by: syzbot+7c48153a9d788824044b@syzkaller.appspotmail.com

Tested on:

commit:         1868f9d0 Merge tag 'for-linux-6.12-ofs1' of git://git...
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=156e6427980000
kernel config:  https://syzkaller.appspot.com/x/.config?x=5a0a1caedf9d578f
dashboard link: https://syzkaller.appspot.com/bug?extid=7c48153a9d788824044b
compiler:       gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch:          https://syzkaller.appspot.com/x/patch.diff?x=13e66427980000

Note: testing is done by a robot and is best-effort only.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance
  2024-09-20 14:26 [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance syzbot
                   ` (4 preceding siblings ...)
  2024-09-21  9:25 ` Hillf Danton
@ 2024-10-29  8:15 ` syzbot
  5 siblings, 0 replies; 12+ messages in thread
From: syzbot @ 2024-10-29  8:15 UTC (permalink / raw)
  To: aha310510, brauner, dhowells, hdanton, jlayton, linux-fsdevel,
	linux-kernel, linux-trace-kernel, mathieu.desnoyers, mhiramat,
	netfs, oliver.sang, rostedt, stfrench, syzkaller-bugs

syzbot suspects this issue was fixed by commit:

commit df9b455633aee0bad3e5c3dc9fc1c860b13c96d2
Author: David Howells <dhowells@redhat.com>
Date:   Thu Sep 26 13:58:30 2024 +0000

    netfs: Fix write oops in generic/346 (9p) and generic/074 (cifs)

bisection log:  https://syzkaller.appspot.com/x/bisect.txt?x=12c2eca7980000
start commit:   a430d95c5efa Merge tag 'lsm-pr-20240911' of git://git.kern..
git tree:       upstream
kernel config:  https://syzkaller.appspot.com/x/.config?x=d85e1e571a820894
dashboard link: https://syzkaller.appspot.com/bug?extid=7c48153a9d788824044b
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=1511a607980000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=10c7d69f980000

If the result looks correct, please mark the issue as fixed by replying with:

#syz fix: netfs: Fix write oops in generic/346 (9p) and generic/074 (cifs)

For information about bisection process see: https://goo.gl/tpsmEJ#bisection

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-10-29  8:15 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-20 14:26 [syzbot] [netfs?] KASAN: slab-use-after-free Read in iov_iter_advance syzbot
2024-09-20 17:14 ` Jeongjun Park
2024-09-20 17:35   ` syzbot
2024-09-20 23:54 ` Hillf Danton
2024-09-21  0:18   ` syzbot
2024-09-21  2:06 ` Hillf Danton
2024-09-21  2:50   ` syzbot
2024-09-21  8:09 ` Hillf Danton
2024-09-21  9:04   ` syzbot
2024-09-21  9:25 ` Hillf Danton
2024-09-21 10:10   ` syzbot
2024-10-29  8:15 ` syzbot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox