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

Side by Side Diff: content/common/sandbox_linux/android/sandbox_bpf_base_policy_android.cc

Issue 2675783003: Revert of [Android] Allow get/setsockopt SOL_SOCKET SO_SNDTIMEO. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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
43 namespace { 41 namespace {
44 42
45 #if !defined(__i386__) 43 #if !defined(__i386__)
46 // Restricts the arguments to sys_socket() to AF_UNIX. Returns a BoolExpr that 44 // Restricts the arguments to sys_socket() to AF_UNIX. Returns a BoolExpr that
47 // evaluates to true if the syscall should be allowed. 45 // evaluates to true if the syscall should be allowed.
48 BoolExpr RestrictSocketArguments(const Arg<int>& domain, 46 BoolExpr RestrictSocketArguments(const Arg<int>& domain,
49 const Arg<int>& type, 47 const Arg<int>& type,
50 const Arg<int>& protocol) { 48 const Arg<int>& protocol) {
51 const int kSockFlags = SOCK_CLOEXEC | SOCK_NONBLOCK; 49 const int kSockFlags = SOCK_CLOEXEC | SOCK_NONBLOCK;
52 return AllOf(domain == AF_UNIX, 50 return AllOf(domain == AF_UNIX,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return If(RestrictSocketArguments(domain, type, protocol), Allow()) 170 return If(RestrictSocketArguments(domain, type, protocol), Allow())
173 .Else(Error(EPERM)); 171 .Else(Error(EPERM));
174 } 172 }
175 173
176 // https://crbug.com/655300 174 // https://crbug.com/655300
177 if (sysno == __NR_getsockname) { 175 if (sysno == __NR_getsockname) {
178 // Rather than blocking with SIGSYS, just return an error. This is not 176 // Rather than blocking with SIGSYS, just return an error. This is not
179 // documented to be a valid errno, but we will use it anyways. 177 // documented to be a valid errno, but we will use it anyways.
180 return Error(EPERM); 178 return Error(EPERM);
181 } 179 }
182
183 // https://crbug.com/682488
184 if (sysno == __NR_getsockopt || sysno == __NR_setsockopt) {
185 // The baseline policy applies other restrictions to these syscalls.
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 }
191 #elif defined(__i386__) 180 #elif defined(__i386__)
192 if (sysno == __NR_socketcall) { 181 if (sysno == __NR_socketcall) {
193 // The baseline policy allows other socketcall sub-calls.
194 const Arg<int> socketcall(0); 182 const Arg<int> socketcall(0);
195 return Switch(socketcall) 183 const Arg<int> domain(1);
196 .CASES((SYS_CONNECT, 184 const Arg<int> type(2);
197 SYS_SOCKET, 185 const Arg<int> protocol(3);
198 SYS_SETSOCKOPT, 186 return If(socketcall == SYS_CONNECT, Allow())
199 SYS_GETSOCKOPT), 187 .ElseIf(socketcall == SYS_SOCKET, Allow())
200 Allow()) 188 .ElseIf(socketcall == SYS_GETSOCKOPT, Allow())
201 .Default(SandboxBPFBasePolicy::EvaluateSyscall(sysno)); 189 .Else(Error(EPERM));
202 } 190 }
203 #endif 191 #endif
204 192
205 if (override_and_allow) 193 if (override_and_allow)
206 return Allow(); 194 return Allow();
207 195
208 return SandboxBPFBasePolicy::EvaluateSyscall(sysno); 196 return SandboxBPFBasePolicy::EvaluateSyscall(sysno);
209 } 197 }
210 198
211 } // namespace content 199 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698