Skip to contentSkip to conversation

HID: make arrays usage and value to be the same

PATCH In review Will McVicker 3 participants 10 messages Dec 5, 2020 – Jan 18, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: make arrays usage and value to be the same

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.

---
 drivers/hid/hid-core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/hid/hid-core.c +3 -3
index 56172fe6995c..8a8b2b982f83 100644
@@ -90,7 +90,7 @@ EXPORT_SYMBOL_GPL(hid_register_report);
  * Register a new field for this report.
  */
 
-static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
+static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages)
 {
 	struct hid_field *field;
 
@@ -101,7 +101,7 @@ static struct hid_field *hid_register_field(struct hid_report *report, unsigned
 
 	field = kzalloc((sizeof(struct hid_field) +
 			 usages * sizeof(struct hid_usage) +
-			 values * sizeof(unsigned)), GFP_KERNEL);
+			 usages * sizeof(unsigned)), GFP_KERNEL);
 	if (!field)
 		return NULL;
 
@@ -300,7 +300,7 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign
 	usages = max_t(unsigned, parser->local.usage_index,
 				 parser->global.report_count);
 
-	field = hid_register_field(report, usages, parser->global.report_count);
+	field = hid_register_field(report, usages);
 	if (!field)
 		return 0;
 
Signature · 1 line
2.29.2.576.ga3fc446d84-goog
maintainer
#1 lore raw
Quoted 8 lines · Will McVicker

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().

Quoted 4 lines

To fix this, let's make sure that both the usage and value arrays are the same size.

Any reason not to also add a cc: stable on this?

And, has this always been the case, or was this caused by some specific commit in the past? If so, a "Fixes:" tag is always nice to included.

And finally, as you have a fix for this already, no need to cc:
[email protected] as there's nothing the people there can do about it now :)

thanks,

greg k-h

#2 lore raw
Quoted 9 lines · Greg KH
Quoted 8 lines · Will McVicker

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().

Quoted 6 lines
Quoted 4 lines

To fix this, let's make sure that both the usage and value arrays are the same size.

Any reason not to also add a cc: stable on this?

No reason not to include stable. CC'd here.

Quoted 3 lines

And, has this always been the case, or was this caused by some specific commit in the past? If so, a "Fixes:" tag is always nice to included.

I dug into the history and it's been like this for the past 10 years. So yeah pretty much always like this.

Quoted 3 lines

And finally, as you have a fix for this already, no need to cc:
[email protected] as there's nothing the people there can do about it now :)

Is that short for [email protected]? If yes, then I did include them. If no, do you mind explaining?

Quoted 4 lines

thanks,

greg k-h

maintainer
#3 lore raw
Quoted 21 lines · Will McVicker
Quoted 9 lines · Greg KH
Quoted 8 lines · Will McVicker

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().

Quoted 6 lines
Quoted 4 lines

To fix this, let's make sure that both the usage and value arrays are the same size.

Any reason not to also add a cc: stable on this?

No reason not to include stable. CC'd here.

Quoted 3 lines

And, has this always been the case, or was this caused by some specific commit in the past? If so, a "Fixes:" tag is always nice to included.

Quoted 8 lines

I dug into the history and it's been like this for the past 10 years. So yeah pretty much always like this.

Quoted 3 lines

And finally, as you have a fix for this already, no need to cc:
[email protected] as there's nothing the people there can do about it now :)

Is that short for [email protected]? If yes, then I did include them. If no, do you mind explaining?

Yes, I see you included it, my point was that once you have a patch, there is no need to include this email address as all we do at this address is work to match up a problem with a developer that can create a fix. You already did this, so no need for us to get involved at all! :)

thanks,

greg k-h

#4 lore raw
Quoted 31 lines · Greg KH
Quoted 21 lines · Will McVicker
Quoted 9 lines · Greg KH
Quoted 8 lines · Will McVicker

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().

Quoted 6 lines
Quoted 4 lines

To fix this, let's make sure that both the usage and value arrays are the same size.

Any reason not to also add a cc: stable on this?

No reason not to include stable. CC'd here.

Quoted 3 lines

And, has this always been the case, or was this caused by some specific commit in the past? If so, a "Fixes:" tag is always nice to included.

Quoted 8 lines

I dug into the history and it's been like this for the past 10 years. So yeah pretty much always like this.

Quoted 3 lines

And finally, as you have a fix for this already, no need to cc:
[email protected] as there's nothing the people there can do about it now :)

Is that short for [email protected]? If yes, then I did include them. If no, do you mind explaining?

Quoted 8 lines

Yes, I see you included it, my point was that once you have a patch, there is no need to include this email address as all we do at this address is work to match up a problem with a developer that can create a fix. You already did this, so no need for us to get involved at all! :)

thanks,

greg k-h

Ah okay, thanks for the explanation!

--Will

#5 lore raw
In reply to Will McVicker
Quoted 50 lines · Will McVicker

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.

---
 drivers/hid/hid-core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/hid/hid-core.c +3 -3
index 56172fe6995c..8a8b2b982f83 100644
@@ -90,7 +90,7 @@ EXPORT_SYMBOL_GPL(hid_register_report);
  * Register a new field for this report.
  */
 
-static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
+static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages)
 {
 	struct hid_field *field;
 
@@ -101,7 +101,7 @@ static struct hid_field *hid_register_field(struct hid_report *report, unsigned
 
 	field = kzalloc((sizeof(struct hid_field) +
 			 usages * sizeof(struct hid_usage) +
-			 values * sizeof(unsigned)), GFP_KERNEL);
+			 usages * sizeof(unsigned)), GFP_KERNEL);
 	if (!field)
 		return NULL;
 
@@ -300,7 +300,7 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign
 	usages = max_t(unsigned, parser->local.usage_index,
 				 parser->global.report_count);
 
-	field = hid_register_field(report, usages, parser->global.report_count);
+	field = hid_register_field(report, usages);
 	if (!field)
 		return 0;
 
Signature · 1 line
2.29.2.576.ga3fc446d84-goog

Hi Jiri and Benjamin,

This is a friendly reminder in case this got lost in your inbox.

Thanks,
Will

maintainer
#6 lore raw
Quoted 47 lines · Will McVicker
Quoted 47 lines

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.

---
 drivers/hid/hid-core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/hid/hid-core.c +3 -3
index 56172fe6995c..8a8b2b982f83 100644
@@ -90,7 +90,7 @@ EXPORT_SYMBOL_GPL(hid_register_report);
  * Register a new field for this report.
  */
 
-static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
+static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages)
 {
 	struct hid_field *field;
 
@@ -101,7 +101,7 @@ static struct hid_field *hid_register_field(struct hid_report *report, unsigned
 
 	field = kzalloc((sizeof(struct hid_field) +
 			 usages * sizeof(struct hid_usage) +
-			 values * sizeof(unsigned)), GFP_KERNEL);
+			 usages * sizeof(unsigned)), GFP_KERNEL);
 	if (!field)
 		return NULL;
 
@@ -300,7 +300,7 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign
 	usages = max_t(unsigned, parser->local.usage_index,
 				 parser->global.report_count);
 
-	field = hid_register_field(report, usages, parser->global.report_count);
+	field = hid_register_field(report, usages);
 	if (!field)
 		return 0;
 
Quoted 7 lines
Quoted 3 lines
Signature · 1 line
2.29.2.576.ga3fc446d84-goog

Hi Jiri and Benjamin,

This is a friendly reminder in case this got lost in your inbox.

Hi Will,

I am planning to merge it once the merge window is over.

Signature · 2 lines
Jiri Kosina
SUSE Labs
#7 lore raw

Great! Thanks for the reply.

--Will

Quoted 66 lines · Jiri Kosina
Quoted 47 lines · Will McVicker
Quoted 47 lines

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.

---
 drivers/hid/hid-core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/hid/hid-core.c +3 -3
index 56172fe6995c..8a8b2b982f83 100644
@@ -90,7 +90,7 @@ EXPORT_SYMBOL_GPL(hid_register_report);
  * Register a new field for this report.
  */
 
-static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
+static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages)
 {
    struct hid_field *field;
 
@@ -101,7 +101,7 @@ static struct hid_field *hid_register_field(struct hid_report *report, unsigned
 
    field = kzalloc((sizeof(struct hid_field) +
                     usages * sizeof(struct hid_usage) +
-                    values * sizeof(unsigned)), GFP_KERNEL);
+                    usages * sizeof(unsigned)), GFP_KERNEL);
    if (!field)
            return NULL;
 
@@ -300,7 +300,7 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign
    usages = max_t(unsigned, parser->local.usage_index,
                             parser->global.report_count);
 
-   field = hid_register_field(report, usages, parser->global.report_count);
+   field = hid_register_field(report, usages);
    if (!field)
            return 0;
 
Quoted 7 lines
Quoted 3 lines

--
2.29.2.576.ga3fc446d84-goog

Hi Jiri and Benjamin,

This is a friendly reminder in case this got lost in your inbox.

Hi Will,

I am planning to merge it once the merge window is over.

--
Jiri Kosina
SUSE Labs

#8 lore raw

Hi Jiri,

I noticed this hasn't merged yet. So just sending a friendly reminder.

Thanks,
Will

Quoted 72 lines · Will McVicker

Great! Thanks for the reply.

--Will

Quoted 66 lines · Jiri Kosina
Quoted 47 lines · Will McVicker
Quoted 47 lines

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.

---
 drivers/hid/hid-core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/hid/hid-core.c +3 -3
index 56172fe6995c..8a8b2b982f83 100644
@@ -90,7 +90,7 @@ EXPORT_SYMBOL_GPL(hid_register_report);
  * Register a new field for this report.
  */
 
-static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
+static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages)
 {
    struct hid_field *field;
 
@@ -101,7 +101,7 @@ static struct hid_field *hid_register_field(struct hid_report *report, unsigned
 
    field = kzalloc((sizeof(struct hid_field) +
                     usages * sizeof(struct hid_usage) +
-                    values * sizeof(unsigned)), GFP_KERNEL);
+                    usages * sizeof(unsigned)), GFP_KERNEL);
    if (!field)
            return NULL;
 
@@ -300,7 +300,7 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign
    usages = max_t(unsigned, parser->local.usage_index,
                             parser->global.report_count);
 
-   field = hid_register_field(report, usages, parser->global.report_count);
+   field = hid_register_field(report, usages);
    if (!field)
            return 0;
 
Quoted 7 lines
Quoted 3 lines

--
2.29.2.576.ga3fc446d84-goog

Hi Jiri and Benjamin,

This is a friendly reminder in case this got lost in your inbox.

Hi Will,

I am planning to merge it once the merge window is over.

--
Jiri Kosina
SUSE Labs

maintainer
#9 lore raw
In reply to Will McVicker
Quoted 10 lines · Will McVicker

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.

Now applied, sorry for the delay and thanks for the fix.

Signature · 2 lines
Jiri Kosina
SUSE Labs