Skip to content

Commit 30fcf49

Browse files
de-nordiccarlescufi
authored andcommitted
mgmt/mcumgr: Fix possible buffer overflow in BT tranport
The commit add checks whether frame received from BT transport will really fit into allocated net_buf form mcumgr. Fixes: #44271 Signed-off-by: Dominik Ermel <[email protected]>
1 parent 199048b commit 30fcf49

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

subsys/mgmt/mcumgr/smp_bt.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,17 @@ static ssize_t smp_bt_chr_write(struct bt_conn *conn,
231231

232232
nb = mcumgr_buf_alloc();
233233
if (!nb) {
234+
LOG_DBG("failed net_buf alloc for SMP packet");
234235
return BT_GATT_ERR(BT_ATT_ERR_INSUFFICIENT_RESOURCES);
235236
}
237+
238+
if (net_buf_tailroom(nb) < len) {
239+
LOG_DBG("SMP packet len (%zu) > net_buf len (%zu)",
240+
len, net_buf_tailroom(nb));
241+
mcumgr_buf_free(nb);
242+
return BT_GATT_ERR(BT_ATT_ERR_INSUFFICIENT_RESOURCES);
243+
}
244+
236245
net_buf_add_mem(nb, buf, len);
237246

238247
ud = net_buf_user_data(nb);

0 commit comments

Comments
 (0)