ksmbd: reject SMB2 read on a file opened without read access
Subsystems (3)
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
@@ -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
Namjae Jeon
maintainerQuoted 14 lines · Hyunjung Ko
smb2_create_open_flags()maps a DesiredAccess that hasFILE_EXECUTEbut noFILE_READ_DATA(e.g.FILE_EXECUTE|FILE_WRITE_DATA) toO_WRONLY, sinceFILE_READ_DESIRED_ACCESS_LEdoes not includeFILE_EXECUTE_LE. The resulting file is opened withoutFMODE_READ, yetfp->daccessstill carriesFILE_EXECUTE_LE.
ksmbd_vfs_read()only checksfp->daccess& (FILE_READ_DATA_LE|FILE_EXECUTE_LE), so such a handle passes the access check and reacheskernel_read(), which hitsWARN_ON_ONCE(!(file->f_mode & FMODE_READ))in__kernel_read(). A remote client can therefore trigger a kernel warning (and a crash underpanic_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.
Signed-off-by Hyunjung Ko <[email protected]>
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").
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 hasFILE_EXECUTEbut noFILE_READ_DATA(e.g.FILE_EXECUTE|FILE_WRITE_DATA) toO_WRONLY, sinceFILE_READ_DESIRED_ACCESS_LEdoes not includeFILE_EXECUTE_LE. The resulting file is opened withoutFMODE_READ, yetfp->daccessstill carriesFILE_EXECUTE_LE.
ksmbd_vfs_read()only checksfp->daccess& (FILE_READ_DATA_LE|FILE_EXECUTE_LE), so such a handle passes the access check and reacheskernel_read(), which hitsWARN_ON_ONCE(!(file->f_mode & FMODE_READ))in__kernel_read(). A remote client can therefore trigger a kernel warning (and a crash underpanic_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.
Signed-off-by Hyunjung Ko <[email protected]>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").