]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Bluetooth: L2CAP: Fix ERTM re-init and zero pdu_len infinite loop
authorHyunwoo Kim <imv4bel@gmail.com>
Fri, 20 Mar 2026 11:23:10 +0000 (20:23 +0900)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 25 Mar 2026 19:32:32 +0000 (15:32 -0400)
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: 96298f640104 ("Bluetooth: L2CAP: handle l2cap config request during open state")
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
net/bluetooth/l2cap_core.c

index 2603c98d7ed10e3b4e33a7976bda3d81c4eaadf9..95c65fece39bdf40391d52811a45c89b781041a1 100644 (file)
@@ -2398,6 +2398,9 @@ static int l2cap_segment_sdu(struct l2cap_chan *chan,
        /* Remote device may have requested smaller PDUs */
        pdu_len = min_t(size_t, pdu_len, chan->remote_mps);
 
+       if (!pdu_len)
+               return -EINVAL;
+
        if (len <= pdu_len) {
                sar = L2CAP_SAR_UNSEGMENTED;
                sdu_len = 0;
@@ -4333,14 +4336,16 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,
        if (test_bit(CONF_INPUT_DONE, &chan->conf_state)) {
                set_default_fcs(chan);
 
-               if (chan->mode == L2CAP_MODE_ERTM ||
-                   chan->mode == L2CAP_MODE_STREAMING)
-                       err = l2cap_ertm_init(chan);
+               if (chan->state != BT_CONNECTED) {
+                       if (chan->mode == L2CAP_MODE_ERTM ||
+                           chan->mode == L2CAP_MODE_STREAMING)
+                               err = l2cap_ertm_init(chan);
 
-               if (err < 0)
-                       l2cap_send_disconn_req(chan, -err);
-               else
-                       l2cap_chan_ready(chan);
+                       if (err < 0)
+                               l2cap_send_disconn_req(chan, -err);
+                       else
+                               l2cap_chan_ready(chan);
+               }
 
                goto unlock;
        }