Skip to content

Commit 3782c0d

Browse files
pietroborrelloJiri Kosina
authored andcommitted
HID: betop: check shape of output reports
betopff_init() only checks the total sum of the report counts for each report field to be at least 4, but hid_betopff_play() expects 4 report fields. A device advertising an output report with one field and 4 report counts would pass the check but crash the kernel with a NULL pointer dereference in hid_betopff_play(). Fixes: 52cd778 ("HID: betop: add drivers/hid/hid-betopff.c") Signed-off-by: Pietro Borrello <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent ccf1e16 commit 3782c0d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

drivers/hid/hid-betopff.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ static int betopff_init(struct hid_device *hid)
6060
struct list_head *report_list =
6161
&hid->report_enum[HID_OUTPUT_REPORT].report_list;
6262
struct input_dev *dev;
63-
int field_count = 0;
6463
int error;
6564
int i, j;
6665

@@ -86,19 +85,21 @@ static int betopff_init(struct hid_device *hid)
8685
* -----------------------------------------
8786
* Do init them with default value.
8887
*/
88+
if (report->maxfield < 4) {
89+
hid_err(hid, "not enough fields in the report: %d\n",
90+
report->maxfield);
91+
return -ENODEV;
92+
}
8993
for (i = 0; i < report->maxfield; i++) {
94+
if (report->field[i]->report_count < 1) {
95+
hid_err(hid, "no values in the field\n");
96+
return -ENODEV;
97+
}
9098
for (j = 0; j < report->field[i]->report_count; j++) {
9199
report->field[i]->value[j] = 0x00;
92-
field_count++;
93100
}
94101
}
95102

96-
if (field_count < 4) {
97-
hid_err(hid, "not enough fields in the report: %d\n",
98-
field_count);
99-
return -ENODEV;
100-
}
101-
102103
betopff = kzalloc(sizeof(*betopff), GFP_KERNEL);
103104
if (!betopff)
104105
return -ENOMEM;

0 commit comments

Comments
 (0)