Open Source Telephony
 help / color / mirror / Atom feed
* [PATCH v2 1/2] modem: remove atom entry prior to invoking the watch callback
@ 2024-04-08 21:56 Denis Kenzior
  2024-04-08 21:56 ` [PATCH v2 2/2] hfp_ag_bluez5: Fix use-after-free Denis Kenzior
  2024-04-08 22:40 ` [PATCH v2 1/2] modem: remove atom entry prior to invoking the watch callback patchwork-bot+ofono
  0 siblings, 2 replies; 3+ messages in thread
From: Denis Kenzior @ 2024-04-08 21:56 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

In __ofono_atom_free, the atom is removed from the list prior to
invoking __ofono_atom_unregister.  This ensures that any invocation of
__ofono_atom_find or __ofono_modem_find_atom() will fail to find the
just-removed object when invoked from the atom watch.

The above does not hold in flush_atoms() implementation, which can lead
to surprising results.  Make sure that the atom is removed from the
modem's atom list prior to invoking __ofono_atom_unregister in all
cases.
---
 src/modem.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/modem.c b/src/modem.c
index bfd5d7a81c45..7d93c3234e83 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -480,13 +480,6 @@ static void flush_atoms(struct ofono_modem *modem, enum modem_state new_state)
 			continue;
 		}
 
-		__ofono_atom_unregister(atom);
-
-		if (atom->destruct)
-			atom->destruct(atom);
-
-		g_free(atom);
-
 		if (prev)
 			prev->next = cur->next;
 		else
@@ -495,6 +488,13 @@ static void flush_atoms(struct ofono_modem *modem, enum modem_state new_state)
 		tmp = cur;
 		cur = cur->next;
 		g_slist_free_1(tmp);
+
+		__ofono_atom_unregister(atom);
+
+		if (atom->destruct)
+			atom->destruct(atom);
+
+		g_free(atom);
 	}
 }
 
-- 
2.43.0


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

end of thread, other threads:[~2024-04-08 22:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-08 21:56 [PATCH v2 1/2] modem: remove atom entry prior to invoking the watch callback Denis Kenzior
2024-04-08 21:56 ` [PATCH v2 2/2] hfp_ag_bluez5: Fix use-after-free Denis Kenzior
2024-04-08 22:40 ` [PATCH v2 1/2] modem: remove atom entry prior to invoking the watch callback patchwork-bot+ofono

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