Bluetooth: L2CAP LE CoC fixes
Subsystems (2)
cover Bluetooth: L2CAP LE CoC fixes
Hi,
These are fixes for missing parameter validity checks in the LE CoC code.
Johan
----------------------------------------------------------------
Johan Hedberg (3):
Bluetooth: L2CAP: Fix returning correct LE CoC response codes
Bluetooth: L2CAP: Fix checked range when allocating new CID
Bluetooth: L2CAP: Add missing checks for invalid LE DCID
include/net/bluetooth/l2cap.h | 2 ++ net/bluetooth/l2cap_core.c | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-)
PATCH 1/3 Bluetooth: L2CAP: Fix returning correct LE CoC response codes
From: Johan Hedberg <[email protected]>
The core spec defines specific response codes for situations when the received CID is incorrect. Add the defines for these and return them as appropriate from the LE Connect Request handler function.
--- include/net/bluetooth/l2cap.h | 2 ++ net/bluetooth/l2cap_core.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-)
include/net/bluetooth/l2cap.h +2 -0
@@ -275,6 +275,8 @@ struct l2cap_conn_rsp {#define L2CAP_CR_AUTHORIZATION 0x0006#define L2CAP_CR_BAD_KEY_SIZE 0x0007#define L2CAP_CR_ENCRYPTION 0x0008 +#define L2CAP_CR_INVALID_SCID 0x0009 +#define L2CAP_CR_SCID_IN_USE 0x0010/* connect/create channel status */ #define L2CAP_CS_NO_INFO 0x0000
net/bluetooth/l2cap_core.c +8 -1
@@ -5437,9 +5437,16 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn, goto response_unlock; } +/* Check for valid dynamic CID range */ +if (scid <L2CAP_CID_DYN_START || scid >L2CAP_CID_LE_DYN_END ) { + result =L2CAP_CR_INVALID_SCID ; + chan =NULL ; + goto response_unlock; + } +/* Check if we already have channel with that dcid */ if (__l2cap_get_chan_by_dcid (conn, scid)) { - result =L2CAP_CR_NO_MEM ; + result =L2CAP_CR_SCID_IN_USE ; chan =NULL ; goto response_unlock; }
Signature · 1 line
2.5.0
PATCH 2/3 Bluetooth: L2CAP: Fix checked range when allocating new CID
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
The 'dyn_end' value is also a valid CID so it should be included in the range of values checked.
--- net/bluetooth/l2cap_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +1 -1
@@ -239,7 +239,7 @@ static u16 l2cap_alloc_cid(struct l2cap_conn *conn)else dyn_end =L2CAP_CID_DYN_END ; -for (cid =L2CAP_CID_DYN_START ; cid < dyn_end; cid++) { +for (cid =L2CAP_CID_DYN_START ; cid <= dyn_end; cid++) {if (!__l2cap_get_chan_by_scid (conn, cid))return cid; }
Signature · 1 line
2.5.0
PATCH 3/3 Bluetooth: L2CAP: Add missing checks for invalid LE DCID
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
When receiving a connect response we should make sure that the DCID is within the valid range and that we don't already have another channel allocated for the same DCID.
--- net/bluetooth/l2cap_core.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +8 -1
@@ -5250,7 +5250,9 @@ static int l2cap_le_connect_rsp(struct l2cap_conn *conn, credits =__le16_to_cpu (rsp->credits); result =__le16_to_cpu (rsp->result); -if (result ==L2CAP_CR_SUCCESS && (mtu <23 || mps <23 )) +if (result ==L2CAP_CR_SUCCESS && (mtu <23 || mps <23 || + dcid <L2CAP_CID_DYN_START || + dcid >L2CAP_CID_LE_DYN_END ))return -EPROTO ; BT_DBG("dcid 0x%4.4x mtu %u mps %u credits %u result 0x%2.2x",
@@ -5270,6 +5272,11 @@ static int l2cap_le_connect_rsp(struct l2cap_conn *conn,switch (result) {case L2CAP_CR_SUCCESS : +if (__l2cap_get_chan_by_dcid (conn, dcid)) { + err = -EBADSLT ; +break ; + } + chan->ident =0 ; chan->dcid = dcid; chan->omtu = mtu;
Signature · 1 line
2.5.0