Skip to content

Commit 25f420a

Browse files
V4belVudentz
authored andcommitted
Bluetooth: L2CAP: Fix ERTM re-init and zero pdu_len infinite loop
l2cap_config_req() processes CONFIG_REQ for channels in BT_CONNECTED state to support L2CAP reconfiguration (e.g. MTU changes). However, since both CONF_INPUT_DONE and CONF_OUTPUT_DONE are already set from the initial configuration, the reconfiguration path falls through to l2cap_ertm_init(), which re-initializes tx_q, srej_q, srej_list, and retrans_list without freeing the previous allocations and sets chan->sdu to NULL without freeing the existing skb. This leaks all previously allocated ERTM resources. Additionally, l2cap_parse_conf_req() does not validate the minimum value of remote_mps derived from the RFC max_pdu_size option. A zero value propagates to l2cap_segment_sdu() where pdu_len becomes zero, causing the while loop to never terminate since len is never decremented, exhausting all available memory. Fix the double-init by skipping l2cap_ertm_init() and l2cap_chan_ready() when the channel is already in BT_CONNECTED state, while still allowing the reconfiguration parameters to be updated through l2cap_parse_conf_req(). Also add a pdu_len zero check in l2cap_segment_sdu() as a safeguard. Fixes: 96298f6 ("Bluetooth: L2CAP: handle l2cap config request during open state") Signed-off-by: Hyunwoo Kim <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 00fdebb commit 25f420a

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

net/bluetooth/l2cap_core.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,6 +2398,9 @@ static int l2cap_segment_sdu(struct l2cap_chan *chan,
23982398
/* Remote device may have requested smaller PDUs */
23992399
pdu_len = min_t(size_t, pdu_len, chan->remote_mps);
24002400

2401+
if (!pdu_len)
2402+
return -EINVAL;
2403+
24012404
if (len <= pdu_len) {
24022405
sar = L2CAP_SAR_UNSEGMENTED;
24032406
sdu_len = 0;
@@ -4333,14 +4336,16 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,
43334336
if (test_bit(CONF_INPUT_DONE, &chan->conf_state)) {
43344337
set_default_fcs(chan);
43354338

4336-
if (chan->mode == L2CAP_MODE_ERTM ||
4337-
chan->mode == L2CAP_MODE_STREAMING)
4338-
err = l2cap_ertm_init(chan);
4339+
if (chan->state != BT_CONNECTED) {
4340+
if (chan->mode == L2CAP_MODE_ERTM ||
4341+
chan->mode == L2CAP_MODE_STREAMING)
4342+
err = l2cap_ertm_init(chan);
43394343

4340-
if (err < 0)
4341-
l2cap_send_disconn_req(chan, -err);
4342-
else
4343-
l2cap_chan_ready(chan);
4344+
if (err < 0)
4345+
l2cap_send_disconn_req(chan, -err);
4346+
else
4347+
l2cap_chan_ready(chan);
4348+
}
43444349

43454350
goto unlock;
43464351
}

0 commit comments

Comments
 (0)