Skip to contentSkip to conversation

Bluetooth: hci_h4: Fix padding calculation error within h4_recv_buf()

PATCH Superseded Zijun Hu 1 participant 2 messages Nov 10, 2021 – Nov 14, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Zijun Hu

author
#0 lore raw

PATCH 1/1 Bluetooth: hci_h4: Fix padding calculation error within h4_recv_buf()

From: Zijun Hu <[email protected]>

it is erroneous to calculate padding by subtracting length of type indication from skb->len, it will cause data analysis error for alignment which is greater than 1, so fixed by adding length of type indication with skb->len.

---
 drivers/bluetooth/hci_h4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/bluetooth/hci_h4.c +2 -2
index 4b3b14a34794..1d0cdf023243 100644
@@ -252,7 +252,7 @@ struct sk_buff *h4_recv_buf(struct hci_dev *hdev, struct sk_buff *skb,
 			}
 
 			if (!dlen) {
-				hu->padding = (skb->len - 1) % alignment;
+				hu->padding = (skb->len + 1) % alignment;
 				hu->padding = (alignment - hu->padding) % alignment;
 
 				/* No more data, complete frame */
@@ -260,7 +260,7 @@ struct sk_buff *h4_recv_buf(struct hci_dev *hdev, struct sk_buff *skb,
 				skb = NULL;
 			}
 		} else {
-			hu->padding = (skb->len - 1) % alignment;
+			hu->padding = (skb->len + 1) % alignment;
 			hu->padding = (alignment - hu->padding) % alignment;
 
 			/* Complete frame */
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
author
#1 lore raw

could you please code review for this patch?

Quoted 35 lines · Zijun Hu

From: Zijun Hu <[email protected]>

it is erroneous to calculate padding by subtracting length of type indication from skb->len, it will cause data analysis error for alignment which is greater than 1, so fixed by adding length of type indication with skb->len.

---
 drivers/bluetooth/hci_h4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/bluetooth/hci_h4.c +2 -2
index 4b3b14a34794..1d0cdf023243 100644
@@ -252,7 +252,7 @@ struct sk_buff *h4_recv_buf(struct hci_dev *hdev, struct sk_buff *skb,
 			}
 
 			if (!dlen) {
-				hu->padding = (skb->len - 1) % alignment;
+				hu->padding = (skb->len + 1) % alignment;
 				hu->padding = (alignment - hu->padding) % alignment;
 
 				/* No more data, complete frame */
@@ -260,7 +260,7 @@ struct sk_buff *h4_recv_buf(struct hci_dev *hdev, struct sk_buff *skb,
 				skb = NULL;
 			}
 		} else {
-			hu->padding = (skb->len - 1) % alignment;
+			hu->padding = (skb->len + 1) % alignment;
 			hu->padding = (alignment - hu->padding) % alignment;
 
 			/* Complete frame */