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/seccomp-bpf-helpers/syscall_parameters_restrictions.h" | 5 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <linux/net.h> | 10 #include <linux/net.h> |
11 #include <sched.h> | 11 #include <sched.h> |
12 #include <signal.h> | 12 #include <signal.h> |
13 #include <stdint.h> | 13 #include <stdint.h> |
14 #include <sys/ioctl.h> | |
15 #include <sys/mman.h> | 14 #include <sys/mman.h> |
16 #include <sys/prctl.h> | 15 #include <sys/prctl.h> |
17 #include <sys/resource.h> | 16 #include <sys/resource.h> |
18 #include <sys/stat.h> | 17 #include <sys/stat.h> |
19 #include <sys/time.h> | 18 #include <sys/time.h> |
20 #include <sys/types.h> | 19 #include <sys/types.h> |
21 #include <time.h> | 20 #include <time.h> |
22 #include <unistd.h> | 21 #include <unistd.h> |
23 | 22 |
24 #include "base/logging.h" | 23 #include "base/logging.h" |
25 #include "base/macros.h" | 24 #include "base/macros.h" |
26 #include "base/time/time.h" | 25 #include "base/time/time.h" |
27 #include "build/build_config.h" | 26 #include "build/build_config.h" |
28 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" | 27 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" |
29 #include "sandbox/linux/bpf_dsl/seccomp_macros.h" | 28 #include "sandbox/linux/bpf_dsl/seccomp_macros.h" |
30 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" | 29 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" |
31 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 30 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
32 #include "sandbox/linux/system_headers/linux_futex.h" | 31 #include "sandbox/linux/system_headers/linux_futex.h" |
33 #include "sandbox/linux/system_headers/linux_syscalls.h" | 32 #include "sandbox/linux/system_headers/linux_syscalls.h" |
34 | 33 |
| 34 // PNaCl toolchain does not provide sys/ioctl.h header. |
| 35 #if !defined(OS_NACL_NONSFI) |
| 36 #include <sys/ioctl.h> |
| 37 #endif |
| 38 |
35 #if defined(OS_ANDROID) | 39 #if defined(OS_ANDROID) |
36 | 40 |
37 #if !defined(F_DUPFD_CLOEXEC) | 41 #if !defined(F_DUPFD_CLOEXEC) |
38 #define F_DUPFD_CLOEXEC (F_LINUX_SPECIFIC_BASE + 6) | 42 #define F_DUPFD_CLOEXEC (F_LINUX_SPECIFIC_BASE + 6) |
39 #endif | 43 #endif |
40 | 44 |
41 // https://android.googlesource.com/platform/bionic/+/lollipop-release/libc/priv
ate/bionic_prctl.h | 45 // https://android.googlesource.com/platform/bionic/+/lollipop-release/libc/priv
ate/bionic_prctl.h |
42 #if !defined(PR_SET_VMA) | 46 #if !defined(PR_SET_VMA) |
43 #define PR_SET_VMA 0x53564d41 | 47 #define PR_SET_VMA 0x53564d41 |
44 #endif | 48 #endif |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 101 |
98 using sandbox::bpf_dsl::Allow; | 102 using sandbox::bpf_dsl::Allow; |
99 using sandbox::bpf_dsl::Arg; | 103 using sandbox::bpf_dsl::Arg; |
100 using sandbox::bpf_dsl::BoolExpr; | 104 using sandbox::bpf_dsl::BoolExpr; |
101 using sandbox::bpf_dsl::Error; | 105 using sandbox::bpf_dsl::Error; |
102 using sandbox::bpf_dsl::If; | 106 using sandbox::bpf_dsl::If; |
103 using sandbox::bpf_dsl::ResultExpr; | 107 using sandbox::bpf_dsl::ResultExpr; |
104 | 108 |
105 namespace sandbox { | 109 namespace sandbox { |
106 | 110 |
| 111 #if !defined(OS_NACL_NONSFI) |
107 // Allow Glibc's and Android pthread creation flags, crash on any other | 112 // Allow Glibc's and Android pthread creation flags, crash on any other |
108 // thread creation attempts and EPERM attempts to use neither | 113 // thread creation attempts and EPERM attempts to use neither |
109 // CLONE_VM, nor CLONE_THREAD, which includes all fork() implementations. | 114 // CLONE_VM, nor CLONE_THREAD, which includes all fork() implementations. |
110 ResultExpr RestrictCloneToThreadsAndEPERMFork() { | 115 ResultExpr RestrictCloneToThreadsAndEPERMFork() { |
111 const Arg<unsigned long> flags(0); | 116 const Arg<unsigned long> flags(0); |
112 | 117 |
113 // TODO(mdempsky): Extend DSL to support (flags & ~mask1) == mask2. | 118 // TODO(mdempsky): Extend DSL to support (flags & ~mask1) == mask2. |
114 const uint64_t kAndroidCloneMask = CLONE_VM | CLONE_FS | CLONE_FILES | | 119 const uint64_t kAndroidCloneMask = CLONE_VM | CLONE_FS | CLONE_FILES | |
115 CLONE_SIGHAND | CLONE_THREAD | | 120 CLONE_SIGHAND | CLONE_THREAD | |
116 CLONE_SYSVSEM; | 121 CLONE_SYSVSEM; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 } | 259 } |
255 | 260 |
256 ResultExpr RestrictGetSetpriority(pid_t target_pid) { | 261 ResultExpr RestrictGetSetpriority(pid_t target_pid) { |
257 const Arg<int> which(0); | 262 const Arg<int> which(0); |
258 const Arg<int> who(1); | 263 const Arg<int> who(1); |
259 return If(which == PRIO_PROCESS, | 264 return If(which == PRIO_PROCESS, |
260 If(who == 0 || who == target_pid, Allow()).Else(Error(EPERM))) | 265 If(who == 0 || who == target_pid, Allow()).Else(Error(EPERM))) |
261 .Else(CrashSIGSYS()); | 266 .Else(CrashSIGSYS()); |
262 } | 267 } |
263 | 268 |
264 ResultExpr RestrictClockID() { | |
265 static_assert(4 == sizeof(clockid_t), "clockid_t is not 32bit"); | |
266 const Arg<clockid_t> clockid(0); | |
267 return If( | |
268 #if defined(OS_CHROMEOS) | |
269 // Allow the special clock for Chrome OS used by Chrome tracing. | |
270 clockid == base::TimeTicks::kClockSystemTrace || | |
271 #endif | |
272 clockid == CLOCK_MONOTONIC || | |
273 clockid == CLOCK_PROCESS_CPUTIME_ID || | |
274 clockid == CLOCK_REALTIME || | |
275 clockid == CLOCK_THREAD_CPUTIME_ID, | |
276 Allow()).Else(CrashSIGSYS()); | |
277 } | |
278 | |
279 ResultExpr RestrictSchedTarget(pid_t target_pid, int sysno) { | 269 ResultExpr RestrictSchedTarget(pid_t target_pid, int sysno) { |
280 switch (sysno) { | 270 switch (sysno) { |
281 case __NR_sched_getaffinity: | 271 case __NR_sched_getaffinity: |
282 case __NR_sched_getattr: | 272 case __NR_sched_getattr: |
283 case __NR_sched_getparam: | 273 case __NR_sched_getparam: |
284 case __NR_sched_getscheduler: | 274 case __NR_sched_getscheduler: |
285 case __NR_sched_rr_get_interval: | 275 case __NR_sched_rr_get_interval: |
286 case __NR_sched_setaffinity: | 276 case __NR_sched_setaffinity: |
287 case __NR_sched_setattr: | 277 case __NR_sched_setattr: |
288 case __NR_sched_setparam: | 278 case __NR_sched_setparam: |
(...skipping 10 matching lines...) Expand all Loading... |
299 | 289 |
300 ResultExpr RestrictPrlimit64(pid_t target_pid) { | 290 ResultExpr RestrictPrlimit64(pid_t target_pid) { |
301 const Arg<pid_t> pid(0); | 291 const Arg<pid_t> pid(0); |
302 return If(pid == 0 || pid == target_pid, Allow()).Else(CrashSIGSYS()); | 292 return If(pid == 0 || pid == target_pid, Allow()).Else(CrashSIGSYS()); |
303 } | 293 } |
304 | 294 |
305 ResultExpr RestrictGetrusage() { | 295 ResultExpr RestrictGetrusage() { |
306 const Arg<int> who(0); | 296 const Arg<int> who(0); |
307 return If(who == RUSAGE_SELF, Allow()).Else(CrashSIGSYS()); | 297 return If(who == RUSAGE_SELF, Allow()).Else(CrashSIGSYS()); |
308 } | 298 } |
| 299 #endif // !defined(OS_NACL_NONSFI) |
| 300 |
| 301 ResultExpr RestrictClockID() { |
| 302 static_assert(4 == sizeof(clockid_t), "clockid_t is not 32bit"); |
| 303 const Arg<clockid_t> clockid(0); |
| 304 return If( |
| 305 #if defined(OS_CHROMEOS) |
| 306 // Allow the special clock for Chrome OS used by Chrome tracing. |
| 307 clockid == base::TimeTicks::kClockSystemTrace || |
| 308 #endif |
| 309 clockid == CLOCK_MONOTONIC || |
| 310 clockid == CLOCK_PROCESS_CPUTIME_ID || |
| 311 clockid == CLOCK_REALTIME || |
| 312 clockid == CLOCK_THREAD_CPUTIME_ID, |
| 313 Allow()).Else(CrashSIGSYS()); |
| 314 } |
309 | 315 |
310 } // namespace sandbox. | 316 } // namespace sandbox. |
OLD | NEW |