[PATCH] ksmbd: fail an open whose stream cannot be created

From: Ian Bridges

Date: Fri Nov 27 2026 - 19:59:20 EST


When smb2_set_stream_name_xattr() cannot store the xattr of a new named
stream, it logs the error and returns success. The open then succeeds
with FILE_CREATED, although the stream does not exist. This happens,
for example, when the caller cannot write the file. Return the error
so that the open fails instead of reporting a stream that was never
created.

Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ian Bridges <icb@xxxxxxxxxxxx>
---
Tested on ksmbd-for-next b9eab18ab72e with KASAN. A user created a
named stream on another user's file that the user could only read. On
the base the open succeeded with no stream. With the patch it fails
with STATUS_ACCESS_DENIED. The same holds for a new stream on an
immutable file, where storing the xattr fails with -EPERM. A stream on
the user's own file is still created. smbtorture gives the same results
as on the base.

This patch was developed with LLM assistance.

fs/smb/server/smb2pdu.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index f286f9818643..3eb275a2ed5e 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -3751,10 +3751,12 @@ static noinline int smb2_set_stream_name_xattr(const struct path *path,
return -EACCES;

rc = ksmbd_vfs_setxattr(idmap, path, xattr_stream_name, NULL, 0, 0, true);
- if (rc < 0)
+ if (rc < 0) {
pr_err("Failed to store XATTR stream name :%d\n", rc);
- else
- *created = true;
+ /* smb2_open() reports -EPERM as a sharing violation */
+ return rc == -EPERM ? -EACCES : rc;
+ }
+ *created = true;
return 0;
}


base-commit: b9eab18ab72ec25abf431cba58e5239f695632f7
--
2.47.3