Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/installer/setup/setup_singleton.h" | 5 #include "chrome/installer/setup/setup_singleton.h" |
| 6 | 6 |
| 7 #include <functional> | 7 #include <functional> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 SETUP_SINGLETON_ACQUISITION_EXIT_EVENT_MUTEX_CREATION_FAILED = 5, | 36 SETUP_SINGLETON_ACQUISITION_EXIT_EVENT_MUTEX_CREATION_FAILED = 5, |
| 37 SETUP_SINGLETON_ACQUISITION_RESULT_COUNT, | 37 SETUP_SINGLETON_ACQUISITION_RESULT_COUNT, |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 void RecordSetupSingletonAcquisitionResultHistogram( | 40 void RecordSetupSingletonAcquisitionResultHistogram( |
| 41 SetupSingletonAcquisitionResult result) { | 41 SetupSingletonAcquisitionResult result) { |
| 42 UMA_HISTOGRAM_ENUMERATION("Setup.Install.SingletonAcquisitionResult", result, | 42 UMA_HISTOGRAM_ENUMERATION("Setup.Install.SingletonAcquisitionResult", result, |
| 43 SETUP_SINGLETON_ACQUISITION_RESULT_COUNT); | 43 SETUP_SINGLETON_ACQUISITION_RESULT_COUNT); |
| 44 } | 44 } |
| 45 | 45 |
| 46 // Initializes |security_attributes| and |security_descriptor| so that a handle | |
| 47 // created using |security_attributes| is accessible to everyone. | |
| 48 // |security_descriptor| must outlive |security_attributes|. | |
| 49 void InitializeAllAccessSecurityAttributes( | |
| 50 SECURITY_ATTRIBUTES* security_attributes, | |
| 51 SECURITY_DESCRIPTOR* security_descriptor) { | |
| 52 DCHECK(security_attributes); | |
| 53 DCHECK(security_descriptor); | |
| 54 | |
| 55 const BOOL initialize_security_descriptor_result = | |
| 56 ::InitializeSecurityDescriptor(security_descriptor, | |
| 57 SECURITY_DESCRIPTOR_REVISION); | |
| 58 DCHECK(initialize_security_descriptor_result); | |
| 59 // A nullptr DACL allows access to everyone. | |
|
grt (UTC plus 2)
2016/10/03 07:49:00
i don't think it's a good idea to allow any proces
| |
| 60 const BOOL set_security_descriptor_dacl_result = | |
| 61 ::SetSecurityDescriptorDacl(security_descriptor, TRUE, nullptr, TRUE); | |
| 62 DCHECK(set_security_descriptor_dacl_result); | |
| 63 | |
| 64 security_attributes->nLength = sizeof(*security_attributes); | |
| 65 security_attributes->lpSecurityDescriptor = security_descriptor; | |
| 66 security_attributes->bInheritHandle = FALSE; | |
| 67 } | |
| 68 | |
| 46 } // namespace | 69 } // namespace |
| 47 | 70 |
| 48 std::unique_ptr<SetupSingleton> SetupSingleton::Acquire( | 71 std::unique_ptr<SetupSingleton> SetupSingleton::Acquire( |
| 49 const base::CommandLine& command_line, | 72 const base::CommandLine& command_line, |
| 50 const MasterPreferences& master_preferences, | 73 const MasterPreferences& master_preferences, |
| 51 InstallationState* original_state, | 74 InstallationState* original_state, |
| 52 InstallerState* installer_state) { | 75 InstallerState* installer_state) { |
| 53 DCHECK(original_state); | 76 DCHECK(original_state); |
| 54 DCHECK(installer_state); | 77 DCHECK(installer_state); |
| 55 | 78 |
| 56 const base::string16 sync_primitive_name_suffix( | 79 const base::string16 sync_primitive_name_suffix( |
| 57 base::SizeTToString16(std::hash<base::FilePath::StringType>()( | 80 base::SizeTToString16(std::hash<base::FilePath::StringType>()( |
| 58 installer_state->target_path().value()))); | 81 installer_state->target_path().value()))); |
| 59 | 82 |
| 83 // The event and mutexes created by this method have security attributes that | |
| 84 // allow access to everyone. This means that a non-elevated installer can | |
| 85 // access the event and mutexes created by an elevated installer. | |
| 86 SECURITY_DESCRIPTOR security_descriptor; | |
| 87 SECURITY_ATTRIBUTES security_attributes; | |
| 88 InitializeAllAccessSecurityAttributes(&security_attributes, | |
| 89 &security_descriptor); | |
| 90 | |
| 60 base::win::ScopedHandle setup_mutex(::CreateMutex( | 91 base::win::ScopedHandle setup_mutex(::CreateMutex( |
| 61 nullptr, FALSE, | 92 &security_attributes, FALSE, |
| 62 (L"Global\\ChromeSetupMutex_" + sync_primitive_name_suffix).c_str())); | 93 (L"Global\\ChromeSetupMutex_" + sync_primitive_name_suffix).c_str())); |
| 63 if (!setup_mutex.IsValid()) { | 94 if (!setup_mutex.IsValid()) { |
| 64 RecordSetupSingletonAcquisitionResultHistogram( | 95 RecordSetupSingletonAcquisitionResultHistogram( |
| 65 SETUP_SINGLETON_ACQUISITION_SETUP_MUTEX_CREATION_FAILED); | 96 SETUP_SINGLETON_ACQUISITION_SETUP_MUTEX_CREATION_FAILED); |
| 66 return nullptr; | 97 return nullptr; |
| 67 } | 98 } |
| 68 | 99 |
| 69 base::win::ScopedHandle exit_event(::CreateEvent( | 100 base::win::ScopedHandle exit_event(::CreateEvent( |
| 70 nullptr, TRUE, FALSE, | 101 &security_attributes, TRUE, FALSE, |
| 71 (L"Global\\ChromeSetupExitEvent_" + sync_primitive_name_suffix).c_str())); | 102 (L"Global\\ChromeSetupExitEvent_" + sync_primitive_name_suffix).c_str())); |
| 72 if (!exit_event.IsValid()) { | 103 if (!exit_event.IsValid()) { |
| 73 RecordSetupSingletonAcquisitionResultHistogram( | 104 RecordSetupSingletonAcquisitionResultHistogram( |
| 74 SETUP_SINGLETON_ACQUISITION_EXIT_EVENT_CREATION_FAILED); | 105 SETUP_SINGLETON_ACQUISITION_EXIT_EVENT_CREATION_FAILED); |
| 75 return nullptr; | 106 return nullptr; |
| 76 } | 107 } |
| 77 | 108 |
| 78 auto setup_singleton = base::WrapUnique( | 109 auto setup_singleton = base::WrapUnique( |
| 79 new SetupSingleton(std::move(setup_mutex), std::move(exit_event))); | 110 new SetupSingleton(std::move(setup_mutex), std::move(exit_event))); |
| 80 | 111 |
| 81 { | 112 { |
| 82 // Acquire a mutex to ensure that a single call to SetupSingleton::Acquire() | 113 // Acquire a mutex to ensure that a single call to SetupSingleton::Acquire() |
| 83 // signals |exit_event_| and waits for |setup_mutex_| to be released at a | 114 // signals |exit_event_| and waits for |setup_mutex_| to be released at a |
| 84 // time. | 115 // time. |
| 85 base::win::ScopedHandle exit_event_mutex(::CreateMutex( | 116 base::win::ScopedHandle exit_event_mutex(::CreateMutex( |
| 86 nullptr, FALSE, | 117 &security_attributes, FALSE, |
| 87 (L"Global\\ChromeSetupExitEventMutex_" + sync_primitive_name_suffix) | 118 (L"Global\\ChromeSetupExitEventMutex_" + sync_primitive_name_suffix) |
| 88 .c_str())); | 119 .c_str())); |
| 89 if (!exit_event_mutex.IsValid()) { | 120 if (!exit_event_mutex.IsValid()) { |
| 90 RecordSetupSingletonAcquisitionResultHistogram( | 121 RecordSetupSingletonAcquisitionResultHistogram( |
| 91 SETUP_SINGLETON_ACQUISITION_EXIT_EVENT_MUTEX_CREATION_FAILED); | 122 SETUP_SINGLETON_ACQUISITION_EXIT_EVENT_MUTEX_CREATION_FAILED); |
| 92 return nullptr; | 123 return nullptr; |
| 93 } | 124 } |
| 94 | 125 |
| 95 ScopedHoldMutex scoped_hold_exit_event_mutex; | 126 ScopedHoldMutex scoped_hold_exit_event_mutex; |
| 96 if (!scoped_hold_exit_event_mutex.Acquire(exit_event_mutex.Get())) { | 127 if (!scoped_hold_exit_event_mutex.Acquire(exit_event_mutex.Get())) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 return false; | 186 return false; |
| 156 } | 187 } |
| 157 | 188 |
| 158 SetupSingleton::SetupSingleton(base::win::ScopedHandle setup_mutex, | 189 SetupSingleton::SetupSingleton(base::win::ScopedHandle setup_mutex, |
| 159 base::win::ScopedHandle exit_event) | 190 base::win::ScopedHandle exit_event) |
| 160 : setup_mutex_(std::move(setup_mutex)), exit_event_(std::move(exit_event)) { | 191 : setup_mutex_(std::move(setup_mutex)), exit_event_(std::move(exit_event)) { |
| 161 DCHECK(setup_mutex_.IsValid()); | 192 DCHECK(setup_mutex_.IsValid()); |
| 162 } | 193 } |
| 163 | 194 |
| 164 } // namespace installer | 195 } // namespace installer |
| OLD | NEW |