ksmbd: OOB read in ksmbd_validate_name_reconnect() via cross-share durable reconnect
Subsystems (2)
Hi,
In ksmbd_validate_name_reconnect() (vfs_cache.c:1701) the name check does:
pathname = kmalloc(PATH_MAX, KSMBD_DEFAULT_GFP); /* :1707 */ ab_pathname = d_path(&fp->filp->f_path, pathname, PATH_MAX); /* :1711 */ ... if (name && strcmp(&ab_pathname[share->path_sz + 1], name)) /* :1717 */
d_path() fills the buffer from the end, so the string ends at pathname + PATH_MAX - 1. Nothing checks that ab_pathname is longer than share->path_sz + 1, or that it starts with share->path. If the file's real path is shorter, strcmp() reads past the end of the 4096-byte buffer; the distance isshare->path_sz + 1 - strlen(ab_pathname), which the client influences through the choice of share.
The path can be shorter because the durable fp is not bound to its original share: session_fd_check() clears fp->conn/fp->tcon (vfs_cache.c:1647-1648), the reconnect looks the fp up globally by persistent id or CreateGuid, and smb2_check_durable_oplock() validates it against the *reconnecting* tree's share (smb2pdu.c:3773 -> oplock.c:2407) - it checks owner, ClientGUID and lease key, but never the share. So:
1. open a file on share A (short path) with a durable handle,
2. drop the connection (the fp survives as durable-disconnected),
3. reconnect to share B (long path), send CREATE with DURABLE_RECONNECT and the original ids,
and strcmp() reads roughly (share B path length) bytes past the kmalloc buffer. With a long enough share B path that is likely unmapped, so probably a kernel oops - a remote DoS. If it lands on a mapped page, the strcmp result is also a byte-equality oracle on adjacent heap: the reconnect succeeds exactly when the out-of-bounds string equals the requested name.
There is also a 1-byte over-read in the same-share case when the durable fp is the share root (strlen(ab_pathname) == share->path_sz, so the index lands exactly one past the buffer).
Preconditions, as far as I can tell: durable handles enabled (KSMBD_GLOBAL_FLAG_DURABLE_HANDLE) and the attacker can reach two shares with different path lengths.
Suggested fix: check the prefix before indexing - strlen(ab_pathname) > share->path_sz && ab_pathname[share->path_sz] == '/' - and ideally bind the durable fp to its original share at reconnect. Happy to write this up as a patch if that sounds right.
From code reading only, my second report here - if I've misread something, please tell me.
Thanks,
Dairui Zhang
Namjae Jeon
maintainerQuoted 4 lines
Suggested fix: check the prefix before indexing -
strlen(ab_pathname)>share->path_sz&& ab_pathname[share->path_sz] == '/' - and ideally bind the durable fp to its original share at reconnect. Happy to write this up as a patch if that sounds right.
Okay, Please send the patch to the list and me.
Thanks.