Skip to content

Commit 495a4f0

Browse files
MisterZ42groeck
authored andcommitted
hwmon: (corsair-cpro) Validate the size of the received input buffer
Add buffer_recv_size to store the size of the received bytes. Validate buffer_recv_size in send_usb_cmd(). Reported-by: [email protected] Closes: https://lore.kernel.org/linux-hwmon/[email protected] Fixes: 40c3a44 ("hwmon: add Corsair Commander Pro driver") Signed-off-by: Marius Zachmann <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 347e9f5 commit 495a4f0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/hwmon/corsair-cpro.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ struct ccp_device {
8989
struct mutex mutex; /* whenever buffer is used, lock before send_usb_cmd */
9090
u8 *cmd_buffer;
9191
u8 *buffer;
92+
int buffer_recv_size; /* number of received bytes in buffer */
9293
int target[6];
9394
DECLARE_BITMAP(temp_cnct, NUM_TEMP_SENSORS);
9495
DECLARE_BITMAP(fan_cnct, NUM_FANS);
@@ -146,6 +147,9 @@ static int send_usb_cmd(struct ccp_device *ccp, u8 command, u8 byte1, u8 byte2,
146147
if (!t)
147148
return -ETIMEDOUT;
148149

150+
if (ccp->buffer_recv_size != IN_BUFFER_SIZE)
151+
return -EPROTO;
152+
149153
return ccp_get_errno(ccp);
150154
}
151155

@@ -157,6 +161,7 @@ static int ccp_raw_event(struct hid_device *hdev, struct hid_report *report, u8
157161
spin_lock(&ccp->wait_input_report_lock);
158162
if (!completion_done(&ccp->wait_input_report)) {
159163
memcpy(ccp->buffer, data, min(IN_BUFFER_SIZE, size));
164+
ccp->buffer_recv_size = size;
160165
complete_all(&ccp->wait_input_report);
161166
}
162167
spin_unlock(&ccp->wait_input_report_lock);

0 commit comments

Comments
 (0)