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 <limits.h> | 8 #include <limits.h> |
9 #include <signal.h> | 9 #include <signal.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
11 #include <stdint.h> | 11 #include <stdint.h> |
12 #include <stdio.h> | 12 #include <stdio.h> |
13 #include <sys/syscall.h> | 13 #include <sys/syscall.h> |
14 #include <sys/types.h> | 14 #include <sys/types.h> |
15 #include <sys/wait.h> | 15 #include <sys/wait.h> |
16 #include <unistd.h> | 16 #include <unistd.h> |
17 | 17 |
18 #include "base/bind.h" | 18 #include "base/bind.h" |
| 19 #include "base/compiler_specific.h" |
19 #include "base/files/file_path.h" | 20 #include "base/files/file_path.h" |
20 #include "base/files/file_util.h" | 21 #include "base/files/file_util.h" |
21 #include "base/logging.h" | 22 #include "base/logging.h" |
22 #include "base/macros.h" | 23 #include "base/macros.h" |
23 #include "base/posix/eintr_wrapper.h" | 24 #include "base/posix/eintr_wrapper.h" |
24 #include "base/process/launch.h" | 25 #include "base/process/launch.h" |
25 #include "base/template_util.h" | 26 #include "base/template_util.h" |
26 #include "base/third_party/valgrind/valgrind.h" | 27 #include "base/third_party/valgrind/valgrind.h" |
27 #include "build/build_config.h" | 28 #include "build/build_config.h" |
28 #include "sandbox/linux/services/namespace_utils.h" | 29 #include "sandbox/linux/services/namespace_utils.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 bool ChrootToSafeEmptyDir() { | 88 bool ChrootToSafeEmptyDir() { |
88 // We need to chroot to a fdinfo that is unique to a process and have that | 89 // We need to chroot to a fdinfo that is unique to a process and have that |
89 // process die. | 90 // process die. |
90 // 1. We don't want to simply fork() because duplicating the page tables is | 91 // 1. We don't want to simply fork() because duplicating the page tables is |
91 // slow with a big address space. | 92 // slow with a big address space. |
92 // 2. We do not use a regular thread (that would unshare CLONE_FILES) because | 93 // 2. We do not use a regular thread (that would unshare CLONE_FILES) because |
93 // when we are in a PID namespace, we cannot easily get a handle to the | 94 // when we are in a PID namespace, we cannot easily get a handle to the |
94 // /proc/tid directory for the thread (since /proc may not be aware of the | 95 // /proc/tid directory for the thread (since /proc may not be aware of the |
95 // PID namespace). With a process, we can just use /proc/self. | 96 // PID namespace). With a process, we can just use /proc/self. |
96 pid_t pid = -1; | 97 pid_t pid = -1; |
97 char stack_buf[PTHREAD_STACK_MIN]; | 98 char stack_buf[PTHREAD_STACK_MIN] ALIGNAS(16); |
98 #if defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARM_FAMILY) || \ | 99 #if defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARM_FAMILY) || \ |
99 defined(ARCH_CPU_MIPS64_FAMILY) || defined(ARCH_CPU_MIPS_FAMILY) | 100 defined(ARCH_CPU_MIPS64_FAMILY) || defined(ARCH_CPU_MIPS_FAMILY) |
100 // The stack grows downward. | 101 // The stack grows downward. |
101 void* stack = stack_buf + sizeof(stack_buf); | 102 void* stack = stack_buf + sizeof(stack_buf); |
102 #else | 103 #else |
103 #error "Unsupported architecture" | 104 #error "Unsupported architecture" |
104 #endif | 105 #endif |
105 | 106 |
106 int clone_flags = CLONE_FS | LINUX_SIGCHLD; | 107 int clone_flags = CLONE_FS | LINUX_SIGCHLD; |
107 void* tls = nullptr; | 108 void* tls = nullptr; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 if (pid != 0) { | 327 if (pid != 0) { |
327 return pid; | 328 return pid; |
328 } | 329 } |
329 | 330 |
330 // Since we just forked, we are single threaded. | 331 // Since we just forked, we are single threaded. |
331 PCHECK(DropAllCapabilitiesOnCurrentThread()); | 332 PCHECK(DropAllCapabilitiesOnCurrentThread()); |
332 return 0; | 333 return 0; |
333 } | 334 } |
334 | 335 |
335 } // namespace sandbox. | 336 } // namespace sandbox. |
OLD | NEW |