Sending Bluetooth L2CAP messages after reconnecting sometimes leads to crashes due to uninitalized net_buf callback #76738
Labels
area: Bluetooth Host
Bluetooth Host (excluding BR/EDR)
area: Bluetooth
bug
The issue is a bug, or the PR is fixing a bug
priority: low
Low impact/importance bug
Describe the bug
When sending Bluetooth L2CAP messages over a dynamic channel (with
bt_l2cap_chan_send()
), the callback closure in thenet_buf
userdata is never initialized (unlike with static channels). This leads tobt_conn_tx_processor()
reading out an invalid callback pointer (this manifests as 0x1 on my device) which later gets called, triggering a crash intx_notify()
when calling the callback.The TODO comment "add sdu_sent callback on last PDU" in
conn.c:1039
seems relevant, since the exact problem is that this PDU has never had its callback set. I don't know why that is though, sincel2cap_data_pull
should add the callback for dynamic channels, but this doesn't seem to happen in all cases.The issue goes away when I manually zero the
net_buf
user_data before passing the buffer tobt_l2cap_chan_send()
.To Reproduce
bt_conn_le_create()
)bt_l2cap_chan_connect()
)chan_ops.sent
callback is called) (bt_l2cap_chan_send()
)I don't have a small enough sample yet that I can share here since this occurred in an internal code base, but if necessary I can try and strip it down.
Expected behavior
Zephyr should not crash.
Impact
Annoyance, leads to occasional power cycles needed
Logs and console output
These logs where done with warn log level and certain log messages patched to be WRN instead of DBG since with debug log level lead to a lot of log output being dropped due to buffer overruns.
The crash dump link register points to
/home/ferdinand/Documents/Work/UWB/UDK1/zephyrproject/zephyr/subsys/bluetooth/host/conn.c:299
, which means this crash happened why trying to call the invalidcb
.Logging patch:
Environment (please complete the following information):
Additional context
Target:
nrf52840dk/nrf52840
Config (
prj.conf
):The text was updated successfully, but these errors were encountered: