Skip to content

Commit

Permalink
[Zephyr] Fix potential data race on multicast configuration (#20722)
Browse files Browse the repository at this point in the history
OpenThread functions for joining or leaving multicast groups
would be called without holding the Thread stack lock.

Signed-off-by: Damian Krolik <[email protected]>
  • Loading branch information
Damian-Nordic authored and pull[bot] committed Aug 7, 2023
1 parent c86a5b2 commit 77aa79c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/platform/Zephyr/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,21 @@ CHIP_ERROR ThreadStackManagerImpl::_InitThreadStack()

UDPEndPointImplSockets::SetJoinMulticastGroupHandler([](InterfaceId, const IPAddress & address) {
const otIp6Address otAddress = ToOpenThreadIP6Address(address);
const auto otError = otIp6SubscribeMulticastAddress(openthread_get_default_instance(), &otAddress);

ThreadStackMgr().LockThreadStack();
const auto otError = otIp6SubscribeMulticastAddress(openthread_get_default_instance(), &otAddress);
ThreadStackMgr().UnlockThreadStack();

return MapOpenThreadError(otError);
});

UDPEndPointImplSockets::SetLeaveMulticastGroupHandler([](InterfaceId, const IPAddress & address) {
const otIp6Address otAddress = ToOpenThreadIP6Address(address);
const auto otError = otIp6UnsubscribeMulticastAddress(openthread_get_default_instance(), &otAddress);

ThreadStackMgr().LockThreadStack();
const auto otError = otIp6UnsubscribeMulticastAddress(openthread_get_default_instance(), &otAddress);
ThreadStackMgr().UnlockThreadStack();

return MapOpenThreadError(otError);
});

Expand Down

0 comments on commit 77aa79c

Please sign in to comment.