This source file includes following definitions.
- IsSystemVSharedMemory
- IsSystemVIpc
- EvaluateSyscall
- RunSandboxSanityChecks
- InitializeBPFSandbox
#include "components/nacl/loader/nacl_sandbox_linux.h"
#include <errno.h>
#include <signal.h>
#include <sys/ptrace.h>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "build/build_config.h"
#if defined(USE_SECCOMP_BPF)
#include "content/public/common/sandbox_init.h"
#include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
#include "sandbox/linux/seccomp-bpf/sandbox_bpf_policy.h"
#include "sandbox/linux/services/linux_syscalls.h"
using sandbox::ErrorCode;
using sandbox::SandboxBPF;
using sandbox::SandboxBPFPolicy;
namespace {
#if defined(__x86_64__) || defined(__arm__)
bool IsSystemVSharedMemory(int sysno) {
switch (sysno) {
case __NR_shmat:
case __NR_shmctl:
case __NR_shmdt:
case __NR_shmget:
return true;
default:
return false;
}
}
#endif
#if defined(__i386__)
bool IsSystemVIpc(int sysno) {
switch (sysno) {
case __NR_ipc:
return true;
default:
return false;
}
}
#endif
class NaClBPFSandboxPolicy : public SandboxBPFPolicy {
public:
NaClBPFSandboxPolicy()
: baseline_policy_(content::GetBPFSandboxBaselinePolicy()) {}
virtual ~NaClBPFSandboxPolicy() {}
virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox_compiler,
int system_call_number) const OVERRIDE;
private:
scoped_ptr<SandboxBPFPolicy> baseline_policy_;
DISALLOW_COPY_AND_ASSIGN(NaClBPFSandboxPolicy);
};
ErrorCode NaClBPFSandboxPolicy::EvaluateSyscall(
sandbox::SandboxBPF* sb, int sysno) const {
DCHECK(baseline_policy_);
switch (sysno) {
#if defined(__x86_64__) || defined(__arm__)
case __NR_accept:
case __NR_setsockopt:
#elif defined(__i386__)
case __NR_socketcall:
#endif
case __NR_rt_sigtimedwait:
#if defined(__i386__)
case __NR_modify_ldt:
#endif
case __NR_prlimit64:
case __NR_sigaltstack:
case __NR_ioctl:
#if defined(__i386__) || defined(__x86_64__)
case __NR_getrlimit:
#endif
#if defined(__i386__) || defined(__arm__)
case __NR_ugetrlimit:
#endif
case __NR_clock_getres:
case __NR_flock:
case __NR_pread64:
case __NR_pwrite64:
case __NR_sched_get_priority_max:
case __NR_sched_get_priority_min:
case __NR_sched_getaffinity:
case __NR_sched_getparam:
case __NR_sched_getscheduler:
case __NR_sched_setscheduler:
case __NR_setpriority:
case __NR_sysinfo:
case __NR_times:
case __NR_uname:
return ErrorCode(ErrorCode::ERR_ALLOWED);
case __NR_ptrace:
return ErrorCode(EPERM);
default:
#if defined(__x86_64__) || defined(__arm__)
if (IsSystemVSharedMemory(sysno))
return ErrorCode(ErrorCode::ERR_ALLOWED);
#elif defined(__i386__)
if (IsSystemVIpc(sysno))
return ErrorCode(ErrorCode::ERR_ALLOWED);
#endif
return baseline_policy_->EvaluateSyscall(sb, sysno);
}
NOTREACHED();
return ErrorCode(EPERM);
}
void RunSandboxSanityChecks() {
errno = 0;
long ptrace_ret = ptrace(PTRACE_PEEKUSER, -1 , NULL, NULL);
CHECK_EQ(-1, ptrace_ret);
CHECK_EQ(EPERM, errno);
}
}
#else
#if !defined(ARCH_CPU_MIPS_FAMILY)
#error "Seccomp-bpf disabled on supported architecture!"
#endif
#endif
bool InitializeBPFSandbox() {
#if defined(USE_SECCOMP_BPF)
bool sandbox_is_initialized = content::InitializeSandbox(
scoped_ptr<SandboxBPFPolicy>(new NaClBPFSandboxPolicy()));
if (sandbox_is_initialized) {
RunSandboxSanityChecks();
return true;
}
#endif
return false;
}