OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/nacl/loader/nonsfi/nonsfi_sandbox.h" | 5 #include "components/nacl/loader/nonsfi/nonsfi_sandbox.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <linux/net.h> | 9 #include <linux/net.h> |
10 #include <sys/prctl.h> | 10 #include <sys/prctl.h> |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 const uint32_t denied_flag_mask = ~(MAP_SHARED | MAP_PRIVATE | | 125 const uint32_t denied_flag_mask = ~(MAP_SHARED | MAP_PRIVATE | |
126 MAP_ANONYMOUS | MAP_STACK | MAP_FIXED); | 126 MAP_ANONYMOUS | MAP_STACK | MAP_FIXED); |
127 // TODO(hamaji): Disallow RWX mmap. | 127 // TODO(hamaji): Disallow RWX mmap. |
128 return sb->Cond(3, ErrorCode::TP_32BIT, | 128 return sb->Cond(3, ErrorCode::TP_32BIT, |
129 ErrorCode::OP_HAS_ANY_BITS, | 129 ErrorCode::OP_HAS_ANY_BITS, |
130 denied_flag_mask, | 130 denied_flag_mask, |
131 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL), | 131 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL), |
132 RestrictMemoryProtection(sb, 2)); | 132 RestrictMemoryProtection(sb, 2)); |
133 } | 133 } |
134 | 134 |
| 135 #if defined(__x86_64__) || defined(__arm__) |
135 ErrorCode RestrictSocketpair(SandboxBPF* sb) { | 136 ErrorCode RestrictSocketpair(SandboxBPF* sb) { |
136 // Only allow AF_UNIX, PF_UNIX. Crash if anything else is seen. | 137 // Only allow AF_UNIX, PF_UNIX. Crash if anything else is seen. |
137 COMPILE_ASSERT(AF_UNIX == PF_UNIX, af_unix_pf_unix_different); | 138 COMPILE_ASSERT(AF_UNIX == PF_UNIX, af_unix_pf_unix_different); |
138 return sb->Cond(0, ErrorCode::TP_32BIT, | 139 return sb->Cond(0, ErrorCode::TP_32BIT, |
139 ErrorCode::OP_EQUAL, AF_UNIX, | 140 ErrorCode::OP_EQUAL, AF_UNIX, |
140 ErrorCode(ErrorCode::ERR_ALLOWED), | 141 ErrorCode(ErrorCode::ERR_ALLOWED), |
141 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL)); | 142 sb->Trap(sandbox::CrashSIGSYS_Handler, NULL)); |
142 } | 143 } |
| 144 #endif |
143 | 145 |
144 bool IsGracefullyDenied(int sysno) { | 146 bool IsGracefullyDenied(int sysno) { |
145 switch (sysno) { | 147 switch (sysno) { |
146 // libevent tries this first and then falls back to poll if | 148 // libevent tries this first and then falls back to poll if |
147 // epoll_create fails. | 149 // epoll_create fails. |
148 case __NR_epoll_create: | 150 case __NR_epoll_create: |
149 // third_party/libevent uses them, but we can just return -1 from | 151 // third_party/libevent uses them, but we can just return -1 from |
150 // them as it is just checking getuid() != geteuid() and | 152 // them as it is just checking getuid() != geteuid() and |
151 // getgid() != getegid() | 153 // getgid() != getegid() |
152 #if defined(__i386__) || defined(__arm__) | 154 #if defined(__i386__) || defined(__arm__) |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 scoped_ptr<sandbox::SandboxBPFPolicy>( | 309 scoped_ptr<sandbox::SandboxBPFPolicy>( |
308 new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy())); | 310 new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy())); |
309 if (!sandbox_is_initialized) | 311 if (!sandbox_is_initialized) |
310 return false; | 312 return false; |
311 RunSandboxSanityChecks(); | 313 RunSandboxSanityChecks(); |
312 return true; | 314 return true; |
313 } | 315 } |
314 | 316 |
315 } // namespace nonsfi | 317 } // namespace nonsfi |
316 } // namespace nacl | 318 } // namespace nacl |
OLD | NEW |