Skip to contentSkip to conversation

ksmbd: reject SMB2 read on a file opened without read access

PATCH In review Hyunjung Ko 2 participants 3 messages Nov 17

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ksmbd: reject SMB2 read on a file opened without read access

smb2_create_open_flags() maps a DesiredAccess that has FILE_EXECUTE but no FILE_READ_DATA (e.g. FILE_EXECUTE | FILE_WRITE_DATA) to O_WRONLY, since FILE_READ_DESIRED_ACCESS_LE does not include FILE_EXECUTE_LE. The resulting file is opened without FMODE_READ, yet fp->daccess still carries FILE_EXECUTE_LE.

ksmbd_vfs_read() only checks fp->daccess & (FILE_READ_DATA_LE | FILE_EXECUTE_LE), so such a handle passes the access check and reaches kernel_read(), which hits WARN_ON_ONCE(!(file->f_mode & FMODE_READ)) in __kernel_read(). A remote client can therefore trigger a kernel warning (and a crash under panic_on_warn) by opening a file for execute+write and issuing a read.

Reject the read when the underlying file was not opened for reading.

---
 fs/smb/server/vfs.c | 4 ++++
 1 file changed, 4 insertions(+)
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;
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 14 lines · Hyunjung Ko

smb2_create_open_flags() maps a DesiredAccess that has FILE_EXECUTE but no FILE_READ_DATA (e.g. FILE_EXECUTE | FILE_WRITE_DATA) to O_WRONLY, since FILE_READ_DESIRED_ACCESS_LE does not include FILE_EXECUTE_LE. The resulting file is opened without FMODE_READ, yet fp->daccess still carries FILE_EXECUTE_LE.

ksmbd_vfs_read() only checks fp->daccess & (FILE_READ_DATA_LE | FILE_EXECUTE_LE), so such a handle passes the access check and reaches kernel_read(), which hits WARN_ON_ONCE(!(file->f_mode & FMODE_READ)) in __kernel_read(). A remote client can therefore trigger a kernel warning (and a crash under panic_on_warn) by opening a file for execute+write and issuing a read.

Quoted 4 lines

Reject the read when the underlying file was not opened for reading.

Thanks for the patch. The same change has already been applied as commit 2fd145f8865b ("ksmbd: refuse to read a handle that is not open for reading").

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/fs/smb/server?id=2fd145f8865bb1a6c38a3dc68fa44290008789d8

author
#2 lore raw

Thanks, I missed that one. Please ignore this patch.

2026년 11월 17일 (화) 오후 7:35, Namjae Jeon <[email protected]>님이 작성:

Quoted 25 lines · Hyunjung Ko
Quoted 14 lines

smb2_create_open_flags() maps a DesiredAccess that has FILE_EXECUTE but no FILE_READ_DATA (e.g. FILE_EXECUTE | FILE_WRITE_DATA) to O_WRONLY, since FILE_READ_DESIRED_ACCESS_LE does not include FILE_EXECUTE_LE. The resulting file is opened without FMODE_READ, yet fp->daccess still carries FILE_EXECUTE_LE.

ksmbd_vfs_read() only checks fp->daccess & (FILE_READ_DATA_LE | FILE_EXECUTE_LE), so such a handle passes the access check and reaches kernel_read(), which hits WARN_ON_ONCE(!(file->f_mode & FMODE_READ)) in __kernel_read(). A remote client can therefore trigger a kernel warning (and a crash under panic_on_warn) by opening a file for execute+write and issuing a read.

Quoted 4 lines

Reject the read when the underlying file was not opened for reading.

Thanks for the patch. The same change has already been applied as commit 2fd145f8865b ("ksmbd: refuse to read a handle that is not open for reading").

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/fs/smb/server?id=2fd145f8865bb1a6c38a3dc68fa44290008789d8