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