Skip to contentSkip to conversation

HID: pxrc: reject short input reports

PATCH New Yousef Alhouseen 2 participants 2 messages Jun 28

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

PATCH 1/1 HID: pxrc: reject short input reports

pxrc_raw_event() unconditionally reads and writes data[7], although a malformed USB device can submit a shorter input report. The raw-event callback runs before the HID core expands short reports to the size from the report descriptor, so this accesses beyond the received buffer.

Ignore reports that do not contain all eight controller axes.

Fixes acc3e34613da ("HID: Add driver for PhoenixRC Flight Controller")
---
 drivers/hid/hid-pxrc.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/hid/hid-pxrc.c +3 -0
index 71fe0c06ddcd..e3755d8b85c2 100644
@@ -55,6 +55,9 @@ static int pxrc_raw_event(struct hid_device *hdev, struct hid_report *report,
 {
 	struct pxrc_priv *priv = hid_get_drvdata(hdev);
 
+	if (size < 8)
+		return 0;
+
 	if (priv->alternate)
 		priv->slider = data[7];
 	else
Signature · 1 line
2.54.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Incomplete fix / logic error: returning 0 for short reports does not drop the report. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Incomplete fix / logic error: returning 0 for short reports does not drop the report. --

commit 601e7ac29ed99f9b83b5ad4f7ade423528b08e79
Author: Yousef Alhouseen <[email protected]>

HID: pxrc: reject short input reports

This commit fixes an out-of-bounds access in pxrc_raw_event() by checking if the incoming input report is shorter than 8 bytes and returning early.

drivers/hid/hid-pxrc.c static int pxrc_raw_event(struct hid_device *hdev, struct hid_report *report, · line 59

Quoted 10 lines
drivers/hid/hid-pxrc.c +2 -0
index 71fe0c06ddcdf..e3755d8b85c22 100644
@@ -55,6 +55,9 @@ static int pxrc_raw_event(struct hid_device *hdev, struct hid_report *report,
 {
 	struct pxrc_priv *priv = hid_get_drvdata(hdev);
 
+	if (size < 8)
+		return 0;

[Severity: Medium]
Does returning 0 here achieve the goal of ignoring the report?

When the driver receives a short report and pxrc_raw_event() returns 0, it signals success to the HID core. Looking at __hid_input_report(), if the raw_event callback returns >= 0, the core falls through to hid_report_raw_event(). This will zero-pad the missing bytes and dispatch the report, which can result in erratic zero-values for the missing axes in userspace applications.

Should this return a negative error code (like -EINVAL) to ensure the malformed report is completely dropped by the core instead of padded?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1