Embedded Linux Library
 help / color / mirror / Atom feed
From: Ryan Walklin <ryan@testtoast.com>
To: ell@lists.linux.dev
Cc: Ryan Walklin <ryan@testtoast.com>
Subject: [PATCH 2/2] station: Unregister BSS objects before freeing
Date: Tue, 17 Nov 2026 11:35:39 +1300	[thread overview]
Message-ID: <20261116223609.3134127-3-ryan@testtoast.com> (raw)
In-Reply-To: <20261116223609.3134127-1-ryan@testtoast.com>

station_free() frees the BSSes in bss_list without unregistering their
D-Bus objects.  Removing the network objects doesn't remove the BSS
objects below them, so a GetManagedObjects call while iwd is shutting
down still reaches the BSSes through the object tree and
network_bss_property_get_address() reads freed memory:

  ERROR: AddressSanitizer: heap-use-after-free
    #0 util_address_to_string src/util.c:115
    #1 network_bss_property_get_address src/network.c:2197
    #2 get_properties_dict ell/dbus-service.c:824
    ...
  freed by thread T0 here:
    #3 station_free src/station.c:5269
    #4 station_destroy_interface src/station.c:5337
    ...
    #8 netdev_free src/netdev.c:1047
    #9 netdev_shutdown src/netdev.c:6896

Unregister each BSS object first.  station_unregister_bss() isn't used
since it warns about BSSes without an object path, which bss_list has
when the security type can't be determined.

Fixes: c639bf0b1942 ("station: move BasicServiceSet DBus management into station")
---
 src/station.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/station.c b/src/station.c
index 8fcf8c70..bc04b3e8 100644
--- a/src/station.c
+++ b/src/station.c
@@ -5193,6 +5193,8 @@ static struct station *station_create(struct netdev *netdev)
 
 static void station_free(struct station *station)
 {
+	struct scan_bss *bss;
+
 	l_debug("");
 
 	if (!l_queue_remove(station_list, station))
@@ -5264,9 +5266,22 @@ static void station_free(struct station *station)
 
 	station_roam_state_clear(station);
 
+	/*
+	 * Unregister the BSS objects before freeing the BSSes, otherwise a
+	 * GetManagedObjects call can still reach them through the object tree.
+	 */
+	while ((bss = l_queue_pop_head(station->bss_list))) {
+		const char *path = station_get_bss_path(station, bss);
+
+		if (path)
+			l_dbus_unregister_object(dbus_get_bus(), path);
+
+		scan_bss_free(bss);
+	}
+
+	l_queue_destroy(station->bss_list, NULL);
 	l_queue_destroy(station->networks_sorted, NULL);
 	l_hashmap_destroy(station->networks, network_free);
-	l_queue_destroy(station->bss_list, bss_free);
 	l_queue_destroy(station->hidden_bss_list_sorted, NULL);
 	l_queue_destroy(station->autoconnect_list, NULL);
 
-- 
2.55.0


      parent reply	other threads:[~2026-11-16 22:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 22:35 [PATCH 0/2] FILS IP address and station shutdown fixes Ryan Walklin
2026-11-16 22:35 ` [PATCH 1/2] ie: Fill in pending FILS IP Address responses Ryan Walklin
2026-11-16 22:35 ` Ryan Walklin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261116223609.3134127-3-ryan@testtoast.com \
    --to=ryan@testtoast.com \
    --cc=ell@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox