Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit b1a4ba8

Browse files
committed
Bug 1505445 - [Mac] With sandbox early startup, start the sandbox after the port exchange r=Alex_Gaynor
Don't start the sandbox until after the port exchange so the parent process does not have to wait longer in ContentParent::LaunchSubprocess() for the (expensive) sandbox_init_with_parameters call to complete in the child. Remove the policy rule allowing access to the parent port now that it is already open when the sandbox is initialized and therefore not needed. Differential Revision: https://phabricator.services.mozilla.com/D11186 --HG-- extra : moz-landing-system : lando
1 parent 80bd2cd commit b1a4ba8

6 files changed

Lines changed: 17 additions & 49 deletions

File tree

browser/app/nsBrowserApp.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@
4343
#include "FuzzerDefs.h"
4444
#endif
4545

46-
#if defined(XP_MACOSX) && defined(MOZ_CONTENT_SANDBOX)
47-
#include "mozilla/Sandbox.h"
48-
#endif
49-
5046
#ifdef MOZ_LINUX_32_SSE2_STARTUP_ERROR
5147
#include <cpuid.h>
5248
#include "mozilla/Unused.h"
@@ -267,16 +263,6 @@ int main(int argc, char* argv[], char* envp[])
267263
{
268264
mozilla::TimeStamp start = mozilla::TimeStamp::Now();
269265

270-
#if defined(XP_MACOSX) && defined(MOZ_CONTENT_SANDBOX)
271-
if (argc > 1 && IsArg(argv[1], "contentproc")) {
272-
std::string err;
273-
if (!mozilla::EarlyStartMacSandboxIfEnabled(argc, argv, err)) {
274-
Output("Sandbox error: %s\n", err.c_str());
275-
MOZ_CRASH("Sandbox initialization failed");
276-
}
277-
}
278-
#endif
279-
280266
#ifdef MOZ_BROWSER_CAN_BE_CONTENTPROC
281267
// We are launching as a content process, delegate to the appropriate
282268
// main

ipc/app/MozillaRuntimeMain.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,11 @@
99
#include "mozilla/Bootstrap.h"
1010
#include "mozilla/WindowsDllBlocklist.h"
1111

12-
#if defined(XP_MACOSX) && defined(MOZ_CONTENT_SANDBOX)
13-
#include "mozilla/Sandbox.h"
14-
#endif
15-
1612
using namespace mozilla;
1713

1814
int
1915
main(int argc, char *argv[])
2016
{
21-
#if defined(XP_MACOSX) && defined(MOZ_CONTENT_SANDBOX)
22-
std::string err;
23-
if (!mozilla::EarlyStartMacSandboxIfEnabled(argc, argv, err)) {
24-
fprintf(stderr, "Sandbox error: %s\n", err.c_str());
25-
MOZ_CRASH("Sandbox initialization failed");
26-
}
27-
#endif
28-
2917
#ifdef HAS_DLL_BLOCKLIST
3018
DllBlocklist_Initialize(eDllBlocklistInitFlagIsChildProcess);
3119
#endif

security/sandbox/mac/Sandbox.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ typedef struct _MacSandboxInfo {
6969
std::string testingReadPath3;
7070
std::string testingReadPath4;
7171

72-
std::string parentPort;
7372
std::string crashServerPort;
7473

7574
bool shouldLog;

security/sandbox/mac/Sandbox.mm

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,6 @@ bool StartMacSandbox(MacSandboxInfo const &aInfo, std::string &aErrorMessage)
234234
params.push_back(aInfo.hasSandboxedProfile ? "TRUE" : "FALSE");
235235
params.push_back("HAS_WINDOW_SERVER");
236236
params.push_back(aInfo.hasWindowServer ? "TRUE" : "FALSE");
237-
if (!aInfo.parentPort.empty()) {
238-
params.push_back("PARENT_PORT");
239-
params.push_back(aInfo.parentPort.c_str());
240-
}
241237
if (!aInfo.crashServerPort.empty()) {
242238
params.push_back("CRASH_PORT");
243239
params.push_back(aInfo.crashServerPort.c_str());
@@ -342,7 +338,6 @@ bool StartMacSandbox(MacSandboxInfo const &aInfo, std::string &aErrorMessage)
342338
// line arguments. Return false if any are missing.
343339
bool foundSandboxLevel = false;
344340
bool foundValidSandboxLevel = false;
345-
bool foundParentPort = false;
346341
bool foundAppPath = false;
347342

348343
// Read access directories used in testing
@@ -416,13 +411,7 @@ bool StartMacSandbox(MacSandboxInfo const &aInfo, std::string &aErrorMessage)
416411
}
417412
#endif // DEBUG
418413

419-
// Handle positional arguments
420-
if (strstr(aArgv[i], "org.mozilla.machname") != NULL) {
421-
foundParentPort = true;
422-
aInfo.parentPort.assign(aArgv[i]);
423-
continue;
424-
}
425-
414+
// Handle crash server positional argument
426415
if (strstr(aArgv[i], "gecko-crash-server-pipe") != NULL) {
427416
aInfo.crashServerPort.assign(aArgv[i]);
428417
continue;
@@ -441,12 +430,6 @@ bool StartMacSandbox(MacSandboxInfo const &aInfo, std::string &aErrorMessage)
441430
return false;
442431
}
443432

444-
if (!foundParentPort) {
445-
fprintf(stderr, "Content sandbox disabled due to "
446-
"missing sandbox CLI parent port parameter.\n");
447-
return false;
448-
}
449-
450433
if (!foundAppPath) {
451434
fprintf(stderr, "Content sandbox disabled due to "
452435
"missing sandbox CLI app path parameter.\n");

security/sandbox/mac/SandboxPolicies.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ static const char contentSandboxRules[] = R"SANDBOX_LITERAL(
6161
(define testingReadPath2 (param "TESTING_READ_PATH2"))
6262
(define testingReadPath3 (param "TESTING_READ_PATH3"))
6363
(define testingReadPath4 (param "TESTING_READ_PATH4"))
64-
(define parentPort (param "PARENT_PORT"))
6564
(define crashPort (param "CRASH_PORT"))
6665
6766
(if (string=? should-log "TRUE")
@@ -188,8 +187,6 @@ static const char contentSandboxRules[] = R"SANDBOX_LITERAL(
188187
(ipc-posix-name-regex #"^CFPBS:"))
189188
190189
(allow signal (target self))
191-
(if (string? parentPort)
192-
(allow mach-lookup (global-name parentPort)))
193190
(if (string? crashPort)
194191
(allow mach-lookup (global-name crashPort)))
195192
(if (string=? hasWindowServer "TRUE")

toolkit/xre/nsEmbedFunctions.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,13 @@ XRE_InitChildProcess(int aArgc,
442442
#ifdef XP_MACOSX
443443
if (aArgc < 1)
444444
return NS_ERROR_FAILURE;
445+
446+
#if defined(MOZ_CONTENT_SANDBOX)
447+
// Save the original number of arguments to pass to the sandbox
448+
// setup routine which also uses the crash server argument.
449+
int allArgc = aArgc;
450+
#endif /* MOZ_CONTENT_SANDBOX */
451+
445452
const char* const mach_port_name = aArgv[--aArgc];
446453

447454
Maybe<recordreplay::AutoPassThroughThreadEvents> pt;
@@ -513,8 +520,16 @@ XRE_InitChildProcess(int aArgc,
513520
return NS_ERROR_FAILURE;
514521
}
515522

523+
#if defined(MOZ_CONTENT_SANDBOX)
524+
std::string sandboxError;
525+
if (!EarlyStartMacSandboxIfEnabled(allArgc, aArgv, sandboxError)) {
526+
printf_stderr("Sandbox error: %s\n", sandboxError.c_str());
527+
MOZ_CRASH("Sandbox initialization failed");
528+
}
529+
#endif /* MOZ_CONTENT_SANDBOX */
530+
516531
pt.reset();
517-
#endif
532+
#endif /* XP_MACOSX */
518533

519534
SetupErrorHandling(aArgv[0]);
520535

0 commit comments

Comments
 (0)