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 // Note: any code in this file MUST be async-signal safe. | 5 // Note: any code in this file MUST be async-signal safe. |
6 | 6 |
7 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" | 7 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" |
8 | 8 |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/posix/eintr_wrapper.h" | 12 #include "base/posix/eintr_wrapper.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 14 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
15 #include "sandbox/linux/services/linux_syscalls.h" | |
15 | 16 |
16 #if defined(__mips__) | 17 #if defined(__mips__) |
17 // __NR_Linux, is defined in <asm/unistd.h>. | 18 // __NR_Linux, is defined in <asm/unistd.h>. |
18 #include <asm/unistd.h> | 19 #include <asm/unistd.h> |
19 #endif | 20 #endif |
20 | 21 |
21 #define SECCOMP_MESSAGE_COMMON_CONTENT "seccomp-bpf failure" | 22 #define SECCOMP_MESSAGE_COMMON_CONTENT "seccomp-bpf failure" |
22 #define SECCOMP_MESSAGE_CLONE_CONTENT "clone() failure" | 23 #define SECCOMP_MESSAGE_CLONE_CONTENT "clone() failure" |
23 #define SECCOMP_MESSAGE_PRCTL_CONTENT "prctl() failure" | 24 #define SECCOMP_MESSAGE_PRCTL_CONTENT "prctl() failure" |
24 #define SECCOMP_MESSAGE_IOCTL_CONTENT "ioctl() failure" | 25 #define SECCOMP_MESSAGE_IOCTL_CONTENT "ioctl() failure" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 static const char kSeccompFutexError[] = | 200 static const char kSeccompFutexError[] = |
200 __FILE__ ":**CRASHING**:" SECCOMP_MESSAGE_FUTEX_CONTENT "\n"; | 201 __FILE__ ":**CRASHING**:" SECCOMP_MESSAGE_FUTEX_CONTENT "\n"; |
201 WriteToStdErr(kSeccompFutexError, sizeof(kSeccompFutexError) - 1); | 202 WriteToStdErr(kSeccompFutexError, sizeof(kSeccompFutexError) - 1); |
202 volatile int futex_op = args.args[1]; | 203 volatile int futex_op = args.args[1]; |
203 volatile char* addr = reinterpret_cast<volatile char*>(futex_op & 0xFFF); | 204 volatile char* addr = reinterpret_cast<volatile char*>(futex_op & 0xFFF); |
204 *addr = '\0'; | 205 *addr = '\0'; |
205 for (;;) | 206 for (;;) |
206 _exit(1); | 207 _exit(1); |
207 } | 208 } |
208 | 209 |
210 intptr_t SIGSYSSchedHandler(const struct arch_seccomp_data& args, | |
211 void* aux) { | |
212 pid_t tid = syscall(__NR_gettid); | |
jln (very slow on Chromium)
2014/09/22 21:56:44
const
rickyz (no longer on Chrome)
2014/09/23 06:03:20
Done.
| |
213 if (args.args[0] == (uint64_t) tid) { | |
jln (very slow on Chromium)
2014/09/22 21:56:44
A nit (feel free to ignore), but I find it a tad a
jln (very slow on Chromium)
2014/09/22 21:56:44
style: C++ static_cast
rickyz (no longer on Chrome)
2014/09/23 06:03:20
Done.
| |
214 switch (args.nr) { | |
215 case __NR_sched_getaffinity: | |
216 case __NR_sched_getattr: | |
217 case __NR_sched_getparam: | |
218 case __NR_sched_getscheduler: | |
219 case __NR_sched_rr_get_interval: | |
220 case __NR_sched_setaffinity: | |
221 case __NR_sched_setattr: | |
222 case __NR_sched_setparam: | |
223 case __NR_sched_setscheduler: | |
224 // The first argument the pid | |
225 return syscall(args.nr, | |
jln (very slow on Chromium)
2014/09/22 21:56:44
glibc's syscall sets errno (which will be discarde
rickyz (no longer on Chrome)
2014/09/23 06:03:20
Ah, good catch - fixed this and added a test that
| |
226 0, | |
227 args.args[1], | |
228 args.args[2], | |
229 args.args[3], | |
230 args.args[4], | |
231 args.args[5]); | |
232 } | |
233 } | |
234 | |
235 CrashSIGSYS_Handler(args, aux); | |
236 NOTREACHED(); | |
jln (very slow on Chromium)
2014/09/22 21:56:44
Don't use NOTREACHED() here, as it's not async sig
rickyz (no longer on Chrome)
2014/09/23 06:03:20
Done.
| |
237 return -1; | |
jln (very slow on Chromium)
2014/09/22 21:56:44
return -ENOSYS maybe?
rickyz (no longer on Chrome)
2014/09/23 06:03:20
Done.
| |
238 } | |
239 | |
209 bpf_dsl::ResultExpr CrashSIGSYS() { | 240 bpf_dsl::ResultExpr CrashSIGSYS() { |
210 return bpf_dsl::Trap(CrashSIGSYS_Handler, NULL); | 241 return bpf_dsl::Trap(CrashSIGSYS_Handler, NULL); |
211 } | 242 } |
212 | 243 |
213 bpf_dsl::ResultExpr CrashSIGSYSClone() { | 244 bpf_dsl::ResultExpr CrashSIGSYSClone() { |
214 return bpf_dsl::Trap(SIGSYSCloneFailure, NULL); | 245 return bpf_dsl::Trap(SIGSYSCloneFailure, NULL); |
215 } | 246 } |
216 | 247 |
217 bpf_dsl::ResultExpr CrashSIGSYSPrctl() { | 248 bpf_dsl::ResultExpr CrashSIGSYSPrctl() { |
218 return bpf_dsl::Trap(SIGSYSPrctlFailure, NULL); | 249 return bpf_dsl::Trap(SIGSYSPrctlFailure, NULL); |
219 } | 250 } |
220 | 251 |
221 bpf_dsl::ResultExpr CrashSIGSYSIoctl() { | 252 bpf_dsl::ResultExpr CrashSIGSYSIoctl() { |
222 return bpf_dsl::Trap(SIGSYSIoctlFailure, NULL); | 253 return bpf_dsl::Trap(SIGSYSIoctlFailure, NULL); |
223 } | 254 } |
224 | 255 |
225 bpf_dsl::ResultExpr CrashSIGSYSKill() { | 256 bpf_dsl::ResultExpr CrashSIGSYSKill() { |
226 return bpf_dsl::Trap(SIGSYSKillFailure, NULL); | 257 return bpf_dsl::Trap(SIGSYSKillFailure, NULL); |
227 } | 258 } |
228 | 259 |
229 bpf_dsl::ResultExpr CrashSIGSYSFutex() { | 260 bpf_dsl::ResultExpr CrashSIGSYSFutex() { |
230 return bpf_dsl::Trap(SIGSYSFutexFailure, NULL); | 261 return bpf_dsl::Trap(SIGSYSFutexFailure, NULL); |
231 } | 262 } |
232 | 263 |
264 bpf_dsl::ResultExpr RewriteSchedSIGSYS() { | |
265 return bpf_dsl::Trap(SIGSYSSchedHandler, NULL); | |
266 } | |
267 | |
233 const char* GetErrorMessageContentForTests() { | 268 const char* GetErrorMessageContentForTests() { |
234 return SECCOMP_MESSAGE_COMMON_CONTENT; | 269 return SECCOMP_MESSAGE_COMMON_CONTENT; |
235 } | 270 } |
236 | 271 |
237 const char* GetCloneErrorMessageContentForTests() { | 272 const char* GetCloneErrorMessageContentForTests() { |
238 return SECCOMP_MESSAGE_CLONE_CONTENT; | 273 return SECCOMP_MESSAGE_CLONE_CONTENT; |
239 } | 274 } |
240 | 275 |
241 const char* GetPrctlErrorMessageContentForTests() { | 276 const char* GetPrctlErrorMessageContentForTests() { |
242 return SECCOMP_MESSAGE_PRCTL_CONTENT; | 277 return SECCOMP_MESSAGE_PRCTL_CONTENT; |
243 } | 278 } |
244 | 279 |
245 const char* GetIoctlErrorMessageContentForTests() { | 280 const char* GetIoctlErrorMessageContentForTests() { |
246 return SECCOMP_MESSAGE_IOCTL_CONTENT; | 281 return SECCOMP_MESSAGE_IOCTL_CONTENT; |
247 } | 282 } |
248 | 283 |
249 const char* GetKillErrorMessageContentForTests() { | 284 const char* GetKillErrorMessageContentForTests() { |
250 return SECCOMP_MESSAGE_KILL_CONTENT; | 285 return SECCOMP_MESSAGE_KILL_CONTENT; |
251 } | 286 } |
252 | 287 |
253 const char* GetFutexErrorMessageContentForTests() { | 288 const char* GetFutexErrorMessageContentForTests() { |
254 return SECCOMP_MESSAGE_FUTEX_CONTENT; | 289 return SECCOMP_MESSAGE_FUTEX_CONTENT; |
255 } | 290 } |
256 | 291 |
257 } // namespace sandbox. | 292 } // namespace sandbox. |
OLD | NEW |