public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] Bluetooth: hci_sync: fix refcounting in le_read_features_complete
@ 2026-03-29 15:40 Pauli Virtanen
  2026-03-29 16:50 ` [v2] " bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Pauli Virtanen @ 2026-03-29 15:40 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Pauli Virtanen

hci_conn_get() refcount acquired in hci_le_read_remote_features() must
be unconditionally released in the destructor, or it leaks.  The
destructor is always called if hci_cmd_sync_queue_once() returned with
success.

It also looks like removing the hold/drop logical refcounting here by
commit 60562bebb651 ("Bluetooth: hci_sync: Fix UAF in le_read_features_complete")
caused a behavior change (mgmt-tester Adv. / Ext. Adv. test failures).

Fix the destructor le_read_features_complete() to always release the
refcount.

Also restore the logical hold/drop refcount, preventing the hci_conn
from timing out during this command.

Fixes: 60562bebb651 ("Bluetooth: hci_sync: Fix UAF in le_read_features_complete")
Signed-off-by: Pauli Virtanen <pav@iki.fi>
---

Notes:
    v2:
    - restore also the hold/drop refcounting
    
    This probably should be fixup in bluetooth-next/master if it wasn't
    pulled yet.
    
    Restoring the hold/drop makes the following mgmt-tester tests pass
    again:
    
    Adv. connectable & connected (central) - Success
    Adv. non-connectable & connected (central) - Success
    Ext Adv. connectable & connected (central)
    Ext Adv. non-connectable & connected (central)
    
    It's not clear to me whether there is something wrong with these tests,
    but probably the behavior change was unintended so it's better to
    restore it.

 net/bluetooth/hci_sync.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 91d0252ae661..0c6baba4e69c 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -7390,9 +7390,7 @@ static void le_read_features_complete(struct hci_dev *hdev, void *data, int err)
 
 	bt_dev_dbg(hdev, "err %d", err);
 
-	if (err == -ECANCELED)
-		return;
-
+	hci_conn_drop(conn);
 	hci_conn_put(conn);
 }
 
@@ -7463,10 +7461,12 @@ int hci_le_read_remote_features(struct hci_conn *conn)
 	if (conn->out || (hdev->le_features[0] & HCI_LE_PERIPHERAL_FEATURES)) {
 		err = hci_cmd_sync_queue_once(hdev,
 					      hci_le_read_remote_features_sync,
-					      hci_conn_get(conn),
+					      hci_conn_hold(hci_conn_get(conn)),
 					      le_read_features_complete);
-		if (err)
+		if (err) {
+			hci_conn_drop(conn);
 			hci_conn_put(conn);
+		}
 	} else {
 		err = -EOPNOTSUPP;
 	}
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-29 16:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-29 15:40 [PATCH v2] Bluetooth: hci_sync: fix refcounting in le_read_features_complete Pauli Virtanen
2026-03-29 16:50 ` [v2] " bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox