This source file includes following definitions.
- IsArchitectureX86_64
- WriteToStdErr
- PrintSyscallError
- CrashSIGSYS_Handler
- SIGSYSCloneFailure
- SIGSYSPrctlFailure
- SIGSYSIoctlFailure
#include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h"
#include <unistd.h>
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
#include "build/build_config.h"
#include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
namespace {
inline bool IsArchitectureX86_64() {
#if defined(__x86_64__)
return true;
#else
return false;
#endif
}
void WriteToStdErr(const char* error_message, size_t size) {
while (size > 0) {
const int ret = HANDLE_EINTR(write(STDERR_FILENO, error_message, size));
if (ret <= 0 || static_cast<size_t>(ret) > size) break;
size -= ret;
error_message += ret;
}
}
void PrintSyscallError(uint32_t sysno) {
if (sysno >= 1024)
sysno = 0;
const size_t kNumDigits = 4;
char sysno_base10[kNumDigits];
uint32_t rem = sysno;
uint32_t mod = 0;
for (int i = kNumDigits - 1; i >= 0; i--) {
mod = rem % 10;
rem /= 10;
sysno_base10[i] = '0' + mod;
}
static const char kSeccompErrorPrefix[] =
__FILE__":**CRASHING**:seccomp-bpf failure in syscall ";
static const char kSeccompErrorPostfix[] = "\n";
WriteToStdErr(kSeccompErrorPrefix, sizeof(kSeccompErrorPrefix) - 1);
WriteToStdErr(sysno_base10, sizeof(sysno_base10));
WriteToStdErr(kSeccompErrorPostfix, sizeof(kSeccompErrorPostfix) - 1);
}
}
namespace sandbox {
intptr_t CrashSIGSYS_Handler(const struct arch_seccomp_data& args, void* aux) {
uint32_t syscall = args.nr;
if (syscall >= 1024)
syscall = 0;
PrintSyscallError(syscall);
syscall |= ((args.args[0] & 0xffUL) << 12);
syscall |= ((args.args[1] & 0xffUL) << 20);
volatile char* addr = reinterpret_cast<volatile char*>(syscall);
*addr = '\0';
syscall &= 0xfffUL;
addr = reinterpret_cast<volatile char*>(syscall);
*addr = '\0';
for (;;)
_exit(1);
}
intptr_t SIGSYSCloneFailure(const struct arch_seccomp_data& args, void* aux) {
#if !defined(NDEBUG)
RAW_LOG(ERROR, __FILE__":**CRASHING**:clone() failure\n");
#endif
volatile uint64_t clone_flags = args.args[0];
volatile char* addr;
if (IsArchitectureX86_64()) {
addr = reinterpret_cast<volatile char*>(clone_flags & 0xFFFFFF);
*addr = '\0';
}
addr = reinterpret_cast<volatile char*>(clone_flags & 0xFFF);
*addr = '\0';
for (;;)
_exit(1);
}
intptr_t SIGSYSPrctlFailure(const struct arch_seccomp_data& args,
void* ) {
#if !defined(NDEBUG)
RAW_LOG(ERROR, __FILE__":**CRASHING**:prctl() failure\n");
#endif
volatile uint64_t option = args.args[0];
volatile char* addr =
reinterpret_cast<volatile char*>(option & 0xFFF);
*addr = '\0';
for (;;)
_exit(1);
}
intptr_t SIGSYSIoctlFailure(const struct arch_seccomp_data& args,
void* ) {
#if !defined(NDEBUG)
RAW_LOG(ERROR, __FILE__":**CRASHING**:ioctl() failure\n");
#endif
volatile uint64_t request = args.args[1];
volatile char* addr = reinterpret_cast<volatile char*>(request & 0xFFFF);
*addr = '\0';
addr = reinterpret_cast<volatile char*>(request & 0xFFF);
*addr = '\0';
for (;;)
_exit(1);
}
}