Skip to contentSkip to conversation

HID: steam: Prevent NULL pointer dereference in steam_{recv,send}_report

PATCH RESEND In review Lee Jones 2 participants 4 messages Aug 3, 2022 – Sep 12, 2022

Subsystems (2)
lore
Share & tools
lore

Lee Jones

author
#0 lore raw

PATCH RESEND 1/1 HID: steam: Prevent NULL pointer dereference in steam_{recv,send}_report

It is possible for a malicious device to forgo submitting a Feature Report. The HID Steam driver presently makes no prevision for this and de-references the 'struct hid_report' pointer obtained from the HID devices without first checking its validity. Let's change that.

Cc Jiri Kosina <[email protected]>
Cc Benjamin Tissoires <[email protected]>
Fixes c164d6abf3841 ("HID: add driver for Valve Steam Controller")
---
 drivers/hid/hid-steam.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/hid/hid-steam.c +10 -0
index a3b151b29bd71..fc616db4231bb 100644
@@ -134,6 +134,11 @@ static int steam_recv_report(struct steam_device *steam,
 	int ret;
 
 	r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0];
+	if (!r) {
+		hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted -  nothing to read\n");
+		return -EINVAL;
+	}
+
 	if (hid_report_len(r) < 64)
 		return -EINVAL;
 
@@ -165,6 +170,11 @@ static int steam_send_report(struct steam_device *steam,
 	int ret;
 
 	r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0];
+	if (!r) {
+		hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted -  nothing to read\n");
+		return -EINVAL;
+	}
+
 	if (hid_report_len(r) < 64)
 		return -EINVAL;
 
Signature · 1 line
2.37.1.455.g008518b4e5-goog
author
#1 lore raw
Quoted 4 lines · Lee Jones

It is possible for a malicious device to forgo submitting a Feature Report. The HID Steam driver presently makes no prevision for this and de-references the 'struct hid_report' pointer obtained from the HID devices without first checking its validity. Let's change that.

This patch has been floating around since the beginning of July.

It fixes a real issue which was found by creating a virtual (software based) malicious device and registering it as a HID device.

There is nothing preventing a real attacker from creating a H/W version of the device in order to instigate an out-of-bounds read, potentially leading to a data leak.

Would someone be kind enough to review please?

Quoted 37 lines
Cc Jiri Kosina <[email protected]>
Cc Benjamin Tissoires <[email protected]>
Fixes c164d6abf3841 ("HID: add driver for Valve Steam Controller")
---
 drivers/hid/hid-steam.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/hid/hid-steam.c +10 -0
index a3b151b29bd71..fc616db4231bb 100644
@@ -134,6 +134,11 @@ static int steam_recv_report(struct steam_device *steam,
 	int ret;
 
 	r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0];
+	if (!r) {
+		hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted -  nothing to read\n");
+		return -EINVAL;
+	}
+
 	if (hid_report_len(r) < 64)
 		return -EINVAL;
 
@@ -165,6 +170,11 @@ static int steam_send_report(struct steam_device *steam,
 	int ret;
 
 	r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0];
+	if (!r) {
+		hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted -  nothing to read\n");
+		return -EINVAL;
+	}
+
 	if (hid_report_len(r) < 64)
 		return -EINVAL;
 
Signature · 1 line
Lee Jones [李琼斯]
#2 lore raw

Hi

Quoted 9 lines · Lee Jones
Quoted 4 lines · Lee Jones

It is possible for a malicious device to forgo submitting a Feature Report. The HID Steam driver presently makes no prevision for this and de-references the 'struct hid_report' pointer obtained from the HID devices without first checking its validity. Let's change that.

This patch has been floating around since the beginning of July.

Quoted 8 lines

It fixes a real issue which was found by creating a virtual (software based) malicious device and registering it as a HID device.

There is nothing preventing a real attacker from creating a H/W version of the device in order to instigate an out-of-bounds read, potentially leading to a data leak.

Would someone be kind enough to review please?

AFACT this patch has been applied by Jiri on the 25th of August already.

Is a review still needed in this case?

Cheers,

Silvan

Quoted 38 lines
Quoted 38 lines
Cc Jiri Kosina <[email protected]>
Cc Benjamin Tissoires <[email protected]>
Fixes c164d6abf3841 ("HID: add driver for Valve Steam Controller")
---
 drivers/hid/hid-steam.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/hid/hid-steam.c +10 -0
index a3b151b29bd71..fc616db4231bb 100644
@@ -134,6 +134,11 @@ static int steam_recv_report(struct steam_device *steam,
 	int ret;
 
 	r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0];
+	if (!r) {
+		hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted -  nothing to read\n");
+		return -EINVAL;
+	}
+
 	if (hid_report_len(r) < 64)
 		return -EINVAL;
 
@@ -165,6 +170,11 @@ static int steam_send_report(struct steam_device *steam,
 	int ret;
 
 	r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0];
+	if (!r) {
+		hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted -  nothing to read\n");
+		return -EINVAL;
+	}
+
 	if (hid_report_len(r) < 64)
 		return -EINVAL;
 
author
#3 lore raw
Quoted 15 lines · Silvan Jegen

Hi

Quoted 12 lines · Lee Jones
Quoted 4 lines · Lee Jones

It is possible for a malicious device to forgo submitting a Feature Report. The HID Steam driver presently makes no prevision for this and de-references the 'struct hid_report' pointer obtained from the HID devices without first checking its validity. Let's change that.

This patch has been floating around since the beginning of July.

It fixes a real issue which was found by creating a virtual (software based) malicious device and registering it as a HID device.

Quoted 7 lines
Quoted 5 lines

There is nothing preventing a real attacker from creating a H/W version of the device in order to instigate an out-of-bounds read, potentially leading to a data leak.

Would someone be kind enough to review please?

AFACT this patch has been applied by Jiri on the 25th of August already.

Ah, I missed his reply to the original patch.

Quoted 1 line

Is a review still needed in this case?

Certainly not. Thank you for your reply.

Signature · 1 line
Lee Jones [李琼斯]