[PATCH] ksmbd: return the cause of a failed link

From: Ian Bridges

Date: Fri Nov 27 2026 - 20:40:08 EST


smb2_create_link() turns every error of the link, and of the removal of
a target that the link replaces, into -EINVAL. A link that fails
because the caller cannot write the directory therefore returns
STATUS_INVALID_PARAMETER. Return the errors as they are, as
smb2_rename() does, so that smb2_set_info() maps them in the same way
as the errors of a rename.

Signed-off-by: Ian Bridges <icb@xxxxxxxxxxxx>
---
Tested on ksmbd-for-next 4543a3349127 with KASAN. A link into a
directory that the caller cannot write now fails with
STATUS_ACCESS_DENIED instead of STATUS_INVALID_PARAMETER. On a Linux
cifs mount, ln into such a directory now reports "Permission denied".
Before, it reported "Operation not supported". A link into a writable
directory still succeeds. smbtorture gives the same results as on the
base.

This patch was developed with LLM assistance.

fs/smb/server/smb2pdu.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 38326db8da40..9504c2e35819 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -8953,11 +8953,9 @@ static int smb2_create_link(struct ksmbd_work *work,
} else {
if (file_info->ReplaceIfExists) {
rc = ksmbd_vfs_remove_file(work, &path);
- if (rc) {
- rc = -EINVAL;
+ if (rc)
ksmbd_debug(SMB, "cannot delete %s\n",
link_name);
- }
} else {
rc = -EEXIST;
ksmbd_debug(SMB, "link already exists\n");
@@ -8967,8 +8965,6 @@ static int smb2_create_link(struct ksmbd_work *work,
goto out;
}
rc = ksmbd_vfs_link(work, target_name, link_name);
- if (rc)
- rc = -EINVAL;
out:

if (!IS_ERR(link_name))

base-commit: 4543a3349127baa8395397b7f4aa930d9a4f8dd5
--
2.47.3