• Marios Makassikis's avatar
    ksmbd: fix recursive locking in vfs helpers · 807252f0
    Marios Makassikis authored
    Running smb2.rename test from Samba smbtorture suite against a kernel built
    with lockdep triggers a "possible recursive locking detected" warning.
    
    This is because mnt_want_write() is called twice with no mnt_drop_write()
    in between:
      -> ksmbd_vfs_mkdir()
        -> ksmbd_vfs_kern_path_create()
           -> kern_path_create()
              -> filename_create()
                -> mnt_want_write()
           -> mnt_want_write()
    
    Fix this by removing the mnt_want_write/mnt_drop_write calls from vfs
    helpers that call kern_path_create().
    
    Full lockdep trace below:
    
    ============================================
    WARNING: possible recursive locking detected
    6.6.0-rc5 #775 Not tainted
    --------------------------------------------
    kworker/1:1/32 is trying to acquire lock:
    ffff888005ac83f8 (sb_writers#5){.+.+}-{0:0}, at: ksmbd_vfs_mkdir+0xe1/0x410
    
    but task is already holding lock:
    ffff888005ac83f8 (sb_writers#5){.+.+}-{0:0}, at: filename_create+0xb6/0x260
    
    other info that might help us debug this:
     Possible unsafe locking scenario:
    
           CPU0
           ----
      lock(sb_writers#5);
      lock(sb_writers#5);
    
     *** DEADLOCK ***
    
     May be due to missing lock nesting notation
    
    4 locks held by kworker/1:1/32:
     #0: ffff8880064e4138 ((wq_completion)ksmbd-io){+.+.}-{0:0}, at: process_one_work+0x40e/0x980
     #1: ffff888005b0fdd0 ((work_completion)(&work->work)){+.+.}-{0:0}, at: process_one_work+0x40e/0x980
     #2: ffff888005ac83f8 (sb_writers#5){.+.+}-{0:0}, at: filename_create+0xb6/0x260
     #3: ffff8880057ce760 (&type->i_mutex_dir_key#3/1){+.+.}-{3:3}, at: filename_create+0x123/0x260
    
    Cc: stable@vger.kernel.org
    Fixes: 40b268d3 ("ksmbd: add mnt_want_write to ksmbd vfs functions")
    Signed-off-by: default avatarMarios Makassikis <mmakassikis@freebox.fr>
    Acked-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
    Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
    807252f0
vfs.c 44.2 KB