 Chromium Code Reviews
 Chromium Code Reviews Issue 1095133003:
  Linux sandbox: workaround colliding system call.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1095133003:
  Linux sandbox: workaround colliding system call.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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/23 18:20:23
Nit: "...syscall, sys_set_media_ext, with..."
 
jln (very slow on Chromium)
2015/04/23 18:23:00
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 // sys_set_media will see this as NULL, which should be a safe (non-crashing) | |
| 71 // way to invoke it. A genuine seccomp syscall will see it as | |
| 72 // SECCOMP_SET_MODE_STRICT. | |
| 73 const unsigned int operation = 0; | |
| 74 // Chosen by fair dice roll. Guaranteed to be random. | |
| 75 const unsigned int flags = 0xf7a46a5c; | |
| 76 const int rv = sys_seccomp(operation, flags, nullptr); | |
| 77 // A genuine kernel would return -EINVAL (which would set rv to -1 and errno | |
| 78 // to EINVAL), or at the very least return some kind of error (which would | |
| 79 // set rv to -1). Any other behavior indicates that whatever code received | |
| 80 // our syscall was not the real seccomp. | |
| 81 if (rv != -1) { | |
| 82 return true; | |
| 83 } | |
| 84 #endif // defined(OS_ANDROID) | |
| 85 | |
| 86 return false; | |
| 87 } | |
| 88 | |
| 62 // Check if the kernel supports seccomp-filter via the seccomp system call | 89 // Check if the kernel supports seccomp-filter via the seccomp system call | 
| 63 // and the TSYNC feature to enable seccomp on all threads. | 90 // and the TSYNC feature to enable seccomp on all threads. | 
| 64 bool KernelSupportsSeccompTsync() { | 91 bool KernelSupportsSeccompTsync() { | 
| 92 if (KernelHasLGBug()) { | |
| 93 return false; | |
| 94 } | |
| 95 | |
| 65 errno = 0; | 96 errno = 0; | 
| 66 const int rv = | 97 const int rv = | 
| 67 sys_seccomp(SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_TSYNC, nullptr); | 98 sys_seccomp(SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_TSYNC, nullptr); | 
| 68 | 99 | 
| 69 if (rv == -1 && errno == EFAULT) { | 100 if (rv == -1 && errno == EFAULT) { | 
| 70 return true; | 101 return true; | 
| 71 } else { | 102 } else { | 
| 72 // TODO(jln): turn these into DCHECK after 417888 is considered fixed. | 103 // TODO(jln): turn these into DCHECK after 417888 is considered fixed. | 
| 73 CHECK_EQ(-1, rv); | 104 CHECK_EQ(-1, rv); | 
| 74 CHECK(ENOSYS == errno || EINVAL == errno); | 105 CHECK(ENOSYS == errno || EINVAL == errno); | 
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 } else { | 270 } else { | 
| 240 if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)) { | 271 if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)) { | 
| 241 SANDBOX_DIE("Kernel refuses to turn on BPF filters"); | 272 SANDBOX_DIE("Kernel refuses to turn on BPF filters"); | 
| 242 } | 273 } | 
| 243 } | 274 } | 
| 244 | 275 | 
| 245 sandbox_has_started_ = true; | 276 sandbox_has_started_ = true; | 
| 246 } | 277 } | 
| 247 | 278 | 
| 248 } // namespace sandbox | 279 } // namespace sandbox | 
| OLD | NEW |