Re: [PATCH] hwmon: fill it with 0 when data size is insufficient

From: Guenter Roeck
Date: Thu Jun 19 2025 - 12:54:54 EST


On 6/19/25 06:37, Edward Adam Davis wrote:
When the data size returned by the sensor is less than IN_BUFFER_SIZE,
it is padded with 0.


The subject is missing the affected driver, and I really very much prefer
actually validating the return data instead of just assuming that it is
ok to fill the buffer with 0. So I'll take Marius' patch instead.

On a side note, please don't send patches as reply to some other e-mail.
That only asks for it to get lost.

Thanks,
Guenter


Reported-by: syzbot+3bbbade4e1a7ab45ca3b@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=3bbbade4e1a7ab45ca3b
Signed-off-by: Edward Adam Davis <eadavis@xxxxxx>
---
drivers/hwmon/corsair-cpro.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/hwmon/corsair-cpro.c b/drivers/hwmon/corsair-cpro.c
index e1a7f7aa7f80..274864e8a8e7 100644
--- a/drivers/hwmon/corsair-cpro.c
+++ b/drivers/hwmon/corsair-cpro.c
@@ -157,6 +157,8 @@ static int ccp_raw_event(struct hid_device *hdev, struct hid_report *report, u8
spin_lock(&ccp->wait_input_report_lock);
if (!completion_done(&ccp->wait_input_report)) {
memcpy(ccp->buffer, data, min(IN_BUFFER_SIZE, size));
+ if (size < IN_BUFFER_SIZE)
+ memset(ccp->buffer + size, 0, IN_BUFFER_SIZE - size);
complete_all(&ccp->wait_input_report);
}
spin_unlock(&ccp->wait_input_report_lock);