| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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. |
| OLD | NEW |