Skip to content

Commit 6b83b03

Browse files
phx0fersmfrench
authored andcommitted
smb: client: fix integer underflow in receive_encrypted_read()
In receive_encrypted_read(), the length of data to read from the socket is computed as: len = le32_to_cpu(tr_hdr->OriginalMessageSize) - server->vals->read_rsp_size; OriginalMessageSize comes from the server's transform header and is untrusted. If a malicious server sends a value smaller than read_rsp_size, the unsigned subtraction wraps to a very large value (~4GB). This value is then passed to netfs_alloc_folioq_buffer() and cifs_read_iter_from_socket(), causing either a massive allocation attempt that fails with -ENOMEM (DoS), or under extreme memory pressure, potential heap corruption. Fix by adding a check that OriginalMessageSize is at least read_rsp_size before the subtraction. On failure, jump to discard_data to drain the remaining PDU from the socket, preventing desync of subsequent reads on the connection. Signed-off-by: Dudu Lu <phx0fer@gmail.com> Reviewed-by: Enzo Matsumiya <ematsumiya@suse.de> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent abce659 commit 6b83b03

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

fs/smb/client/smb2ops.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4943,6 +4943,14 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
49434943
goto free_dw;
49444944
server->total_read += rc;
49454945

4946+
if (le32_to_cpu(tr_hdr->OriginalMessageSize) <
4947+
server->vals->read_rsp_size) {
4948+
cifs_server_dbg(VFS, "OriginalMessageSize %u too small for read response (%zu)\n",
4949+
le32_to_cpu(tr_hdr->OriginalMessageSize),
4950+
server->vals->read_rsp_size);
4951+
rc = -EINVAL;
4952+
goto discard_data;
4953+
}
49464954
len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
49474955
server->vals->read_rsp_size;
49484956
dw->len = len;

0 commit comments

Comments
 (0)