Skip to content

Commit 297243e

Browse files
Haoxiang Ligregkh
authored andcommitted
smb: client: Fix next buffer leak in receive_encrypted_standard()
commit 1c6267a upstream. receive_encrypted_standard() allocates next_buffer before checking whether the number of compound PDUs already reached MAX_COMPOUND. If the limit check fails, the function returns immediately and the newly allocated next_buffer is not assigned to server->smallbuf/server->bigbuf, making it leaked. Move the MAX_COMPOUND check before allocating next_buffer. Fixes: b24df3e ("cifs: update receive_encrypted_standard to handle compounded responses") Cc: stable@vger.kernel.org Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com> Signed-off-by: Steve French <stfrench@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d15d831 commit 297243e

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

fs/smb/client/smb2ops.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5096,6 +5096,12 @@ receive_encrypted_standard(struct TCP_Server_Info *server,
50965096
one_more:
50975097
shdr = (struct smb2_hdr *)buf;
50985098
next_cmd = le32_to_cpu(shdr->NextCommand);
5099+
5100+
if (*num_mids >= MAX_COMPOUND) {
5101+
cifs_server_dbg(VFS, "too many PDUs in compound\n");
5102+
return -1;
5103+
}
5104+
50995105
if (next_cmd) {
51005106
if (WARN_ON_ONCE(next_cmd > pdu_length))
51015107
return -1;
@@ -5119,10 +5125,6 @@ receive_encrypted_standard(struct TCP_Server_Info *server,
51195125
mid_entry->resp_buf_size = server->pdu_size;
51205126
}
51215127

5122-
if (*num_mids >= MAX_COMPOUND) {
5123-
cifs_server_dbg(VFS, "too many PDUs in compound\n");
5124-
return -1;
5125-
}
51265128
bufs[*num_mids] = buf;
51275129
mids[(*num_mids)++] = mid_entry;
51285130

0 commit comments

Comments
 (0)