Skip to contentSkip to conversation

FAILED: patch "[PATCH] ksmbd: refuse to read a handle that is not open for reading" failed to apply to 6.6-stable tree

PATCH New [email protected] 2 participants 2 messages Nov 25

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 2fd145f8865bb1a6c38a3dc68fa44290008789d8
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026112525-paprika-cricket-1873@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 2fd145f8865bb1a6c38a3dc68fa44290008789d8 Mon Sep 17 00:00:00 2001
From: Wahid Khan <[email protected]>
Date: Thu, 5 Nov 2026 23:08:38 +0530
Subject: [PATCH] ksmbd: refuse to read a handle that is not open for reading

smb2_create_open_flags() picks the open mode from the read and write bits of the desired access. FILE_EXECUTE and FILE_READ_ATTRIBUTES select neither, so a request for FILE_WRITE_DATA | FILE_EXECUTE | FILE_READ_ATTRIBUTES opens the file O_WRONLY.

smb2_read() accepts FILE_READ_ATTRIBUTES and ksmbd_vfs_read() accepts FILE_EXECUTE, so a later READ on that handle passes both checks and reaches __kernel_read() on a file that has no FMODE_READ:

  WARNING: fs/read_write.c:518 at __kernel_read
   __kernel_read
   ksmbd_vfs_read
   smb2_read
   handle_ksmbd_work

Any client that can open a file with write access on a share, including a guest session, can trigger it; with panic_on_warn it takes the machine down.

Return STATUS_ACCESS_DENIED when the file is not readable.

Fixes f44158485826 ("cifsd: add file operations")
fs/smb/server/vfs.c +4 -0
index 1f2bc76f0d09..cb3f4f5fe9cf 100644
@@ -367,6 +367,10 @@ int ksmbd_vfs_read(struct ksmbd_work *work, struct ksmbd_file *fp, size_t count,
 	if (ksmbd_stream_fd(fp))
 		return ksmbd_vfs_stream_read(fp, rbuf, pos, count);
 
+	/* The access granted on open can include FILE_EXECUTE for a write-only file */
+	if (!(filp->f_mode & FMODE_READ))
+		return -EACCES;
+
 	if (!fp->is_posix_ctxt) {
 		int ret;
 
maintainer
#1 lore raw

PATCH 1/1 ksmbd: refuse to read a handle that is not open for reading

From: Wahid Khan <[email protected]>

[ Upstream commit 2fd145f8865bb1a6c38a3dc68fa44290008789d8 ]

smb2_create_open_flags() picks the open mode from the read and write bits of the desired access. FILE_EXECUTE and FILE_READ_ATTRIBUTES select neither, so a request for FILE_WRITE_DATA | FILE_EXECUTE | FILE_READ_ATTRIBUTES opens the file O_WRONLY.

smb2_read() accepts FILE_READ_ATTRIBUTES and ksmbd_vfs_read() accepts FILE_EXECUTE, so a later READ on that handle passes both checks and reaches __kernel_read() on a file that has no FMODE_READ:

  WARNING: fs/read_write.c:518 at __kernel_read
   __kernel_read
   ksmbd_vfs_read
   smb2_read
   handle_ksmbd_work

Any client that can open a file with write access on a share, including a guest session, can trigger it; with panic_on_warn it takes the machine down.

Return STATUS_ACCESS_DENIED when the file is not readable.

Fixes f44158485826 ("cifsd: add file operations")
[ sashal: Replaced the fp->is_posix_ctxt check with work->tcon->posix_extensions to match this tree's context. ]
---
 fs/smb/server/vfs.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/smb/server/vfs.c +4 -0
index 54bd3e7012d7b..64178954a54db 100644
@@ -391,6 +391,10 @@ int ksmbd_vfs_read(struct ksmbd_work *work, struct ksmbd_file *fp, size_t count,
 	if (ksmbd_stream_fd(fp))
 		return ksmbd_vfs_stream_read(fp, rbuf, pos, count);
 
+	/* The access granted on open can include FILE_EXECUTE for a write-only file */
+	if (!(filp->f_mode & FMODE_READ))
+		return -EACCES;
+
 	if (!work->tcon->posix_extensions) {
 		int ret;
 
Signature · 1 line
2.53.0