All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH BlueZ 0/1] advertising: Fix double-free in client_free
@ 2026-11-12 17:03 Pavel Bozhko
  2026-11-12 17:03 ` [RFC PATCH BlueZ 1/1] " Pavel Bozhko
  0 siblings, 1 reply; 4+ messages in thread
From: Pavel Bozhko @ 2026-11-12 17:03 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Pavel Bozhko

bluetoothd 5.79 aborts with SIGABRT in client_free() while freeing
client->owner, called from client_free_idle_cb(). The crash shows up
at random intervals. I cannot force it by hand.

The frames that match the 5.79 tree are:

  client_free (advertising.c:150)
  client_free_idle_cb (advertising.c:161)

Line 150 is g_free(client->owner), and glibc reports a double free.
The minidump also contains unrelated frames from a bad unwind
(open_cfm, _init). Those are not this path.

No commit on origin/master since 5.79 stops the second idle free.
0d57c12f5aca ("advertising: Fix leaking clients that exit while
registering") installs the disconnect watch during
RegisterAdvertisement, and the remove and failure paths still each
queue a free. We cannot leave 5.79 yet: buildroot pins that release.

Please comment on both changes. The diff below is what we apply on
5.79. It does not apply to current master: client_remove() takes
struct btd_adv_client *, and the disconnect watch is set from
RegisterAdvertisement. Patch 1/1 is that fix rebased on origin/master.

--- 5.79 example, not for application on master ---

    diff --git a/src/advertising.c b/src/advertising.c
    index bd121e525..45fdb5b43 100644
    --- a/src/advertising.c
    +++ b/src/advertising.c
    @@ -88,6 +88,7 @@ struct btd_adv_client {
     	uint32_t max_interval;
     	int8_t tx_power;
     	mgmt_request_func_t refresh_done_func;
    +	bool pending_destroy;
     };
 
     struct dbus_obj_match {
    @@ -200,6 +201,12 @@ static void client_remove(void *data)
     	struct btd_adv_client *client = data;
     	struct mgmt_cp_remove_advertising cp;
 
    +	/* Prevent double-free if client_remove is called multiple times */
    +	if (client->pending_destroy)
    +		return;
    +
    +	client->pending_destroy = true;
    +
     	g_dbus_client_set_proxy_handlers(client->client, NULL, NULL, NULL,
     									client);
     	g_dbus_client_set_disconnect_watch(client->client, NULL, NULL);
    @@ -1265,6 +1272,12 @@ static void add_client_complete(struct btd_adv_client *client, uint8_t status)
     		return;
 
     	if (status) {
    +		/* Prevent double-free if already pending destroy */
    +		if (client->pending_destroy)
    +			return;
    +
    +		client->pending_destroy = true;
    +
     		reply = btd_error_failed(client->reg,
     					"Failed to register advertisement");
     		queue_remove(client->manager->clients, client);
    @@ -1286,6 +1299,10 @@ static void add_adv_callback(uint8_t status, uint16_t length,
 
     	client->add_adv_id = 0;
 
    +	/* Client is already being destroyed, skip processing */
    +	if (client->pending_destroy)
    +		return;
    +
     	if (status)
     		goto done;
 
    @@ -1332,6 +1349,10 @@ static void add_adv_params_callback(uint8_t status, uint16_t length,
 
     	client->add_adv_id = 0;
 
    +	/* Client is already being destroyed, skip processing */
    +	if (client->pending_destroy)
    +		return;
    +
     	if (status)
     		goto fail;
 
    @@ -1509,6 +1530,12 @@ static void client_proxy_added(GDBusProxy *proxy, void *data)
     	if (!reply)
     		return;
 
    +	/* Prevent double-free if already pending destroy */
    +	if (client->pending_destroy)
    +		return;
    +
    +	client->pending_destroy = true;
    +
     	/* Failed to publish for some reason, remove. */
     	queue_remove(client->manager->clients, client);
 

Pavel Bozhko (1):
  advertising: Fix double-free in client_free

 src/advertising.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 52 insertions(+), 10 deletions(-)

base-commit: 9659adb6819d7e0284d0d2ba226a3894423d8db4
-- 
2.50.1 (Apple Git-155)

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

end of thread, other threads:[~2026-11-13  3:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 17:03 [RFC PATCH BlueZ 0/1] advertising: Fix double-free in client_free Pavel Bozhko
2026-11-12 17:03 ` [RFC PATCH BlueZ 1/1] " Pavel Bozhko
2026-11-12 17:33   ` Luiz Augusto von Dentz
2026-11-13  3:33   ` bluez.test.bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.