Skip to content

Commit 7dd2448

Browse files
committed
smb/server: avoid deadlock when linking with ReplaceIfExists
Signed-off-by: Namjae Jeon <[email protected]>
1 parent f791457 commit 7dd2448

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

smb2pdu.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6491,7 +6491,6 @@ static int smb2_create_link(struct ksmbd_work *work,
64916491
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
64926492
struct path parent_path;
64936493
#endif
6494-
bool file_present = false;
64956494
int rc;
64966495

64976496
if (buf_len < (u64)sizeof(struct smb2_file_link_info) +
@@ -6529,14 +6528,10 @@ static int smb2_create_link(struct ksmbd_work *work,
65296528
if (rc != -ENOENT)
65306529
goto out;
65316530
} else {
6532-
file_present = true;
65336531
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0)
65346532
path_put(&path);
65356533
#endif
6536-
}
6537-
6538-
if (file_info->ReplaceIfExists) {
6539-
if (file_present) {
6534+
if (file_info->ReplaceIfExists) {
65406535
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
65416536
rc = ksmbd_vfs_remove_file(work, &path);
65426537
#else
@@ -6548,23 +6543,20 @@ static int smb2_create_link(struct ksmbd_work *work,
65486543
link_name);
65496544
goto out;
65506545
}
6551-
}
6552-
} else {
6553-
if (file_present) {
6546+
} else {
65546547
rc = -EEXIST;
65556548
ksmbd_debug(SMB, "link already exists\n");
65566549
goto out;
65576550
}
6551+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
6552+
ksmbd_vfs_kern_path_unlock(&parent_path, &path);
6553+
#endif
65586554
}
6559-
65606555
rc = ksmbd_vfs_link(work, target_name, link_name);
65616556
if (rc)
65626557
rc = -EINVAL;
65636558
out:
6564-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
6565-
if (file_present)
6566-
ksmbd_vfs_kern_path_unlock(&parent_path, &path);
6567-
#endif
6559+
65686560
if (!IS_ERR(link_name))
65696561
kfree(link_name);
65706562
kfree(pathname);

0 commit comments

Comments
 (0)