Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(943)

Side by Side Diff: chrome/app/chrome_exe_main_mac.cc

Issue 2921733002: Add flags for v2 sandbox to Chrome and Helper executable. (Closed)
Patch Set: Address review feedback Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // The entry point for all Mac Chromium processes, including the outer app 5 // The entry point for all Mac Chromium processes, including the outer app
6 // bundle (browser) and helper app (renderer, plugin, and friends). 6 // bundle (browser) and helper app (renderer, plugin, and friends).
7 7
8 #include <dlfcn.h> 8 #include <dlfcn.h>
9 #include <errno.h> 9 #include <errno.h>
10 #include <libgen.h> 10 #include <libgen.h>
(...skipping 14 matching lines...) Expand all
25 #include "sandbox/mac/seatbelt_exec.h" 25 #include "sandbox/mac/seatbelt_exec.h"
26 #endif // defined(HELPER_EXECUTABLE) 26 #endif // defined(HELPER_EXECUTABLE)
27 27
28 namespace { 28 namespace {
29 29
30 typedef int (*ChromeMainPtr)(int, char**); 30 typedef int (*ChromeMainPtr)(int, char**);
31 31
32 #if defined(HELPER_EXECUTABLE) 32 #if defined(HELPER_EXECUTABLE)
33 // The command line parameter to engage the v2 sandbox. 33 // The command line parameter to engage the v2 sandbox.
34 constexpr char v2_sandbox_arg[] = "--v2-sandbox"; 34 constexpr char v2_sandbox_arg[] = "--v2-sandbox";
35 // The command line paramter indicating that the v2 sandbox is enabled. This
36 // must be different than the "v2-sandbox" flag to avoid endless re-executing.
37 // The flag tells the sandbox initialization code inside Chrome that the sandbox
38 // should already be enabled.
Charlie Reis 2017/06/02 20:50:41 Can you repeat this comment in content_switches.cc
Greg K 2017/06/02 23:59:02 Done.
39 // TODO(kerrnel): Remove this once the V2 sandbox migration is complete.
40 constexpr char v2_sandbox_enabled_arg[] = "--v2-sandbox-enabled";
35 // The command line parameter for the file descriptor used to receive the 41 // The command line parameter for the file descriptor used to receive the
36 // sandbox policy. 42 // sandbox policy.
37 constexpr char fd_mapping_arg[] = "--fd_mapping="; 43 constexpr char fd_mapping_arg[] = "--fd_mapping=";
38 44
39 __attribute__((noreturn)) void SandboxExec(const char* exec_path, 45 __attribute__((noreturn)) void SandboxExec(const char* exec_path,
40 int argc, 46 int argc,
41 char* argv[], 47 char* argv[],
42 int fd_mapping) { 48 int fd_mapping) {
43 char rp[MAXPATHLEN]; 49 char rp[MAXPATHLEN];
44 if (realpath(exec_path, rp) == NULL) { 50 if (realpath(exec_path, rp) == NULL) {
(...skipping 19 matching lines...) Expand all
64 abort(); 70 abort();
65 } 71 }
66 72
67 std::vector<char*> new_argv; 73 std::vector<char*> new_argv;
68 for (int i = 1; i < argc; ++i) { 74 for (int i = 1; i < argc; ++i) {
69 if (strcmp(argv[i], v2_sandbox_arg) != 0 && 75 if (strcmp(argv[i], v2_sandbox_arg) != 0 &&
70 strncmp(argv[i], fd_mapping_arg, strlen(fd_mapping_arg)) != 0) { 76 strncmp(argv[i], fd_mapping_arg, strlen(fd_mapping_arg)) != 0) {
71 new_argv.push_back(argv[i]); 77 new_argv.push_back(argv[i]);
72 } 78 }
73 } 79 }
80 // Tell Chrome that the sandbox should already be enabled.
81 // Note that execv() is documented to treat the argv as constants, so the
82 // const_cast is safe.
83 new_argv.push_back(const_cast<char*>(v2_sandbox_enabled_arg));
74 new_argv.push_back(nullptr); 84 new_argv.push_back(nullptr);
75 85
76 // The helper executable re-executes itself under the sandbox. 86 // The helper executable re-executes itself under the sandbox.
77 execv(exec_path, new_argv.data()); 87 execv(exec_path, new_argv.data());
78 perror("execve"); 88 perror("execve");
79 abort(); 89 abort();
80 } 90 }
81 #endif // defined(HELPER_EXECUTABLE) 91 #endif // defined(HELPER_EXECUTABLE)
82 92
83 } // namespace 93 } // namespace
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 if (!chrome_main) { 166 if (!chrome_main) {
157 fprintf(stderr, "dlsym ChromeMain: %s\n", dlerror()); 167 fprintf(stderr, "dlsym ChromeMain: %s\n", dlerror());
158 abort(); 168 abort();
159 } 169 }
160 rv = chrome_main(argc, argv); 170 rv = chrome_main(argc, argv);
161 171
162 // exit, don't return from main, to avoid the apparent removal of main from 172 // exit, don't return from main, to avoid the apparent removal of main from
163 // stack backtraces under tail call optimization. 173 // stack backtraces under tail call optimization.
164 exit(rv); 174 exit(rv);
165 } 175 }
OLDNEW
« no previous file with comments | « no previous file | content/common/sandbox_init_mac.cc » ('j') | content/public/common/content_switches.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698