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

Side by Side Diff: sandbox/linux/suid/client/setuid_sandbox_client.cc

Issue 885673007: Minor refactoring of setuid_sandbox_client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « sandbox/linux/suid/client/setuid_sandbox_client.h ('k') | no next file » | 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 "sandbox/linux/suid/client/setuid_sandbox_client.h" 5 #include "sandbox/linux/suid/client/setuid_sandbox_client.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <sys/socket.h> 9 #include <sys/socket.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
11 #include <sys/types.h> 11 #include <sys/types.h>
12 #include <sys/wait.h> 12 #include <sys/wait.h>
13 #include <unistd.h> 13 #include <unistd.h>
14 14
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/environment.h" 16 #include "base/environment.h"
17 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
18 #include "base/files/file_util.h" 18 #include "base/files/file_util.h"
19 #include "base/files/scoped_file.h" 19 #include "base/files/scoped_file.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/macros.h"
22 #include "base/memory/scoped_ptr.h" 21 #include "base/memory/scoped_ptr.h"
23 #include "base/path_service.h" 22 #include "base/path_service.h"
24 #include "base/posix/eintr_wrapper.h" 23 #include "base/posix/eintr_wrapper.h"
25 #include "base/process/launch.h" 24 #include "base/process/launch.h"
26 #include "base/process/process_metrics.h" 25 #include "base/process/process_metrics.h"
27 #include "base/strings/string_number_conversions.h" 26 #include "base/strings/string_number_conversions.h"
28 #include "sandbox/linux/services/init_process_reaper.h" 27 #include "sandbox/linux/services/init_process_reaper.h"
29 #include "sandbox/linux/suid/common/sandbox.h" 28 #include "sandbox/linux/suid/common/sandbox.h"
30 #include "sandbox/linux/suid/common/suid_unsafe_environment_variables.h" 29 #include "sandbox/linux/suid/common/suid_unsafe_environment_variables.h"
31 30
32 namespace { 31 namespace {
33 32
34 bool IsFileSystemAccessDenied() { 33 bool IsFileSystemAccessDenied() {
35 base::ScopedFD self_exe(HANDLE_EINTR(open(base::kProcSelfExe, O_RDONLY))); 34 base::ScopedFD self_exe(HANDLE_EINTR(open("/", O_RDONLY)));
jln (very slow on Chromium) 2015/02/05 00:12:52 This seems like it could easily regress. What was
mdempsky 2015/02/05 01:41:19 Removing base::kProcSelfExe was so this function c
36 return !self_exe.is_valid(); 35 return !self_exe.is_valid();
37 } 36 }
38 37
39 // Set an environment variable that reflects the API version we expect from the 38 // Set an environment variable that reflects the API version we expect from the
40 // setuid sandbox. Old versions of the sandbox will ignore this. 39 // setuid sandbox. Old versions of the sandbox will ignore this.
41 void SetSandboxAPIEnvironmentVariable(base::Environment* env) { 40 void SetSandboxAPIEnvironmentVariable(base::Environment* env) {
42 env->SetVar(sandbox::kSandboxEnvironmentApiRequest, 41 env->SetVar(sandbox::kSandboxEnvironmentApiRequest,
43 base::IntToString(sandbox::kSUIDSandboxApiNumber)); 42 base::IntToString(sandbox::kSUIDSandboxApiNumber));
44 } 43 }
45 44
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 return false; 200 return false;
202 } 201 }
203 202
204 // We now consider ourselves "fully sandboxed" as far as the 203 // We now consider ourselves "fully sandboxed" as far as the
205 // setuid sandbox is concerned. 204 // setuid sandbox is concerned.
206 CHECK(IsFileSystemAccessDenied()); 205 CHECK(IsFileSystemAccessDenied());
207 sandboxed_ = true; 206 sandboxed_ = true;
208 return true; 207 return true;
209 } 208 }
210 209
211 bool SetuidSandboxClient::CreateInitProcessReaper(
212 base::Closure* post_fork_parent_callback) {
213 return sandbox::CreateInitProcessReaper(post_fork_parent_callback);
214 }
215
216 bool SetuidSandboxClient::IsSuidSandboxUpToDate() const { 210 bool SetuidSandboxClient::IsSuidSandboxUpToDate() const {
217 return GetHelperApi(env_) == kSUIDSandboxApiNumber; 211 return GetHelperApi(env_) == kSUIDSandboxApiNumber;
218 } 212 }
219 213
220 bool SetuidSandboxClient::IsSuidSandboxChild() const { 214 bool SetuidSandboxClient::IsSuidSandboxChild() const {
221 return GetIPCDescriptor(env_) >= 0; 215 return GetIPCDescriptor(env_) >= 0;
222 } 216 }
223 217
224 bool SetuidSandboxClient::IsInNewPIDNamespace() const { 218 bool SetuidSandboxClient::IsInNewPIDNamespace() const {
225 return env_->HasVar(kSandboxPIDNSEnvironmentVarName); 219 return env_->HasVar(kSandboxPIDNSEnvironmentVarName);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 // kZygoteIdFd. Fixing this requires a sandbox API change. :( 304 // kZygoteIdFd. Fixing this requires a sandbox API change. :(
311 fds_to_remap->push_back(std::make_pair(dummy_fd->get(), kZygoteIdFd)); 305 fds_to_remap->push_back(std::make_pair(dummy_fd->get(), kZygoteIdFd));
312 } 306 }
313 307
314 void SetuidSandboxClient::SetupLaunchEnvironment() { 308 void SetuidSandboxClient::SetupLaunchEnvironment() {
315 SaveSUIDUnsafeEnvironmentVariables(env_); 309 SaveSUIDUnsafeEnvironmentVariables(env_);
316 SetSandboxAPIEnvironmentVariable(env_); 310 SetSandboxAPIEnvironmentVariable(env_);
317 } 311 }
318 312
319 } // namespace sandbox 313 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/linux/suid/client/setuid_sandbox_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698