Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/common/sandbox_linux/bpf_cros_arm_gpu_policy_linux.h" | 5 #include "content/common/sandbox_linux/bpf_cros_arm_gpu_policy_linux.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| 11 #include <sys/stat.h> | 11 #include <sys/stat.h> |
| 12 #include <sys/types.h> | 12 #include <sys/types.h> |
| 13 #include <unistd.h> | 13 #include <unistd.h> |
| 14 | 14 |
| 15 #include <string> | 15 #include <string> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "base/bind.h" | 18 #include "base/bind.h" |
| 19 #include "base/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
| 20 #include "base/logging.h" | 20 #include "base/logging.h" |
| 21 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
| 22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 23 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" | 23 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" |
| 24 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" | 24 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" |
| 25 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" | 25 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" |
| 26 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" | 26 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" |
| 27 #include "sandbox/linux/services/linux_syscalls.h" | 27 #include "sandbox/linux/services/linux_syscalls.h" |
| 28 #include "sandbox/linux/syscall_broker/broker_process.h" | |
| 28 | 29 |
| 29 using sandbox::SyscallSets; | |
| 30 using sandbox::bpf_dsl::Allow; | 30 using sandbox::bpf_dsl::Allow; |
| 31 using sandbox::bpf_dsl::Arg; | 31 using sandbox::bpf_dsl::Arg; |
| 32 using sandbox::bpf_dsl::Error; | 32 using sandbox::bpf_dsl::Error; |
| 33 using sandbox::bpf_dsl::If; | 33 using sandbox::bpf_dsl::If; |
| 34 using sandbox::bpf_dsl::ResultExpr; | 34 using sandbox::bpf_dsl::ResultExpr; |
| 35 using sandbox::syscall_broker::BrokerFilePermission; | |
|
Jorge Lucangeli Obes
2014/11/20 00:13:20
Should we change this to be simply "FilePermission
leecam
2014/11/20 00:56:38
As discussed as everything else in the syscall_bro
| |
| 36 using sandbox::SyscallSets; | |
| 35 | 37 |
| 36 namespace content { | 38 namespace content { |
| 37 | 39 |
| 38 namespace { | 40 namespace { |
| 39 | 41 |
| 40 inline bool IsChromeOS() { | 42 inline bool IsChromeOS() { |
| 41 #if defined(OS_CHROMEOS) | 43 #if defined(OS_CHROMEOS) |
| 42 return true; | 44 return true; |
| 43 #else | 45 #else |
| 44 return false; | 46 return false; |
| 45 #endif | 47 #endif |
| 46 } | 48 } |
| 47 | 49 |
| 48 inline bool IsArchitectureArm() { | 50 inline bool IsArchitectureArm() { |
| 49 #if defined(__arm__) | 51 #if defined(__arm__) |
| 50 return true; | 52 return true; |
| 51 #else | 53 #else |
| 52 return false; | 54 return false; |
| 53 #endif | 55 #endif |
| 54 } | 56 } |
| 55 | 57 |
| 56 void AddArmMaliGpuWhitelist(std::vector<std::string>* read_whitelist, | 58 void AddArmMaliGpuWhitelist(std::vector<BrokerFilePermission>* permissions) { |
| 57 std::vector<std::string>* write_whitelist) { | |
| 58 // Device file needed by the ARM GPU userspace. | 59 // Device file needed by the ARM GPU userspace. |
| 59 static const char kMali0Path[] = "/dev/mali0"; | 60 static const char kMali0Path[] = "/dev/mali0"; |
| 60 | 61 |
| 61 // Devices needed for video decode acceleration on ARM. | 62 // Devices needed for video decode acceleration on ARM. |
| 62 static const char kDevMfcDecPath[] = "/dev/mfc-dec"; | 63 static const char kDevMfcDecPath[] = "/dev/mfc-dec"; |
| 63 static const char kDevGsc1Path[] = "/dev/gsc1"; | 64 static const char kDevGsc1Path[] = "/dev/gsc1"; |
| 64 | 65 |
| 65 // Devices needed for video encode acceleration on ARM. | 66 // Devices needed for video encode acceleration on ARM. |
| 66 static const char kDevMfcEncPath[] = "/dev/mfc-enc"; | 67 static const char kDevMfcEncPath[] = "/dev/mfc-enc"; |
| 67 | 68 |
| 68 read_whitelist->push_back(kMali0Path); | 69 permissions->push_back(BrokerFilePermission::ReadWrite(kMali0Path)); |
| 69 read_whitelist->push_back(kDevMfcDecPath); | 70 permissions->push_back(BrokerFilePermission::ReadWrite(kDevMfcDecPath)); |
| 70 read_whitelist->push_back(kDevGsc1Path); | 71 permissions->push_back(BrokerFilePermission::ReadWrite(kDevGsc1Path)); |
| 71 read_whitelist->push_back(kDevMfcEncPath); | 72 permissions->push_back(BrokerFilePermission::ReadWrite(kDevMfcEncPath)); |
| 72 | |
| 73 write_whitelist->push_back(kMali0Path); | |
| 74 write_whitelist->push_back(kDevMfcDecPath); | |
| 75 write_whitelist->push_back(kDevGsc1Path); | |
| 76 write_whitelist->push_back(kDevMfcEncPath); | |
| 77 } | 73 } |
| 78 | 74 |
| 79 void AddArmGpuWhitelist(std::vector<std::string>* read_whitelist, | 75 void AddArmGpuWhitelist(std::vector<BrokerFilePermission>* permissions) { |
| 80 std::vector<std::string>* write_whitelist) { | |
| 81 // On ARM we're enabling the sandbox before the X connection is made, | 76 // On ARM we're enabling the sandbox before the X connection is made, |
| 82 // so we need to allow access to |.Xauthority|. | 77 // so we need to allow access to |.Xauthority|. |
| 83 static const char kXAuthorityPath[] = "/home/chronos/.Xauthority"; | 78 static const char kXAuthorityPath[] = "/home/chronos/.Xauthority"; |
| 84 static const char kLdSoCache[] = "/etc/ld.so.cache"; | 79 static const char kLdSoCache[] = "/etc/ld.so.cache"; |
| 85 | 80 |
| 86 // Files needed by the ARM GPU userspace. | 81 // Files needed by the ARM GPU userspace. |
| 87 static const char kLibGlesPath[] = "/usr/lib/libGLESv2.so.2"; | 82 static const char kLibGlesPath[] = "/usr/lib/libGLESv2.so.2"; |
| 88 static const char kLibEglPath[] = "/usr/lib/libEGL.so.1"; | 83 static const char kLibEglPath[] = "/usr/lib/libEGL.so.1"; |
| 89 | 84 |
| 90 read_whitelist->push_back(kXAuthorityPath); | 85 permissions->push_back(BrokerFilePermission::ReadOnly(kXAuthorityPath)); |
| 91 read_whitelist->push_back(kLdSoCache); | 86 permissions->push_back(BrokerFilePermission::ReadOnly(kLdSoCache)); |
| 92 read_whitelist->push_back(kLibGlesPath); | 87 permissions->push_back(BrokerFilePermission::ReadOnly(kLibGlesPath)); |
| 93 read_whitelist->push_back(kLibEglPath); | 88 permissions->push_back(BrokerFilePermission::ReadOnly(kLibEglPath)); |
| 94 | 89 |
| 95 AddArmMaliGpuWhitelist(read_whitelist, write_whitelist); | 90 AddArmMaliGpuWhitelist(permissions); |
| 96 } | 91 } |
| 97 | 92 |
| 98 class CrosArmGpuBrokerProcessPolicy : public CrosArmGpuProcessPolicy { | 93 class CrosArmGpuBrokerProcessPolicy : public CrosArmGpuProcessPolicy { |
| 99 public: | 94 public: |
| 100 static sandbox::bpf_dsl::Policy* Create() { | 95 static sandbox::bpf_dsl::Policy* Create() { |
| 101 return new CrosArmGpuBrokerProcessPolicy(); | 96 return new CrosArmGpuBrokerProcessPolicy(); |
| 102 } | 97 } |
| 103 ~CrosArmGpuBrokerProcessPolicy() override {} | 98 ~CrosArmGpuBrokerProcessPolicy() override {} |
| 104 | 99 |
| 105 ResultExpr EvaluateSyscall(int system_call_number) const override; | 100 ResultExpr EvaluateSyscall(int system_call_number) const override; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 // Default to the generic GPU policy. | 151 // Default to the generic GPU policy. |
| 157 return GpuProcessPolicy::EvaluateSyscall(sysno); | 152 return GpuProcessPolicy::EvaluateSyscall(sysno); |
| 158 } | 153 } |
| 159 } | 154 } |
| 160 | 155 |
| 161 bool CrosArmGpuProcessPolicy::PreSandboxHook() { | 156 bool CrosArmGpuProcessPolicy::PreSandboxHook() { |
| 162 DCHECK(IsChromeOS() && IsArchitectureArm()); | 157 DCHECK(IsChromeOS() && IsArchitectureArm()); |
| 163 // Create a new broker process. | 158 // Create a new broker process. |
| 164 DCHECK(!broker_process()); | 159 DCHECK(!broker_process()); |
| 165 | 160 |
| 166 std::vector<std::string> read_whitelist_extra; | |
| 167 std::vector<std::string> write_whitelist_extra; | |
| 168 // Add ARM-specific files to whitelist in the broker. | 161 // Add ARM-specific files to whitelist in the broker. |
| 162 std::vector<BrokerFilePermission> permissions; | |
| 169 | 163 |
| 170 AddArmGpuWhitelist(&read_whitelist_extra, &write_whitelist_extra); | 164 AddArmGpuWhitelist(&permissions); |
| 171 InitGpuBrokerProcess(CrosArmGpuBrokerProcessPolicy::Create, | 165 |
| 172 read_whitelist_extra, | 166 InitGpuBrokerProcess(CrosArmGpuBrokerProcessPolicy::Create, permissions); |
| 173 write_whitelist_extra); | |
| 174 | 167 |
| 175 const int dlopen_flag = RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE; | 168 const int dlopen_flag = RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE; |
| 176 | 169 |
| 177 // Preload the Mali library. | 170 // Preload the Mali library. |
| 178 dlopen("/usr/lib/libmali.so", dlopen_flag); | 171 dlopen("/usr/lib/libmali.so", dlopen_flag); |
| 179 // Preload the Tegra V4L2 (video decode acceleration) library. | 172 // Preload the Tegra V4L2 (video decode acceleration) library. |
| 180 dlopen("/usr/lib/libtegrav4l2.so", dlopen_flag); | 173 dlopen("/usr/lib/libtegrav4l2.so", dlopen_flag); |
| 181 // Resetting errno since platform-specific libraries will fail on other | 174 // Resetting errno since platform-specific libraries will fail on other |
| 182 // platforms. | 175 // platforms. |
| 183 errno = 0; | 176 errno = 0; |
| 184 | 177 |
| 185 return true; | 178 return true; |
| 186 } | 179 } |
| 187 | 180 |
| 188 } // namespace content | 181 } // namespace content |
| OLD | NEW |