Skip to content

Commit 7282ea0

Browse files
man-gckartben
authored andcommitted
net: dhcpv4: fix deadlock issue
There is a deadlock issue when calling stop using address conflict detection. This is due to the fact that some net_mgmt events are fired and trigger the dhcpv4_acd_event_handler() with lock held even if they are of no interest for this callback. Therefore, before acquiring the lock, make sure the event we received is one we are expecting. Also, do the same for dhcpv4_iface_event_handler(). Signed-off-by: Mathieu Anquetin <mathieu.anquetin@groupe-cahors.com>
1 parent 3342ef3 commit 7282ea0

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

subsys/net/lib/dhcpv4/dhcpv4.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,11 @@ static void dhcpv4_iface_event_handler(struct net_mgmt_event_callback *cb,
15551555
{
15561556
sys_snode_t *node = NULL;
15571557

1558+
if (mgmt_event != NET_EVENT_IF_UP &&
1559+
mgmt_event != NET_EVENT_IF_DOWN) {
1560+
return;
1561+
}
1562+
15581563
k_mutex_lock(&lock, K_FOREVER);
15591564

15601565
SYS_SLIST_FOR_EACH_NODE(&dhcpv4_ifaces, node) {
@@ -1602,6 +1607,16 @@ static void dhcpv4_acd_event_handler(struct net_mgmt_event_callback *cb,
16021607
sys_snode_t *node = NULL;
16031608
struct in_addr *addr;
16041609

1610+
if (mgmt_event != NET_EVENT_IPV4_ACD_FAILED &&
1611+
mgmt_event != NET_EVENT_IPV4_ACD_CONFLICT) {
1612+
return;
1613+
}
1614+
1615+
if (cb->info_length != sizeof(struct in_addr)) {
1616+
return;
1617+
}
1618+
1619+
addr = (struct in_addr *)cb->info;
16051620

16061621
k_mutex_lock(&lock, K_FOREVER);
16071622

@@ -1615,17 +1630,6 @@ static void dhcpv4_acd_event_handler(struct net_mgmt_event_callback *cb,
16151630
goto out;
16161631
}
16171632

1618-
if (mgmt_event != NET_EVENT_IPV4_ACD_FAILED &&
1619-
mgmt_event != NET_EVENT_IPV4_ACD_CONFLICT) {
1620-
goto out;
1621-
}
1622-
1623-
if (cb->info_length != sizeof(struct in_addr)) {
1624-
goto out;
1625-
}
1626-
1627-
addr = (struct in_addr *)cb->info;
1628-
16291633
if (!net_ipv4_addr_cmp(&iface->config.dhcpv4.requested_ip, addr)) {
16301634
goto out;
16311635
}

0 commit comments

Comments
 (0)