Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Bluetooth: hci_conn: fix potential UAF in create_big_sync

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: eca0ae4aea66 ("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>

authored by

David Carlier and committed by
Luiz Augusto von Dentz
0beddb0c b819db93

+18 -1
+18 -1
net/bluetooth/hci_conn.c
··· 2130 2130 u32 flags = 0; 2131 2131 int err; 2132 2132 2133 + if (!hci_conn_valid(hdev, conn)) 2134 + return -ECANCELED; 2135 + 2133 2136 if (qos->bcast.out.phys == BIT(1)) 2134 2137 flags |= MGMT_ADV_FLAG_SEC_2M; 2135 2138 ··· 2207 2204 2208 2205 bt_dev_dbg(hdev, "conn %p", conn); 2209 2206 2207 + if (err == -ECANCELED) 2208 + goto done; 2209 + 2210 + hci_dev_lock(hdev); 2211 + 2212 + if (!hci_conn_valid(hdev, conn)) 2213 + goto unlock; 2214 + 2210 2215 if (err) { 2211 2216 bt_dev_err(hdev, "Unable to create BIG: %d", err); 2212 2217 hci_connect_cfm(conn, err); 2213 2218 hci_conn_del(conn); 2214 2219 } 2220 + 2221 + unlock: 2222 + hci_dev_unlock(hdev); 2223 + done: 2224 + hci_conn_put(conn); 2215 2225 } 2216 2226 2217 2227 struct hci_conn *hci_bind_bis(struct hci_dev *hdev, bdaddr_t *dst, __u8 sid, ··· 2352 2336 BT_BOUND, &data); 2353 2337 2354 2338 /* Queue start periodic advertising and create BIG */ 2355 - err = hci_cmd_sync_queue(hdev, create_big_sync, conn, 2339 + err = hci_cmd_sync_queue(hdev, create_big_sync, hci_conn_get(conn), 2356 2340 create_big_complete); 2357 2341 if (err < 0) { 2358 2342 hci_conn_drop(conn); 2343 + hci_conn_put(conn); 2359 2344 return ERR_PTR(err); 2360 2345 } 2361 2346