OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sandbox_bpf.h" | 5 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
6 | 6 |
7 // Some headers on Android are missing cdefs: crbug.com/172337. | 7 // Some headers on Android are missing cdefs: crbug.com/172337. |
8 // (We can't use OS_ANDROID here since build_config.h is not included). | 8 // (We can't use OS_ANDROID here since build_config.h is not included). |
9 #if defined(ANDROID) | 9 #if defined(ANDROID) |
10 #include <sys/cdefs.h> | 10 #include <sys/cdefs.h> |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 bool KernelSupportsSeccompBPF() { | 52 bool KernelSupportsSeccompBPF() { |
53 errno = 0; | 53 errno = 0; |
54 const int rv = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, nullptr); | 54 const int rv = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, nullptr); |
55 | 55 |
56 if (rv == -1 && EFAULT == errno) { | 56 if (rv == -1 && EFAULT == errno) { |
57 return true; | 57 return true; |
58 } | 58 } |
59 return false; | 59 return false; |
60 } | 60 } |
61 | 61 |
62 // LG introduced a buggy syscall, sys_set_media_ext with the same number as | |
palmer
2015/04/21 03:28:43
Typo: s/ /, /
jln (very slow on Chromium)
2015/04/23 00:02:51
Done.
| |
63 // seccomp. Return true if the current kernel has this buggy syscall. | |
64 // | |
65 // We want this to work with upcoming versions of seccomp, so we pass bogus | |
66 // flags that are unlikely to ever be used by the kernel. A normal kernel would | |
67 // return -EINVAL, but a buggy LG kernel would return 1. | |
68 bool KernelHasLGBug() { | |
69 #if defined(OS_ANDROID) | |
70 // This has to be seen as a NULL pointer by sys_set_media_ext to not crash, | |
palmer
2015/04/21 03:28:43
Nit: I think this comment could be stated more cle
jln (very slow on Chromium)
2015/04/23 00:02:51
Done.
| |
71 // it will be seen as SECCOMP_SET_MODE_STRICT in a genuine seccomp syscall. | |
72 const unsigned int operation = 0; | |
73 // Chosen by fair dice roll. Guaranteed to be random. | |
74 const unsigned int flags = 0xf7a46a5c; | |
75 const int rv = sys_seccomp(operation, flags, nullptr); | |
76 // A genuine kernel would EINVAL, or at the very least return some kind of | |
palmer
2015/04/21 03:28:44
"...would return -1 and set errno to EINVAL. Any o
jln (very slow on Chromium)
2015/04/23 00:02:51
Done.
| |
77 // error. | |
78 if (rv != -1) { | |
79 return true; | |
80 } | |
81 #endif // defined(OS_ANDROID) | |
82 | |
83 return false; | |
84 } | |
85 | |
62 // Check if the kernel supports seccomp-filter via the seccomp system call | 86 // Check if the kernel supports seccomp-filter via the seccomp system call |
63 // and the TSYNC feature to enable seccomp on all threads. | 87 // and the TSYNC feature to enable seccomp on all threads. |
64 bool KernelSupportsSeccompTsync() { | 88 bool KernelSupportsSeccompTsync() { |
89 if (KernelHasLGBug()) { | |
90 return false; | |
91 } | |
92 | |
65 errno = 0; | 93 errno = 0; |
66 const int rv = | 94 const int rv = |
67 sys_seccomp(SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_TSYNC, nullptr); | 95 sys_seccomp(SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_TSYNC, nullptr); |
68 | 96 |
69 if (rv == -1 && errno == EFAULT) { | 97 if (rv == -1 && errno == EFAULT) { |
70 return true; | 98 return true; |
71 } else { | 99 } else { |
72 // TODO(jln): turn these into DCHECK after 417888 is considered fixed. | 100 // TODO(jln): turn these into DCHECK after 417888 is considered fixed. |
73 CHECK_EQ(-1, rv); | 101 CHECK_EQ(-1, rv); |
74 CHECK(ENOSYS == errno || EINVAL == errno); | 102 CHECK(ENOSYS == errno || EINVAL == errno); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 } else { | 267 } else { |
240 if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)) { | 268 if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)) { |
241 SANDBOX_DIE("Kernel refuses to turn on BPF filters"); | 269 SANDBOX_DIE("Kernel refuses to turn on BPF filters"); |
242 } | 270 } |
243 } | 271 } |
244 | 272 |
245 sandbox_has_started_ = true; | 273 sandbox_has_started_ = true; |
246 } | 274 } |
247 | 275 |
248 } // namespace sandbox | 276 } // namespace sandbox |
OLD | NEW |