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

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

Issue 299683004: Rewrite all BPF policies to use DSL API Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Overhaul of DSL and implementation Created 6 years, 7 months 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 | Annotate | Revision Log
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_gpu_policy_linux.h" 5 #include "content/common/sandbox_linux/bpf_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>
(...skipping 12 matching lines...) Expand all
23 #include "build/build_config.h" 23 #include "build/build_config.h"
24 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" 24 #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h"
25 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" 25 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h"
26 #include "content/common/set_process_title.h" 26 #include "content/common/set_process_title.h"
27 #include "content/public/common/content_switches.h" 27 #include "content/public/common/content_switches.h"
28 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h" 28 #include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h"
29 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" 29 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
30 #include "sandbox/linux/services/broker_process.h" 30 #include "sandbox/linux/services/broker_process.h"
31 #include "sandbox/linux/services/linux_syscalls.h" 31 #include "sandbox/linux/services/linux_syscalls.h"
32 32
33 using namespace sandbox::bpf_dsl;
33 using sandbox::BrokerProcess; 34 using sandbox::BrokerProcess;
34 using sandbox::ErrorCode;
35 using sandbox::SandboxBPF;
36 using sandbox::SyscallSets; 35 using sandbox::SyscallSets;
37 using sandbox::arch_seccomp_data; 36 using sandbox::arch_seccomp_data;
38 37
39 namespace content { 38 namespace content {
40 39
41 namespace { 40 namespace {
42 41
43 inline bool IsChromeOS() { 42 inline bool IsChromeOS() {
44 #if defined(OS_CHROMEOS) 43 #if defined(OS_CHROMEOS)
45 return true; 44 return true;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 107 }
109 } 108 }
110 109
111 class GpuBrokerProcessPolicy : public GpuProcessPolicy { 110 class GpuBrokerProcessPolicy : public GpuProcessPolicy {
112 public: 111 public:
113 static sandbox::SandboxBPFPolicy* Create() { 112 static sandbox::SandboxBPFPolicy* Create() {
114 return new GpuBrokerProcessPolicy(); 113 return new GpuBrokerProcessPolicy();
115 } 114 }
116 virtual ~GpuBrokerProcessPolicy() {} 115 virtual ~GpuBrokerProcessPolicy() {}
117 116
118 virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox_compiler, 117 virtual sandbox::bpf_dsl::ResultExpr EvaluateSyscall(
119 int system_call_number) const OVERRIDE; 118 int sysno) const OVERRIDE;
120 119
121 private: 120 private:
122 GpuBrokerProcessPolicy() {} 121 GpuBrokerProcessPolicy() {}
123 DISALLOW_COPY_AND_ASSIGN(GpuBrokerProcessPolicy); 122 DISALLOW_COPY_AND_ASSIGN(GpuBrokerProcessPolicy);
124 }; 123 };
125 124
126 // x86_64/i386 or desktop ARM. 125 // x86_64/i386 or desktop ARM.
127 // A GPU broker policy is the same as a GPU policy with open and 126 // A GPU broker policy is the same as a GPU policy with open and
128 // openat allowed. 127 // openat allowed.
129 ErrorCode GpuBrokerProcessPolicy::EvaluateSyscall(SandboxBPF* sandbox, 128 ResultExpr GpuBrokerProcessPolicy::EvaluateSyscall(int sysno) const {
130 int sysno) const {
131 switch (sysno) { 129 switch (sysno) {
132 case __NR_access: 130 case __NR_access:
133 case __NR_open: 131 case __NR_open:
134 case __NR_openat: 132 case __NR_openat:
135 return ErrorCode(ErrorCode::ERR_ALLOWED); 133 return Allow();
136 default: 134 default:
137 return GpuProcessPolicy::EvaluateSyscall(sandbox, sysno); 135 return GpuProcessPolicy::EvaluateSyscall(sysno);
138 } 136 }
139 } 137 }
140 138
141 void UpdateProcessTypeToGpuBroker() { 139 void UpdateProcessTypeToGpuBroker() {
142 CommandLine::StringVector exec = CommandLine::ForCurrentProcess()->GetArgs(); 140 CommandLine::StringVector exec = CommandLine::ForCurrentProcess()->GetArgs();
143 CommandLine::Reset(); 141 CommandLine::Reset();
144 CommandLine::Init(0, NULL); 142 CommandLine::Init(0, NULL);
145 CommandLine::ForCurrentProcess()->InitFromArgv(exec); 143 CommandLine::ForCurrentProcess()->InitFromArgv(exec);
146 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kProcessType, 144 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kProcessType,
147 "gpu-broker"); 145 "gpu-broker");
(...skipping 12 matching lines...) Expand all
160 make_scoped_ptr(broker_sandboxer_allocator())); 158 make_scoped_ptr(broker_sandboxer_allocator()));
161 } 159 }
162 160
163 } // namespace 161 } // namespace
164 162
165 GpuProcessPolicy::GpuProcessPolicy() : broker_process_(NULL) {} 163 GpuProcessPolicy::GpuProcessPolicy() : broker_process_(NULL) {}
166 164
167 GpuProcessPolicy::~GpuProcessPolicy() {} 165 GpuProcessPolicy::~GpuProcessPolicy() {}
168 166
169 // Main policy for x86_64/i386. Extended by CrosArmGpuProcessPolicy. 167 // Main policy for x86_64/i386. Extended by CrosArmGpuProcessPolicy.
170 ErrorCode GpuProcessPolicy::EvaluateSyscall(SandboxBPF* sandbox, 168 ResultExpr GpuProcessPolicy::EvaluateSyscall(int sysno) const {
171 int sysno) const {
172 switch (sysno) { 169 switch (sysno) {
173 case __NR_ioctl: 170 case __NR_ioctl:
174 #if defined(__i386__) || defined(__x86_64__) 171 #if defined(__i386__) || defined(__x86_64__)
175 // The Nvidia driver uses flags not in the baseline policy 172 // The Nvidia driver uses flags not in the baseline policy
176 // (MAP_LOCKED | MAP_EXECUTABLE | MAP_32BIT) 173 // (MAP_LOCKED | MAP_EXECUTABLE | MAP_32BIT)
177 case __NR_mmap: 174 case __NR_mmap:
178 #endif 175 #endif
179 // We also hit this on the linux_chromeos bot but don't yet know what 176 // We also hit this on the linux_chromeos bot but don't yet know what
180 // weird flags were involved. 177 // weird flags were involved.
181 case __NR_mprotect: 178 case __NR_mprotect:
182 case __NR_sched_getaffinity: 179 case __NR_sched_getaffinity:
183 case __NR_sched_setaffinity: 180 case __NR_sched_setaffinity:
184 case __NR_setpriority: 181 case __NR_setpriority:
185 return ErrorCode(ErrorCode::ERR_ALLOWED); 182 return Allow();
186 case __NR_access: 183 case __NR_access:
187 case __NR_open: 184 case __NR_open:
188 case __NR_openat: 185 case __NR_openat:
189 DCHECK(broker_process_); 186 DCHECK(broker_process_);
190 return sandbox->Trap(GpuSIGSYS_Handler, broker_process_); 187 return Trap(GpuSIGSYS_Handler, broker_process_);
191 default: 188 default:
192 if (SyscallSets::IsEventFd(sysno)) 189 if (SyscallSets::IsEventFd(sysno))
193 return ErrorCode(ErrorCode::ERR_ALLOWED); 190 return Allow();
194 191
195 // Default on the baseline policy. 192 // Default on the baseline policy.
196 return SandboxBPFBasePolicy::EvaluateSyscall(sandbox, sysno); 193 return SandboxBPFBasePolicy::EvaluateSyscall(sysno);
197 } 194 }
198 } 195 }
199 196
200 bool GpuProcessPolicy::PreSandboxHook() { 197 bool GpuProcessPolicy::PreSandboxHook() {
201 // Warm up resources needed by the policy we're about to enable and 198 // Warm up resources needed by the policy we're about to enable and
202 // eventually start a broker process. 199 // eventually start a broker process.
203 const bool chromeos_arm_gpu = IsChromeOS() && IsArchitectureArm(); 200 const bool chromeos_arm_gpu = IsChromeOS() && IsArchitectureArm();
204 // This policy is for x86 or Desktop. 201 // This policy is for x86 or Desktop.
205 DCHECK(!chromeos_arm_gpu); 202 DCHECK(!chromeos_arm_gpu);
206 203
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 broker_process_ = new BrokerProcess(GetFSDeniedErrno(), 257 broker_process_ = new BrokerProcess(GetFSDeniedErrno(),
261 read_whitelist, 258 read_whitelist,
262 write_whitelist); 259 write_whitelist);
263 // The initialization callback will perform generic initialization and then 260 // The initialization callback will perform generic initialization and then
264 // call broker_sandboxer_callback. 261 // call broker_sandboxer_callback.
265 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, 262 CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox,
266 broker_sandboxer_allocator))); 263 broker_sandboxer_allocator)));
267 } 264 }
268 265
269 } // namespace content 266 } // namespace content
OLDNEW
« no previous file with comments | « content/common/sandbox_linux/bpf_gpu_policy_linux.h ('k') | content/common/sandbox_linux/bpf_ppapi_policy_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698