mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Bridges <icb@fastmail.org>
To: linkinjeon@kernel.org
Cc: senozhatsky@chromium.org, tom@talpey.com,
	chenxiaosong@chenxiaosong.com, linux-cifs@vger.kernel.org,
	linux-kernel@vger.kernel.org, Ian Bridges <icb@fastmail.org>
Subject: [PATCH 3/4] ksmbd: fail an overwrite that would clear the hidden or system attribute
Date: Sun, 29 Nov 2026 23:13:48 -0600	[thread overview]
Message-ID: <1e9d0d310e99c409b50f25d2ae005bc69eb69d0b.1796015315.git.icb@fastmail.org> (raw)
In-Reply-To: <cover.1796015315.git.icb@fastmail.org>

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@fastmail.org>
---
 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


  parent reply	other threads:[~2026-11-30  5:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  5:13 [PATCH 0/4] ksmbd: fix the checks on an open of an existing file Ian Bridges
2026-11-30  5:13 ` [PATCH 1/4] ksmbd: check the cached read-only attribute for delete-on-close Ian Bridges
2026-11-30  5:13 ` [PATCH 2/4] ksmbd: fail an overwrite or supersede of a directory Ian Bridges
2026-11-30  5:13 ` Ian Bridges [this message]
2026-11-30  5:13 ` [PATCH 4/4] ksmbd: refuse write access to a read-only file at open Ian Bridges
2026-11-30 12:42 ` [PATCH 0/4] ksmbd: fix the checks on an open of an existing file Namjae Jeon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1e9d0d310e99c409b50f25d2ae005bc69eb69d0b.1796015315.git.icb@fastmail.org \
    --to=icb@fastmail.org \
    --cc=chenxiaosong@chenxiaosong.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=senozhatsky@chromium.org \
    --cc=tom@talpey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®