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

Side by Side Diff: sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc

Issue 2028303005: Add PTHREAD_PRIO_INHERIT to POSIX Locks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR Feedback Created 4 years, 6 months 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-helpers/baseline_policy_unittest.cc ('k') | no next file » | 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/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/mman.h> 14 #include <sys/mman.h>
15 #include <sys/prctl.h> 15 #include <sys/prctl.h>
16 #include <sys/resource.h> 16 #include <sys/resource.h>
17 #include <sys/stat.h> 17 #include <sys/stat.h>
18 #include <sys/time.h> 18 #include <sys/time.h>
19 #include <sys/types.h> 19 #include <sys/types.h>
20 #include <time.h> 20 #include <time.h>
21 #include <unistd.h> 21 #include <unistd.h>
22 22
23 #include "base/logging.h" 23 #include "base/logging.h"
24 #include "base/macros.h" 24 #include "base/macros.h"
25 #include "base/synchronization/lock.h"
25 #include "build/build_config.h" 26 #include "build/build_config.h"
26 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" 27 #include "sandbox/linux/bpf_dsl/bpf_dsl.h"
28 #include "sandbox/linux/bpf_dsl/bpf_dsl_impl.h"
27 #include "sandbox/linux/bpf_dsl/seccomp_macros.h" 29 #include "sandbox/linux/bpf_dsl/seccomp_macros.h"
28 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" 30 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h"
29 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" 31 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
30 #include "sandbox/linux/system_headers/linux_futex.h" 32 #include "sandbox/linux/system_headers/linux_futex.h"
31 #include "sandbox/linux/system_headers/linux_syscalls.h" 33 #include "sandbox/linux/system_headers/linux_syscalls.h"
32 #include "sandbox/linux/system_headers/linux_time.h" 34 #include "sandbox/linux/system_headers/linux_time.h"
33 35
34 // PNaCl toolchain does not provide sys/ioctl.h header. 36 // PNaCl toolchain does not provide sys/ioctl.h header.
35 #if !defined(OS_NACL_NONSFI) 37 #if !defined(OS_NACL_NONSFI)
36 #include <sys/ioctl.h> 38 #include <sys/ioctl.h>
(...skipping 21 matching lines...) Expand all
58 60
59 #endif // defined(OS_ANDROID) 61 #endif // defined(OS_ANDROID)
60 62
61 #if defined(__arm__) && !defined(MAP_STACK) 63 #if defined(__arm__) && !defined(MAP_STACK)
62 #define MAP_STACK 0x20000 // Daisy build environment has old headers. 64 #define MAP_STACK 0x20000 // Daisy build environment has old headers.
63 #endif 65 #endif
64 66
65 #if defined(__mips__) && !defined(MAP_STACK) 67 #if defined(__mips__) && !defined(MAP_STACK)
66 #define MAP_STACK 0x40000 68 #define MAP_STACK 0x40000
67 #endif 69 #endif
70
71 #define CASES SANDBOX_BPF_DSL_CASES
72
73 using sandbox::bpf_dsl::Allow;
74 using sandbox::bpf_dsl::Arg;
75 using sandbox::bpf_dsl::BoolExpr;
76 using sandbox::bpf_dsl::Error;
77 using sandbox::bpf_dsl::If;
78 using sandbox::bpf_dsl::Kill;
79 using sandbox::bpf_dsl::ResultExpr;
80
81 namespace sandbox {
82
68 namespace { 83 namespace {
69 84
70 inline bool IsArchitectureX86_64() { 85 inline bool IsArchitectureX86_64() {
71 #if defined(__x86_64__) 86 #if defined(__x86_64__)
72 return true; 87 return true;
73 #else 88 #else
74 return false; 89 return false;
75 #endif 90 #endif
76 } 91 }
77 92
(...skipping 14 matching lines...) Expand all
92 } 107 }
93 108
94 inline bool IsArchitectureMips() { 109 inline bool IsArchitectureMips() {
95 #if defined(__mips__) 110 #if defined(__mips__)
96 return true; 111 return true;
97 #else 112 #else
98 return false; 113 return false;
99 #endif 114 #endif
100 } 115 }
101 116
117 // Default case for futexes since they occur twice, once when priority
118 // inheritance is disallowed and again for the disallowed futex op.
119 inline sandbox::bpf_dsl::ResultExpr DisallowFutexOp() {
102 // Ubuntu's version of glibc has a race condition in sem_post that can cause 120 // Ubuntu's version of glibc has a race condition in sem_post that can cause
103 // it to call futex(2) with bogus op arguments. To workaround this, we need 121 // it to call futex(2) with bogus op arguments. To workaround this, we need
104 // to allow those futex(2) calls to fail with EINVAL, instead of crashing the 122 // to allow those futex(2) calls to fail with EINVAL, instead of crashing the
105 // process. See crbug.com/598471. 123 // process. See crbug.com/598471.
106 inline bool IsBuggyGlibcSemPost() {
107 #if defined(LIBC_GLIBC) && !defined(OS_CHROMEOS) 124 #if defined(LIBC_GLIBC) && !defined(OS_CHROMEOS)
108 return true; 125 return Error(EINVAL);
109 #else 126 #else
110 return false; 127 return CrashSIGSYSFutex();
111 #endif 128 #endif
112 } 129 }
113 130
114 } // namespace. 131 } // namespace
115
116 #define CASES SANDBOX_BPF_DSL_CASES
117
118 using sandbox::bpf_dsl::Allow;
119 using sandbox::bpf_dsl::Arg;
120 using sandbox::bpf_dsl::BoolExpr;
121 using sandbox::bpf_dsl::Error;
122 using sandbox::bpf_dsl::If;
123 using sandbox::bpf_dsl::ResultExpr;
124
125 namespace sandbox {
126 132
127 #if !defined(OS_NACL_NONSFI) 133 #if !defined(OS_NACL_NONSFI)
128 // Allow Glibc's and Android pthread creation flags, crash on any other 134 // Allow Glibc's and Android pthread creation flags, crash on any other
129 // thread creation attempts and EPERM attempts to use neither 135 // thread creation attempts and EPERM attempts to use neither
130 // CLONE_VM, nor CLONE_THREAD, which includes all fork() implementations. 136 // CLONE_VM, nor CLONE_THREAD, which includes all fork() implementations.
131 ResultExpr RestrictCloneToThreadsAndEPERMFork() { 137 ResultExpr RestrictCloneToThreadsAndEPERMFork() {
132 const Arg<unsigned long> flags(0); 138 const Arg<unsigned long> flags(0);
133 139
134 // TODO(mdempsky): Extend DSL to support (flags & ~mask1) == mask2. 140 // TODO(mdempsky): Extend DSL to support (flags & ~mask1) == mask2.
135 const uint64_t kAndroidCloneMask = CLONE_VM | CLONE_FS | CLONE_FILES | 141 const uint64_t kAndroidCloneMask = CLONE_VM | CLONE_FS | CLONE_FILES |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 NOTREACHED(); 265 NOTREACHED();
260 return CrashSIGSYS(); 266 return CrashSIGSYS();
261 } 267 }
262 } 268 }
263 269
264 ResultExpr RestrictFutex() { 270 ResultExpr RestrictFutex() {
265 const uint64_t kAllowedFutexFlags = FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME; 271 const uint64_t kAllowedFutexFlags = FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME;
266 const Arg<int> op(1); 272 const Arg<int> op(1);
267 return Switch(op & ~kAllowedFutexFlags) 273 return Switch(op & ~kAllowedFutexFlags)
268 .CASES((FUTEX_WAIT, FUTEX_WAKE, FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, 274 .CASES((FUTEX_WAIT, FUTEX_WAKE, FUTEX_REQUEUE, FUTEX_CMP_REQUEUE,
269 FUTEX_WAKE_OP, FUTEX_WAIT_BITSET, FUTEX_WAKE_BITSET), 275 FUTEX_WAKE_OP, FUTEX_WAIT_BITSET, FUTEX_WAKE_BITSET), Allow())
270 Allow()) 276 #if PRIORITY_INHERITANCE_LOCKS_POSSIBLE()
271 .Default(IsBuggyGlibcSemPost() ? Error(EINVAL) : CrashSIGSYSFutex()); 277 .CASES((FUTEX_LOCK_PI, FUTEX_UNLOCK_PI, FUTEX_WAIT_REQUEUE_PI,
278 FUTEX_CMP_REQUEUE_PI),
279 base::Lock::PriorityInheritanceAvailable()
280 ? Allow()
281 : DisallowFutexOp())
282 #endif
283 .Default(DisallowFutexOp());
272 } 284 }
273 285
274 ResultExpr RestrictGetSetpriority(pid_t target_pid) { 286 ResultExpr RestrictGetSetpriority(pid_t target_pid) {
275 const Arg<int> which(0); 287 const Arg<int> which(0);
276 const Arg<int> who(1); 288 const Arg<int> who(1);
277 return If(which == PRIO_PROCESS, 289 return If(which == PRIO_PROCESS,
278 Switch(who).CASES((0, target_pid), Allow()).Default(Error(EPERM))) 290 Switch(who).CASES((0, target_pid), Allow()).Default(Error(EPERM)))
279 .Else(CrashSIGSYS()); 291 .Else(CrashSIGSYS());
280 } 292 }
281 293
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 CLOCK_MONOTONIC_COARSE, 336 CLOCK_MONOTONIC_COARSE,
325 CLOCK_PROCESS_CPUTIME_ID, 337 CLOCK_PROCESS_CPUTIME_ID,
326 CLOCK_REALTIME, 338 CLOCK_REALTIME,
327 CLOCK_REALTIME_COARSE, 339 CLOCK_REALTIME_COARSE,
328 CLOCK_THREAD_CPUTIME_ID), 340 CLOCK_THREAD_CPUTIME_ID),
329 Allow()) 341 Allow())
330 .Default(CrashSIGSYS()); 342 .Default(CrashSIGSYS());
331 } 343 }
332 344
333 } // namespace sandbox. 345 } // namespace sandbox.
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf-helpers/baseline_policy_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698