Skip to content

Commit 9d87cb2

Browse files
Minseo ParkVudentz
authored andcommitted
Bluetooth: L2CAP: Fix stack-out-of-bounds read in l2cap_ecred_conn_req
Syzbot reported a KASAN stack-out-of-bounds read in l2cap_build_cmd() that is triggered by a malformed Enhanced Credit Based Connection Request. The vulnerability stems from l2cap_ecred_conn_req(). The function allocates a local stack buffer (`pdu`) designed to hold a maximum of 5 Source Channel IDs (SCIDs), totaling 18 bytes. When an attacker sends a request with more than 5 SCIDs, the function calculates `rsp_len` based on this unvalidated `cmd_len` before checking if the number of SCIDs exceeds L2CAP_ECRED_MAX_CID. If the SCID count is too high, the function correctly jumps to the `response` label to reject the packet, but `rsp_len` retains the attacker's oversized value. Consequently, l2cap_send_cmd() is instructed to read past the end of the 18-byte `pdu` buffer, triggering a KASAN panic. Fix this by moving the assignment of `rsp_len` to after the `num_scid` boundary check. If the packet is rejected, `rsp_len` will safely remain 0, and the error response will only read the 8-byte base header from the stack. Fixes: c28d2bf ("Bluetooth: L2CAP: Fix result of L2CAP_ECRED_CONN_RSP when MTU is too short") Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=b7f3e7d9a596bf6a63e3 Tested-by: [email protected] Signed-off-by: Minseo Park <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 7ab4a7c commit 9d87cb2

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

net/bluetooth/l2cap_core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5081,14 +5081,14 @@ static inline int l2cap_ecred_conn_req(struct l2cap_conn *conn,
50815081
cmd_len -= sizeof(*req);
50825082
num_scid = cmd_len / sizeof(u16);
50835083

5084-
/* Always respond with the same number of scids as in the request */
5085-
rsp_len = cmd_len;
5086-
50875084
if (num_scid > L2CAP_ECRED_MAX_CID) {
50885085
result = L2CAP_CR_LE_INVALID_PARAMS;
50895086
goto response;
50905087
}
50915088

5089+
/* Always respond with the same number of scids as in the request */
5090+
rsp_len = cmd_len;
5091+
50925092
mtu = __le16_to_cpu(req->mtu);
50935093
mps = __le16_to_cpu(req->mps);
50945094

0 commit comments

Comments
 (0)