sigsys_handlers.h revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
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" 10c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "sandbox/linux/sandbox_export.h" 11a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The handlers are suitable for use in Trap() error codes. They are 13a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// guaranteed to be async-signal safe. 14a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// See sandbox/linux/seccomp-bpf/trap.h to see how they work. 15a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)namespace sandbox { 17a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)struct arch_seccomp_data; 19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// This handler will crash the currently running process. The crashing address 21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// will be the number of the current system call, extracted from |args|. 22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// This handler will also print to stderr the number of the crashing syscall. 23c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochSANDBOX_EXPORT intptr_t 24c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch CrashSIGSYS_Handler(const struct arch_seccomp_data& args, void* aux); 25a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 26a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The following three handlers are suitable to report failures with the 27a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// clone(), prctl() and ioctl() system calls respectively. 28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 29a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The crashing address will be (clone_flags & 0xFFFFFF), where clone_flags is 30a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// the clone(2) argument, extracted from |args|. 31c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochSANDBOX_EXPORT intptr_t 32c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch SIGSYSCloneFailure(const struct arch_seccomp_data& args, void* aux); 33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The crashing address will be (option & 0xFFF), where option is the prctl(2) 34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// argument. 35c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochSANDBOX_EXPORT intptr_t 36c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch SIGSYSPrctlFailure(const struct arch_seccomp_data& args, void* aux); 37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The crashing address will be request & 0xFFFF, where request is the ioctl(2) 38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// argument. 39c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochSANDBOX_EXPORT intptr_t 40c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch SIGSYSIoctlFailure(const struct arch_seccomp_data& args, void* aux); 415c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// The crashing address will be (pid & 0xFFF), where pid is the first 425c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// argument (and can be a tid). 435c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuintptr_t SIGSYSKillFailure(const struct arch_seccomp_data& args, void* aux); 44a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Following four functions return substrings of error messages used 460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// in the above four functions. They are useful in death tests. 470529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochSANDBOX_EXPORT const char* GetErrorMessageContentForTests(); 480529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochSANDBOX_EXPORT const char* GetCloneErrorMessageContentForTests(); 490529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochSANDBOX_EXPORT const char* GetPrctlErrorMessageContentForTests(); 500529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochSANDBOX_EXPORT const char* GetIoctlErrorMessageContentForTests(); 510529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 52a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} // namespace sandbox. 53a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 54a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif // SANDBOX_LINUX_SECCOMP_BPF_HELPERS_SIGSYS_HANDLERS_H_ 55