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 <errno.h> | 7 #include <errno.h> |
8 #include <signal.h> | 8 #include <signal.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 #include <sys/syscall.h> | 11 #include <sys/syscall.h> |
12 #include <sys/types.h> | 12 #include <sys/types.h> |
13 #include <sys/wait.h> | 13 #include <sys/wait.h> |
14 #include <unistd.h> | 14 #include <unistd.h> |
15 | 15 |
16 #include "base/bind.h" | 16 #include "base/bind.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/logging.h" | 19 #include "base/logging.h" |
20 #include "base/posix/eintr_wrapper.h" | 20 #include "base/posix/eintr_wrapper.h" |
21 #include "base/process/launch.h" | 21 #include "base/process/launch.h" |
22 #include "base/template_util.h" | 22 #include "base/template_util.h" |
23 #include "base/third_party/valgrind/valgrind.h" | 23 #include "base/third_party/valgrind/valgrind.h" |
24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
25 #include "sandbox/linux/services/namespace_utils.h" | 25 #include "sandbox/linux/services/namespace_utils.h" |
26 #include "sandbox/linux/services/proc_util.h" | 26 #include "sandbox/linux/services/proc_util.h" |
27 #include "sandbox/linux/services/syscall_wrappers.h" | 27 #include "sandbox/linux/services/syscall_wrappers.h" |
28 #include "sandbox/linux/services/thread_helpers.h" | 28 #include "sandbox/linux/services/thread_helpers.h" |
29 #include "sandbox/linux/system_headers/capability.h" | 29 #include "sandbox/linux/system_headers/capability.h" |
| 30 #include "sandbox/linux/system_headers/linux_signal.h" |
30 | 31 |
31 namespace sandbox { | 32 namespace sandbox { |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 // Signal ABI for some toolchain is incompatible with Linux's. In particular, | |
36 // PNaCl toolchain defines SIGCHLD = 20. So, here, directly define Linux's | |
37 // value. | |
38 const int kLinuxSIGCHLD = 17; | |
39 | |
40 bool IsRunningOnValgrind() { return RUNNING_ON_VALGRIND; } | 36 bool IsRunningOnValgrind() { return RUNNING_ON_VALGRIND; } |
41 | 37 |
42 // Checks that the set of RES-uids and the set of RES-gids have | 38 // Checks that the set of RES-uids and the set of RES-gids have |
43 // one element each and return that element in |resuid| and |resgid| | 39 // one element each and return that element in |resuid| and |resgid| |
44 // respectively. It's ok to pass NULL as one or both of the ids. | 40 // respectively. It's ok to pass NULL as one or both of the ids. |
45 bool GetRESIds(uid_t* resuid, gid_t* resgid) { | 41 bool GetRESIds(uid_t* resuid, gid_t* resgid) { |
46 uid_t ruid, euid, suid; | 42 uid_t ruid, euid, suid; |
47 gid_t rgid, egid, sgid; | 43 gid_t rgid, egid, sgid; |
48 PCHECK(sys_getresuid(&ruid, &euid, &suid) == 0); | 44 PCHECK(sys_getresuid(&ruid, &euid, &suid) == 0); |
49 PCHECK(sys_getresgid(&rgid, &egid, &sgid) == 0); | 45 PCHECK(sys_getresgid(&rgid, &egid, &sgid) == 0); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 char stack_buf[PTHREAD_STACK_MIN]; | 85 char stack_buf[PTHREAD_STACK_MIN]; |
90 #if defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARM_FAMILY) || \ | 86 #if defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARM_FAMILY) || \ |
91 defined(ARCH_CPU_MIPS64_FAMILY) || defined(ARCH_CPU_MIPS_FAMILY) | 87 defined(ARCH_CPU_MIPS64_FAMILY) || defined(ARCH_CPU_MIPS_FAMILY) |
92 // The stack grows downward. | 88 // The stack grows downward. |
93 void* stack = stack_buf + sizeof(stack_buf); | 89 void* stack = stack_buf + sizeof(stack_buf); |
94 #else | 90 #else |
95 #error "Unsupported architecture" | 91 #error "Unsupported architecture" |
96 #endif | 92 #endif |
97 | 93 |
98 pid = clone(ChrootToSelfFdinfo, stack, | 94 pid = clone(ChrootToSelfFdinfo, stack, |
99 CLONE_VM | CLONE_VFORK | CLONE_FS | kLinuxSIGCHLD, | 95 CLONE_VM | CLONE_VFORK | CLONE_FS | LINUX_SIGCHLD, nullptr, |
100 nullptr, nullptr, nullptr, nullptr); | 96 nullptr, nullptr, nullptr); |
101 PCHECK(pid != -1); | 97 PCHECK(pid != -1); |
102 | 98 |
103 int status = -1; | 99 int status = -1; |
104 PCHECK(HANDLE_EINTR(waitpid(pid, &status, 0)) == pid); | 100 PCHECK(HANDLE_EINTR(waitpid(pid, &status, 0)) == pid); |
105 | 101 |
106 return WIFEXITED(status) && WEXITSTATUS(status) == kExitSuccess; | 102 return WIFEXITED(status) && WEXITSTATUS(status) == kExitSuccess; |
107 } | 103 } |
108 | 104 |
109 // CHECK() that an attempt to move to a new user namespace raised an expected | 105 // CHECK() that an attempt to move to a new user namespace raised an expected |
110 // errno. | 106 // errno. |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 CHECK_LE(0, proc_fd); | 290 CHECK_LE(0, proc_fd); |
295 | 291 |
296 CHECK(ChrootToSafeEmptyDir()); | 292 CHECK(ChrootToSafeEmptyDir()); |
297 CHECK(!base::DirectoryExists(base::FilePath("/proc"))); | 293 CHECK(!base::DirectoryExists(base::FilePath("/proc"))); |
298 CHECK(!ProcUtil::HasOpenDirectory(proc_fd)); | 294 CHECK(!ProcUtil::HasOpenDirectory(proc_fd)); |
299 // We never let this function fail. | 295 // We never let this function fail. |
300 return true; | 296 return true; |
301 } | 297 } |
302 | 298 |
303 } // namespace sandbox. | 299 } // namespace sandbox. |
OLD | NEW |