Bug 1256992 Part 2: Move SandboxBroker Initialization earlier and add telemetry and extra null checks. r=aklotz

MozReview-Commit-ID: Fu05wLn27UG
This commit is contained in:
Bob Owen 2016-04-07 08:28:14 +01:00
parent dd6ade76ab
commit 907939a278
3 changed files with 41 additions and 20 deletions

View File

@ -434,6 +434,10 @@ SandboxBroker::SetSecurityLevelForGMPlugin()
bool
SandboxBroker::AllowReadFile(wchar_t const *file)
{
if (!mPolicy) {
return false;
}
auto result =
mPolicy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES,
sandbox::TargetPolicy::FILES_ALLOW_READONLY,
@ -444,6 +448,10 @@ SandboxBroker::AllowReadFile(wchar_t const *file)
bool
SandboxBroker::AllowReadWriteFile(wchar_t const *file)
{
if (!mPolicy) {
return false;
}
auto result =
mPolicy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES,
sandbox::TargetPolicy::FILES_ALLOW_ANY,
@ -454,6 +462,10 @@ SandboxBroker::AllowReadWriteFile(wchar_t const *file)
bool
SandboxBroker::AllowDirectory(wchar_t const *dir)
{
if (!mPolicy) {
return false;
}
auto result =
mPolicy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES,
sandbox::TargetPolicy::FILES_ALLOW_DIR_ANY,
@ -464,6 +476,10 @@ SandboxBroker::AllowDirectory(wchar_t const *dir)
bool
SandboxBroker::AddTargetPeer(HANDLE aPeerProcess)
{
if (!sBrokerService) {
return false;
}
sandbox::ResultCode result = sBrokerService->AddTargetPeer(aPeerProcess);
return (sandbox::SBOX_ALL_OK == result);
}

View File

@ -10465,5 +10465,12 @@
"n_buckets": 50,
"keyed": true,
"description": "Measures the size of message manager messages by message name"
},
"SANDBOX_BROKER_INITIALIZED": {
"alert_emails": ["bowen@mozilla.com"],
"bug_numbers": [1256992],
"expires_in_version": "55",
"kind": "boolean",
"description": "Result of call to SandboxBroker::Initialize"
}
}

View File

@ -3366,6 +3366,24 @@ XREMain::XRE_mainInit(bool* aExitFlag)
}
#endif
#if defined(MOZ_SANDBOX) && defined(XP_WIN)
bool brokerInitialized = SandboxBroker::Initialize();
Telemetry::Accumulate(Telemetry::SANDBOX_BROKER_INITIALIZED,
brokerInitialized);
if (!brokerInitialized) {
#if defined(MOZ_CONTENT_SANDBOX)
// If we're sandboxing content and we fail to initialize, then crashing here
// seems like the sensible option.
if (BrowserTabsRemoteAutostart()) {
MOZ_CRASH("Failed to initialize broker services, can't continue.");
}
#endif
// Otherwise just warn for the moment, as most things will work.
NS_WARNING("Failed to initialize broker services, sandboxed processes will "
"fail to start.");
}
#endif
#ifdef XP_MACOSX
if (EnvHasValue("MOZ_LAUNCHED_CHILD")) {
// This is needed, on relaunch, to force the OS to use the "Cocoa Dock
@ -3729,12 +3747,6 @@ XREMain::XRE_mainStartup(bool* aExitFlag)
int result;
#ifdef XP_WIN
UseParentConsole();
#if defined(MOZ_SANDBOX)
if (!SandboxBroker::Initialize()) {
NS_WARNING("Failed to initialize broker services, sandboxed processes "
"will fail to start.");
}
#endif
#endif
// RunGTest will only be set if we're in xul-unit
if (mozilla::RunGTest) {
@ -4320,20 +4332,6 @@ XREMain::XRE_mainRun()
}
#endif /* MOZ_INSTRUMENT_EVENT_LOOP */
#if defined(MOZ_SANDBOX) && defined(XP_WIN)
if (!SandboxBroker::Initialize()) {
#if defined(MOZ_CONTENT_SANDBOX)
// If we're sandboxing content and we fail to initialize, then crashing here
// seems like the sensible option.
if (BrowserTabsRemoteAutostart()) {
MOZ_CRASH("Failed to initialize broker services, can't continue.");
}
#endif
// Otherwise just warn for the moment, as most things will work.
NS_WARNING("Failed to initialize broker services, sandboxed processes will "
"fail to start.");
}
#endif
#if (defined(XP_WIN) || defined(XP_MACOSX)) && defined(MOZ_CONTENT_SANDBOX)
SetUpSandboxEnvironment();
#endif