Skip to content

Commit

Permalink
Bluetooth: Classic: Add length check in bluetooth classic
Browse files Browse the repository at this point in the history
Added length checks for user input in `sdp_client_receive` and
`l2cap_br_info_rsp`.

Signed-off-by: Eunkyu Lee <[email protected]>
(cherry picked from commit 8888125)
  • Loading branch information
ekleezg authored and MaureenHelm committed Sep 6, 2024
1 parent ecfc6e1 commit a0c8a43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions subsys/bluetooth/host/l2cap_br.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ static int l2cap_br_info_rsp(struct bt_l2cap_br *l2cap, uint8_t ident,

switch (type) {
case BT_L2CAP_INFO_FEAT_MASK:
if (buf->len < sizeof(uint32_t)) {
LOG_ERR("Invalid remote info feat mask");
err = -EINVAL;
break;
}
l2cap->info_feat_mask = net_buf_pull_le32(buf);
LOG_DBG("remote info mask 0x%08x", l2cap->info_feat_mask);

Expand All @@ -402,6 +407,11 @@ static int l2cap_br_info_rsp(struct bt_l2cap_br *l2cap, uint8_t ident,
l2cap_br_get_info(l2cap, BT_L2CAP_INFO_FIXED_CHAN);
return 0;
case BT_L2CAP_INFO_FIXED_CHAN:
if (buf->len < sizeof(uint8_t)) {
LOG_ERR("Invalid remote info fixed chan");
err = -EINVAL;
break;
}
l2cap->info_fixed_chan = net_buf_pull_u8(buf);
LOG_DBG("remote fixed channel mask 0x%02x", l2cap->info_fixed_chan);

Expand Down
5 changes: 5 additions & 0 deletions subsys/bluetooth/host/sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1750,6 +1750,11 @@ static int sdp_client_receive(struct bt_l2cap_chan *chan, struct net_buf *buf)

switch (hdr->op_code) {
case BT_SDP_SVC_SEARCH_ATTR_RSP:
/* Check the buffer len for the length field */
if (buf->len < sizeof(uint16_t)) {
LOG_ERR("Invalid frame payload length");
return 0;
}
/* Get number of attributes in this frame. */
frame_len = net_buf_pull_be16(buf);
/* Check valid buf len for attribute list and cont state */
Expand Down

0 comments on commit a0c8a43

Please sign in to comment.