net/route: Add missing lock in net_route_mcast_add()

This is a public API for the subsystem, can be called from app
context, unlocks the local k_mutex on one of its three exit paths, and
it's quite clear that nothing ever locks that mutex!

The code used to work because k_mutex simply returned an error if you
tried to unlock an unlocked object.  Now zync will panic (when
CONFIG_ZYNC_VALIDATE=y) if you try that.

Signed-off-by: Andy Ross <andyross@google.com>
This commit is contained in:
Andy Ross 2022-10-12 07:14:12 -07:00 committed by Carles Cufí
parent 633c41d52c
commit 95101e6890

View file

@ -876,10 +876,13 @@ struct net_route_entry_mcast *net_route_mcast_add(struct net_if *iface,
{
int i;
k_mutex_lock(&lock, K_FOREVER);
if ((!net_if_flag_is_set(iface, NET_IF_FORWARD_MULTICASTS)) ||
(!net_ipv6_is_addr_mcast(group)) ||
(net_ipv6_is_addr_mcast_iface(group)) ||
(net_ipv6_is_addr_mcast_link(group))) {
k_mutex_unlock(&lock);
return NULL;
}
@ -898,6 +901,7 @@ struct net_route_entry_mcast *net_route_mcast_add(struct net_if *iface,
}
}
k_mutex_unlock(&lock);
return NULL;
}