ksmbd: validate DataOffset in smb2_write_pipe()
Subsystems (2)
PATCH 1/1 ksmbd: validate DataOffset in smb2_write_pipe()
The check of DataOffset in smb2_write_pipe() is insufficient. If DataOffset is 0 or smaller than offsetof(struct smb2_write_req, Buffer), data_buf will point to the SMB2 header instead of the actual data buffer, leading to out-of-bounds read.
This is the same issue that was fixed in smb2_write() by commit ac60778b87e4 ("ksmbd: prevent out of bound read for SMB2_WRITE"), but the fix was not applied to smb2_write_pipe().
Add a check to ensure DataOffset is at least offsetof(struct smb2_write_req, Buffer) to prevent this issue.
--- fs/smb/server/smb2pdu.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/smb/server/smb2pdu.c +6 -0
@@ -6932,6 +6932,12 @@ static noinline int smb2_write_pipe(struct ksmbd_work *work) goto out; } +if (le16_to_cpu (req->DataOffset) < + offsetof(struct smb2_write_req , Buffer)) { + err = -EINVAL ; + goto out; + } + data_buf = (char *)(((char *)&req->hdr.ProtocolId) +le16_to_cpu (req->DataOffset));
Signature · 1 line
2.34.1
Namjae Jeon
maintainerQuoted 5 lines · Kery Qi
The check of DataOffset in
smb2_write_pipe()is insufficient. If DataOffset is 0 or smaller thanoffsetof(struct smb2_write_req, Buffer),data_bufwill point to the SMB2 header instead of the actual data buffer, leading to out-of-bounds read.
How can out-of-bounds occur when the previous checks ensure that the length does not exceed the request buffer?