diff --git a/chrome/updater/policy/service.cc b/chrome/updater/policy/service.cc index a7fb3843f1b02..53c0f08c06e89 100644 --- a/chrome/updater/policy/service.cc +++ b/chrome/updater/policy/service.cc @@ -131,12 +131,14 @@ bool PolicyService::PolicyManagers::CloudPolicyOverridesPlatformPolicy( void PolicyService::PolicyManagers::ResetDeviceManagementManager( scoped_refptr dm_manager) { + base::AutoLock lock(managers_lock_); dm_policy_manager_ = dm_manager; InitializeManagersVector(); } void PolicyService::PolicyManagers::SetManagersForTesting( std::vector> managers) { + base::AutoLock lock(managers_lock_); managers_ = std::move(managers); SortManagersVector(); } diff --git a/chrome/updater/policy/service.h b/chrome/updater/policy/service.h index ede8beaa90ecc..c8e3fe48cad28 100644 --- a/chrome/updater/policy/service.h +++ b/chrome/updater/policy/service.h @@ -16,6 +16,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_refptr.h" #include "base/sequence_checker.h" +#include "base/synchronization/lock.h" #include "base/strings/string_util.h" #include "base/time/time.h" #include "base/values.h" @@ -159,6 +160,11 @@ class PolicyService : public base::RefCountedThreadSafe { scoped_refptr dm_manager); std::vector> managers() const { + // Called on arbitrary COM RPC threads (see crbug.com/1517079) while + // `ResetDeviceManagementManager()` mutates `managers_` on the main + // sequence. Take the lock so the by-value copy is atomic w.r.t. the + // clear()/rebuild in `InitializeManagersVector()`. + base::AutoLock lock(managers_lock_); return managers_; } @@ -172,6 +178,11 @@ class PolicyService : public base::RefCountedThreadSafe { static bool CloudPolicyOverridesPlatformPolicy( const std::vector>& providers); + // Guards `managers_` against concurrent reads (COM RPC threads via + // `managers()`) and writes (`ResetDeviceManagementManager()` / + // `InitializeManagersVector()` / `SetManagersForTesting()` on the main + // sequence). See crbug.com/1517079. + mutable base::Lock managers_lock_; std::vector> managers_; scoped_refptr dm_policy_manager_; scoped_refptr external_constants_policy_manager_;