nuttx/wireless/bluetooth
AlmAck 5e92a05dc4 wireless/bluetooth: fix inverted MTU cap in bt_conn_send()
bt_conn_send() splits an outgoing L2CAP PDU into HCI ACL fragments no
larger than g_btdev.le_mtu, the controller's HCI ACL data packet length.
The first fragment caps its length correctly:

  len = remaining;
  if (len > g_btdev.le_mtu)
    {
      len = g_btdev.le_mtu;
    }

The continuation loop below uses '<' instead of '>', so a continuation
shorter than le_mtu has its length raised to le_mtu rather than left
alone.  Both len and remaining are uint16_t, which turns a wrong length
into an underflow:

With le_mtu 251 and a 300-byte PDU, the first fragment takes 251 bytes
and leaves remaining == 49.  The loop then raises len from 49 to 251, so

  memcpy(bt_buf_extend(buf, len), ptr, len);

reads 202 bytes past the end of the source, and

  remaining -= len;

evaluates 49 - 251 as a uint16_t, wrapping to 65334.  On the next
iteration len is 65334, which is not less than le_mtu, so it survives
the cap.  bt_buf_extend() carries only a DEBUGASSERT on tailroom, so
with assertions disabled it adds 65334 to buf->len and returns, and the
memcpy writes 64 KB into a pooled buffer sized for a few hundred bytes.

Only the last fragment of a multi-fragment PDU is normally shorter than
le_mtu, so the first fragmented transmission triggers it.

Signed-off-by: AlmAck <gluca86@gmail.com>
2026-08-30 10:48:18 -03:00
..
bt_atomic.h nuttx/atomic: replace atomic_fetch_xxx with atomic_xxx just like zephyr 2026-08-24 13:20:45 +08:00
bt_att.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
bt_att.h wireless: migrate to SPDX identifier 2024-09-11 19:49:34 +08:00
bt_buf.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
bt_buf.h wireless: migrate to SPDX identifier 2024-09-11 19:49:34 +08:00
bt_conn.c wireless/bluetooth: fix inverted MTU cap in bt_conn_send() 2026-08-30 10:48:18 -03:00
bt_conn.h style: Fix "the the" typo across the codebase. 2026-03-23 11:07:49 +01:00
bt_gatt.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
bt_hcicore.c wireless/bluetooth/bt_hcicore.c: Balance conn and buffer refs in hci_acl(). 2026-08-15 11:51:19 +08:00
bt_hcicore.h bluetooth: set bt_driver_register/unregister to xx_set/unset 2024-10-17 18:09:32 +08:00
bt_ioctl.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
bt_ioctl.h wireless: migrate to SPDX identifier 2024-09-11 19:49:34 +08:00
bt_keys.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
bt_keys.h Bluetooth SMP: added support for Legacy pairing (MITM) with passkey 2025-05-28 21:49:08 +08:00
bt_l2cap.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
bt_l2cap.h wireless: migrate to SPDX identifier 2024-09-11 19:49:34 +08:00
bt_netdev.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
bt_queue.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
bt_queue.h wireless: migrate to SPDX identifier 2024-09-11 19:49:34 +08:00
bt_services.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
bt_smp.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
bt_smp.h Bluetooth SMP: added support for Legacy pairing (MITM) with passkey 2025-05-28 21:49:08 +08:00
bt_uuid.c wireless: migrate to SPDX identifier 2024-09-11 19:49:34 +08:00
CMakeLists.txt bt_atomic: use atomic macro to replace wireless/bluetooth/bt_atomic.c 2024-12-04 13:54:45 +08:00
Kconfig Bluetooth SMP: added support for Legacy pairing (MITM) with passkey 2025-05-28 21:49:08 +08:00
Make.defs bt_atomic: use atomic macro to replace wireless/bluetooth/bt_atomic.c 2024-12-04 13:54:45 +08:00