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>,
	stable@vger.kernel.org
Subject: [PATCH] ksmbd: fail an open whose stream cannot be created
Date: Fri, 27 Nov 2026 18:59:05 -0600	[thread overview]
Message-ID: <20261128005905.1687065-1-icb@fastmail.org> (raw)

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@vger.kernel.org
Signed-off-by: Ian Bridges <icb@fastmail.org>
---
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


             reply	other threads:[~2026-11-28  0:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  0:59 Ian Bridges [this message]
2026-11-28  1:16 ` 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=20261128005905.1687065-1-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=stable@vger.kernel.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®