• Namjae Jeon's avatar
    ksmbd: fix possible deadlock in smb2_open · 864fb5d3
    Namjae Jeon authored
    [ 8743.393379] ======================================================
    [ 8743.393385] WARNING: possible circular locking dependency detected
    [ 8743.393391] 6.4.0-rc1+ #11 Tainted: G           OE
    [ 8743.393397] ------------------------------------------------------
    [ 8743.393402] kworker/0:2/12921 is trying to acquire lock:
    [ 8743.393408] ffff888127a14460 (sb_writers#8){.+.+}-{0:0}, at: ksmbd_vfs_setxattr+0x3d/0xd0 [ksmbd]
    [ 8743.393510]
                   but task is already holding lock:
    [ 8743.393515] ffff8880360d97f0 (&type->i_mutex_dir_key#6/1){+.+.}-{3:3}, at: ksmbd_vfs_kern_path_locked+0x181/0x670 [ksmbd]
    [ 8743.393618]
                   which lock already depends on the new lock.
    
    [ 8743.393623]
                   the existing dependency chain (in reverse order) is:
    [ 8743.393628]
                   -> #1 (&type->i_mutex_dir_key#6/1){+.+.}-{3:3}:
    [ 8743.393648]        down_write_nested+0x9a/0x1b0
    [ 8743.393660]        filename_create+0x128/0x270
    [ 8743.393670]        do_mkdirat+0xab/0x1f0
    [ 8743.393680]        __x64_sys_mkdir+0x47/0x60
    [ 8743.393690]        do_syscall_64+0x5d/0x90
    [ 8743.393701]        entry_SYSCALL_64_after_hwframe+0x72/0xdc
    [ 8743.393711]
                   -> #0 (sb_writers#8){.+.+}-{0:0}:
    [ 8743.393728]        __lock_acquire+0x2201/0x3b80
    [ 8743.393737]        lock_acquire+0x18f/0x440
    [ 8743.393746]        mnt_want_write+0x5f/0x240
    [ 8743.393755]        ksmbd_vfs_setxattr+0x3d/0xd0 [ksmbd]
    [ 8743.393839]        ksmbd_vfs_set_dos_attrib_xattr+0xcc/0x110 [ksmbd]
    [ 8743.393924]        compat_ksmbd_vfs_set_dos_attrib_xattr+0x39/0x50 [ksmbd]
    [ 8743.394010]        smb2_open+0x3432/0x3cc0 [ksmbd]
    [ 8743.394099]        handle_ksmbd_work+0x2c9/0x7b0 [ksmbd]
    [ 8743.394187]        process_one_work+0x65a/0xb30
    [ 8743.394198]        worker_thread+0x2cf/0x700
    [ 8743.394209]        kthread+0x1ad/0x1f0
    [ 8743.394218]        ret_from_fork+0x29/0x50
    
    This patch add mnt_want_write() above parent inode lock and remove
    nested mnt_want_write calls in smb2_open().
    
    Fixes: 40b268d3 ("ksmbd: add mnt_want_write to ksmbd vfs functions")
    Cc: stable@vger.kernel.org
    Reported-by: default avatarMarios Makassikis <mmakassikis@freebox.fr>
    Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
    Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
    864fb5d3
smbacl.h 6.52 KB