Skip to content

Commit 6823f73

Browse files
devnexengregkh
authored andcommitted
Bluetooth: hci_conn: fix potential UAF in create_big_sync
[ Upstream commit 0beddb0 ] Add hci_conn_valid() check in create_big_sync() to detect stale connections before proceeding with BIG creation. Handle the resulting -ECANCELED in create_big_complete() and re-validate the connection under hci_dev_lock() before dereferencing, matching the pattern used by create_le_conn_complete() and create_pa_complete(). Keep the hci_conn object alive across the async boundary by taking a reference via hci_conn_get() when queueing create_big_sync(), and dropping it in the completion callback. The refcount and the lock are complementary: the refcount keeps the object allocated, while hci_dev_lock() serializes hci_conn_hash_del()'s list_del_rcu() on hdev->conn_hash, as required by hci_conn_del(). hci_conn_put() is called outside hci_dev_unlock() so the final put (which resolves to kfree() via bt_link_release) does not run under hdev->lock, though the release path would be safe either way. Without this, create_big_complete() would unconditionally dereference the conn pointer on error, causing a use-after-free via hci_connect_cfm() and hci_conn_del(). Fixes: eca0ae4 ("Bluetooth: Add initial implementation of BIS connections") Cc: stable@vger.kernel.org Co-developed-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Signed-off-by: David Carlier <devnexen@gmail.com> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> [ kept stable's `qos->bcast.out.phy == 0x02` context line instead of upstream's renamed `qos->bcast.out.phys == BIT(1)` ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b4a53ad commit 6823f73

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

net/bluetooth/hci_conn.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,9 @@ static int create_big_sync(struct hci_dev *hdev, void *data)
20142014
u32 flags = 0;
20152015
int err;
20162016

2017+
if (!hci_conn_valid(hdev, conn))
2018+
return -ECANCELED;
2019+
20172020
if (qos->bcast.out.phy == 0x02)
20182021
flags |= MGMT_ADV_FLAG_SEC_2M;
20192022

@@ -2125,11 +2128,24 @@ static void create_big_complete(struct hci_dev *hdev, void *data, int err)
21252128

21262129
bt_dev_dbg(hdev, "conn %p", conn);
21272130

2131+
if (err == -ECANCELED)
2132+
goto done;
2133+
2134+
hci_dev_lock(hdev);
2135+
2136+
if (!hci_conn_valid(hdev, conn))
2137+
goto unlock;
2138+
21282139
if (err) {
21292140
bt_dev_err(hdev, "Unable to create BIG: %d", err);
21302141
hci_connect_cfm(conn, err);
21312142
hci_conn_del(conn);
21322143
}
2144+
2145+
unlock:
2146+
hci_dev_unlock(hdev);
2147+
done:
2148+
hci_conn_put(conn);
21332149
}
21342150

21352151
struct hci_conn *hci_bind_bis(struct hci_dev *hdev, bdaddr_t *dst,
@@ -2230,10 +2246,11 @@ struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst,
22302246
BT_BOUND, &data);
22312247

22322248
/* Queue start periodic advertising and create BIG */
2233-
err = hci_cmd_sync_queue(hdev, create_big_sync, conn,
2249+
err = hci_cmd_sync_queue(hdev, create_big_sync, hci_conn_get(conn),
22342250
create_big_complete);
22352251
if (err < 0) {
22362252
hci_conn_drop(conn);
2253+
hci_conn_put(conn);
22372254
return ERR_PTR(err);
22382255
}
22392256

0 commit comments

Comments
 (0)