Skip to content

Commit 2c93d14

Browse files
VudentzSherryYang1
authored andcommitted
Bluetooth: hci_event: Detect if HCI_EV_NUM_COMP_PKTS is unbalanced
[ Upstream commit 15bf2c6391bafb14a3020d06ec0761bce0803463 ] This attempts to detect if HCI_EV_NUM_COMP_PKTS contain an unbalanced (more than currently considered outstanding) number of packets otherwise it could cause the hcon->sent to underflow and loop around breaking the tracking of the outstanding packets pending acknowledgment. Fixes: f428091 ("Bluetooth: Simplify num_comp_pkts_evt function") Signed-off-by: Luiz Augusto von Dentz <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit dc205c0883a298367ac25ca972046678145ab188) Signed-off-by: Sherry Yang <[email protected]>
1 parent 4b163af commit 2c93d14

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

net/bluetooth/hci_event.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3681,7 +3681,17 @@ static void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb)
36813681
if (!conn)
36823682
continue;
36833683

3684-
conn->sent -= count;
3684+
/* Check if there is really enough packets outstanding before
3685+
* attempting to decrease the sent counter otherwise it could
3686+
* underflow..
3687+
*/
3688+
if (conn->sent >= count) {
3689+
conn->sent -= count;
3690+
} else {
3691+
bt_dev_warn(hdev, "hcon %p sent %u < count %u",
3692+
conn, conn->sent, count);
3693+
conn->sent = 0;
3694+
}
36853695

36863696
switch (conn->type) {
36873697
case ACL_LINK:

0 commit comments

Comments
 (0)