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

Side by Side Diff: components/nacl/loader/nonsfi/nonsfi_sandbox.cc

Issue 1029283003: WIP: Implement seccomp-bpf sandbox for nacl_helper_nonsfi. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/nacl/loader/nonsfi/nonsfi_sandbox.h" 5 #include "components/nacl/loader/nonsfi/nonsfi_sandbox.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <linux/futex.h>
10 #include <linux/net.h>
11 #include <sys/mman.h> 9 #include <sys/mman.h>
12 #include <sys/prctl.h> 10 #include <sys/prctl.h>
13 #include <sys/ptrace.h>
14 #include <sys/socket.h> 11 #include <sys/socket.h>
15 #include <sys/syscall.h> 12 #include <sys/syscall.h>
16 #include <sys/time.h> 13 #include <sys/time.h>
17 14
18 #include "base/basictypes.h" 15 #include "base/basictypes.h"
19 #include "base/logging.h" 16 #include "base/logging.h"
20 #include "base/time/time.h" 17 #include "base/time/time.h"
21 #include "build/build_config.h" 18 #include "build/build_config.h"
22 #include "content/public/common/sandbox_init.h" 19 #include "content/public/common/sandbox_init.h"
23 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" 20 #include "sandbox/linux/bpf_dsl/bpf_dsl.h"
24 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h" 21 #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h"
25 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h" 22 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h"
23 #include "sandbox/linux/system_headers/android_futex.h"
26 #include "sandbox/linux/system_headers/linux_syscalls.h" 24 #include "sandbox/linux/system_headers/linux_syscalls.h"
27 25
26 #if !defined(OS_NACL_NONSFI)
27 #include <linux/net.h> // TODO move SYS_SOCKETPAIR etc to there.
28 #include <sys/ptrace.h>
29 #endif
30
28 #if defined(__arm__) && !defined(MAP_STACK) 31 #if defined(__arm__) && !defined(MAP_STACK)
29 // Chrome OS Daisy (ARM) build environment has old headers. 32 // Chrome OS Daisy (ARM) build environment has old headers.
30 #define MAP_STACK 0x20000 33 #define MAP_STACK 0x20000
31 #endif 34 #endif
32 35
36 // TODO
37 #if !defined(PR_SET_NAME)
38 #define PR_SET_NAME 15
39 #endif
40 #if !defined(MAP_STACK)
41 #define MAP_STACK 0x20000
42 #endif
43
33 #define CASES SANDBOX_BPF_DSL_CASES 44 #define CASES SANDBOX_BPF_DSL_CASES
34 45
35 using sandbox::CrashSIGSYS; 46 using sandbox::CrashSIGSYS;
36 using sandbox::CrashSIGSYSClone; 47 using sandbox::CrashSIGSYSClone;
37 using sandbox::CrashSIGSYSFutex; 48 using sandbox::CrashSIGSYSFutex;
38 using sandbox::CrashSIGSYSPrctl; 49 using sandbox::CrashSIGSYSPrctl;
39 using sandbox::bpf_dsl::Allow; 50 using sandbox::bpf_dsl::Allow;
40 using sandbox::bpf_dsl::Arg; 51 using sandbox::bpf_dsl::Arg;
41 using sandbox::bpf_dsl::BoolExpr; 52 using sandbox::bpf_dsl::BoolExpr;
42 using sandbox::bpf_dsl::Error; 53 using sandbox::bpf_dsl::Error;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 case __NR_time: 187 case __NR_time:
177 #endif 188 #endif
178 return true; 189 return true;
179 190
180 default: 191 default:
181 return false; 192 return false;
182 } 193 }
183 } 194 }
184 195
185 void RunSandboxSanityChecks() { 196 void RunSandboxSanityChecks() {
197 #if !defined(OS_NACL_NONSFI)
198 // TODO: Is this sanity check needed? Can we have alternative?
186 errno = 0; 199 errno = 0;
187 // Make a ptrace request with an invalid PID. 200 // Make a ptrace request with an invalid PID.
188 long ptrace_ret = ptrace(PTRACE_PEEKUSER, -1 /* pid */, NULL, NULL); 201 long ptrace_ret = ptrace(PTRACE_PEEKUSER, -1 /* pid */, NULL, NULL);
189 CHECK_EQ(-1, ptrace_ret); 202 CHECK_EQ(-1, ptrace_ret);
190 // Without the sandbox on, this ptrace call would ESRCH instead. 203 // Without the sandbox on, this ptrace call would ESRCH instead.
191 CHECK_EQ(EPERM, errno); 204 CHECK_EQ(EPERM, errno);
205 #endif
192 } 206 }
193 207
194 } // namespace 208 } // namespace
195 209
196 ResultExpr NaClNonSfiBPFSandboxPolicy::EvaluateSyscall(int sysno) const { 210 ResultExpr NaClNonSfiBPFSandboxPolicy::EvaluateSyscall(int sysno) const {
197 switch (sysno) { 211 switch (sysno) {
198 // Allowed syscalls. 212 // Allowed syscalls.
199 #if defined(__i386__) || defined(__arm__) 213 #if defined(__i386__) || defined(__arm__)
200 case __NR__llseek: 214 case __NR__llseek:
201 #elif defined(__x86_64__) 215 #elif defined(__x86_64__)
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy()), 320 new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy()),
307 proc_fd.Pass()); 321 proc_fd.Pass());
308 if (!sandbox_is_initialized) 322 if (!sandbox_is_initialized)
309 return false; 323 return false;
310 RunSandboxSanityChecks(); 324 RunSandboxSanityChecks();
311 return true; 325 return true;
312 } 326 }
313 327
314 } // namespace nonsfi 328 } // namespace nonsfi
315 } // namespace nacl 329 } // namespace nacl
OLDNEW
« no previous file with comments | « components/nacl/loader/nacl_helper_linux.cc ('k') | components/nacl/loader/sandbox_linux/nacl_sandbox_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698