* [PATCH] ksmbd: return the cause of a failed link
@ 2026-11-28 1:39 Ian Bridges
2026-11-28 2:27 ` Namjae Jeon
0 siblings, 1 reply; 3+ messages in thread
From: Ian Bridges @ 2026-11-28 1:39 UTC (permalink / raw)
To: linkinjeon
Cc: senozhatsky, tom, chenxiaosong, linux-cifs, linux-kernel, Ian Bridges
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@fastmail.org>
---
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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] ksmbd: return the cause of a failed link
2026-11-28 1:39 [PATCH] ksmbd: return the cause of a failed link Ian Bridges
@ 2026-11-28 2:27 ` Namjae Jeon
2026-11-28 3:16 ` Ian Bridges
0 siblings, 1 reply; 3+ messages in thread
From: Namjae Jeon @ 2026-11-28 2:27 UTC (permalink / raw)
To: Ian Bridges; +Cc: senozhatsky, tom, chenxiaosong, linux-cifs, linux-kernel
> @@ -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;
When smb2_create_link() passes through errors from the backing
filesystem, smb2_set_info() needs to map them to the appropriate
NTSTATUS values for FileLinkInformation. For example, vfs_link()
returns -EPERM when the filesystem has no ->link operation, as on
exFAT. With this patch, ksmbd returns STATUS_ACCESS_DENIED. The
expected status is STATUS_NOT_SUPPORTED. Also, -EMLINK should map to
STATUS_TOO_MANY_LINKS. We should check the NTSTATUS mappings for the
other errors this patch propagates as well...
Thanks.
> out:
>
> if (!IS_ERR(link_name))
>
> base-commit: 4543a3349127baa8395397b7f4aa930d9a4f8dd5
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ksmbd: return the cause of a failed link
2026-11-28 2:27 ` Namjae Jeon
@ 2026-11-28 3:16 ` Ian Bridges
0 siblings, 0 replies; 3+ messages in thread
From: Ian Bridges @ 2026-11-28 3:16 UTC (permalink / raw)
To: linkinjeon
Cc: senozhatsky, tom, chenxiaosong, linux-cifs, linux-kernel, Ian Bridges
Hi Namjae,
Thanks for the review. You're right that passing the errors through
does not handle all the link failures correctly.
I'd like to propose one default mapping for errors from the VFS, shared
by the handlers, with the link path as its first user. It would cover
the cases you named, STATUS_NOT_SUPPORTED for a filesystem without hard
links and STATUS_TOO_MANY_LINKS. Results that a handler carries in an
errno today, such as -EPERM for a sharing violation in smb2_open(),
would set the status directly instead. The other handlers would move
over later, each in its own patch.
Would you like a v2 of this patch along those lines?
Thanks,
Ian
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-28 3:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-28 1:39 [PATCH] ksmbd: return the cause of a failed link Ian Bridges
2026-11-28 2:27 ` Namjae Jeon
2026-11-28 3:16 ` Ian Bridges
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®