You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This service is created in the ClearCostmapService class, but this class does not seem to have a destructor, meaning there is no active release or shutdown behavior for the service.
[Notice.1.]:
In ROS2, the service is a smart pointer, which means that if the callback function is still executing, the smart pointer of this service will not be automatically released, and its execution thread will not automatically exit but will continue to perform tasks.
This function accesses the inflation_layer_, which is a plugin belonging to costmap_ros_.
The call stack for the access is: clearEntireCallback() -> costmap_ros_->resetLayers(). At this point, pointers to plugins are obtained from costmap_ros_'s layered_costmap_ and read:
It is worth noting that costmap_ros_->resetLayers() accesses pointers to the vector (non-smart pointers), and this vector is also released along with layered_costmap_.reset(), causing the reference count of the smart pointer pointing to inflation_layer_ to drop to zero, thereby releasing inflation_layer_.
At this point, inflation_layer_ is released, but the clearEntireCallback() thread that accesses inflation_layer_ does not stop, leading to the use-after-free bug.
suggestion:
Shall we actively close the service created by ClearCostmapService in its destructor like following ?
Bug report
Required Info:
Steps to reproduce issue
Bug happened in my normal usage.
Launch the navigation2 as following steps:
Expected behavior
no bug occured.
Actual behavior
the Asan report of this bug is as following:
Additional information
It's a shutdown-issue
First, based on my execution logs, I can confirm this is a shutdown issue.
It is caused by the
clear_entire_service_
in the costmap not being actively closed.The callback function
clearEntireCallback()
that triggers the bug is executed by the serviceclear_entire_service_
:navigation2/nav2_costmap_2d/src/clear_costmap_service.cpp
Lines 55 to 59 in 9fbae3e
This service is created in the
ClearCostmapService
class, but this class does not seem to have a destructor, meaning there is no active release or shutdown behavior for the service.navigation2/nav2_costmap_2d/include/nav2_costmap_2d/clear_costmap_service.hpp
Lines 38 to 59 in 9fbae3e
[Notice.1.]:
In ROS2, the service is a smart pointer, which means that if the callback function is still executing, the smart pointer of this service will not be automatically released, and its execution thread will not automatically exit but will continue to perform tasks.
This function accesses the
inflation_layer_
, which is a plugin belonging tocostmap_ros_
.The call stack for the access is:
clearEntireCallback()
->costmap_ros_->resetLayers()
. At this point, pointers to plugins are obtained fromcostmap_ros_
'slayered_costmap_
and read:navigation2/nav2_costmap_2d/src/costmap_2d_ros.cpp
Lines 667 to 686 in 9fbae3e
inflation_layer_
is one of these plugins, which means access to the address ofinflation_layer_
starts here.During the
on_cleanup()
process of thecostmap_ros_
node,inflation_layer_
is released:As a member of
layered_costmap_
,inflation_layer_
is released along withlayered_costmap_.reset()
:navigation2/nav2_costmap_2d/src/costmap_2d_ros.cpp
Line 364 in 9fbae3e
It is worth noting that
costmap_ros_->resetLayers()
accesses pointers to the vector (non-smart pointers), and this vector is also released along withlayered_costmap_.reset()
, causing the reference count of the smart pointer pointing toinflation_layer_
to drop to zero, thereby releasinginflation_layer_
.At this point,
inflation_layer_
is released, but theclearEntireCallback()
thread that accessesinflation_layer_
does not stop, leading to the use-after-free bug.suggestion:
Shall we actively close the service created by
ClearCostmapService
in its destructor like following ?or provide a lifecyle for
ClearCostmapService()
:The text was updated successfully, but these errors were encountered: