This source file includes following definitions.
- IsChromeOS
- IsArchitectureArm
- AddArmMaliGpuWhitelist
- AddArmGpuWhitelist
- EvaluateSyscall
- EvaluateSyscall
- PreSandboxHook
#include "content/common/sandbox_linux/bpf_cros_arm_gpu_policy_linux.h"
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string>
#include <vector>
#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "build/build_config.h"
#include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h"
#include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h"
#include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h"
#include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
#include "sandbox/linux/services/linux_syscalls.h"
using sandbox::ErrorCode;
using sandbox::SandboxBPF;
using sandbox::SyscallSets;
namespace content {
namespace {
inline bool IsChromeOS() {
#if defined(OS_CHROMEOS)
return true;
#else
return false;
#endif
}
inline bool IsArchitectureArm() {
#if defined(__arm__)
return true;
#else
return false;
#endif
}
void AddArmMaliGpuWhitelist(std::vector<std::string>* read_whitelist,
std::vector<std::string>* write_whitelist) {
static const char kMali0Path[] = "/dev/mali0";
static const char kDevMfcDecPath[] = "/dev/mfc-dec";
static const char kDevGsc1Path[] = "/dev/gsc1";
static const char kDevMfcEncPath[] = "/dev/mfc-enc";
read_whitelist->push_back(kMali0Path);
read_whitelist->push_back(kDevMfcDecPath);
read_whitelist->push_back(kDevGsc1Path);
read_whitelist->push_back(kDevMfcEncPath);
write_whitelist->push_back(kMali0Path);
write_whitelist->push_back(kDevMfcDecPath);
write_whitelist->push_back(kDevGsc1Path);
write_whitelist->push_back(kDevMfcEncPath);
}
void AddArmGpuWhitelist(std::vector<std::string>* read_whitelist,
std::vector<std::string>* write_whitelist) {
static const char kXAuthorityPath[] = "/home/chronos/.Xauthority";
static const char kLdSoCache[] = "/etc/ld.so.cache";
static const char kLibGlesPath[] = "/usr/lib/libGLESv2.so.2";
static const char kLibEglPath[] = "/usr/lib/libEGL.so.1";
read_whitelist->push_back(kXAuthorityPath);
read_whitelist->push_back(kLdSoCache);
read_whitelist->push_back(kLibGlesPath);
read_whitelist->push_back(kLibEglPath);
AddArmMaliGpuWhitelist(read_whitelist, write_whitelist);
}
class CrosArmGpuBrokerProcessPolicy : public CrosArmGpuProcessPolicy {
public:
CrosArmGpuBrokerProcessPolicy() : CrosArmGpuProcessPolicy(false) {}
virtual ~CrosArmGpuBrokerProcessPolicy() {}
virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox_compiler,
int system_call_number) const OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(CrosArmGpuBrokerProcessPolicy);
};
ErrorCode CrosArmGpuBrokerProcessPolicy::EvaluateSyscall(SandboxBPF* sandbox,
int sysno) const {
switch (sysno) {
case __NR_access:
case __NR_open:
case __NR_openat:
return ErrorCode(ErrorCode::ERR_ALLOWED);
default:
return CrosArmGpuProcessPolicy::EvaluateSyscall(sandbox, sysno);
}
}
}
CrosArmGpuProcessPolicy::CrosArmGpuProcessPolicy(bool allow_shmat)
: allow_shmat_(allow_shmat) {}
CrosArmGpuProcessPolicy::~CrosArmGpuProcessPolicy() {}
ErrorCode CrosArmGpuProcessPolicy::EvaluateSyscall(SandboxBPF* sandbox,
int sysno) const {
#if defined(__arm__)
if (allow_shmat_ && sysno == __NR_shmat)
return ErrorCode(ErrorCode::ERR_ALLOWED);
#endif
switch (sysno) {
#if defined(__arm__)
case __NR_connect:
case __NR_getpeername:
case __NR_getsockname:
case __NR_sysinfo:
case __NR_uname:
return ErrorCode(ErrorCode::ERR_ALLOWED);
case __NR_socket:
case __NR_socketpair:
return sandbox->Cond(0, ErrorCode::TP_32BIT,
ErrorCode::OP_EQUAL, AF_UNIX,
ErrorCode(ErrorCode::ERR_ALLOWED),
ErrorCode(EPERM));
#endif
default:
if (SyscallSets::IsAdvancedScheduler(sysno))
return ErrorCode(ErrorCode::ERR_ALLOWED);
return GpuProcessPolicy::EvaluateSyscall(sandbox, sysno);
}
}
bool CrosArmGpuProcessPolicy::PreSandboxHook() {
DCHECK(IsChromeOS() && IsArchitectureArm());
DCHECK(!broker_process());
std::vector<std::string> read_whitelist_extra;
std::vector<std::string> write_whitelist_extra;
AddArmGpuWhitelist(&read_whitelist_extra, &write_whitelist_extra);
InitGpuBrokerProcess(
base::Bind(&SandboxSeccompBPF::StartSandboxWithExternalPolicy,
base::Passed(scoped_ptr<sandbox::SandboxBPFPolicy>(
new CrosArmGpuBrokerProcessPolicy))),
read_whitelist_extra,
write_whitelist_extra);
const int dlopen_flag = RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE;
dlopen("/usr/lib/libmali.so", dlopen_flag);
dlopen("/usr/lib/libtegrav4l2.so", dlopen_flag);
errno = 0;
return true;
}
}