bpf_libassistant_policy_linux.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "sandbox/policy/linux/bpf_libassistant_policy_linux.h"
  5. #include <sys/socket.h>
  6. #include "sandbox/linux/bpf_dsl/bpf_dsl.h"
  7. #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h"
  8. #include "sandbox/linux/syscall_broker/broker_process.h"
  9. #include "sandbox/linux/system_headers/linux_syscalls.h"
  10. #include "sandbox/policy/linux/sandbox_linux.h"
  11. using sandbox::bpf_dsl::Allow;
  12. using sandbox::bpf_dsl::ResultExpr;
  13. using sandbox::bpf_dsl::Trap;
  14. using sandbox::syscall_broker::BrokerProcess;
  15. namespace sandbox {
  16. namespace policy {
  17. LibassistantProcessPolicy::LibassistantProcessPolicy() = default;
  18. LibassistantProcessPolicy::~LibassistantProcessPolicy() = default;
  19. ResultExpr LibassistantProcessPolicy::EvaluateSyscall(int sysno) const {
  20. switch (sysno) {
  21. #if defined(__NR_getcpu)
  22. // Needed by arm devices.
  23. case __NR_getcpu:
  24. return Allow();
  25. #endif
  26. #if defined(__NR_sched_setscheduler)
  27. case __NR_sched_setscheduler:
  28. return Allow();
  29. #endif
  30. default:
  31. auto* sandbox_linux = SandboxLinux::GetInstance();
  32. if (sandbox_linux->ShouldBrokerHandleSyscall(sysno))
  33. return sandbox_linux->HandleViaBroker(sysno);
  34. return BPFBasePolicy::EvaluateSyscall(sysno);
  35. }
  36. }
  37. } // namespace policy
  38. } // namespace sandbox