@@ -1929,6 +1929,22 @@ static void le_ecred_conn_rsp(struct bt_l2cap *l2cap, uint8_t ident,
1929
1929
1930
1930
LOG_DBG ("mtu 0x%04x mps 0x%04x credits 0x%04x result %u" , mtu , mps , credits , result );
1931
1931
1932
+ /* Validate parameters on successful connection. There are no limits for
1933
+ * credits as values from 0 to UINT16_MAX are valid.
1934
+ */
1935
+ if (result == BT_L2CAP_LE_SUCCESS ) {
1936
+ if (!L2CAP_LE_CID_IS_DYN (dcid )) {
1937
+ LOG_ERR ("dcid 0x%04x is not dynamic" , dcid );
1938
+ result = BT_L2CAP_LE_ERR_UNACCEPT_PARAMS ;
1939
+ } else if (!IN_RANGE (mtu , BT_L2CAP_ECRED_MIN_MTU , UINT16_MAX )) {
1940
+ LOG_ERR ("Invalid mtu %u" , mtu );
1941
+ result = BT_L2CAP_LE_ERR_UNACCEPT_PARAMS ;
1942
+ } else if (!IN_RANGE (mps , BT_L2CAP_ECRED_MIN_MPS , BT_L2CAP_MAX_MPS )) {
1943
+ LOG_ERR ("Invalid mps %u" , mps );
1944
+ result = BT_L2CAP_LE_ERR_UNACCEPT_PARAMS ;
1945
+ }
1946
+ }
1947
+
1932
1948
chan = l2cap_lookup_ident (conn , ident );
1933
1949
if (chan ) {
1934
1950
psm = chan -> psm ;
@@ -2059,6 +2075,22 @@ static void le_conn_rsp(struct bt_l2cap *l2cap, uint8_t ident,
2059
2075
LOG_DBG ("dcid 0x%04x mtu %u mps %u credits %u result 0x%04x" , dcid , mtu , mps , credits ,
2060
2076
result );
2061
2077
2078
+ /* Validate parameters on successful connection. There are no limits for
2079
+ * credits as values from 0 to UINT16_MAX are valid.
2080
+ */
2081
+ if (result == BT_L2CAP_LE_SUCCESS ) {
2082
+ if (!L2CAP_LE_CID_IS_DYN (dcid )) {
2083
+ LOG_ERR ("dcid 0x%04x is not dynamic" , dcid );
2084
+ result = BT_L2CAP_LE_ERR_UNACCEPT_PARAMS ;
2085
+ } else if (!IN_RANGE (mtu , L2CAP_LE_MIN_MTU , UINT16_MAX )) {
2086
+ LOG_ERR ("Invalid mtu: %u" , mtu );
2087
+ result = BT_L2CAP_LE_ERR_UNACCEPT_PARAMS ;
2088
+ } else if (!IN_RANGE (mps , L2CAP_LE_MIN_MPS , BT_L2CAP_MAX_MPS )) {
2089
+ LOG_ERR ("Invalid mps: %u" , mps );
2090
+ result = BT_L2CAP_LE_ERR_UNACCEPT_PARAMS ;
2091
+ }
2092
+ }
2093
+
2062
2094
/* Keep the channel in case of security errors */
2063
2095
if (result == BT_L2CAP_LE_SUCCESS ||
2064
2096
result == BT_L2CAP_LE_ERR_AUTHENTICATION ||
0 commit comments