Skip to content

Commit

Permalink
CIFS: Fix null pointer deref during read resp processing
Browse files Browse the repository at this point in the history
Currently during receiving a read response mid->resp_buf can be
NULL when it is being passed to cifs_discard_remaining_data() from
cifs_readv_discard(). Fix it by always passing server->smallbuf
instead and initializing mid->resp_buf at the end of read response
processing.

Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
CC: Stable <stable@vger.kernel.org>
Acked-by: Sachin Prabhu <sprabhu@redhat.com>
Signed-off-by: Steve French <smfrench@gmail.com>
  • Loading branch information
piastry authored and smfrench committed Apr 11, 2017
1 parent c08e611 commit 350be25
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
3 changes: 1 addition & 2 deletions fs/cifs/cifsproto.h
Expand Up @@ -79,8 +79,7 @@ extern void cifs_delete_mid(struct mid_q_entry *mid);
extern void cifs_wake_up_task(struct mid_q_entry *mid);
extern int cifs_handle_standard(struct TCP_Server_Info *server,
struct mid_q_entry *mid);
extern int cifs_discard_remaining_data(struct TCP_Server_Info *server,
char *buf);
extern int cifs_discard_remaining_data(struct TCP_Server_Info *server);
extern int cifs_call_async(struct TCP_Server_Info *server,
struct smb_rqst *rqst,
mid_receive_t *receive, mid_callback_t *callback,
Expand Down
15 changes: 8 additions & 7 deletions fs/cifs/cifssmb.c
Expand Up @@ -1400,9 +1400,9 @@ CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, int *oplock,
* current bigbuf.
*/
int
cifs_discard_remaining_data(struct TCP_Server_Info *server, char *buf)
cifs_discard_remaining_data(struct TCP_Server_Info *server)
{
unsigned int rfclen = get_rfc1002_length(buf);
unsigned int rfclen = get_rfc1002_length(server->smallbuf);
int remaining = rfclen + 4 - server->total_read;

while (remaining > 0) {
Expand All @@ -1426,8 +1426,10 @@ cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid)
int length;
struct cifs_readdata *rdata = mid->callback_data;

length = cifs_discard_remaining_data(server, mid->resp_buf);
length = cifs_discard_remaining_data(server);
dequeue_mid(mid, rdata->result);
mid->resp_buf = server->smallbuf;
server->smallbuf = NULL;
return length;
}

Expand Down Expand Up @@ -1459,7 +1461,7 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)

if (server->ops->is_status_pending &&
server->ops->is_status_pending(buf, server, 0)) {
cifs_discard_remaining_data(server, buf);
cifs_discard_remaining_data(server);
return -1;
}

Expand Down Expand Up @@ -1519,9 +1521,6 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
cifs_dbg(FYI, "0: iov_base=%p iov_len=%u\n",
rdata->iov[0].iov_base, server->total_read);

mid->resp_buf = server->smallbuf;
server->smallbuf = NULL;

/* how much data is in the response? */
data_len = server->ops->read_data_length(buf);
if (data_offset + data_len > buflen) {
Expand All @@ -1544,6 +1543,8 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
return cifs_readv_discard(server, mid);

dequeue_mid(mid, false);
mid->resp_buf = server->smallbuf;
server->smallbuf = NULL;
return length;
}

Expand Down
4 changes: 2 additions & 2 deletions fs/cifs/smb2ops.c
Expand Up @@ -2195,7 +2195,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid)
if (rc)
goto free_pages;

rc = cifs_discard_remaining_data(server, buf);
rc = cifs_discard_remaining_data(server);
if (rc)
goto free_pages;

Expand All @@ -2221,7 +2221,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid)
kfree(pages);
return rc;
discard_data:
cifs_discard_remaining_data(server, buf);
cifs_discard_remaining_data(server);
goto free_pages;
}

Expand Down

0 comments on commit 350be25

Please sign in to comment.