Re: [PATCH] ksmbd: fail FILE_CREATE of a named stream that exists
From: ChenXiaoSong
Date: Mon Nov 30 2026 - 22:14:04 EST
Sashiko's comment seems valid: https://sashiko.dev/#/patchset/20261201022248.2167102-1-icb%40fastmail.org
We can also include the following changes:
```
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -3690,7 +3690,7 @@ static int smb2_set_ea(struct smb2_ea_info *eabuf, unsigned int buf_len,
static noinline int smb2_set_stream_name_xattr(const struct path *path,
struct ksmbd_file *fp,
char *stream_name, int s_type,
- bool *created)
+ struct stream *stream, bool *created)
{
const struct mnt_idmap *idmap = mnt_idmap(path->mnt);
size_t xattr_stream_size;
@@ -3704,8 +3704,8 @@ static noinline int smb2_set_stream_name_xattr(const struct path *path,
if (rc)
return rc;
- fp->stream.name = xattr_stream_name;
- fp->stream.size = xattr_stream_size;
+ stream->name = xattr_stream_name;
+ stream->size = xattr_stream_size;
/* Keep the existing xattr's case for subsequent writes and removal. */
rc = ksmbd_vfs_casexattr_len(idmap,
@@ -5291,13 +5291,20 @@ int smb2_open(struct ksmbd_work *work)
}
if (stream_name) {
+ struct stream stream = {};
+
rc = smb2_set_stream_name_xattr(&path,
fp,
stream_name,
s_type,
+ &stream,
&stream_created);
- if (rc)
+ if (rc) {
+ kfree(stream.name);
goto err_out;
+ }
+ /* Only an opened stream may participate in delete-on-close. */
+ fp->stream = stream;
file_info = FILE_CREATED;
}
```
On 12/1/26 10:22, Ian Bridges wrote:
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -3712,7 +3712,7 @@ static noinline int smb2_set_stream_name_xattr(const struct path *path,
xattr_stream_name,
xattr_stream_size, xattr_stream_name);
if (rc >= 0)
- return 0;
+ return fp->cdoption == FILE_CREATE_LE ? -EEXIST : 0;
if (rc != -ENOENT && rc != -ENODATA)
return rc;
--
ChenXiaoSong <chenxiaosong@xxxxxxxxxxxxxxxx>
Chinese Homepage: https://chenxiaosong.com
English Homepage: https://chenxiaosong.com/en