mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ksmbd: don't take an existing file's attributes from an open request
@ 2026-11-28  0:09 Ian Bridges
  0 siblings, 0 replies; only message in thread
From: Ian Bridges @ 2026-11-28  0:09 UTC (permalink / raw)
  To: linkinjeon
  Cc: senozhatsky, tom, chenxiaosong, linux-cifs, linux-kernel,
	Ian Bridges, stable

When smb2_open() opens an existing file that has no other open handle,
it sets the cached attributes of the file from the FileAttributes field
of the request. MS-FSA uses that field only when a file is created or
overwritten. Any other open of an existing file ignores it.

The cached attributes are shared by all handles to the file. So the
client that first opens an existing file decides the attributes that
the other clients see while its handle is open. Stored DOS attributes
replace them only on a share that stores DOS attributes and only if
the file has them. If the DOS attributes are written while the handle
is open, the attributes from the request are stored and stay after the
last close. ksmbd also bases its own checks on the cached attributes.

Take the attributes from the request only for a new file. An open of an
existing file starts from the attributes that the inode implies, and
the stored DOS attributes are read as before. An overwrite still takes
the attributes from the request.

Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Cc: stable@vger.kernel.org
Signed-off-by: Ian Bridges <icb@fastmail.org>
---
Tested on ksmbd-for-next 3dcffd93d4da with KASAN, on a share that
stores DOS attributes. One user opened a file that had no stored DOS
attributes, with FILE_READ_ATTRIBUTES access and FileAttributes set to
FILE_ATTRIBUTE_READONLY, and kept the handle. On the base a second user
saw the attribute and could not set delete pending. A creation time set
by the second user stored the attribute, and the file was still
read-only after the last close. With the patch the attribute does not
appear. Stored attributes, the attributes of a new file, and attributes
set by an overwrite are reported as on the base. 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, 7 insertions(+), 1 deletion(-)

diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 28fb77bcd3dc..c375d5c71231 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -5484,9 +5484,15 @@ int smb2_open(struct ksmbd_work *work)
 	fp->change_time = ksmbd_UnixTimeToNT(stat.ctime);
 	fp->allocation_size = S_ISDIR(stat.mode) ? 0 :
 		(alloc_size ?: stat.blocks << 9);
-	if (created || fp->f_ci->m_fattr == 0)
+	/*
+	 * The requested attributes are for a new file. An open of an existing
+	 * file does not change its attributes, except for an overwrite below.
+	 */
+	if (created)
 		fp->f_ci->m_fattr =
 			cpu_to_le32(smb2_get_dos_mode(&stat, le32_to_cpu(req->FileAttributes)));
+	else if (fp->f_ci->m_fattr == 0)
+		fp->f_ci->m_fattr = cpu_to_le32(smb2_get_dos_mode(&stat, 0));
 
 	if (!created)
 		smb2_update_xattrs(tcon, &path, fp);

base-commit: 3dcffd93d4da3b3231cbb845993194342fdd2150
-- 
2.47.3


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-28  0:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-28  0:09 [PATCH] ksmbd: don't take an existing file's attributes from an open request 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®