Skip to content

Commit 37ba3c3

Browse files
jwrdegoedeJiri Kosina
authored andcommitted
HID: intel_ish-hid: Move header size check to inside the loop
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 <[email protected]> Reviewed-by: Benjamin Tissoires <[email protected]> Acked-by: Srinivas Pandruvada <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 097b8f6 commit 37ba3c3

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

drivers/hid/intel-ish-hid/ishtp-hid-client.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,21 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf,
7777
struct ishtp_cl_data *client_data = hid_ishtp_cl->client_data;
7878
int curr_hid_dev = client_data->cur_hid_dev;
7979

80-
if (data_len < sizeof(struct hostif_msg_hdr)) {
81-
dev_err(&client_data->cl_device->dev,
82-
"[hid-ish]: error, received %u which is less than data header %u\n",
83-
(unsigned int)data_len,
84-
(unsigned int)sizeof(struct hostif_msg_hdr));
85-
++client_data->bad_recv_cnt;
86-
ish_hw_reset(hid_ishtp_cl->dev);
87-
return;
88-
}
89-
9080
payload = recv_buf + sizeof(struct hostif_msg_hdr);
9181
total_len = data_len;
9282
cur_pos = 0;
9383

9484
do {
85+
if (cur_pos + sizeof(struct hostif_msg) > total_len) {
86+
dev_err(&client_data->cl_device->dev,
87+
"[hid-ish]: error, received %u which is less than data header %u\n",
88+
(unsigned int)data_len,
89+
(unsigned int)sizeof(struct hostif_msg_hdr));
90+
++client_data->bad_recv_cnt;
91+
ish_hw_reset(hid_ishtp_cl->dev);
92+
break;
93+
}
94+
9595
recv_msg = (struct hostif_msg *)(recv_buf + cur_pos);
9696
payload_len = recv_msg->hdr.size;
9797

0 commit comments

Comments
 (0)