ell.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] dhcp-server: Fix double free in l_dhcp_server_expire_by_mac
@ 2021-08-06 23:52 Andrew Zaborowski
  2021-08-06 23:52 ` [PATCH 2/3] dhcp-server: Validate chaddr against source MAC Andrew Zaborowski
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrew Zaborowski @ 2021-08-06 23:52 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 1867 bytes --]

When using l_queue_foreach_remove() on lease_list we can't call
lease_release() because that will try to do l_queue_remove() on the same
queue, in addition to all the things we need it to do.
---
 ell/dhcp-server.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/ell/dhcp-server.c b/ell/dhcp-server.c
index f92807a..84dc41d 100644
--- a/ell/dhcp-server.c
+++ b/ell/dhcp-server.c
@@ -1418,25 +1418,42 @@ LIB_EXPORT bool l_dhcp_server_lease_remove(struct l_dhcp_server *server,
 struct dhcp_expire_by_mac_data {
 	struct l_dhcp_server *server;
 	const uint8_t *mac;
+	unsigned int expired_cnt;
 };
 
 static bool dhcp_expire_by_mac(void *data, void *user_data)
 {
 	struct l_dhcp_lease *lease = data;
 	struct dhcp_expire_by_mac_data *expire_data = user_data;
+	struct l_dhcp_server *server = expire_data->server;
 
 	if (!match_lease_mac(lease, expire_data->mac))
 		return false;
 
-	lease_release(expire_data->server, lease);
+	if (server->event_handler)
+		server->event_handler(server, L_DHCP_SERVER_EVENT_LEASE_EXPIRED,
+					server->user_data, lease);
+
+	if (!lease->offering) {
+		if (l_queue_length(server->expired_list) > server->max_expired)
+			_dhcp_lease_free(l_queue_pop_head(server->expired_list));
+
+		l_queue_push_tail(server->expired_list, lease);
+	} else
+		_dhcp_lease_free(lease);
+
+	expire_data->expired_cnt++;
 	return true;
 }
 
 LIB_EXPORT void l_dhcp_server_expire_by_mac(struct l_dhcp_server *server,
 						const uint8_t *mac)
 {
-	struct dhcp_expire_by_mac_data expire_data = { server, mac };
+	struct dhcp_expire_by_mac_data expire_data = { server, mac, 0 };
 
 	l_queue_foreach_remove(server->lease_list, dhcp_expire_by_mac,
 				&expire_data);
+
+	if (expire_data.expired_cnt)
+		set_next_expire_timer(server, NULL);
 }
-- 
2.30.2

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

end of thread, other threads:[~2021-08-13  1:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-06 23:52 [PATCH 1/3] dhcp-server: Fix double free in l_dhcp_server_expire_by_mac Andrew Zaborowski
2021-08-06 23:52 ` [PATCH 2/3] dhcp-server: Validate chaddr against source MAC Andrew Zaborowski
2021-08-06 23:52 ` [PATCH 3/3] unit: In test-dhcp update rx callback parameters Andrew Zaborowski
2021-08-13  1:27 ` [PATCH 1/3] dhcp-server: Fix double free in l_dhcp_server_expire_by_mac Denis Kenzior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).