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

Side by Side Diff: sandbox/linux/seccomp-bpf/sandbox_bpf.cc

Issue 10542028: Explicitly test bit 30 in the system call number to distinguish between the new x32 API and older I… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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
« no previous file with comments | « sandbox/linux/seccomp-bpf/sandbox_bpf.h ('k') | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "sandbox/linux/seccomp-bpf/sandbox_bpf.h" 5 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
6 6
7 // The kernel gives us a sandbox, we turn it into a playground :-) 7 // The kernel gives us a sandbox, we turn it into a playground :-)
8 // This is version 2 of the playground; version 1 was built on top of 8 // This is version 2 of the playground; version 1 was built on top of
9 // pre-BPF seccomp mode. 9 // pre-BPF seccomp mode.
10 namespace playground2 { 10 namespace playground2 {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // We can't handle stacked evaluators, yet. We'll get there eventually 208 // We can't handle stacked evaluators, yet. We'll get there eventually
209 // though. Hang tight. 209 // though. Hang tight.
210 if (evaluators_.size() != 1) { 210 if (evaluators_.size() != 1) {
211 die("Not implemented"); 211 die("Not implemented");
212 } 212 }
213 213
214 // If the architecture doesn't match SECCOMP_ARCH, disallow the 214 // If the architecture doesn't match SECCOMP_ARCH, disallow the
215 // system call. 215 // system call.
216 std::vector<struct sock_filter> program; 216 std::vector<struct sock_filter> program;
217 program.push_back((struct sock_filter) 217 program.push_back((struct sock_filter)
218 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 218 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct arch_seccomp_data, arch)));
219 offsetof(struct arch_seccomp_data, arch)));
220 program.push_back((struct sock_filter) 219 program.push_back((struct sock_filter)
221 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, SECCOMP_ARCH, 1, 0)); 220 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, SECCOMP_ARCH, 1, 0));
222 program.push_back((struct sock_filter) 221 program.push_back((struct sock_filter)
223 BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ERRNO + SECCOMP_DENY_ERRNO)); 222 BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ERRNO + SECCOMP_DENY_ERRNO));
Chris Evans 2012/06/07 01:02:38 This should probably be SECCOMP_RET_KILL too, see
Markus (顧孟勤) 2012/06/07 01:33:28 I don't particularly like SECCOMP_RET_KILL, as it
224 223
225 // Grab the system call number, so that we can implement jump tables. 224 // Grab the system call number, so that we can implement jump tables.
226 program.push_back((struct sock_filter) 225 program.push_back((struct sock_filter)
227 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct arch_seccomp_data, nr))); 226 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct arch_seccomp_data, nr)));
228 227
228 // On Intel architectures, verify that system call numbers are in the
229 // expected number range. The older i386 and x86-64 APIs clear bit 30
230 // on all system calls. The newer x86-32 API always sets bit 30.
231 #if defined(__i386__) || defined(__x86_64__)
Chris Evans 2012/06/07 01:02:38 I don't quite get this bit. If we're compiling for
Markus (顧孟勤) 2012/06/07 01:33:28 The preprocessor tests check for the expected API
232 #if defined(__x86_64__) && defined(__ILP32__)
233 program.push_back((struct sock_filter)
234 BPF_JUMP(BPF_JMP+BPF_JSET+BPF_K, 0x40000000, 1, 0));
235 #else
236 program.push_back((struct sock_filter)
237 BPF_JUMP(BPF_JMP+BPF_JSET+BPF_K, 0x40000000, 0, 1));
238 #endif
239 program.push_back((struct sock_filter)
240 BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ERRNO + SECCOMP_DENY_ERRNO));
Chris Evans 2012/06/07 01:02:38 If we get here, seems like something extraordinari
Markus (顧孟勤) 2012/06/07 01:33:28 Let me know, what you prefer until we get a better
241 #endif
242
229 // Evaluate all possible system calls and depending on their 243 // Evaluate all possible system calls and depending on their
230 // exit codes generate a BPF filter. 244 // exit codes generate a BPF filter.
231 // This is very inefficient right now. We need to be much smarter 245 // This is very inefficient right now. We need to be much smarter
232 // eventually. 246 // eventually.
233 // We currently incur a O(N) overhead on each system call, with N 247 // We currently incur a O(N) overhead on each system call, with N
234 // being the number of system calls. It is easy to get this down to 248 // being the number of system calls. It is easy to get this down to
235 // O(log_2(M)) with M being the number of system calls that need special 249 // O(log_2(M)) with M being the number of system calls that need special
236 // treatment. 250 // treatment.
237 EvaluateSyscall evaluateSyscall = evaluators_.begin()->first; 251 EvaluateSyscall evaluateSyscall = evaluators_.begin()->first;
238 for (int sysnum = MIN_SYSCALL; sysnum <= MAX_SYSCALL; ++sysnum) { 252 for (int sysnum = MIN_SYSCALL; sysnum <= MAX_SYSCALL; ++sysnum) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 324 }
311 325
312 326
313 bool Sandbox::suppressLogging_ = false; 327 bool Sandbox::suppressLogging_ = false;
314 Sandbox::SandboxStatus Sandbox::status_ = STATUS_UNKNOWN; 328 Sandbox::SandboxStatus Sandbox::status_ = STATUS_UNKNOWN;
315 int Sandbox::proc_fd_ = -1; 329 int Sandbox::proc_fd_ = -1;
316 std::vector<std::pair<Sandbox::EvaluateSyscall, 330 std::vector<std::pair<Sandbox::EvaluateSyscall,
317 Sandbox::EvaluateArguments> > Sandbox::evaluators_; 331 Sandbox::EvaluateArguments> > Sandbox::evaluators_;
318 332
319 } // namespace 333 } // namespace
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/sandbox_bpf.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698