Skip to content

Commit

Permalink
HID: intel_ish-hid: Move header size check to inside the loop
Browse files Browse the repository at this point in the history
With the headersize check outside of the loop, the second time through
the loop the: "payload_len = recv_msg->hdr.size;" statement may deref
recv_msg while it is pointing outside of our input buffer.

Move the headersize check to inside the loop to fix this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Hans de Goede authored and Jiri Kosina committed Apr 25, 2018
1 parent 097b8f6 commit 37ba3c3
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions drivers/hid/intel-ish-hid/ishtp-hid-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,21 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf,
struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;
int curr_hid_dev = client_data->cur_hid_dev;

if (data_len < sizeof(struct hostif_msg_hdr)) {
dev_err(&client_data->cl_device->dev,
"[hid-ish]: error, received %u which is less than data header %u\n",
(unsigned int)data_len,
(unsigned int)sizeof(struct hostif_msg_hdr));
++client_data->bad_recv_cnt;
ish_hw_reset(hid_ishtp_cl->dev);
return;
}

payload = recv_buf + sizeof(struct hostif_msg_hdr);
total_len = data_len;
cur_pos = 0;

do {
if (cur_pos + sizeof(struct hostif_msg) > total_len) {
dev_err(&client_data->cl_device->dev,
"[hid-ish]: error, received %u which is less than data header %u\n",
(unsigned int)data_len,
(unsigned int)sizeof(struct hostif_msg_hdr));
++client_data->bad_recv_cnt;
ish_hw_reset(hid_ishtp_cl->dev);
break;
}

recv_msg = (struct hostif_msg *)(recv_buf + cur_pos);
payload_len = recv_msg->hdr.size;

Expand Down

0 comments on commit 37ba3c3

Please sign in to comment.