Bluetooth: L2CAP: validate frame length before control and FCS access

l2cap_data_rcv() unpacks either a two-byte or four-byte control field
without first ensuring that it is present. A short ERTM or streaming-mode
frame can therefore cause an out-of-bounds read.

There is a second short-frame case when CRC16 is enabled. After the
control field is pulled, l2cap_check_fcs() subtracts two from skb->len
without checking it. If fewer than two bytes remain, the subtraction
wraps; skb_trim() leaves the buffer unchanged and the subsequent FCS
load reads past the logical end of the frame.

Validate that the frame contains both its control field and, when
enabled, its FCS before either field is accessed.

Fixes: 1c2acffb76 ("Bluetooth: Add initial support for ERTM packets transfers")
Fixes: fcc203c30d ("Bluetooth: Add support for FCS option to L2CAP")
Cc: stable@vger.kernel.org
Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Aldo Ariel Panzardo 2026-09-15 13:02:39 -03:00 committed by Luiz Augusto von Dentz
parent 4c94557dd0
commit 6c78a213d9

View File

@ -6702,9 +6702,17 @@ static int l2cap_stream_rx(struct l2cap_chan *chan, struct l2cap_ctrl *control,
static int l2cap_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)
{
struct l2cap_ctrl *control = &bt_cb(skb)->l2cap;
u16 len;
u16 len, min_len;
u8 event;
min_len = test_bit(FLAG_EXT_CTRL, &chan->flags) ?
L2CAP_EXT_CTRL_SIZE : L2CAP_ENH_CTRL_SIZE;
if (chan->fcs == L2CAP_FCS_CRC16)
min_len += L2CAP_FCS_SIZE;
if (skb->len < min_len)
goto drop;
__unpack_control(chan, skb);
len = skb->len;