Bug 1256992: Initialize Windows sandbox BrokerServices before any child processes are created. r=aklotz, r=bholley

This commit is contained in:
Bob Owen 2016-03-22 07:40:03 +00:00
parent 99f8b5b2e3
commit 72e4566fa4
4 changed files with 51 additions and 12 deletions

View File

@ -44,6 +44,9 @@
#ifdef XP_WIN
#include "mozilla/widget/AudioSession.h"
#include <windows.h>
#if defined(MOZ_SANDBOX)
#include "SandboxBroker.h"
#endif
#endif
// all this crap is needed to do the interactive shell stuff
@ -1518,6 +1521,14 @@ XRE_XPCShellMain(int argc, char** argv, char** envp)
// Plugin may require audio session if installed plugin can initialize
// asynchronized.
AutoAudioSession audioSession;
#if defined(MOZ_SANDBOX)
// Required for sandboxed child processes.
if (!SandboxBroker::Initialize()) {
NS_WARNING("Failed to initialize broker services, sandboxed "
"processes will fail to start.");
}
#endif
#endif
{

View File

@ -17,21 +17,28 @@ namespace mozilla
sandbox::BrokerServices *SandboxBroker::sBrokerService = nullptr;
SandboxBroker::SandboxBroker()
/* static */
bool
SandboxBroker::Initialize()
{
// XXX: This is not thread-safe! Two threads could simultaneously try
// to set `sBrokerService`
sBrokerService = sandbox::SandboxFactory::GetBrokerServices();
if (!sBrokerService) {
sBrokerService = sandbox::SandboxFactory::GetBrokerServices();
if (sBrokerService) {
sandbox::ResultCode result = sBrokerService->Init();
if (result != sandbox::SBOX_ALL_OK) {
sBrokerService = nullptr;
}
}
return false;
}
mPolicy = sBrokerService->CreatePolicy();
if (sBrokerService->Init() != sandbox::SBOX_ALL_OK) {
sBrokerService = nullptr;
return false;
}
return true;
}
SandboxBroker::SandboxBroker()
{
if (sBrokerService) {
mPolicy = sBrokerService->CreatePolicy();
}
}
bool

View File

@ -27,6 +27,9 @@ class SANDBOX_EXPORT SandboxBroker
{
public:
SandboxBroker();
static bool Initialize();
bool LaunchApp(const wchar_t *aPath,
const wchar_t *aArguments,
const bool aEnableLogging,

View File

@ -210,8 +210,12 @@
#include "AndroidBridge.h"
#endif
#if defined(MOZ_SANDBOX) && defined(XP_LINUX) && !defined(ANDROID)
#if defined(MOZ_SANDBOX)
#if defined(XP_LINUX) && !defined(ANDROID)
#include "mozilla/SandboxInfo.h"
#elif defined(XP_WIN)
#include "SandboxBroker.h"
#endif
#endif
extern uint32_t gRestartMode;
@ -4308,6 +4312,20 @@ 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