]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
smb/server: avoid deadlock when linking with ReplaceIfExists
authorNeilBrown <neil@brown.name>
Sun, 8 Jun 2025 23:35:09 +0000 (09:35 +1000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:28:14 +0000 (16:28 +0200)
commit1e858a7a51c7b8b009d8f246de7ceb7743b44a71
treedef83b0684a2586f2be7cdba6ddc89e9c66f7163
parent61ad294996c03db054342644e6a6068fc9038885
smb/server: avoid deadlock when linking with ReplaceIfExists

[ Upstream commit d5fc1400a34b4ea5e8f2ce296ea12bf8c8421694 ]

If smb2_create_link() is called with ReplaceIfExists set and the name
does exist then a deadlock will happen.

ksmbd_vfs_kern_path_locked() will return with success and the parent
directory will be locked.  ksmbd_vfs_remove_file() will then remove the
file.  ksmbd_vfs_link() will then be called while the parent is still
locked.  It will try to lock the same parent and will deadlock.

This patch moves the ksmbd_vfs_kern_path_unlock() call to *before*
ksmbd_vfs_link() and then simplifies the code, removing the file_present
flag variable.

Signed-off-by: NeilBrown <neil@brown.name>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/smb/server/smb2pdu.c