Skip to content

Commit dabe815

Browse files
ceolincfriedt
authored andcommitted
bt: host/classic: Fix possible integer overflow
Invalid header length and cause an integer overflow in bt_br_acl_recv leading to undesired behavior. Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
1 parent 2b8e614 commit dabe815

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

subsys/bluetooth/host/classic/conn_br.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <zephyr/sys/byteorder.h>
1717
#include <zephyr/sys/check.h>
1818
#include <zephyr/sys/iterable_sections.h>
19+
#include <zephyr/sys/math_extras.h>
1920
#include <zephyr/sys/util.h>
2021
#include <zephyr/sys/util_macro.h>
2122
#include <zephyr/sys/slist.h>
@@ -154,7 +155,11 @@ void bt_br_acl_recv(struct bt_conn *conn, struct net_buf *buf, bool complete)
154155
net_buf_simple_save(&buf->b, &state);
155156

156157
hdr = (void *)buf->data;
157-
acl_total_len = sys_le16_to_cpu(hdr->len) + sizeof(*hdr);
158+
if (u16_add_overflow(sys_le16_to_cpu(hdr->len),
159+
sizeof(*hdr), &acl_total_len)) {
160+
LOG_ERR("L2CAP PDU length overflow");
161+
break;
162+
}
158163
if (buf->len > acl_total_len) {
159164
LOG_DBG("Multiple L2CAP packet (%u > %u)", buf->len, acl_total_len);
160165
buf->len = acl_total_len;

0 commit comments

Comments
 (0)