Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: content/common/sandbox_linux/bpf_cros_arm_gpu_policy_linux.cc

Issue 721553002: sandbox: Extend BrokerPolicy to support file creation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding comments Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
30 using sandbox::syscall_broker::BrokerFilePermission;
31 using sandbox::syscall_broker::BrokerFilePermissionReadOnly;
32 using sandbox::syscall_broker::BrokerFilePermissionReadWrite;
33 using sandbox::syscall_broker::
34 BrokerFilePermissionReadWriteCreateUnlinkRecursive;
29 using sandbox::SyscallSets; 35 using sandbox::SyscallSets;
30 using sandbox::bpf_dsl::Allow; 36 using sandbox::bpf_dsl::Allow;
31 using sandbox::bpf_dsl::Arg; 37 using sandbox::bpf_dsl::Arg;
32 using sandbox::bpf_dsl::Error; 38 using sandbox::bpf_dsl::Error;
33 using sandbox::bpf_dsl::If; 39 using sandbox::bpf_dsl::If;
34 using sandbox::bpf_dsl::ResultExpr; 40 using sandbox::bpf_dsl::ResultExpr;
35 41
36 namespace content { 42 namespace content {
37 43
38 namespace { 44 namespace {
39 45
40 inline bool IsChromeOS() { 46 inline bool IsChromeOS() {
41 #if defined(OS_CHROMEOS) 47 #if defined(OS_CHROMEOS)
42 return true; 48 return true;
43 #else 49 #else
44 return false; 50 return false;
45 #endif 51 #endif
46 } 52 }
47 53
48 inline bool IsArchitectureArm() { 54 inline bool IsArchitectureArm() {
49 #if defined(__arm__) 55 #if defined(__arm__)
50 return true; 56 return true;
51 #else 57 #else
52 return false; 58 return false;
53 #endif 59 #endif
54 } 60 }
55 61
56 void AddArmMaliGpuWhitelist(std::vector<std::string>* read_whitelist, 62 void AddArmMaliGpuWhitelist(std::vector<BrokerFilePermission>* permissions) {
Jorge Lucangeli Obes 2014/11/14 18:48:06 Does it make sense to split this CL in two and fir
leecam 2014/11/18 21:40:53 Not changing the behavior of the policies here but
57 std::vector<std::string>* write_whitelist) {
58 // Device file needed by the ARM GPU userspace. 63 // Device file needed by the ARM GPU userspace.
59 static const char kMali0Path[] = "/dev/mali0"; 64 static const char kMali0Path[] = "/dev/mali0";
60 65
61 // Devices needed for video decode acceleration on ARM. 66 // Devices needed for video decode acceleration on ARM.
62 static const char kDevMfcDecPath[] = "/dev/mfc-dec"; 67 static const char kDevMfcDecPath[] = "/dev/mfc-dec";
63 static const char kDevGsc1Path[] = "/dev/gsc1"; 68 static const char kDevGsc1Path[] = "/dev/gsc1";
64 69
65 // Devices needed for video encode acceleration on ARM. 70 // Devices needed for video encode acceleration on ARM.
66 static const char kDevMfcEncPath[] = "/dev/mfc-enc"; 71 static const char kDevMfcEncPath[] = "/dev/mfc-enc";
67 72
68 read_whitelist->push_back(kMali0Path); 73 permissions->push_back(BrokerFilePermissionReadWrite(kMali0Path));
69 read_whitelist->push_back(kDevMfcDecPath); 74 permissions->push_back(BrokerFilePermissionReadWrite(kDevMfcDecPath));
70 read_whitelist->push_back(kDevGsc1Path); 75 permissions->push_back(BrokerFilePermissionReadWrite(kDevGsc1Path));
71 read_whitelist->push_back(kDevMfcEncPath); 76 permissions->push_back(BrokerFilePermissionReadWrite(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 } 77 }
78 78
79 void AddArmGpuWhitelist(std::vector<std::string>* read_whitelist, 79 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, 80 // On ARM we're enabling the sandbox before the X connection is made,
82 // so we need to allow access to |.Xauthority|. 81 // so we need to allow access to |.Xauthority|.
83 static const char kXAuthorityPath[] = "/home/chronos/.Xauthority"; 82 static const char kXAuthorityPath[] = "/home/chronos/.Xauthority";
84 static const char kLdSoCache[] = "/etc/ld.so.cache"; 83 static const char kLdSoCache[] = "/etc/ld.so.cache";
85 84
86 // Files needed by the ARM GPU userspace. 85 // Files needed by the ARM GPU userspace.
87 static const char kLibGlesPath[] = "/usr/lib/libGLESv2.so.2"; 86 static const char kLibGlesPath[] = "/usr/lib/libGLESv2.so.2";
88 static const char kLibEglPath[] = "/usr/lib/libEGL.so.1"; 87 static const char kLibEglPath[] = "/usr/lib/libEGL.so.1";
89 88
90 read_whitelist->push_back(kXAuthorityPath); 89 permissions->push_back(BrokerFilePermissionReadOnly(kXAuthorityPath));
91 read_whitelist->push_back(kLdSoCache); 90 permissions->push_back(BrokerFilePermissionReadOnly(kLdSoCache));
92 read_whitelist->push_back(kLibGlesPath); 91 permissions->push_back(BrokerFilePermissionReadOnly(kLibGlesPath));
93 read_whitelist->push_back(kLibEglPath); 92 permissions->push_back(BrokerFilePermissionReadOnly(kLibEglPath));
94 93
95 AddArmMaliGpuWhitelist(read_whitelist, write_whitelist); 94 AddArmMaliGpuWhitelist(permissions);
96 } 95 }
97 96
98 class CrosArmGpuBrokerProcessPolicy : public CrosArmGpuProcessPolicy { 97 class CrosArmGpuBrokerProcessPolicy : public CrosArmGpuProcessPolicy {
99 public: 98 public:
100 static sandbox::bpf_dsl::Policy* Create() { 99 static sandbox::bpf_dsl::Policy* Create() {
101 return new CrosArmGpuBrokerProcessPolicy(); 100 return new CrosArmGpuBrokerProcessPolicy();
102 } 101 }
103 ~CrosArmGpuBrokerProcessPolicy() override {} 102 ~CrosArmGpuBrokerProcessPolicy() override {}
104 103
105 ResultExpr EvaluateSyscall(int system_call_number) const override; 104 ResultExpr EvaluateSyscall(int system_call_number) const override;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // Default to the generic GPU policy. 155 // Default to the generic GPU policy.
157 return GpuProcessPolicy::EvaluateSyscall(sysno); 156 return GpuProcessPolicy::EvaluateSyscall(sysno);
158 } 157 }
159 } 158 }
160 159
161 bool CrosArmGpuProcessPolicy::PreSandboxHook() { 160 bool CrosArmGpuProcessPolicy::PreSandboxHook() {
162 DCHECK(IsChromeOS() && IsArchitectureArm()); 161 DCHECK(IsChromeOS() && IsArchitectureArm());
163 // Create a new broker process. 162 // Create a new broker process.
164 DCHECK(!broker_process()); 163 DCHECK(!broker_process());
165 164
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. 165 // Add ARM-specific files to whitelist in the broker.
166 std::vector<BrokerFilePermission> permissions;
169 167
170 AddArmGpuWhitelist(&read_whitelist_extra, &write_whitelist_extra); 168 AddArmGpuWhitelist(&permissions);
171 InitGpuBrokerProcess(CrosArmGpuBrokerProcessPolicy::Create, 169
172 read_whitelist_extra, 170 InitGpuBrokerProcess(CrosArmGpuBrokerProcessPolicy::Create, permissions);
173 write_whitelist_extra);
174 171
175 const int dlopen_flag = RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE; 172 const int dlopen_flag = RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE;
176 173
177 // Preload the Mali library. 174 // Preload the Mali library.
178 dlopen("/usr/lib/libmali.so", dlopen_flag); 175 dlopen("/usr/lib/libmali.so", dlopen_flag);
179 // Preload the Tegra V4L2 (video decode acceleration) library. 176 // Preload the Tegra V4L2 (video decode acceleration) library.
180 dlopen("/usr/lib/libtegrav4l2.so", dlopen_flag); 177 dlopen("/usr/lib/libtegrav4l2.so", dlopen_flag);
181 // Resetting errno since platform-specific libraries will fail on other 178 // Resetting errno since platform-specific libraries will fail on other
182 // platforms. 179 // platforms.
183 errno = 0; 180 errno = 0;
184 181
185 return true; 182 return true;
186 } 183 }
187 184
188 } // namespace content 185 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698