Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential deadlock in PolicyHandler #3383

Conversation

LuxoftAKutsan
Copy link
Contributor

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:

  • Create script to reproduce
  • Luxoft internal review
  • Regression testing

CLA

SYNC-10345

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.
@jacobkeeler jacobkeeler merged commit 137d328 into smartdevicelink:develop Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants