Skip to content

Commit a58c5af

Browse files
mjbommarsmfrench
authored andcommitted
smb: client: fix OOB read in smb2_ioctl_query_info QUERY_INFO path
smb2_ioctl_query_info() has two response-copy branches: PASSTHRU_FSCTL and the default QUERY_INFO path. The QUERY_INFO branch clamps qi.input_buffer_length to the server-reported OutputBufferLength and then copies qi.input_buffer_length bytes from qi_rsp->Buffer to userspace, but it never verifies that the flexible-array payload actually fits within rsp_iov[1].iov_len. A malicious server can return OutputBufferLength larger than the actual QUERY_INFO response, causing copy_to_user() to walk past the response buffer and expose adjacent kernel heap to userspace. Guard the QUERY_INFO copy with a bounds check on the actual Buffer payload. Use struct_size(qi_rsp, Buffer, qi.input_buffer_length) rather than an open-coded addition so the guard cannot overflow on 32-bit builds. Fixes: f5778c3 ("SMB3: Allow SMB3 FSCTL queries to be sent to server from tools") Cc: stable@vger.kernel.org Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com> Assisted-by: Claude:claude-opus-4-6 Assisted-by: Codex:gpt-5-4 Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 90ea1d0 commit a58c5af

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

fs/smb/client/smb2ops.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,12 @@ smb2_ioctl_query_info(const unsigned int xid,
17831783
qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
17841784
if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
17851785
qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1786+
if (qi.input_buffer_length > 0 &&
1787+
struct_size(qi_rsp, Buffer, qi.input_buffer_length) >
1788+
rsp_iov[1].iov_len) {
1789+
rc = -EFAULT;
1790+
goto out;
1791+
}
17861792
if (copy_to_user(&pqi->input_buffer_length,
17871793
&qi.input_buffer_length,
17881794
sizeof(qi.input_buffer_length))) {

0 commit comments

Comments
 (0)