@@ -1475,11 +1475,6 @@ static void le_conn_req(struct bt_l2cap *l2cap, uint8_t ident,
1475
1475
1476
1476
LOG_DBG ("psm 0x%02x scid 0x%04x mtu %u mps %u credits %u" , psm , scid , mtu , mps , credits );
1477
1477
1478
- if (mtu < L2CAP_LE_MIN_MTU || mps < L2CAP_LE_MIN_MPS ) {
1479
- LOG_ERR ("Invalid LE-Conn Req params: mtu %u mps %u" , mtu , mps );
1480
- return ;
1481
- }
1482
-
1483
1478
buf = l2cap_create_le_sig_pdu (BT_L2CAP_LE_CONN_RSP , ident ,
1484
1479
sizeof (* rsp ));
1485
1480
if (!buf ) {
@@ -1489,6 +1484,16 @@ static void le_conn_req(struct bt_l2cap *l2cap, uint8_t ident,
1489
1484
rsp = net_buf_add (buf , sizeof (* rsp ));
1490
1485
(void )memset (rsp , 0 , sizeof (* rsp ));
1491
1486
1487
+ /* Validate parameters. Requirements are from Core Spec v6.0, Vol 3.A.4.22. Valid credit
1488
+ * range is from 0 to UINT16_MAX, thus no credit validation is needed.
1489
+ */
1490
+ if (!IN_RANGE (mtu , L2CAP_LE_MIN_MTU , BT_L2CAP_MAX_MTU ) ||
1491
+ !IN_RANGE (mps , L2CAP_LE_MIN_MPS , BT_L2CAP_MAX_MPS )) {
1492
+ LOG_ERR ("Invalid le conn req params: mtu %u mps %u" , mtu , mps );
1493
+ result = BT_L2CAP_LE_ERR_UNACCEPT_PARAMS ;
1494
+ goto rsp ;
1495
+ }
1496
+
1492
1497
/* Check if there is a server registered */
1493
1498
server = bt_l2cap_server_lookup_psm (psm );
1494
1499
if (!server ) {
@@ -1574,8 +1579,12 @@ static void le_ecred_conn_req(struct bt_l2cap *l2cap, uint8_t ident,
1574
1579
1575
1580
LOG_DBG ("psm 0x%02x mtu %u mps %u credits %u" , psm , mtu , mps , credits );
1576
1581
1577
- if (mtu < BT_L2CAP_ECRED_MIN_MTU || mps < BT_L2CAP_ECRED_MIN_MPS ) {
1578
- LOG_ERR ("Invalid ecred conn req params. mtu %u mps %u" , mtu , mps );
1582
+ /* Validate parameters. Requirements are from Core Spec v6.0, Vol 3.A.4.25. */
1583
+ if (!IN_RANGE (mtu , BT_L2CAP_ECRED_MIN_MTU , BT_L2CAP_MAX_MTU ) ||
1584
+ !IN_RANGE (mps , BT_L2CAP_ECRED_MIN_MPS , BT_L2CAP_MAX_MPS ) ||
1585
+ !IN_RANGE (credits , BT_L2CAP_ECRED_CREDITS_MIN , BT_L2CAP_ECRED_CREDITS_MAX )) {
1586
+ LOG_ERR ("Invalid le ecred conn req params: mtu %u mps %u credits %u" , mtu , mps ,
1587
+ credits );
1579
1588
result = BT_L2CAP_LE_ERR_INVALID_PARAMS ;
1580
1589
goto response ;
1581
1590
}
@@ -1978,13 +1987,24 @@ static void le_ecred_conn_rsp(struct bt_l2cap *l2cap, uint8_t ident,
1978
1987
1979
1988
LOG_DBG ("dcid 0x%04x" , dcid );
1980
1989
1981
- /* If a Destination CID is 0x0000, the channel was not
1990
+ /* Validate parameters before assignment. Requirements are from Core Spec
1991
+ * v6.0, Vol 3.A.4.26. If a Destination CID is 0x0000, the channel was not
1982
1992
* established.
1983
1993
*/
1984
- if (! dcid ) {
1994
+ if (dcid == 0U ) {
1985
1995
bt_l2cap_chan_remove (conn , & chan -> chan );
1986
1996
bt_l2cap_chan_del (& chan -> chan );
1987
1997
continue ;
1998
+ } else if (!L2CAP_LE_CID_IS_DYN (dcid ) ||
1999
+ !IN_RANGE (mtu , BT_L2CAP_ECRED_MIN_MTU , BT_L2CAP_MAX_MTU ) ||
2000
+ !IN_RANGE (mps , BT_L2CAP_ECRED_MIN_MPS , BT_L2CAP_MAX_MPS ) ||
2001
+ !IN_RANGE (credits , BT_L2CAP_ECRED_CREDITS_MIN ,
2002
+ BT_L2CAP_ECRED_CREDITS_MAX )) {
2003
+ LOG_WRN ("Invalid ecred conn rsp params: dcid 0x%04x mtu %u mps %u "
2004
+ "credits %u. Disconnecting." ,
2005
+ dcid , mtu , mps , credits );
2006
+ bt_conn_disconnect (conn , BT_HCI_ERR_UNACCEPT_CONN_PARAM );
2007
+ return ;
1988
2008
}
1989
2009
1990
2010
c = bt_l2cap_le_lookup_tx_cid (conn , dcid );
@@ -2082,6 +2102,20 @@ static void le_conn_rsp(struct bt_l2cap *l2cap, uint8_t ident,
2082
2102
2083
2103
switch (result ) {
2084
2104
case BT_L2CAP_LE_SUCCESS :
2105
+ /* Validate parameters on successful connection. Requirements are from Core Spec
2106
+ * v6.0, Vol 3.A.4.23. Valid credit range is from 0 to UINT16_MAX, thus no credit
2107
+ * validation is needed.
2108
+ */
2109
+ if ((!L2CAP_LE_CID_IS_DYN (dcid ) ||
2110
+ !IN_RANGE (mtu , L2CAP_LE_MIN_MTU , BT_L2CAP_MAX_MTU ) ||
2111
+ !IN_RANGE (mps , L2CAP_LE_MIN_MPS , BT_L2CAP_MAX_MPS ))) {
2112
+ LOG_WRN ("Invalid conn rsp params: dcid 0x%04x mtu %u mps %u. "
2113
+ "Disconnecting." ,
2114
+ dcid , mtu , mps );
2115
+ bt_conn_disconnect (conn , BT_HCI_ERR_UNACCEPT_CONN_PARAM );
2116
+ return ;
2117
+ }
2118
+
2085
2119
chan -> tx .cid = dcid ;
2086
2120
chan -> tx .mtu = mtu ;
2087
2121
chan -> tx .mps = mps ;
0 commit comments