syzbot


possible deadlock in do_page_mkwrite (3)

Status: upstream: reported on 2025/06/15 09:03
Subsystems: kernfs
[Documentation on labels]
Reported-by: syzbot+47c7d1a51f51d13f5723@syzkaller.appspotmail.com
First crash: 196d, last: 12d
Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [kernfs?] possible deadlock in do_page_mkwrite (3) 0 (1) 2025/06/15 09:03
Similar bugs (4)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream possible deadlock in do_page_mkwrite (2) dri 4 5 329d 389d 0/29 auto-obsoleted due to no activity on 2025/05/09 03:36
linux-6.1 possible deadlock in do_page_mkwrite origin:upstream missing-backport 4 C done 15 5d09h 970d 0/3 upstream: reported C repro on 2023/04/29 03:26
upstream possible deadlock in do_page_mkwrite fs 4 C error done 114 693d 1108d 0/29 auto-obsoleted due to no activity on 2024/04/09 15:57
linux-5.15 possible deadlock in do_page_mkwrite missing-backport origin:upstream 4 C done 21 5h29m 926d 0/3 upstream: reported C repro on 2023/06/12 00:09

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Not tainted
------------------------------------------------------
syz.6.295/8707 is trying to acquire lock:
ffff888023e425f8 (sb_pagefaults#2){.+.+}-{0:0}, at: do_page_mkwrite+0x150/0x310 mm/memory.c:3528

but task is already holding lock:
ffff88813ff74238 (&root->kernfs_rwsem){++++}-{4:4}, at: kernfs_fop_readdir+0x267/0x870 fs/kernfs/dir.c:1896

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #4 (&root->kernfs_rwsem){++++}-{4:4}:
       down_write+0x3a/0x50 kernel/locking/rwsem.c:1590
       kernfs_add_one+0x41/0x5c0 fs/kernfs/dir.c:794
       kernfs_create_dir_ns+0xde/0x130 fs/kernfs/dir.c:1096
       sysfs_create_dir_ns+0x123/0x280 fs/sysfs/dir.c:59
       create_dir lib/kobject.c:73 [inline]
       kobject_add_internal+0x6b1/0xcd0 lib/kobject.c:240
       kobject_add_varg lib/kobject.c:374 [inline]
       kobject_init_and_add+0x125/0x190 lib/kobject.c:457
       btrfs_sysfs_add_qgroups+0x111/0x2b0 fs/btrfs/sysfs.c:2697
       btrfs_quota_enable+0x25b/0x2900 fs/btrfs/qgroup.c:1002
       btrfs_ioctl_quota_ctl+0x186/0x1c0 fs/btrfs/ioctl.c:3613
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:597 [inline]
       __se_sys_ioctl+0xff/0x170 fs/ioctl.c:583
       do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
       do_syscall_64+0xfa/0xf80 arch/x86/entry/syscall_64.c:94
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #3 (&fs_info->qgroup_ioctl_lock){+.+.}-{4:4}:
       __mutex_lock_common kernel/locking/rtmutex_api.c:533 [inline]
       mutex_lock_nested+0x5a/0x1d0 kernel/locking/rtmutex_api.c:552
       btrfs_quota_enable+0x29d/0x2900 fs/btrfs/qgroup.c:1031
       btrfs_ioctl_quota_ctl+0x186/0x1c0 fs/btrfs/ioctl.c:3613
       vfs_ioctl fs/ioctl.c:51 [inline]
       __do_sys_ioctl fs/ioctl.c:597 [inline]
       __se_sys_ioctl+0xff/0x170 fs/ioctl.c:583
       do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
       do_syscall_64+0xfa/0xf80 arch/x86/entry/syscall_64.c:94
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #2 (btrfs_trans_num_extwriters){++++}-{0:0}:
       join_transaction+0x1a4/0xc90 fs/btrfs/transaction.c:323
       start_transaction+0x6b7/0x15f0 fs/btrfs/transaction.c:707
       btrfs_rebuild_free_space_tree+0xad/0x6c0 fs/btrfs/free-space-tree.c:1330
       btrfs_start_pre_rw_mount+0x128f/0x1bf0 fs/btrfs/disk-io.c:3052
       open_ctree+0x2b11/0x3d20 fs/btrfs/disk-io.c:3603
       btrfs_fill_super fs/btrfs/super.c:983 [inline]
       btrfs_get_tree_super fs/btrfs/super.c:1946 [inline]
       btrfs_get_tree_subvol fs/btrfs/super.c:2089 [inline]
       btrfs_get_tree+0x1061/0x1920 fs/btrfs/super.c:2123
       vfs_get_tree+0x92/0x2a0 fs/super.c:1751
       fc_mount fs/namespace.c:1199 [inline]
       do_new_mount_fc fs/namespace.c:3636 [inline]
       do_new_mount+0x302/0xa10 fs/namespace.c:3712
       do_mount fs/namespace.c:4035 [inline]
       __do_sys_mount fs/namespace.c:4224 [inline]
       __se_sys_mount+0x313/0x410 fs/namespace.c:4201
       do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
       do_syscall_64+0xfa/0xf80 arch/x86/entry/syscall_64.c:94
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

-> #1 (btrfs_trans_num_writers){++++}-{0:0}:
       __lock_release kernel/locking/lockdep.c:5574 [inline]
       lock_release+0x1ab/0x3b0 kernel/locking/lockdep.c:5889
       percpu_up_read include/linux/percpu-rwsem.h:112 [inline]
       __sb_end_write include/linux/fs/super.h:14 [inline]
       sb_end_intwrite+0x26/0x1c0 include/linux/fs/super.h:101
       __btrfs_end_transaction+0x248/0x640 fs/btrfs/transaction.c:1083
       btrfs_dirty_inode+0x14c/0x190 fs/btrfs/inode.c:6337
       inode_update_time fs/inode.c:2167 [inline]
       file_update_time_flags+0x38d/0x4f0 fs/inode.c:2395
       btrfs_page_mkwrite+0x5dd/0x1a80 fs/btrfs/file.c:1916
       do_page_mkwrite+0x150/0x310 mm/memory.c:3528
       do_shared_fault mm/memory.c:5831 [inline]
       do_fault mm/memory.c:5893 [inline]
       do_pte_missing+0x78b/0x27a0 mm/memory.c:4401
       handle_pte_fault mm/memory.c:6273 [inline]
       __handle_mm_fault mm/memory.c:6411 [inline]
       handle_mm_fault+0xcc1/0x1330 mm/memory.c:6580
       do_user_addr_fault+0x764/0x1380 arch/x86/mm/fault.c:1387
       handle_page_fault arch/x86/mm/fault.c:1476 [inline]
       exc_page_fault+0x82/0x100 arch/x86/mm/fault.c:1532
       asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:618

-> #0 (sb_pagefaults#2){.+.+}-{0:0}:
       check_prev_add kernel/locking/lockdep.c:3165 [inline]
       check_prevs_add kernel/locking/lockdep.c:3284 [inline]
       validate_chain kernel/locking/lockdep.c:3908 [inline]
       __lock_acquire+0x15a6/0x2cf0 kernel/locking/lockdep.c:5237
       lock_acquire+0x117/0x340 kernel/locking/lockdep.c:5868
       percpu_down_read_internal include/linux/percpu-rwsem.h:53 [inline]
       percpu_down_read_freezable include/linux/percpu-rwsem.h:83 [inline]
       __sb_start_write include/linux/fs/super.h:19 [inline]
       sb_start_pagefault include/linux/fs/super.h:159 [inline]
       btrfs_page_mkwrite+0x32c/0x1a80 fs/btrfs/file.c:1875
       do_page_mkwrite+0x150/0x310 mm/memory.c:3528
       wp_page_shared mm/memory.c:3929 [inline]
       do_wp_page+0x25e8/0x4970 mm/memory.c:4148
       handle_pte_fault mm/memory.c:6289 [inline]
       __handle_mm_fault mm/memory.c:6411 [inline]
       handle_mm_fault+0x9f6/0x1330 mm/memory.c:6580
       do_user_addr_fault+0x764/0x1380 arch/x86/mm/fault.c:1387
       handle_page_fault arch/x86/mm/fault.c:1476 [inline]
       exc_page_fault+0x82/0x100 arch/x86/mm/fault.c:1532
       asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:618
       user_access_begin arch/x86/include/asm/uaccess.h:-1 [inline]
       filldir64+0x29d/0x690 fs/readdir.c:373
       dir_emit include/linux/fs.h:3527 [inline]
       kernfs_fop_readdir+0x53a/0x870 fs/kernfs/dir.c:1913
       iterate_dir+0x3a5/0x580 fs/readdir.c:108
       __do_sys_getdents64 fs/readdir.c:410 [inline]
       __se_sys_getdents64+0xe4/0x260 fs/readdir.c:396
       do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
       do_syscall_64+0xfa/0xf80 arch/x86/entry/syscall_64.c:94
       entry_SYSCALL_64_after_hwframe+0x77/0x7f

other info that might help us debug this:

Chain exists of:
  sb_pagefaults#2 --> &fs_info->qgroup_ioctl_lock --> &root->kernfs_rwsem

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  rlock(&root->kernfs_rwsem);
                               lock(&fs_info->qgroup_ioctl_lock);
                               lock(&root->kernfs_rwsem);
  rlock(sb_pagefaults#2);

 *** DEADLOCK ***

4 locks held by syz.6.295/8707:
 #0: ffff88804cb9db28 (&f->f_pos_lock){+.+.}-{4:4}, at: fdget_pos+0x253/0x320 fs/file.c:1255
 #1: ffff8880638ad3f8 (&type->i_mutex_dir_key#4){++++}-{4:4}, at: iterate_dir+0x29e/0x580 fs/readdir.c:101
 #2: ffff88813ff74238 (&root->kernfs_rwsem){++++}-{4:4}, at: kernfs_fop_readdir+0x267/0x870 fs/kernfs/dir.c:1896
 #3: ffff8880315d36b0 (&mm->mmap_lock){++++}-{4:4}, at: mmap_read_trylock include/linux/mmap_lock.h:410 [inline]
 #3: ffff8880315d36b0 (&mm->mmap_lock){++++}-{4:4}, at: get_mmap_lock_carefully mm/mmap_lock.c:390 [inline]
 #3: ffff8880315d36b0 (&mm->mmap_lock){++++}-{4:4}, at: lock_mm_and_find_vma+0x32/0x300 mm/mmap_lock.c:450

stack backtrace:
CPU: 1 UID: 0 PID: 8707 Comm: syz.6.295 Not tainted syzkaller #0 PREEMPT_{RT,(full)} 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025
Call Trace:
 <TASK>
 dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
 print_circular_bug+0x2e2/0x300 kernel/locking/lockdep.c:2043
 check_noncircular+0x12e/0x150 kernel/locking/lockdep.c:2175
 check_prev_add kernel/locking/lockdep.c:3165 [inline]
 check_prevs_add kernel/locking/lockdep.c:3284 [inline]
 validate_chain kernel/locking/lockdep.c:3908 [inline]
 __lock_acquire+0x15a6/0x2cf0 kernel/locking/lockdep.c:5237
 lock_acquire+0x117/0x340 kernel/locking/lockdep.c:5868
 percpu_down_read_internal include/linux/percpu-rwsem.h:53 [inline]
 percpu_down_read_freezable include/linux/percpu-rwsem.h:83 [inline]
 __sb_start_write include/linux/fs/super.h:19 [inline]
 sb_start_pagefault include/linux/fs/super.h:159 [inline]
 btrfs_page_mkwrite+0x32c/0x1a80 fs/btrfs/file.c:1875
 do_page_mkwrite+0x150/0x310 mm/memory.c:3528
 wp_page_shared mm/memory.c:3929 [inline]
 do_wp_page+0x25e8/0x4970 mm/memory.c:4148
 handle_pte_fault mm/memory.c:6289 [inline]
 __handle_mm_fault mm/memory.c:6411 [inline]
 handle_mm_fault+0x9f6/0x1330 mm/memory.c:6580
 do_user_addr_fault+0x764/0x1380 arch/x86/mm/fault.c:1387
 handle_page_fault arch/x86/mm/fault.c:1476 [inline]
 exc_page_fault+0x82/0x100 arch/x86/mm/fault.c:1532
 asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:618
RIP: 0010:filldir64+0x29d/0x690 fs/readdir.c:377
Code: 8b ff 4c 89 ff 4c 89 e6 e8 20 53 8b ff 4d 39 e7 0f 82 5b 02 00 00 49 39 ef 0f 87 52 02 00 00 0f 01 cb 0f ae e8 48 8b 44 24 50 <49> 89 44 24 08 48 8b 4c 24 08 48 8b 44 24 58 48 89 01 48 8b 04 24
RSP: 0018:ffffc900054afc58 EFLAGS: 00050287
RAX: 00000000158f045c RBX: ffffc900054afe38 RCX: ffff88802b1cbc80
RDX: 0000000000000002 RSI: 0000200000003340 RDI: 0000200000003360
RBP: 00007ffffffff000 R08: 0000000000000000 R09: 0000000000000000
R10: dffffc0000000000 R11: ffffffff82351f40 R12: 0000200000003340
R13: ffffffff8bdc46a0 R14: 0000000000000007 R15: 0000200000003360
 dir_emit include/linux/fs.h:3527 [inline]
 kernfs_fop_readdir+0x53a/0x870 fs/kernfs/dir.c:1913
 iterate_dir+0x3a5/0x580 fs/readdir.c:108
 __do_sys_getdents64 fs/readdir.c:410 [inline]
 __se_sys_getdents64+0xe4/0x260 fs/readdir.c:396
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xfa/0xf80 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7feacc7ff749
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:00007feacaa3d038 EFLAGS: 00000246 ORIG_RAX: 00000000000000d9
RAX: ffffffffffffffda RBX: 00007feacca56090 RCX: 00007feacc7ff749
RDX: 0000000000000030 RSI: 0000200000003340 RDI: 0000000000000008
RBP: 00007feacc883f91 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007feacca56128 R14: 00007feacca56090 R15: 00007ffc891e7d78
 </TASK>
----------------
Code disassembly (best guess):
   0:	8b ff                	mov    %edi,%edi
   2:	4c 89 ff             	mov    %r15,%rdi
   5:	4c 89 e6             	mov    %r12,%rsi
   8:	e8 20 53 8b ff       	call   0xff8b532d
   d:	4d 39 e7             	cmp    %r12,%r15
  10:	0f 82 5b 02 00 00    	jb     0x271
  16:	49 39 ef             	cmp    %rbp,%r15
  19:	0f 87 52 02 00 00    	ja     0x271
  1f:	0f 01 cb             	stac
  22:	0f ae e8             	lfence
  25:	48 8b 44 24 50       	mov    0x50(%rsp),%rax
* 2a:	49 89 44 24 08       	mov    %rax,0x8(%r12) <-- trapping instruction
  2f:	48 8b 4c 24 08       	mov    0x8(%rsp),%rcx
  34:	48 8b 44 24 58       	mov    0x58(%rsp),%rax
  39:	48 89 01             	mov    %rax,(%rcx)
  3c:	48 8b 04 24          	mov    (%rsp),%rax

Crashes (6):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2025/12/12 02:13 upstream d358e5254674 d6526ea3 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in do_page_mkwrite
2025/10/27 09:49 upstream dcb6fa37fd7b c0460fcd .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in do_page_mkwrite
2025/08/26 04:24 upstream b6add54ba618 bf27483f .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in do_page_mkwrite
2025/07/26 21:35 upstream 302f88ff3584 fb8f743d .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in do_page_mkwrite
2025/06/11 08:56 upstream aef17cb3d3c4 5d7e17ca .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in do_page_mkwrite
2025/06/11 08:56 upstream aef17cb3d3c4 5d7e17ca .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-fs possible deadlock in do_page_mkwrite
* Struck through repros no longer work on HEAD.