Commit eec04ea1 authored by Paulo Alcantara's avatar Paulo Alcantara Committed by Steve French

smb: client: fix OOB in receive_encrypted_standard()

Fix potential OOB in receive_encrypted_standard() if server returned a
large shdr->NextCommand that would end up writing off the end of
@next_buffer.

Fixes: b24df3e3 ("cifs: update receive_encrypted_standard to handle compounded responses")
Cc: stable@vger.kernel.org
Reported-by: default avatarRobert Morris <rtm@csail.mit.edu>
Signed-off-by: default avatarPaulo Alcantara (SUSE) <pc@manguebit.com>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent a39b6ac3
...@@ -4943,6 +4943,7 @@ receive_encrypted_standard(struct TCP_Server_Info *server, ...@@ -4943,6 +4943,7 @@ receive_encrypted_standard(struct TCP_Server_Info *server,
struct smb2_hdr *shdr; struct smb2_hdr *shdr;
unsigned int pdu_length = server->pdu_size; unsigned int pdu_length = server->pdu_size;
unsigned int buf_size; unsigned int buf_size;
unsigned int next_cmd;
struct mid_q_entry *mid_entry; struct mid_q_entry *mid_entry;
int next_is_large; int next_is_large;
char *next_buffer = NULL; char *next_buffer = NULL;
...@@ -4971,14 +4972,15 @@ receive_encrypted_standard(struct TCP_Server_Info *server, ...@@ -4971,14 +4972,15 @@ receive_encrypted_standard(struct TCP_Server_Info *server,
next_is_large = server->large_buf; next_is_large = server->large_buf;
one_more: one_more:
shdr = (struct smb2_hdr *)buf; shdr = (struct smb2_hdr *)buf;
if (shdr->NextCommand) { next_cmd = le32_to_cpu(shdr->NextCommand);
if (next_cmd) {
if (WARN_ON_ONCE(next_cmd > pdu_length))
return -1;
if (next_is_large) if (next_is_large)
next_buffer = (char *)cifs_buf_get(); next_buffer = (char *)cifs_buf_get();
else else
next_buffer = (char *)cifs_small_buf_get(); next_buffer = (char *)cifs_small_buf_get();
memcpy(next_buffer, memcpy(next_buffer, buf + next_cmd, pdu_length - next_cmd);
buf + le32_to_cpu(shdr->NextCommand),
pdu_length - le32_to_cpu(shdr->NextCommand));
} }
mid_entry = smb2_find_mid(server, buf); mid_entry = smb2_find_mid(server, buf);
...@@ -5002,8 +5004,8 @@ receive_encrypted_standard(struct TCP_Server_Info *server, ...@@ -5002,8 +5004,8 @@ receive_encrypted_standard(struct TCP_Server_Info *server,
else else
ret = cifs_handle_standard(server, mid_entry); ret = cifs_handle_standard(server, mid_entry);
if (ret == 0 && shdr->NextCommand) { if (ret == 0 && next_cmd) {
pdu_length -= le32_to_cpu(shdr->NextCommand); pdu_length -= next_cmd;
server->large_buf = next_is_large; server->large_buf = next_is_large;
if (next_is_large) if (next_is_large)
server->bigbuf = buf = next_buffer; server->bigbuf = buf = next_buffer;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment