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

Side by Side Diff: content/browser/zygote_host_impl_linux.cc

Issue 10807059: Refactor the setuid sandbox client code to its own class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address reviewer's comments and other minor nits. Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « base/linux_util.cc ('k') | content/zygote/zygote_main_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/zygote_host_impl_linux.h" 5 #include "content/browser/zygote_host_impl_linux.h"
6 6
7 #include <sys/socket.h> 7 #include <sys/socket.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 13 matching lines...) Expand all
24 #include "base/process_util.h" 24 #include "base/process_util.h"
25 #include "base/string_number_conversions.h" 25 #include "base/string_number_conversions.h"
26 #include "base/string_util.h" 26 #include "base/string_util.h"
27 #include "base/time.h" 27 #include "base/time.h"
28 #include "base/utf_string_conversions.h" 28 #include "base/utf_string_conversions.h"
29 #include "content/browser/renderer_host/render_sandbox_host_linux.h" 29 #include "content/browser/renderer_host/render_sandbox_host_linux.h"
30 #include "content/common/zygote_commands_linux.h" 30 #include "content/common/zygote_commands_linux.h"
31 #include "content/public/browser/content_browser_client.h" 31 #include "content/public/browser/content_browser_client.h"
32 #include "content/public/common/content_switches.h" 32 #include "content/public/common/content_switches.h"
33 #include "content/public/common/result_codes.h" 33 #include "content/public/common/result_codes.h"
34 #include "sandbox/linux/suid/sandbox.h" 34 #include "sandbox/linux/suid/client/setuid_sandbox_client.h"
35 #include "sandbox/linux/suid/suid_unsafe_environment_variables.h" 35 #include "sandbox/linux/suid/common/sandbox.h"
36 36
37 #if defined(USE_TCMALLOC) 37 #if defined(USE_TCMALLOC)
38 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" 38 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h"
39 #endif 39 #endif
40 40
41 // Set an environment variable that reflects the API version we expect from the
42 // setuid sandbox. Old versions of the sandbox will ignore this.
43 static void SetSandboxAPIEnvironmentVariable() {
44 scoped_ptr<base::Environment> env(base::Environment::Create());
45 env->SetVar(base::kSandboxEnvironmentApiRequest,
46 base::IntToString(base::kSUIDSandboxApiNumber));
47 }
48
49 static void SaveSUIDUnsafeEnvironmentVariables() {
50 // The ELF loader will clear many environment variables so we save them to
51 // different names here so that the SUID sandbox can resolve them for the
52 // renderer.
53
54 for (unsigned i = 0; kSUIDUnsafeEnvironmentVariables[i]; ++i) {
55 const char* const envvar = kSUIDUnsafeEnvironmentVariables[i];
56 char* const saved_envvar = SandboxSavedEnvironmentVariable(envvar);
57 if (!saved_envvar)
58 continue;
59
60 scoped_ptr<base::Environment> env(base::Environment::Create());
61 std::string value;
62 if (env->GetVar(envvar, &value))
63 env->SetVar(saved_envvar, value);
64 else
65 env->UnSetVar(saved_envvar);
66
67 free(saved_envvar);
68 }
69 }
70
71 // static 41 // static
72 content::ZygoteHost* content::ZygoteHost::GetInstance() { 42 content::ZygoteHost* content::ZygoteHost::GetInstance() {
73 return ZygoteHostImpl::GetInstance(); 43 return ZygoteHostImpl::GetInstance();
74 } 44 }
75 45
76 ZygoteHostImpl::ZygoteHostImpl() 46 ZygoteHostImpl::ZygoteHostImpl()
77 : control_fd_(-1), 47 : control_fd_(-1),
78 pid_(-1), 48 pid_(-1),
79 init_(false), 49 init_(false),
80 using_suid_sandbox_(false), 50 using_suid_sandbox_(false),
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 << sandbox_binary_ << " Aborting now."; 116 << sandbox_binary_ << " Aborting now.";
147 } 117 }
148 118
149 if (access(sandbox_binary_.c_str(), X_OK) == 0 && 119 if (access(sandbox_binary_.c_str(), X_OK) == 0 &&
150 (st.st_uid == 0) && 120 (st.st_uid == 0) &&
151 (st.st_mode & S_ISUID) && 121 (st.st_mode & S_ISUID) &&
152 (st.st_mode & S_IXOTH)) { 122 (st.st_mode & S_IXOTH)) {
153 using_suid_sandbox_ = true; 123 using_suid_sandbox_ = true;
154 cmd_line.PrependWrapper(sandbox_binary_); 124 cmd_line.PrependWrapper(sandbox_binary_);
155 125
156 SaveSUIDUnsafeEnvironmentVariables(); 126 scoped_ptr<sandbox::SetuidSandboxClient>
157 SetSandboxAPIEnvironmentVariable(); 127 sandbox_client(sandbox::SetuidSandboxClient::Create());
128 sandbox_client->SetupLaunchEnvironment();
158 } else { 129 } else {
159 LOG(FATAL) << "The SUID sandbox helper binary was found, but is not " 130 LOG(FATAL) << "The SUID sandbox helper binary was found, but is not "
160 "configured correctly. Rather than run without sandboxing " 131 "configured correctly. Rather than run without sandboxing "
161 "I'm aborting now. You need to make sure that " 132 "I'm aborting now. You need to make sure that "
162 << sandbox_binary_ << " is owned by root and has mode 4755."; 133 << sandbox_binary_ << " is owned by root and has mode 4755.";
163 } 134 }
164 } else { 135 } else {
165 LOG(WARNING) << "Running without the SUID sandbox! See " 136 LOG(WARNING) << "Running without the SUID sandbox! See "
166 "http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment " 137 "http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment "
167 "for more information on developing with the sandbox on."; 138 "for more information on developing with the sandbox on.";
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 471
501 pid_t ZygoteHostImpl::GetSandboxHelperPid() const { 472 pid_t ZygoteHostImpl::GetSandboxHelperPid() const {
502 return RenderSandboxHostLinux::GetInstance()->pid(); 473 return RenderSandboxHostLinux::GetInstance()->pid();
503 } 474 }
504 475
505 int ZygoteHostImpl::GetSandboxStatus() const { 476 int ZygoteHostImpl::GetSandboxStatus() const {
506 if (have_read_sandbox_status_word_) 477 if (have_read_sandbox_status_word_)
507 return sandbox_status_; 478 return sandbox_status_;
508 return 0; 479 return 0;
509 } 480 }
OLDNEW
« no previous file with comments | « base/linux_util.cc ('k') | content/zygote/zygote_main_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698