Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "content/common/sandbox_linux/android/sandbox_bpf_base_policy_android.h " | 5 #include "content/common/sandbox_linux/android/sandbox_bpf_base_policy_android.h " |
| 6 | 6 |
| 7 #include <linux/net.h> | |
| 8 #include <sys/socket.h> | |
| 7 #include <sys/syscall.h> | 9 #include <sys/syscall.h> |
| 8 #include <sys/types.h> | 10 #include <sys/types.h> |
| 9 | 11 |
| 10 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 11 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" | 13 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" |
| 12 | 14 |
| 15 using sandbox::bpf_dsl::AllOf; | |
| 13 using sandbox::bpf_dsl::Allow; | 16 using sandbox::bpf_dsl::Allow; |
| 17 using sandbox::bpf_dsl::AnyOf; | |
| 18 using sandbox::bpf_dsl::Arg; | |
| 19 using sandbox::bpf_dsl::If; | |
| 20 using sandbox::bpf_dsl::Error; | |
| 14 using sandbox::bpf_dsl::ResultExpr; | 21 using sandbox::bpf_dsl::ResultExpr; |
| 15 | 22 |
| 16 namespace content { | 23 namespace content { |
| 17 | 24 |
| 25 #ifndef SOCK_TYPE_MASK | |
| 26 #define SOCK_TYPE_MASK 0xf | |
| 27 #endif | |
| 28 | |
| 18 SandboxBPFBasePolicyAndroid::SandboxBPFBasePolicyAndroid() | 29 SandboxBPFBasePolicyAndroid::SandboxBPFBasePolicyAndroid() |
| 19 : SandboxBPFBasePolicy() {} | 30 : SandboxBPFBasePolicy() {} |
| 20 | 31 |
| 21 SandboxBPFBasePolicyAndroid::~SandboxBPFBasePolicyAndroid() {} | 32 SandboxBPFBasePolicyAndroid::~SandboxBPFBasePolicyAndroid() {} |
| 22 | 33 |
| 23 ResultExpr SandboxBPFBasePolicyAndroid::EvaluateSyscall(int sysno) const { | 34 ResultExpr SandboxBPFBasePolicyAndroid::EvaluateSyscall(int sysno) const { |
| 24 bool override_and_allow = false; | 35 bool override_and_allow = false; |
| 25 | 36 |
| 26 switch (sysno) { | 37 switch (sysno) { |
| 27 // TODO(rsesek): restrict clone parameters. | 38 // TODO(rsesek): restrict clone parameters. |
| 28 case __NR_clone: | 39 case __NR_clone: |
| 29 case __NR_epoll_pwait: | 40 case __NR_epoll_pwait: |
| 30 case __NR_flock: | 41 case __NR_flock: |
| 31 #if defined(__x86_64__) || defined(__aarch64__) | 42 #if defined(__x86_64__) || defined(__aarch64__) |
| 32 case __NR_newfstatat: | 43 case __NR_newfstatat: |
| 44 case __NR_getdents64: | |
| 33 #elif defined(__i386__) || defined(__arm__) || defined(__mips__) | 45 #elif defined(__i386__) || defined(__arm__) || defined(__mips__) |
| 34 case __NR_fstatat64: | 46 case __NR_fstatat64: |
| 47 case __NR_getdents: | |
| 35 #endif | 48 #endif |
| 36 case __NR_getpriority: | 49 case __NR_getpriority: |
| 37 case __NR_ioctl: | 50 case __NR_ioctl: |
| 38 case __NR_mremap: | 51 case __NR_mremap: |
| 39 // File system access cannot be restricted with seccomp-bpf on Android, | 52 // File system access cannot be restricted with seccomp-bpf on Android, |
| 40 // since the JVM classloader and other Framework features require file | 53 // since the JVM classloader and other Framework features require file |
| 41 // access. It may be possible to restrict the filesystem with SELinux. | 54 // access. It may be possible to restrict the filesystem with SELinux. |
| 42 // Currently we rely on the app/service UID isolation to create a | 55 // Currently we rely on the app/service UID isolation to create a |
| 43 // filesystem "sandbox". | 56 // filesystem "sandbox". |
| 44 #if !defined(ARCH_CPU_ARM64) | 57 #if !defined(ARCH_CPU_ARM64) |
| 45 case __NR_open: | 58 case __NR_open: |
| 46 #endif | 59 #endif |
| 47 case __NR_openat: | 60 case __NR_openat: |
| 48 case __NR_pread64: | 61 case __NR_pread64: |
| 49 case __NR_rt_sigtimedwait: | 62 case __NR_rt_sigtimedwait: |
| 50 case __NR_setpriority: | 63 case __NR_setpriority: |
| 51 case __NR_set_tid_address: | 64 case __NR_set_tid_address: |
| 52 case __NR_sigaltstack: | 65 case __NR_sigaltstack: |
| 53 #if defined(__i386__) || defined(__arm__) | 66 #if defined(__i386__) || defined(__arm__) |
| 54 case __NR_ugetrlimit: | 67 case __NR_ugetrlimit: |
| 55 #else | 68 #else |
| 56 case __NR_getrlimit: | 69 case __NR_getrlimit: |
| 57 #endif | 70 #endif |
| 58 case __NR_uname: | 71 case __NR_uname: |
| 72 | |
| 73 // Permit socket operations so that renderers can connect to logd and | |
| 74 // debuggerd. The arguments to socket() are further restricted below. | |
| 75 case __NR_socket: | |
| 76 case __NR_connect: | |
| 77 | |
| 78 // Ptrace is allowed so the Breakpad Microdumper can fork in a renderer | |
| 79 // and then ptrace the parent. | |
| 80 case __NR_ptrace: | |
| 59 override_and_allow = true; | 81 override_and_allow = true; |
| 60 break; | 82 break; |
| 61 } | 83 } |
| 62 | 84 |
| 85 if (sysno == __NR_socket) { | |
| 86 const Arg<int> domain(0); | |
| 87 const Arg<int> type(1); | |
| 88 return If(AllOf(AnyOf(domain == PF_LOCAL, domain == PF_UNIX), | |
|
mdempsky
2016/02/05 20:14:02
Nit: Unless Android is goofy, I would just check f
Robert Sesek
2016/02/05 21:27:06
Android isn't goofy, IMO PF is more semantically c
mdempsky
2016/02/05 22:56:55
Agreed that historically PF was more semantically
| |
| 89 AnyOf((type & SOCK_TYPE_MASK) == SOCK_DGRAM, | |
|
mdempsky
2016/02/05 20:14:02
Any opinions on writing this instead as:
const
Robert Sesek
2016/02/05 21:27:06
I like that. Prevent extra bits being set.
| |
| 90 (type & SOCK_TYPE_MASK) == SOCK_STREAM)), | |
| 91 Allow()) | |
| 92 .Else(Error(EPERM)); | |
| 93 } | |
| 94 | |
| 63 if (override_and_allow) | 95 if (override_and_allow) |
| 64 return Allow(); | 96 return Allow(); |
| 65 | 97 |
| 66 return SandboxBPFBasePolicy::EvaluateSyscall(sysno); | 98 return SandboxBPFBasePolicy::EvaluateSyscall(sysno); |
| 67 } | 99 } |
| 68 | 100 |
| 69 } // namespace content | 101 } // namespace content |
| OLD | NEW |