Skip to contentSkip to conversation

Bluetooth: HIDP: fix missing length checks in hidp_input_report()

PATCH Superseded Muhammad Bilal 5 participants 9 messages May 17 – May 21

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

PATCH 1/1 Bluetooth: HIDP: fix missing length checks in hidp_input_report()

hidp_input_report() reads keyboard and mouse payload data from an skb without first verifying that skb->len contains enough data.

hidp_recv_intr_frame() pulls the 1-byte HIDP header before dispatching to hidp_input_report(). If a paired device sends a truncated packet, the handler reads beyond the valid skb data, resulting in an out-of-bounds read of skb data.
The OOB bytes may be interpreted as phantom key presses or spurious mouse movement.

Add a check that skb->len is non-zero before the type switch, and per-report-type minimum length checks before accessing the payload.

---
 net/bluetooth/hidp/core.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
net/bluetooth/hidp/core.c +16 -3
index 976f91eeb..03838a6ff 100644
@@ -179,12 +179,22 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb)
 {
 	struct input_dev *dev = session->input;
 	unsigned char *keys = session->keys;
-	unsigned char *udata = skb->data + 1;
-	signed char *sdata = skb->data + 1;
-	int i, size = skb->len - 1;
+	unsigned char *udata;
+	signed char *sdata;
+	int i, size;
+
+	if (!skb->len)
+		return;
+
+	udata = skb->data + 1;
+	sdata = skb->data + 1;
+	size = skb->len - 1;
 
 	switch (skb->data[0]) {
 	case 0x01:	/* Keyboard report */
+		if (size < 8)
+			break;
+
 		for (i = 0; i < 8; i++)
 			input_report_key(dev, hidp_keycode[i + 224], (udata[0] >> i) & 1);
 
@@ -213,6 +223,9 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb)
 		break;
 
 	case 0x02:	/* Mouse report */
+		if (size < 3)
+			break;
+
 		input_report_key(dev, BTN_LEFT,   sdata[0] & 0x01);
 		input_report_key(dev, BTN_RIGHT,  sdata[0] & 0x02);
 		input_report_key(dev, BTN_MIDDLE, sdata[0] & 0x04);
Signature · 1 line
2.54.0
#1 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1096211

---Test result---

Test Summary:

CheckPatch                    PASS      0.61 seconds
GitLint                       PASS      0.25 seconds
SubjectPrefix                 PASS      0.09 seconds
BuildKernel                   PASS      25.57 seconds
CheckAllWarning               PASS      27.88 seconds
CheckSparse                   PASS      26.78 seconds
BuildKernel32                 PASS      24.79 seconds
TestRunnerSetup               PASS      530.22 seconds
TestRunner_l2cap-tester       PASS      378.32 seconds
TestRunner_iso-tester         PASS      596.24 seconds
TestRunner_bnep-tester        PASS      18.62 seconds
TestRunner_mgmt-tester        PASS      2023.70 seconds
TestRunner_rfcomm-tester      PASS      63.42 seconds
TestRunner_sco-tester         PASS      141.24 seconds
TestRunner_ioctl-tester       PASS      133.47 seconds
TestRunner_mesh-tester        PASS      59.92 seconds
TestRunner_smp-tester         PASS      17.98 seconds
TestRunner_userchan-tester    PASS      19.13 seconds
TestRunner_6lowpan-tester     PASS      51.17 seconds
IncrementalBuild              PASS      23.75 seconds

https://github.com/bluez/bluetooth-next/pull/206

---
Regards,
Linux Bluetooth

maintainer
#2 lore raw
In reply to Muhammad Bilal
Quoted 62 lines · Muhammad Bilal

hidp_input_report() reads keyboard and mouse payload data from an skb without first verifying that skb->len contains enough data.

hidp_recv_intr_frame() pulls the 1-byte HIDP header before dispatching to hidp_input_report(). If a paired device sends a truncated packet, the handler reads beyond the valid skb data, resulting in an out-of-bounds read of skb data.
The OOB bytes may be interpreted as phantom key presses or spurious mouse movement.

Add a check that skb->len is non-zero before the type switch, and per-report-type minimum length checks before accessing the payload.

---
 net/bluetooth/hidp/core.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
net/bluetooth/hidp/core.c +16 -3
index 976f91eeb..03838a6ff 100644
@@ -179,12 +179,22 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb)
 {
 	struct input_dev *dev = session->input;
 	unsigned char *keys = session->keys;
-	unsigned char *udata = skb->data + 1;
-	signed char *sdata = skb->data + 1;
-	int i, size = skb->len - 1;
+	unsigned char *udata;
+	signed char *sdata;
+	int i, size;
+
+	if (!skb->len)
+		return;
+
+	udata = skb->data + 1;
+	sdata = skb->data + 1;
+	size = skb->len - 1;
 
 	switch (skb->data[0]) {
 	case 0x01:	/* Keyboard report */
+		if (size < 8)
+			break;
+
 		for (i = 0; i < 8; i++)
 			input_report_key(dev, hidp_keycode[i + 224], (udata[0] >> i) & 1);
 
@@ -213,6 +223,9 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb)
 		break;
 
 	case 0x02:	/* Mouse report */
+		if (size < 3)
+			break;
+
 		input_report_key(dev, BTN_LEFT,   sdata[0] & 0x01);
 		input_report_key(dev, BTN_RIGHT,  sdata[0] & 0x02);
 		input_report_key(dev, BTN_MIDDLE, sdata[0] & 0x04);
Signature · 1 line
2.54.0

<formletter>

This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

#3 lore raw

PATCH v2 1/1 Bluetooth: HIDP: fix missing length checks in hidp_input_report()

In reply to Muhammad Bilal

hidp_input_report() reads keyboard and mouse payload data from an skb without first verifying that skb->len contains enough data.

hidp_recv_intr_frame() pulls the 1-byte HIDP header before dispatching to hidp_input_report(). If a paired device sends a truncated packet, the handler reads beyond the valid skb data, resulting in an out-of-bounds read of skb data. The OOB bytes may be interpreted as phantom key presses or spurious mouse movement.

Add a check that skb->len is non-zero before the type switch, and per-report-type minimum length checks before accessing the payload.

---
 net/bluetooth/hidp/core.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
net/bluetooth/hidp/core.c +16 -3
index 976f91eeb..03838a6ff 100644
@@ -179,12 +179,22 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb)
 {
 	struct input_dev *dev = session->input;
 	unsigned char *keys = session->keys;
-	unsigned char *udata = skb->data + 1;
-	signed char *sdata = skb->data + 1;
-	int i, size = skb->len - 1;
+	unsigned char *udata;
+	signed char *sdata;
+	int i, size;
+
+	if (!skb->len)
+		return;
+
+	udata = skb->data + 1;
+	sdata = skb->data + 1;
+	size = skb->len - 1;
 
 	switch (skb->data[0]) {
 	case 0x01:	/* Keyboard report */
+		if (size < 8)
+			break;
+
 		for (i = 0; i < 8; i++)
 			input_report_key(dev, hidp_keycode[i + 224], (udata[0] >> i) & 1);
 
@@ -213,6 +223,9 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb)
 		break;
 
 	case 0x02:	/* Mouse report */
+		if (size < 3)
+			break;
+
 		input_report_key(dev, BTN_LEFT,   sdata[0] & 0x01);
 		input_report_key(dev, BTN_RIGHT,  sdata[0] & 0x02);
 		input_report_key(dev, BTN_MIDDLE, sdata[0] & 0x04);
Signature · 1 line
2.54.0
#4 lore raw

Hi Muhammad,

Quoted 30 lines · Muhammad Bilal

hidp_input_report() reads keyboard and mouse payload data from an skb without first verifying that skb->len contains enough data.

hidp_recv_intr_frame() pulls the 1-byte HIDP header before dispatching to hidp_input_report(). If a paired device sends a truncated packet, the handler reads beyond the valid skb data, resulting in an out-of-bounds read of skb data. The OOB bytes may be interpreted as phantom key presses or spurious mouse movement.

Add a check that skb->len is non-zero before the type switch, and per-report-type minimum length checks before accessing the payload.

---
 net/bluetooth/hidp/core.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
net/bluetooth/hidp/core.c +0 -3
index 976f91eeb..03838a6ff 100644
@@ -179,12 +179,22 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb)
 {
        struct input_dev *dev = session->input;
        unsigned char *keys = session->keys;
-       unsigned char *udata = skb->data + 1;
-       signed char *sdata = skb->data + 1;
-       int i, size = skb->len - 1;

net/bluetooth/hidp/core.c static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb) · line 191

Quoted 10 lines
net/bluetooth/hidp/core.c +10 -0
+       unsigned char *udata;
+       signed char *sdata;
+       int i, size;
+
+       if (!skb->len)
+               return;
+
+       udata = skb->data + 1;
+       sdata = skb->data + 1;
+       size = skb->len - 1;

If you use skb_pull_data, you won't need to use pointer arithmetic, or store the actual size.

Quoted 22 lines
net/bluetooth/hidp/core.c +6 -1
        switch (skb->data[0]) {
        case 0x01:      /* Keyboard report */
+               if (size < 8)
+                       break;
+
                for (i = 0; i < 8; i++)
                        input_report_key(dev, hidp_keycode[i + 224], (udata[0] >> i) & 1);
 
@@ -213,6 +223,9 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb)
                break;
 
        case 0x02:      /* Mouse report */
+               if (size < 3)
+                       break;
+
                input_report_key(dev, BTN_LEFT,   sdata[0] & 0x01);
                input_report_key(dev, BTN_RIGHT,  sdata[0] & 0x02);
                input_report_key(dev, BTN_MIDDLE, sdata[0] & 0x04);
--

2.54.0

Signature · 1 line
Luiz Augusto von Dentz
#5 lore raw

PATCH v3 1/1 Bluetooth: HIDP: fix missing length checks in hidp_input_report()

hidp_input_report() reads keyboard and mouse payload data from an skb without first verifying that skb->len contains enough data.

hidp_recv_intr_frame() pulls the 1-byte HIDP header before dispatching to hidp_input_report(). If a paired device sends a truncated packet, the handler reads beyond the valid skb data, resulting in an out-of-bounds read of skb data. The OOB bytes may be interpreted as phantom key presses or spurious mouse movement.

Replace the open-coded length tracking and pointer arithmetic with skb_pull_data() calls. skb_pull_data() returns NULL if the requested bytes are not present, eliminating the need for a manual size variable and the separate skb->len guard.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

---
v3:
- Replace manual length checks and pointer arithmetic with skb_pull_data() per Luiz's review
v2:
- Add Cc: [email protected] per Greg KH's note

---
 net/bluetooth/hidp/core.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
net/bluetooth/hidp/core.c +18 -5
index 976f91eeb..70344bd32 100644
@@ -179,12 +179,21 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb)
 {
 	struct input_dev *dev = session->input;
 	unsigned char *keys = session->keys;
-	unsigned char *udata = skb->data + 1;
-	signed char *sdata = skb->data + 1;
-	int i, size = skb->len - 1;
+	unsigned char *udata;
+	signed char *sdata;
+	u8 *hdr;
+	int i;
+
+	hdr = skb_pull_data(skb, 1);
+	if (!hdr)
+		return;
 
-	switch (skb->data[0]) {
+	switch (*hdr) {
 	case 0x01:	/* Keyboard report */
+		udata = skb_pull_data(skb, 8);
+		if (!udata)
+			break;
+
 		for (i = 0; i < 8; i++)
 			input_report_key(dev, hidp_keycode[i + 224], (udata[0] >> i) & 1);
 
@@ -213,6 +222,10 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb)
 		break;
 
 	case 0x02:	/* Mouse report */
+		sdata = skb_pull_data(skb, 3);
+		if (!sdata)
+			break;
+
 		input_report_key(dev, BTN_LEFT,   sdata[0] & 0x01);
 		input_report_key(dev, BTN_RIGHT,  sdata[0] & 0x02);
 		input_report_key(dev, BTN_MIDDLE, sdata[0] & 0x04);
@@ -222,7 +235,7 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb)
 		input_report_rel(dev, REL_X, sdata[1]);
 		input_report_rel(dev, REL_Y, sdata[2]);
 
-		if (size > 3)
+		if (skb->len > 0)
 			input_report_rel(dev, REL_WHEEL, sdata[3]);
 		break;
 	}
Signature · 1 line
2.54.0
#6 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1098338

---Test result---

Test Summary:

CheckPatch                    PASS      0.74 seconds
GitLint                       PASS      0.33 seconds
SubjectPrefix                 PASS      0.12 seconds
BuildKernel                   PASS      25.49 seconds
CheckAllWarning               PASS      28.49 seconds
CheckSparse                   PASS      26.31 seconds
BuildKernel32                 PASS      24.53 seconds
TestRunnerSetup               PASS      525.22 seconds
TestRunner_l2cap-tester       PASS      378.59 seconds
TestRunner_iso-tester         PASS      597.04 seconds
TestRunner_bnep-tester        PASS      19.00 seconds
TestRunner_mgmt-tester        PASS      2023.48 seconds
TestRunner_rfcomm-tester      PASS      63.40 seconds
TestRunner_sco-tester         PASS      141.63 seconds
TestRunner_ioctl-tester       PASS      133.58 seconds
TestRunner_mesh-tester        PASS      60.44 seconds
TestRunner_smp-tester         PASS      17.83 seconds
TestRunner_userchan-tester    PASS      19.21 seconds
TestRunner_6lowpan-tester     PASS      50.92 seconds
IncrementalBuild              PASS      24.01 seconds

https://github.com/bluez/bluetooth-next/pull/224

---
Regards,
Linux Bluetooth

#7 lore raw
In reply to Muhammad Bilal
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 10 lines · On Wed, 20 May 2026 18:56:43 -0400 you wrote:

hidp_input_report() reads keyboard and mouse payload data from an skb without first verifying that skb->len contains enough data.

hidp_recv_intr_frame() pulls the 1-byte HIDP header before dispatching to hidp_input_report(). If a paired device sends a truncated packet, the handler reads beyond the valid skb data, resulting in an out-of-bounds read of skb data. The OOB bytes may be interpreted as phantom key presses or spurious mouse movement.

[...]

Here is the summary with links:
- [v3] Bluetooth: HIDP: fix missing length checks in hidp_input_report()

    https://git.kernel.org/bluetooth/bluetooth-next/c/6522ecbcd122

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#8 lore raw
In reply to Muhammad Bilal

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1098310

---Test result---

Test Summary:

CheckPatch                    FAIL      0.65 seconds
GitLint                       PASS      0.27 seconds
SubjectPrefix                 PASS      0.10 seconds
BuildKernel                   PASS      25.15 seconds
CheckAllWarning               PASS      28.02 seconds
CheckSparse                   PASS      27.24 seconds
BuildKernel32                 PASS      26.55 seconds
TestRunnerSetup               PASS      541.52 seconds
TestRunner_l2cap-tester       PASS      378.34 seconds
TestRunner_iso-tester         PASS      597.47 seconds
TestRunner_bnep-tester        PASS      18.47 seconds
TestRunner_mgmt-tester        PASS      2023.12 seconds
TestRunner_rfcomm-tester      PASS      63.46 seconds
TestRunner_sco-tester         PASS      141.48 seconds
TestRunner_ioctl-tester       PASS      133.21 seconds
TestRunner_mesh-tester        PASS      59.62 seconds
TestRunner_smp-tester         PASS      17.73 seconds
TestRunner_userchan-tester    PASS      19.12 seconds
TestRunner_6lowpan-tester     PASS      51.01 seconds
IncrementalBuild              PASS      26.59 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[v2] Bluetooth: HIDP: fix missing length checks in hidp_input_report()
WARNING: The commit message has 'stable@', perhaps it also needs a 'Fixes:' tag?

total: 0 errors, 1 warnings, 0 checks, 34 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/patch/14585274.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

https://github.com/bluez/bluetooth-next/pull/223

---
Regards,
Linux Bluetooth