Skip to content

Commit

Permalink
platforms/common/uORB/uORBManager.cpp: Fix a race condition in uORB c…
Browse files Browse the repository at this point in the history
…allback unregistration

In protected modes, the callback needs to be removed from the processes list of callbacks before
unregistering it from the device node. Otherwise there is a risk for callback thread trying to
access a callback which was already removed from the publishing node's list.

Signed-off-by: Jukka Laitinen <[email protected]>
  • Loading branch information
jlaitine committed Feb 21, 2024
1 parent 656095d commit 093c7bf
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions platforms/common/uORB/uORBManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,11 @@ uORB::Manager::unregisterCallback(orb_advert_t &node_handle, SubscriptionCallbac
#ifndef CONFIG_BUILD_FLAT
lock_cb_list();

// Remove the callback from the list. This must be done before unregistering from the device node
// otherwise the callback thread might try to call an already unregistered cb

per_process_cb_list.remove(callback_sub);

// Unregister the callback from the device node and retrieve amount of unhandled callback triggers
// The unregister from the node needs to be done callback_thread locked; otherwise we don't know
// if there are unhandled triggers left or not (due to a race between the callback thread and
Expand All @@ -598,10 +603,6 @@ uORB::Manager::unregisterCallback(orb_advert_t &node_handle, SubscriptionCallbac

callback_count += DeviceNode::unregister_callback(node_handle, cb_handle);

// Remove the callback from the list

per_process_cb_list.remove(callback_sub);

unlock_cb_list();
#else
DeviceNode::unregister_callback(node_handle, cb_handle);
Expand Down

0 comments on commit 093c7bf

Please sign in to comment.