Skip to content

Commit

Permalink
santa-driver: Fix rare panic in CacheCheck where lock upgrade fails.
Browse files Browse the repository at this point in the history
lck_rw_lock_shared_to_exclusive can return false if a previous reader upgraded. The result is the lock being unlocked and the panic is caused when unlocking a lock that isn't locked.
  • Loading branch information
russellhancox committed May 20, 2015
1 parent d72547e commit 32707fb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Source/santa-driver/SantaDecisionManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,12 @@ void SantaDecisionManager::CacheCheck(const char *identifier) {
lck_rw_lock_shared(cached_decisions_lock_);
bool shouldInvalidate = (cached_decisions_->getObject(identifier) != NULL);
if (shouldInvalidate) {
lck_rw_lock_shared_to_exclusive(cached_decisions_lock_);
if (!lck_rw_lock_shared_to_exclusive(cached_decisions_lock_)) {
// shared_to_exclusive will return false if a previous reader upgraded
// and if that happens the lock will have been unlocked. If that happens,
// which is rare, relock exclusively.
lck_rw_lock_exclusive(cached_decisions_lock_);
}
cached_decisions_->removeObject(identifier);
lck_rw_unlock_exclusive(cached_decisions_lock_);
} else {
Expand Down Expand Up @@ -282,7 +287,7 @@ santa_action_t SantaDecisionManager::GetFromDaemon(
CacheCheck(vnode_id_str);
return ACTION_ERROR;
}

return return_action;
}

Expand Down

0 comments on commit 32707fb

Please sign in to comment.