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> |
(...skipping 15 matching lines...) Expand all Loading... |
26 #if defined(OS_ANDROID) | 26 #if defined(OS_ANDROID) |
27 #if !defined(F_DUPFD_CLOEXEC) | 27 #if !defined(F_DUPFD_CLOEXEC) |
28 #define F_DUPFD_CLOEXEC (F_LINUX_SPECIFIC_BASE + 6) | 28 #define F_DUPFD_CLOEXEC (F_LINUX_SPECIFIC_BASE + 6) |
29 #endif | 29 #endif |
30 #endif | 30 #endif |
31 | 31 |
32 #if defined(__arm__) && !defined(MAP_STACK) | 32 #if defined(__arm__) && !defined(MAP_STACK) |
33 #define MAP_STACK 0x20000 // Daisy build environment has old headers. | 33 #define MAP_STACK 0x20000 // Daisy build environment has old headers. |
34 #endif | 34 #endif |
35 | 35 |
| 36 #if defined(__mips__) && !defined(MAP_STACK) |
| 37 #define MAP_STACK 0x40000 |
| 38 #endif |
36 namespace { | 39 namespace { |
37 | 40 |
38 inline bool RunningOnASAN() { | 41 inline bool RunningOnASAN() { |
39 #if defined(ADDRESS_SANITIZER) | 42 #if defined(ADDRESS_SANITIZER) |
40 return true; | 43 return true; |
41 #else | 44 #else |
42 return false; | 45 return false; |
43 #endif | 46 #endif |
44 } | 47 } |
45 | 48 |
46 inline bool IsArchitectureX86_64() { | 49 inline bool IsArchitectureX86_64() { |
47 #if defined(__x86_64__) | 50 #if defined(__x86_64__) |
48 return true; | 51 return true; |
49 #else | 52 #else |
50 return false; | 53 return false; |
51 #endif | 54 #endif |
52 } | 55 } |
53 | 56 |
54 inline bool IsArchitectureI386() { | 57 inline bool IsArchitectureI386() { |
55 #if defined(__i386__) | 58 #if defined(__i386__) |
56 return true; | 59 return true; |
57 #else | 60 #else |
58 return false; | 61 return false; |
59 #endif | 62 #endif |
60 } | 63 } |
61 | 64 |
| 65 inline bool IsArchitectureMips() { |
| 66 #if defined(__mips__) |
| 67 return true; |
| 68 #else |
| 69 return false; |
| 70 #endif |
| 71 } |
62 } // namespace. | 72 } // namespace. |
63 | 73 |
64 namespace sandbox { | 74 namespace sandbox { |
65 | 75 |
66 ErrorCode RestrictCloneToThreadsAndEPERMFork(SandboxBPF* sandbox) { | 76 ErrorCode RestrictCloneToThreadsAndEPERMFork(SandboxBPF* sandbox) { |
67 // Glibc's pthread. | 77 // Glibc's pthread. |
68 // TODO(jln): fix this on ASAN. | 78 // TODO(jln): fix this on ASAN. |
69 if (!RunningOnASAN()) { | 79 if (!RunningOnASAN()) { |
70 return sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, | 80 return sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, |
71 CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | | 81 CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 ErrorCode(ErrorCode::ERR_ALLOWED)); | 142 ErrorCode(ErrorCode::ERR_ALLOWED)); |
133 } | 143 } |
134 | 144 |
135 ErrorCode RestrictFcntlCommands(SandboxBPF* sandbox) { | 145 ErrorCode RestrictFcntlCommands(SandboxBPF* sandbox) { |
136 // We also restrict the flags in F_SETFL. We don't want to permit flags with | 146 // We also restrict the flags in F_SETFL. We don't want to permit flags with |
137 // a history of trouble such as O_DIRECT. The flags you see are actually the | 147 // a history of trouble such as O_DIRECT. The flags you see are actually the |
138 // allowed ones, and the variable is a "denied" mask because of the negation | 148 // allowed ones, and the variable is a "denied" mask because of the negation |
139 // operator. | 149 // operator. |
140 // Glibc overrides the kernel's O_LARGEFILE value. Account for this. | 150 // Glibc overrides the kernel's O_LARGEFILE value. Account for this. |
141 int kOLargeFileFlag = O_LARGEFILE; | 151 int kOLargeFileFlag = O_LARGEFILE; |
142 if (IsArchitectureX86_64() || IsArchitectureI386()) | 152 if (IsArchitectureX86_64() || IsArchitectureI386() || IsArchitectureMips()) |
143 kOLargeFileFlag = 0100000; | 153 kOLargeFileFlag = 0100000; |
144 | 154 |
145 // TODO(jln): add TP_LONG/TP_SIZET types. | 155 // TODO(jln): add TP_LONG/TP_SIZET types. |
146 ErrorCode::ArgType mask_long_type; | 156 ErrorCode::ArgType mask_long_type; |
147 if (sizeof(long) == 8) | 157 if (sizeof(long) == 8) |
148 mask_long_type = ErrorCode::TP_64BIT; | 158 mask_long_type = ErrorCode::TP_64BIT; |
149 else if (sizeof(long) == 4) | 159 else if (sizeof(long) == 4) |
150 mask_long_type = ErrorCode::TP_32BIT; | 160 mask_long_type = ErrorCode::TP_32BIT; |
151 else | 161 else |
152 NOTREACHED(); | 162 NOTREACHED(); |
(...skipping 26 matching lines...) Expand all Loading... |
179 ErrorCode(ErrorCode::ERR_ALLOWED), | 189 ErrorCode(ErrorCode::ERR_ALLOWED), |
180 sandbox->Cond(1, ErrorCode::TP_32BIT, | 190 sandbox->Cond(1, ErrorCode::TP_32BIT, |
181 ErrorCode::OP_EQUAL, F_GETLK, | 191 ErrorCode::OP_EQUAL, F_GETLK, |
182 ErrorCode(ErrorCode::ERR_ALLOWED), | 192 ErrorCode(ErrorCode::ERR_ALLOWED), |
183 sandbox->Cond(1, ErrorCode::TP_32BIT, | 193 sandbox->Cond(1, ErrorCode::TP_32BIT, |
184 ErrorCode::OP_EQUAL, F_DUPFD_CLOEXEC, | 194 ErrorCode::OP_EQUAL, F_DUPFD_CLOEXEC, |
185 ErrorCode(ErrorCode::ERR_ALLOWED), | 195 ErrorCode(ErrorCode::ERR_ALLOWED), |
186 sandbox->Trap(CrashSIGSYS_Handler, NULL)))))))))); | 196 sandbox->Trap(CrashSIGSYS_Handler, NULL)))))))))); |
187 } | 197 } |
188 | 198 |
189 #if defined(__i386__) | 199 #if defined(__i386__) || defined(__mips__) |
190 ErrorCode RestrictSocketcallCommand(SandboxBPF* sandbox) { | 200 ErrorCode RestrictSocketcallCommand(SandboxBPF* sandbox) { |
191 // Unfortunately, we are unable to restrict the first parameter to | 201 // Unfortunately, we are unable to restrict the first parameter to |
192 // socketpair(2). Whilst initially sounding bad, it's noteworthy that very | 202 // socketpair(2). Whilst initially sounding bad, it's noteworthy that very |
193 // few protocols actually support socketpair(2). The scary call that we're | 203 // few protocols actually support socketpair(2). The scary call that we're |
194 // worried about, socket(2), remains blocked. | 204 // worried about, socket(2), remains blocked. |
195 return sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, | 205 return sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, |
196 SYS_SOCKETPAIR, ErrorCode(ErrorCode::ERR_ALLOWED), | 206 SYS_SOCKETPAIR, ErrorCode(ErrorCode::ERR_ALLOWED), |
197 sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, | 207 sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, |
198 SYS_SEND, ErrorCode(ErrorCode::ERR_ALLOWED), | 208 SYS_SEND, ErrorCode(ErrorCode::ERR_ALLOWED), |
199 sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, | 209 sandbox->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 // TODO(jln): fix this. | 249 // TODO(jln): fix this. |
240 return ErrorCode(ErrorCode::ERR_ALLOWED); | 250 return ErrorCode(ErrorCode::ERR_ALLOWED); |
241 default: | 251 default: |
242 NOTREACHED(); | 252 NOTREACHED(); |
243 return sandbox->Trap(CrashSIGSYS_Handler, NULL); | 253 return sandbox->Trap(CrashSIGSYS_Handler, NULL); |
244 } | 254 } |
245 } | 255 } |
246 } | 256 } |
247 | 257 |
248 } // namespace sandbox. | 258 } // namespace sandbox. |
OLD | NEW |