Skip to content

Commit

Permalink
SMB3: Resolve data corruption of TCP server info fields
Browse files Browse the repository at this point in the history
commit 6259301 upstream.

TCP server info field server->total_read is modified in parallel by
demultiplex thread and decrypt offload worker thread. server->total_read
is used in calculation to discard the remaining data of PDU which is
not read into memory.

Because of parallel modification, server->total_read can get corrupted
and can result in discarding the valid data of next PDU.

Signed-off-by: Rohith Surabattula <rohiths@microsoft.com>
Reviewed-by: Aurelien Aptel <aaptel@suse.com>
Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>
CC: Stable <stable@vger.kernel.org> #5.4+
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
rohiths-msft authored and gregkh committed Oct 29, 2020
1 parent c7c2f24 commit 1b890b8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions fs/cifs/smb2ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -4103,7 +4103,8 @@ smb3_is_transform_hdr(void *buf)
static int
decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
unsigned int buf_data_size, struct page **pages,
unsigned int npages, unsigned int page_data_size)
unsigned int npages, unsigned int page_data_size,
bool is_offloaded)
{
struct kvec iov[2];
struct smb_rqst rqst = {NULL};
Expand All @@ -4129,7 +4130,8 @@ decrypt_raw_data(struct TCP_Server_Info *server, char *buf,

memmove(buf, iov[1].iov_base, buf_data_size);

server->total_read = buf_data_size + page_data_size;
if (!is_offloaded)
server->total_read = buf_data_size + page_data_size;

return rc;
}
Expand Down Expand Up @@ -4342,7 +4344,7 @@ static void smb2_decrypt_offload(struct work_struct *work)
struct mid_q_entry *mid;

rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
dw->ppages, dw->npages, dw->len);
dw->ppages, dw->npages, dw->len, true);
if (rc) {
cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
goto free_pages;
Expand Down Expand Up @@ -4448,7 +4450,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,

non_offloaded_decrypt:
rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
pages, npages, len);
pages, npages, len, false);
if (rc)
goto free_pages;

Expand Down Expand Up @@ -4504,7 +4506,7 @@ receive_encrypted_standard(struct TCP_Server_Info *server,
server->total_read += length;

buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0);
length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0, false);
if (length)
return length;

Expand Down

0 comments on commit 1b890b8

Please sign in to comment.