]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
Bluetooth: hci_sync: hold conn in hci_connect_pa_sync() callback
authorPauli Virtanen <pav@iki.fi>
Sat, 25 Jul 2026 09:59:20 +0000 (12:59 +0300)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 28 Jul 2026 20:13:13 +0000 (16:13 -0400)
There is theoretical UAF if the conn is freed while the hci_sync task is
running.

Hold refcount to avoid that.

Fixes: 6d0417e4e1cf ("Bluetooth: hci_conn: Fix not setting conn_timeout for Broadcast Receiver")
Signed-off-by: Pauli Virtanen <pav@iki.fi>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
net/bluetooth/hci_sync.c

index cdc7dff7054c725609f698ddc738f464d5eb477d..f50d7cd3a331df66cf05000def3d9118d978b27b 100644 (file)
@@ -7336,7 +7336,7 @@ static void create_pa_complete(struct hci_dev *hdev, void *data, int err)
        bt_dev_dbg(hdev, "err %d", err);
 
        if (err == -ECANCELED)
-               return;
+               goto done;
 
        hci_dev_lock(hdev);
 
@@ -7360,6 +7360,8 @@ static void create_pa_complete(struct hci_dev *hdev, void *data, int err)
 
 unlock:
        hci_dev_unlock(hdev);
+done:
+       hci_conn_put(conn);
 }
 
 static int hci_le_past_params_sync(struct hci_dev *hdev, struct hci_conn *conn,
@@ -7510,8 +7512,11 @@ int hci_connect_pa_sync(struct hci_dev *hdev, struct hci_conn *conn)
 {
        int err;
 
-       err = hci_cmd_sync_queue_once(hdev, hci_le_pa_create_sync, conn,
+       err = hci_cmd_sync_queue_once(hdev, hci_le_pa_create_sync,
+                                     hci_conn_get(conn),
                                      create_pa_complete);
+       if (err)
+               hci_conn_put(conn);
        return (err == -EEXIST) ? 0 : err;
 }