* [PATCH] ksmbd: fail a non-directory delete-on-close open of a directory
@ 2026-11-27 3:15 Ian Bridges
0 siblings, 0 replies; only message in thread
From: Ian Bridges @ 2026-11-27 3:15 UTC (permalink / raw)
To: linkinjeon
Cc: senozhatsky, tom, chenxiaosong, linux-cifs, linux-kernel,
Ian Bridges, stable
smb2_open() fails an open with FILE_NON_DIRECTORY_FILE when the target
is a directory, unless FILE_DELETE_ON_CLOSE is also set. With both
options the directory opens and is marked delete-on-close. An empty
directory is then removed at close, although the client asked for a
non-directory. A directory that is not empty stays, and the close
still succeeds.
MS-FSA requires STATUS_FILE_IS_A_DIRECTORY for a non-directory open of
the unnamed data stream of a directory, and delete-on-close makes no
difference. Fail that open whatever the other options are. A
delete-on-close open of a named stream of a directory still succeeds
and removes the stream at close.
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 3c31349456c5 with KASAN. An open of a
directory with FILE_NON_DIRECTORY_FILE and FILE_DELETE_ON_CLOSE now
fails with STATUS_FILE_IS_A_DIRECTORY, and the directory stays. Before,
an empty directory was removed at close. A directory that was not empty
stayed, and the close returned STATUS_SUCCESS. A delete-on-close open
of a named stream of a directory still removes the stream.
smbtorture first tries to remove a test directory with such an open. On
the base that open succeeded, so later tests in the same run found the
old directory and failed. Those tests now pass, and each of them gives
the same result on the base when run alone. The other smbtorture
results are the same as on the base.
This patch was developed with LLM assistance.
fs/smb/server/smb2pdu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 5a7842264b98..28fb77bcd3dc 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -4976,7 +4976,8 @@ int smb2_open(struct ksmbd_work *work)
if (file_present && req->CreateOptions & FILE_NON_DIRECTORY_FILE_LE &&
S_ISDIR(d_inode(path.dentry)->i_mode) &&
- !(req->CreateOptions & FILE_DELETE_ON_CLOSE_LE)) {
+ (!stream_name ||
+ !(req->CreateOptions & FILE_DELETE_ON_CLOSE_LE))) {
ksmbd_debug(SMB, "open() argument is a directory: %s, %x\n",
name, le32_to_cpu(req->CreateOptions));
rsp->hdr.Status = STATUS_FILE_IS_A_DIRECTORY;
--
2.47.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-27 3:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27 3:15 [PATCH] ksmbd: fail a non-directory delete-on-close open of a directory 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®