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

Side by Side Diff: sandbox/linux/services/credentials.cc

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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/seccomp-bpf/sandbox_bpf.cc ('k') | sandbox/linux/services/scoped_process.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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/services/credentials.h" 5 #include "sandbox/linux/services/credentials.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <signal.h> 10 #include <signal.h>
11 #include <stdio.h> 11 #include <stdio.h>
12 #include <sys/capability.h> 12 #include <sys/capability.h>
13 #include <sys/stat.h> 13 #include <sys/stat.h>
14 #include <sys/syscall.h> 14 #include <sys/syscall.h>
15 #include <sys/types.h> 15 #include <sys/types.h>
16 #include <sys/wait.h> 16 #include <sys/wait.h>
17 #include <unistd.h> 17 #include <unistd.h>
18 18
19 #include "base/basictypes.h" 19 #include "base/basictypes.h"
20 #include "base/bind.h" 20 #include "base/bind.h"
21 #include "base/logging.h" 21 #include "base/logging.h"
22 #include "base/posix/eintr_wrapper.h" 22 #include "base/posix/eintr_wrapper.h"
23 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
24 #include "base/template_util.h" 24 #include "base/template_util.h"
25 #include "base/third_party/valgrind/valgrind.h" 25 #include "base/third_party/valgrind/valgrind.h"
26 #include "base/threading/thread.h" 26 #include "base/threading/thread.h"
27 #include "sandbox/linux/services/syscall_wrappers.h"
27 28
28 namespace { 29 namespace {
29 30
30 bool IsRunningOnValgrind() { return RUNNING_ON_VALGRIND; } 31 bool IsRunningOnValgrind() { return RUNNING_ON_VALGRIND; }
31 32
32 struct CapFreeDeleter { 33 struct CapFreeDeleter {
33 inline void operator()(cap_t cap) const { 34 inline void operator()(cap_t cap) const {
34 int ret = cap_free(cap); 35 int ret = cap_free(cap);
35 CHECK_EQ(0, ret); 36 CHECK_EQ(0, ret);
36 } 37 }
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 280
280 // static 281 // static
281 bool Credentials::SupportsNewUserNS() { 282 bool Credentials::SupportsNewUserNS() {
282 // Valgrind will let clone(2) pass-through, but doesn't support unshare(), 283 // Valgrind will let clone(2) pass-through, but doesn't support unshare(),
283 // so always consider UserNS unsupported there. 284 // so always consider UserNS unsupported there.
284 if (IsRunningOnValgrind()) { 285 if (IsRunningOnValgrind()) {
285 return false; 286 return false;
286 } 287 }
287 288
288 // This is roughly a fork(). 289 // This is roughly a fork().
289 const pid_t pid = syscall(__NR_clone, CLONE_NEWUSER | SIGCHLD, 0, 0, 0); 290 const pid_t pid = sys_clone(CLONE_NEWUSER | SIGCHLD, 0, 0, 0, 0);
290 291
291 if (pid == -1) { 292 if (pid == -1) {
292 CheckCloneNewUserErrno(errno); 293 CheckCloneNewUserErrno(errno);
293 return false; 294 return false;
294 } 295 }
295 296
296 // The parent process could have had threads. In the child, these threads 297 // The parent process could have had threads. In the child, these threads
297 // have disappeared. Make sure to not do anything in the child, as this is a 298 // have disappeared. Make sure to not do anything in the child, as this is a
298 // fragile execution environment. 299 // fragile execution environment.
299 if (pid == 0) { 300 if (pid == 0) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 } 339 }
339 340
340 bool Credentials::DropFileSystemAccess() { 341 bool Credentials::DropFileSystemAccess() {
341 // Chrooting to a safe empty dir will only be safe if no directory file 342 // Chrooting to a safe empty dir will only be safe if no directory file
342 // descriptor is available to the process. 343 // descriptor is available to the process.
343 DCHECK(!HasOpenDirectory(-1)); 344 DCHECK(!HasOpenDirectory(-1));
344 return ChrootToSafeEmptyDir(); 345 return ChrootToSafeEmptyDir();
345 } 346 }
346 347
347 } // namespace sandbox. 348 } // namespace sandbox.
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/sandbox_bpf.cc ('k') | sandbox/linux/services/scoped_process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698