Skip to content

nimble/host: Fix race in HCI ACL TX outstanding packets counter#2199

Merged
sjanc merged 1 commit intoapache:masterfrom
rojer:fix_hci_pkts_race
Apr 3, 2026
Merged

nimble/host: Fix race in HCI ACL TX outstanding packets counter#2199
sjanc merged 1 commit intoapache:masterfrom
rojer:fix_hci_pkts_race

Conversation

@rojer
Copy link
Copy Markdown
Contributor

@rojer rojer commented Mar 31, 2026

The outstanding packets counter (bhc_outstanding_pkts / avail_pkts) was decremented after ble_hs_tx_data() returned. However, by that point the controller may have already processed the packet and sent a Number of Completed Packets event, which increments avail_pkts. This race can cause avail_pkts to momentarily exceed the controller maximum, leading to buffer overflows.

Move the counter update before ble_hs_tx_data() and roll back on error.

Forward-port of espressif@f5136d2

Copy link
Copy Markdown
Contributor

@sjanc sjanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks ok, could you just update commit message to fit 72 char limit to make compliance CI happy?

The outstanding packets counter (bhc_outstanding_pkts / avail_pkts)
was decremented after ble_hs_tx_data() returned. However, by that
point the controller may have already processed the packet and sent
a Number of Completed Packets event, which increments avail_pkts.
This race can cause avail_pkts to momentarily exceed the controller
maximum, leading to buffer overflows.

Move the counter update before ble_hs_tx_data() and roll back on
error.

Forward-port of espressif@f5136d2b3
@rojer
Copy link
Copy Markdown
Contributor Author

rojer commented Apr 3, 2026

looks ok, could you just update commit message to fit 72 char limit to make compliance CI happy?

done

@sjanc sjanc merged commit 55c2d46 into apache:master Apr 3, 2026
25 checks passed
@rojer rojer deleted the fix_hci_pkts_race branch April 4, 2026 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants