MCPcopy Create free account
hub / github.com/ElementsProject/elements / SyscallSandboxDebugSignalHandler

Function SyscallSandboxDebugSignalHandler

src/util/syscall_sandbox.cpp:470–494  ·  view source on GitHub ↗

See Linux kernel developer Kees Cook's seccomp guide at for an accessible introduction to using seccomp. This function largely follows and . Seccomp BPF resources: Seccomp BPF documentation: <https://www.kernel.org/doc/html/latest/userspace-ap

Source from the content-addressed store, hash-verified

468// * seccomp(2) manual page: <https://www.kernel.org/doc/man-pages/online/pages/man2/seccomp.2.html>
469// * Seccomp BPF demo code samples: <https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/samples/seccomp>
470void SyscallSandboxDebugSignalHandler(int, siginfo_t* signal_info, void* void_signal_context)
471{
472 // The si_code field inside the siginfo_t argument that is passed to a SA_SIGINFO signal handler
473 // is a value indicating why the signal was sent.
474 //
475 // The following value can be placed in si_code for a SIGSYS signal:
476 // * SYS_SECCOMP (since Linux 3.5): Triggered by a seccomp(2) filter rule.
477 constexpr int32_t SYS_SECCOMP_SI_CODE{1};
478 assert(signal_info->si_code == SYS_SECCOMP_SI_CODE);
479
480 // The ucontext_t structure contains signal context information that was saved on the user-space
481 // stack by the kernel.
482 const ucontext_t* signal_context = static_cast<ucontext_t*>(void_signal_context);
483 assert(signal_context != nullptr);
484
485 std::set_new_handler(std::terminate);
486 // Portability note: REG_RAX is Linux x86_64 specific.
487 const uint32_t syscall_number = static_cast<uint32_t>(signal_context->uc_mcontext.gregs[REG_RAX]);
488 const std::string syscall_name = GetLinuxSyscallName(syscall_number);
489 const std::string thread_name = !util::ThreadGetInternalName().empty() ? util::ThreadGetInternalName() : "*unnamed*";
490 const std::string error_message = strprintf("ERROR: The syscall \"%s\" (syscall number %d) is not allowed by the syscall sandbox in thread \"%s\". Please report.", syscall_name, syscall_number, thread_name);
491 tfm::format(std::cerr, "%s\n", error_message);
492 LogPrintf("%s\n", error_message);
493 std::terminate();
494}
495
496// This function largely follows install_syscall_reporter from Kees Cook's seccomp guide:
497// <https://outflux.net/teach-seccomp/step-3/syscall-reporter.c>

Callers

nothing calls this directly

Calls 3

GetLinuxSyscallNameFunction · 0.85
formatFunction · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected