Fix potential deadlock in PolicyHandler #3383
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3176
This PR is ready for review.
Risk
This PR makes no API changes.
Testing Plan
Script for reproducing in open sdl will be created.
Summary
There was a vulnerability in the PolicyHandler which causes a mutex deadlock.
For example - MessageLoop thread of RpcService handles incoming messages. In
case when SDL receives AllowSDLFunctionality notification, this thread calls
OnAllowSDLFunctionalityNotification inside PolicyHandler. At some point of time
this function captures accessor from AM which holds applications_list_lock_
there. At this moment thread AM Pool 0 of RequestController processes some RPC
from queue and captures policy_manager_lock_ in PolicyHandler. After that at
some moment thread AM Pool 0 tries to get application shared pointer from AM
and locks itself as this mutex are already locked with thread MessageLoop.
Also, MessageLoop thread at some moment tries to acquire policy_manager_lock_
and locks itself as this mutex are already locked with thread AM Pool 0, which
is waiting for applications_list_lock_ to unlock. As a result we have a
classical thread deadlock after which SDL stuck forewer.
To avoid such situations, there was analyzed all bottlenecks related to
applications_list_lock_ and its accessors. Accessors were scoped in several
places to avoid similar deadlocks in future.
Tasks Remaining:
CLA