[PATCH 3/4] ksmbd: fail an overwrite that would clear the hidden or system attribute

From: Ian Bridges

Date: Mon Nov 30 2026 - 00:14:25 EST


ksmbd accepts an overwrite or supersede of a file with
FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_SYSTEM when the request leaves
that attribute out. The open can empty the file and clear the
attribute. Such a request should fail with STATUS_ACCESS_DENIED, so
that a client does not overwrite a hidden or system file by accident.

Fail the request. Extend the existing attribute read to cover
overwrites and supersedes. Keep the existing behavior for POSIX opens.

Signed-off-by: Ian Bridges <icb@xxxxxxxxxxxx>
---
fs/smb/server/smb2pdu.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index e500653084ee..2312765cad8f 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -5044,10 +5044,24 @@ int smb2_open(struct ksmbd_work *work)
* for a named stream or a POSIX open, read only the stored attributes,
* as before.
*/
- if (file_present && req->CreateOptions & FILE_DELETE_ON_CLOSE_LE)
+ if (file_present &&
+ (req->CreateOptions & FILE_DELETE_ON_CLOSE_LE ||
+ (!stream_name && !posix_ctxt && overwrite)))
file_attrs = smb2_file_attributes(tcon, &path,
!stream_name && !posix_ctxt);

+ /*
+ * An overwrite of a file's unnamed stream keeps its hidden and system
+ * attributes. A POSIX open does not use them.
+ */
+ if (!stream_name && !posix_ctxt && file_present && overwrite &&
+ file_attrs & ~req->FileAttributes &
+ (FILE_ATTRIBUTE_HIDDEN_LE | FILE_ATTRIBUTE_SYSTEM_LE)) {
+ rsp->hdr.Status = STATUS_ACCESS_DENIED;
+ rc = -EACCES;
+ goto err_out;
+ }
+
/* A read-only file is not deleted on close */
if (file_present && req->CreateOptions & FILE_DELETE_ON_CLOSE_LE &&
file_attrs & FILE_ATTRIBUTE_READONLY_LE) {
--
2.47.3