Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-33648

Attempting to perform user- and role-management commands in db.eval() with nolock=false can lead to deadlock

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Gone away
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: JavaScript, Security
    • Labels:
      None
    • Operating System:
      ALL
    • Epic Link:
    • Sprint:
      Platforms 2018-05-07
    • Linked BF Score:
      16

      Description

      Attempting to acquire a LockManager lock while holding a mutex is prone to deadlock. The AuthorizationManager::getAuthorizationVersion() function constructs a CacheGuard which acquires the AuthorizationManager::_cacheMutex. While holding the mutex, it calls AuthorizationManager::getStoredAuthorizationVersion(), which attempts to acquire the global lock as part of constructing AutoGetCollectionForReadCommand in AuthzManagerExternalStateMongod::findOne(). Edit: As noted in SERVER-24083, the AuthorizationManager::_cacheMutex is released as part of AuthorizationManager::beginFetchPhase() ; however, a thread must wait if another thread is already calling into AuthorizationManager::getStoredAuthorizationVersion().

      A thread running the db.eval() with nolock=false (thus holding the global X lock) would therefore deadlock if it ran any command that constructed a CacheGuard and attempted to acquire the AuthorizationManager::_cacheMutex.

      The doc comment for the AuthorizationManager::CacheGuard class describes this general issue; however, it appears we are missing code to enforce it doesn't happen in practice.

      NOTE: It is not safe to enter fetch phase while holding a database lock. Fetch phase operations are allowed to acquire database locks themselves, so entering fetch while holding a database lock may lead to deadlock.

      https://github.com/mongodb/mongo/blob/r3.7.2/src/mongo/db/auth/authorization_manager.cpp#L167-L169

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: