public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/2] gatt-client: fix use-after-free
@ 2026-01-08 10:01 Lasse Dalegaard
  2026-01-08 10:01 ` [PATCH BlueZ 2/2] device: fix memory leak Lasse Dalegaard
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Lasse Dalegaard @ 2026-01-08 10:01 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Lasse Dalegaard

Clients with an acquired characteristic subscription would free the
client during disconnect. When notify_io_destroy then tries to remove
the client, it'll use-after-free.

Add another reference when allocating the notify_io and unref it again
in notify_io_destroy.
---
 src/gatt-client.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/gatt-client.c b/src/gatt-client.c
index 44ec95db0..374e67c34 100644
--- a/src/gatt-client.c
+++ b/src/gatt-client.c
@@ -1566,6 +1566,7 @@ static void notify_io_destroy(void *data)
 
 	if (queue_remove(client->chrc->notify_clients, client))
 		notify_client_unref(client);
+	notify_client_unref(client);
 }
 
 static DBusMessage *characteristic_acquire_notify(DBusConnection *conn,
@@ -1607,7 +1608,7 @@ static DBusMessage *characteristic_acquire_notify(DBusConnection *conn,
 	queue_push_tail(chrc->notify_clients, client);
 
 	chrc->notify_io = new0(struct sock_io, 1);
-	chrc->notify_io->data = client;
+	chrc->notify_io->data = notify_client_ref(client);
 	chrc->notify_io->msg = dbus_message_ref(msg);
 	chrc->notify_io->destroy = notify_io_destroy;
 
-- 
2.52.0


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

end of thread, other threads:[~2026-01-09 22:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-08 10:01 [PATCH BlueZ 1/2] gatt-client: fix use-after-free Lasse Dalegaard
2026-01-08 10:01 ` [PATCH BlueZ 2/2] device: fix memory leak Lasse Dalegaard
2026-01-08 15:27   ` Luiz Augusto von Dentz
2026-01-08 18:50     ` Lasse Dalegaard
2026-01-08 19:08       ` Luiz Augusto von Dentz
2026-01-08 11:10 ` [BlueZ,1/2] gatt-client: fix use-after-free bluez.test.bot
2026-01-08 15:23 ` [PATCH BlueZ 1/2] " Luiz Augusto von Dentz
2026-01-08 18:46   ` Lasse Dalegaard
2026-01-08 19:06     ` Luiz Augusto von Dentz
2026-01-09 22:40 ` patchwork-bot+bluetooth

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