OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <time.h> | 5 #include <time.h> |
6 | 6 |
7 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 7 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
8 #include "sandbox/linux/seccomp-bpf/verifier.h" | 8 #include "sandbox/linux/seccomp-bpf/verifier.h" |
9 | 9 |
10 // The kernel gives us a sandbox, we turn it into a playground :-) | 10 // The kernel gives us a sandbox, we turn it into a playground :-) |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 // all CPU registers at the time of the signal. | 595 // all CPU registers at the time of the signal. |
596 ucontext_t *ctx = reinterpret_cast<ucontext_t *>(void_context); | 596 ucontext_t *ctx = reinterpret_cast<ucontext_t *>(void_context); |
597 | 597 |
598 // Obtain the siginfo information that is specific to SIGSYS. Unfortunately, | 598 // Obtain the siginfo information that is specific to SIGSYS. Unfortunately, |
599 // most versions of glibc don't include this information in siginfo_t. So, | 599 // most versions of glibc don't include this information in siginfo_t. So, |
600 // we need to explicitly copy it into a arch_sigsys structure. | 600 // we need to explicitly copy it into a arch_sigsys structure. |
601 struct arch_sigsys sigsys; | 601 struct arch_sigsys sigsys; |
602 memcpy(&sigsys, &info->_sifields, sizeof(sigsys)); | 602 memcpy(&sigsys, &info->_sifields, sizeof(sigsys)); |
603 | 603 |
604 // Some more sanity checks. | 604 // Some more sanity checks. |
605 if (sigsys.ip != reinterpret_cast<void *>(ctx->uc_mcontext.gregs[REG_IP]) || | 605 if (sigsys.ip != reinterpret_cast<void *>(SECCOMP_IP(ctx)) || |
606 sigsys.nr != static_cast<int>(ctx->uc_mcontext.gregs[REG_SYSCALL]) || | 606 sigsys.nr != static_cast<int>(SECCOMP_SYSCALL(ctx)) || |
607 sigsys.arch != SECCOMP_ARCH) { | 607 sigsys.arch != SECCOMP_ARCH) { |
608 goto sigsys_err; | 608 goto sigsys_err; |
609 } | 609 } |
610 | 610 |
611 // Copy the seccomp-specific data into a arch_seccomp_data structure. This | 611 // Copy the seccomp-specific data into a arch_seccomp_data structure. This |
612 // is what we are showing to TrapFnc callbacks that the system call evaluator | 612 // is what we are showing to TrapFnc callbacks that the system call evaluator |
613 // registered with the sandbox. | 613 // registered with the sandbox. |
614 struct arch_seccomp_data data = { | 614 struct arch_seccomp_data data = { |
615 sigsys.nr, | 615 sigsys.nr, |
616 SECCOMP_ARCH, | 616 SECCOMP_ARCH, |
617 reinterpret_cast<uint64_t>(sigsys.ip), | 617 reinterpret_cast<uint64_t>(sigsys.ip), |
618 { | 618 { |
619 static_cast<uint64_t>(ctx->uc_mcontext.gregs[REG_PARM1]), | 619 static_cast<uint64_t>(SECCOMP_PARM1(ctx)), |
620 static_cast<uint64_t>(ctx->uc_mcontext.gregs[REG_PARM2]), | 620 static_cast<uint64_t>(SECCOMP_PARM2(ctx)), |
621 static_cast<uint64_t>(ctx->uc_mcontext.gregs[REG_PARM3]), | 621 static_cast<uint64_t>(SECCOMP_PARM3(ctx)), |
622 static_cast<uint64_t>(ctx->uc_mcontext.gregs[REG_PARM4]), | 622 static_cast<uint64_t>(SECCOMP_PARM4(ctx)), |
623 static_cast<uint64_t>(ctx->uc_mcontext.gregs[REG_PARM5]), | 623 static_cast<uint64_t>(SECCOMP_PARM5(ctx)), |
624 static_cast<uint64_t>(ctx->uc_mcontext.gregs[REG_PARM6]) | 624 static_cast<uint64_t>(SECCOMP_PARM6(ctx)) |
625 } | 625 } |
626 }; | 626 }; |
627 | 627 |
628 // Now call the TrapFnc callback associated with this particular instance | 628 // Now call the TrapFnc callback associated with this particular instance |
629 // of SECCOMP_RET_TRAP. | 629 // of SECCOMP_RET_TRAP. |
630 const ErrorCode& err = trapArray_[info->si_errno - 1]; | 630 const ErrorCode& err = trapArray_[info->si_errno - 1]; |
631 intptr_t rc = err.fnc_(data, err.aux_); | 631 intptr_t rc = err.fnc_(data, err.aux_); |
632 | 632 |
633 // Update the CPU register that stores the return code of the system call | 633 // Update the CPU register that stores the return code of the system call |
634 // that we just handled, and restore "errno" to the value that it had | 634 // that we just handled, and restore "errno" to the value that it had |
635 // before entering the signal handler. | 635 // before entering the signal handler. |
636 ctx->uc_mcontext.gregs[REG_RESULT] = static_cast<greg_t>(rc); | 636 SECCOMP_RESULT(ctx) = static_cast<greg_t>(rc); |
637 errno = old_errno; | 637 errno = old_errno; |
638 | 638 |
639 return; | 639 return; |
640 } | 640 } |
641 | 641 |
642 intptr_t Sandbox::bpfFailure(const struct arch_seccomp_data&, void *aux) { | 642 intptr_t Sandbox::bpfFailure(const struct arch_seccomp_data&, void *aux) { |
643 die(static_cast<char *>(aux)); | 643 die(static_cast<char *>(aux)); |
644 } | 644 } |
645 | 645 |
646 int Sandbox::getTrapId(Sandbox::TrapFnc fnc, const void *aux) { | 646 int Sandbox::getTrapId(Sandbox::TrapFnc fnc, const void *aux) { |
647 // Each unique pair of TrapFnc and auxiliary data make up a distinct instance | 647 // Each unique pair of TrapFnc and auxiliary data make up a distinct instance |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 bool Sandbox::dryRun_ = false; | 686 bool Sandbox::dryRun_ = false; |
687 Sandbox::SandboxStatus Sandbox::status_ = STATUS_UNKNOWN; | 687 Sandbox::SandboxStatus Sandbox::status_ = STATUS_UNKNOWN; |
688 int Sandbox::proc_fd_ = -1; | 688 int Sandbox::proc_fd_ = -1; |
689 Sandbox::Evaluators Sandbox::evaluators_; | 689 Sandbox::Evaluators Sandbox::evaluators_; |
690 Sandbox::Traps *Sandbox::traps_ = NULL; | 690 Sandbox::Traps *Sandbox::traps_ = NULL; |
691 Sandbox::TrapIds Sandbox::trapIds_; | 691 Sandbox::TrapIds Sandbox::trapIds_; |
692 Sandbox::ErrorCode *Sandbox::trapArray_ = NULL; | 692 Sandbox::ErrorCode *Sandbox::trapArray_ = NULL; |
693 size_t Sandbox::trapArraySize_ = 0; | 693 size_t Sandbox::trapArraySize_ = 0; |
694 | 694 |
695 } // namespace | 695 } // namespace |
OLD | NEW |