Skip to content

Commit a827da9

Browse files
HID: make arrays usage and value to be the same
jira VULN-7717 cve CVE-2021-0512 commit-author Will McVicker <willmcvicker@google.com> commit ed9be64 The HID subsystem allows an "HID report field" to have a different number of "values" and "usages" when it is allocated. When a field struct is created, the size of the usage array is guaranteed to be at least as large as the values array, but it may be larger. This leads to a potential out-of-bounds write in __hidinput_change_resolution_multipliers() and an out-of-bounds read in hidinput_count_leds(). To fix this, let's make sure that both the usage and value arrays are the same size. Cc: stable@vger.kernel.org Signed-off-by: Will McVicker <willmcvicker@google.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz> (cherry picked from commit ed9be64) Signed-off-by: Pratham Patel <ppatel@ciq.com>
1 parent 12a4d42 commit a827da9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/hid/hid-core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ EXPORT_SYMBOL_GPL(hid_register_report);
9090
* Register a new field for this report.
9191
*/
9292

93-
static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
93+
static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages)
9494
{
9595
struct hid_field *field;
9696

@@ -101,7 +101,7 @@ static struct hid_field *hid_register_field(struct hid_report *report, unsigned
101101

102102
field = kzalloc((sizeof(struct hid_field) +
103103
usages * sizeof(struct hid_usage) +
104-
values * sizeof(unsigned)), GFP_KERNEL);
104+
usages * sizeof(unsigned)), GFP_KERNEL);
105105
if (!field)
106106
return NULL;
107107

@@ -253,7 +253,7 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign
253253
usages = max_t(unsigned, parser->local.usage_index,
254254
parser->global.report_count);
255255

256-
field = hid_register_field(report, usages, parser->global.report_count);
256+
field = hid_register_field(report, usages);
257257
if (!field)
258258
return 0;
259259

0 commit comments

Comments
 (0)