Skip to content

Commit 07e0ab8

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 eb4736a commit 07e0ab8

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
@@ -5189,6 +5189,12 @@ receive_encrypted_standard(struct TCP_Server_Info *server,
51895189
one_more:
51905190
shdr = (struct smb2_hdr *)buf;
51915191
next_cmd = le32_to_cpu(shdr->NextCommand);
5192+
5193+
if (*num_mids >= MAX_COMPOUND) {
5194+
cifs_server_dbg(VFS, "too many PDUs in compound\n");
5195+
return -1;
5196+
}
5197+
51925198
if (next_cmd) {
51935199
if (WARN_ON_ONCE(next_cmd > pdu_length))
51945200
return -1;
@@ -5212,10 +5218,6 @@ receive_encrypted_standard(struct TCP_Server_Info *server,
52125218
mid_entry->resp_buf_size = server->pdu_size;
52135219
}
52145220

5215-
if (*num_mids >= MAX_COMPOUND) {
5216-
cifs_server_dbg(VFS, "too many PDUs in compound\n");
5217-
return -1;
5218-
}
52195221
bufs[*num_mids] = buf;
52205222
mids[(*num_mids)++] = mid_entry;
52215223

0 commit comments

Comments
 (0)