| 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 <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <linux/net.h> | 9 #include <linux/net.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 namespace content { | 31 namespace content { |
| 32 | 32 |
| 33 #ifndef SOCK_CLOEXEC | 33 #ifndef SOCK_CLOEXEC |
| 34 #define SOCK_CLOEXEC O_CLOEXEC | 34 #define SOCK_CLOEXEC O_CLOEXEC |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 #ifndef SOCK_NONBLOCK | 37 #ifndef SOCK_NONBLOCK |
| 38 #define SOCK_NONBLOCK O_NONBLOCK | 38 #define SOCK_NONBLOCK O_NONBLOCK |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 #define CASES SANDBOX_BPF_DSL_CASES |
| 42 |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 43 #if !defined(__i386__) | 45 #if !defined(__i386__) |
| 44 // Restricts the arguments to sys_socket() to AF_UNIX. Returns a BoolExpr that | 46 // Restricts the arguments to sys_socket() to AF_UNIX. Returns a BoolExpr that |
| 45 // evaluates to true if the syscall should be allowed. | 47 // evaluates to true if the syscall should be allowed. |
| 46 BoolExpr RestrictSocketArguments(const Arg<int>& domain, | 48 BoolExpr RestrictSocketArguments(const Arg<int>& domain, |
| 47 const Arg<int>& type, | 49 const Arg<int>& type, |
| 48 const Arg<int>& protocol) { | 50 const Arg<int>& protocol) { |
| 49 const int kSockFlags = SOCK_CLOEXEC | SOCK_NONBLOCK; | 51 const int kSockFlags = SOCK_CLOEXEC | SOCK_NONBLOCK; |
| 50 return AllOf(domain == AF_UNIX, | 52 return AllOf(domain == AF_UNIX, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 return If(RestrictSocketArguments(domain, type, protocol), Allow()) | 172 return If(RestrictSocketArguments(domain, type, protocol), Allow()) |
| 171 .Else(Error(EPERM)); | 173 .Else(Error(EPERM)); |
| 172 } | 174 } |
| 173 | 175 |
| 174 // https://crbug.com/655300 | 176 // https://crbug.com/655300 |
| 175 if (sysno == __NR_getsockname) { | 177 if (sysno == __NR_getsockname) { |
| 176 // Rather than blocking with SIGSYS, just return an error. This is not | 178 // Rather than blocking with SIGSYS, just return an error. This is not |
| 177 // documented to be a valid errno, but we will use it anyways. | 179 // documented to be a valid errno, but we will use it anyways. |
| 178 return Error(EPERM); | 180 return Error(EPERM); |
| 179 } | 181 } |
| 182 |
| 183 // https://crbug.com/682488 |
| 184 if (sysno == __NR_setsockopt) { |
| 185 // The baseline policy applies other restrictions to setsockopt. |
| 186 const Arg<int> level(1); |
| 187 const Arg<int> option(2); |
| 188 return If(AllOf(level == SOL_SOCKET, option == SO_SNDTIMEO), Allow()) |
| 189 .Else(SandboxBPFBasePolicy::EvaluateSyscall(sysno)); |
| 190 } |
| 180 #elif defined(__i386__) | 191 #elif defined(__i386__) |
| 181 if (sysno == __NR_socketcall) { | 192 if (sysno == __NR_socketcall) { |
| 193 // The baseline policy allows other socketcall sub-calls. |
| 182 const Arg<int> socketcall(0); | 194 const Arg<int> socketcall(0); |
| 183 const Arg<int> domain(1); | 195 return Switch(socketcall) |
| 184 const Arg<int> type(2); | 196 .CASES((SYS_CONNECT, |
| 185 const Arg<int> protocol(3); | 197 SYS_SOCKET, |
| 186 return If(socketcall == SYS_CONNECT, Allow()) | 198 SYS_SETSOCKOPT, |
| 187 .ElseIf(socketcall == SYS_SOCKET, Allow()) | 199 SYS_GETSOCKOPT), |
| 188 .ElseIf(socketcall == SYS_GETSOCKOPT, Allow()) | 200 Allow()) |
| 189 .Else(Error(EPERM)); | 201 .Default(SandboxBPFBasePolicy::EvaluateSyscall(sysno)); |
| 190 } | 202 } |
| 191 #endif | 203 #endif |
| 192 | 204 |
| 193 if (override_and_allow) | 205 if (override_and_allow) |
| 194 return Allow(); | 206 return Allow(); |
| 195 | 207 |
| 196 return SandboxBPFBasePolicy::EvaluateSyscall(sysno); | 208 return SandboxBPFBasePolicy::EvaluateSyscall(sysno); |
| 197 } | 209 } |
| 198 | 210 |
| 199 } // namespace content | 211 } // namespace content |
| OLD | NEW |