1a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// found in the LICENSE file. 4a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 5a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#ifndef SANDBOX_LINUX_SECCOMP_BPF_HELPERS_SIGSYS_HANDLERS_H_ 6a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#define SANDBOX_LINUX_SECCOMP_BPF_HELPERS_SIGSYS_HANDLERS_H_ 7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 8a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/basictypes.h" 9a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "build/build_config.h" 105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "sandbox/linux/bpf_dsl/bpf_dsl.h" 11cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "sandbox/sandbox_export.h" 12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 13a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The handlers are suitable for use in Trap() error codes. They are 14a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// guaranteed to be async-signal safe. 15a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// See sandbox/linux/seccomp-bpf/trap.h to see how they work. 16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 17a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)namespace sandbox { 18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)struct arch_seccomp_data; 20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// This handler will crash the currently running process. The crashing address 22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// will be the number of the current system call, extracted from |args|. 23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// This handler will also print to stderr the number of the crashing syscall. 24c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochSANDBOX_EXPORT intptr_t 25c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch CrashSIGSYS_Handler(const struct arch_seccomp_data& args, void* aux); 26a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 27a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The following three handlers are suitable to report failures with the 28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// clone(), prctl() and ioctl() system calls respectively. 29a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 30a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The crashing address will be (clone_flags & 0xFFFFFF), where clone_flags is 31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// the clone(2) argument, extracted from |args|. 32c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochSANDBOX_EXPORT intptr_t 33c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch SIGSYSCloneFailure(const struct arch_seccomp_data& args, void* aux); 34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The crashing address will be (option & 0xFFF), where option is the prctl(2) 35a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// argument. 36c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochSANDBOX_EXPORT intptr_t 37c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch SIGSYSPrctlFailure(const struct arch_seccomp_data& args, void* aux); 38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The crashing address will be request & 0xFFFF, where request is the ioctl(2) 39a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// argument. 40c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochSANDBOX_EXPORT intptr_t 41c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch SIGSYSIoctlFailure(const struct arch_seccomp_data& args, void* aux); 425c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// The crashing address will be (pid & 0xFFF), where pid is the first 435c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// argument (and can be a tid). 4446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)SANDBOX_EXPORT intptr_t 4546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) SIGSYSKillFailure(const struct arch_seccomp_data& args, void* aux); 4646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// The crashing address will be (op & 0xFFF), where op is the second 4746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// argument. 4846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)SANDBOX_EXPORT intptr_t 4946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) SIGSYSFutexFailure(const struct arch_seccomp_data& args, void* aux); 501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// If the syscall is not being called on the current tid, crashes in the same 511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// way as CrashSIGSYS_Handler. Otherwise, returns the result of calling the 521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// syscall with the pid argument set to 0 (which for these calls means the 531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// current thread). The following syscalls are supported: 541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// 551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// sched_getaffinity(), sched_getattr(), sched_getparam(), sched_getscheduler(), 561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// sched_rr_get_interval(), sched_setaffinity(), sched_setattr(), 571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// sched_setparam(), sched_setscheduler() 581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciSANDBOX_EXPORT intptr_t 591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci SIGSYSSchedHandler(const struct arch_seccomp_data& args, void* aux); 60a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Variants of the above functions for use with bpf_dsl. 625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYS(); 635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYSClone(); 645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYSPrctl(); 655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYSIoctl(); 665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYSKill(); 675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYSFutex(); 681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciSANDBOX_EXPORT bpf_dsl::ResultExpr RewriteSchedSIGSYS(); 695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Following four functions return substrings of error messages used 710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// in the above four functions. They are useful in death tests. 720529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochSANDBOX_EXPORT const char* GetErrorMessageContentForTests(); 730529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochSANDBOX_EXPORT const char* GetCloneErrorMessageContentForTests(); 740529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochSANDBOX_EXPORT const char* GetPrctlErrorMessageContentForTests(); 750529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochSANDBOX_EXPORT const char* GetIoctlErrorMessageContentForTests(); 76cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)SANDBOX_EXPORT const char* GetKillErrorMessageContentForTests(); 7746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)SANDBOX_EXPORT const char* GetFutexErrorMessageContentForTests(); 780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 79a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} // namespace sandbox. 80a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 81a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif // SANDBOX_LINUX_SECCOMP_BPF_HELPERS_SIGSYS_HANDLERS_H_ 82