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

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

Issue 10536048: Instead of outputting one BPF check per possible system call. Coalesce (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Does this result in easier-to-read diffs? 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
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 #ifndef SANDBOX_BPF_H__ 5 #ifndef SANDBOX_BPF_H__
6 #define SANDBOX_BPF_H__ 6 #define SANDBOX_BPF_H__
7 7
8 #include <endian.h> 8 #include <endian.h>
9 #include <errno.h> 9 #include <errno.h>
10 #include <fcntl.h> 10 #include <fcntl.h>
(...skipping 15 matching lines...) Expand all
26 #include <sys/mman.h> 26 #include <sys/mman.h>
27 #include <sys/prctl.h> 27 #include <sys/prctl.h>
28 #include <sys/shm.h> 28 #include <sys/shm.h>
29 #include <sys/stat.h> 29 #include <sys/stat.h>
30 #include <sys/types.h> 30 #include <sys/types.h>
31 #include <sys/uio.h> 31 #include <sys/uio.h>
32 #include <sys/wait.h> 32 #include <sys/wait.h>
33 #include <unistd.h> 33 #include <unistd.h>
34 34
35 #include <algorithm> 35 #include <algorithm>
36 #include <limits>
36 #include <utility> 37 #include <utility>
37 #include <vector> 38 #include <vector>
38 39
39 #ifndef SECCOMP_BPF_STANDALONE 40 #ifndef SECCOMP_BPF_STANDALONE
40 #include "base/basictypes.h" 41 #include "base/basictypes.h"
41 #include "base/eintr_wrapper.h" 42 #include "base/eintr_wrapper.h"
42 #include "base/logging.h" 43 #include "base/logging.h"
43 #endif 44 #endif
44 45
45 // The Seccomp2 kernel ABI is not part of older versions of glibc. 46 // The Seccomp2 kernel ABI is not part of older versions of glibc.
(...skipping 18 matching lines...) Expand all
64 #define SECCOMP_RET_ALLOW 0x7fff0000U // Allow 65 #define SECCOMP_RET_ALLOW 0x7fff0000U // Allow
65 #define SECCOMP_RET_ACTION 0xffff0000U // Masks for the return value 66 #define SECCOMP_RET_ACTION 0xffff0000U // Masks for the return value
66 #define SECCOMP_RET_DATA 0x0000ffffU // sections 67 #define SECCOMP_RET_DATA 0x0000ffffU // sections
67 #endif 68 #endif
68 #define SECCOMP_DENY_ERRNO EPERM 69 #define SECCOMP_DENY_ERRNO EPERM
69 #ifndef SYS_SECCOMP 70 #ifndef SYS_SECCOMP
70 #define SYS_SECCOMP 1 71 #define SYS_SECCOMP 1
71 #endif 72 #endif
72 73
73 #if defined(__i386__) 74 #if defined(__i386__)
74 #define MIN_SYSCALL 0 75 #define MIN_SYSCALL 0u
75 #define MAX_SYSCALL 1024 76 #define MAX_SYSCALL 1024u
76 #define SECCOMP_ARCH AUDIT_ARCH_I386 77 #define SECCOMP_ARCH AUDIT_ARCH_I386
77 #define REG_RESULT REG_EAX 78 #define REG_RESULT REG_EAX
78 #define REG_SYSCALL REG_EAX 79 #define REG_SYSCALL REG_EAX
79 #define REG_PARM1 REG_EBX 80 #define REG_PARM1 REG_EBX
80 #define REG_PARM2 REG_ECX 81 #define REG_PARM2 REG_ECX
81 #define REG_PARM3 REG_EDX 82 #define REG_PARM3 REG_EDX
82 #define REG_PARM4 REG_ESI 83 #define REG_PARM4 REG_ESI
83 #define REG_PARM5 REG_EDI 84 #define REG_PARM5 REG_EDI
84 #define REG_PARM6 REG_EBP 85 #define REG_PARM6 REG_EBP
85 #elif defined(__x86_64__) 86 #elif defined(__x86_64__)
86 #define MIN_SYSCALL 0 87 #define MIN_SYSCALL 0u
87 #define MAX_SYSCALL 1024 88 #define MAX_SYSCALL 1024u
88 #define SECCOMP_ARCH AUDIT_ARCH_X86_64 89 #define SECCOMP_ARCH AUDIT_ARCH_X86_64
89 #define REG_RESULT REG_RAX 90 #define REG_RESULT REG_RAX
90 #define REG_SYSCALL REG_RAX 91 #define REG_SYSCALL REG_RAX
91 #define REG_PARM1 REG_RDI 92 #define REG_PARM1 REG_RDI
92 #define REG_PARM2 REG_RSI 93 #define REG_PARM2 REG_RSI
93 #define REG_PARM3 REG_RDX 94 #define REG_PARM3 REG_RDX
94 #define REG_PARM4 REG_R10 95 #define REG_PARM4 REG_R10
95 #define REG_PARM5 REG_R8 96 #define REG_PARM5 REG_R8
96 #define REG_PARM6 REG_R9 97 #define REG_PARM6 REG_R9
97 #else 98 #else
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 // notice and file a bug... 224 // notice and file a bug...
224 syscall(__NR_exit_group, 1); 225 syscall(__NR_exit_group, 1);
225 _exit(1); 226 _exit(1);
226 } 227 }
227 } 228 }
228 229
229 // Get a file descriptor pointing to "/proc", if currently available. 230 // Get a file descriptor pointing to "/proc", if currently available.
230 static int getProcFd() { return proc_fd_; } 231 static int getProcFd() { return proc_fd_; }
231 232
232 private: 233 private:
234 struct Range {
235 Range(uint32_t f, uint32_t t, ErrorCode e) :
236 from(f),
237 to(t),
238 err(e) {
239 }
240 uint32_t from, to;
241 ErrorCode err;
242 };
243 typedef std::vector<Range> Ranges;
244 typedef std::vector<struct sock_filter> Program;
245
233 static ErrorCode probeEvaluator(int signo); 246 static ErrorCode probeEvaluator(int signo);
234 static bool kernelSupportSeccompBPF(int proc_fd); 247 static bool kernelSupportSeccompBPF(int proc_fd);
235 248 static bool isSingleThreaded(int proc_fd);
236 static bool isSingleThreaded(int proc_fd); 249 static bool disableFilesystem();
237 static bool disableFilesystem(); 250 static void installFilter();
238 static void installFilter(); 251 static void findRanges(Ranges *ranges);
239 static void sigSys(int nr, siginfo_t *info, void *void_context); 252 static void rangesToBPF(Program *program, const Ranges& ranges);
253 static void sigSys(int nr, siginfo_t *info, void *void_context);
240 254
241 static bool suppressLogging_; 255 static bool suppressLogging_;
242 static SandboxStatus status_; 256 static SandboxStatus status_;
243 static int proc_fd_; 257 static int proc_fd_;
244 static Evaluators evaluators_; 258 static Evaluators evaluators_;
245 }; 259 };
246 260
247 } // namespace 261 } // namespace
248 262
249 #endif // SANDBOX_BPF_H__ 263 #endif // SANDBOX_BPF_H__
OLDNEW
« no previous file with comments | « no previous file | sandbox/linux/seccomp-bpf/sandbox_bpf.cc » ('j') | sandbox/linux/seccomp-bpf/sandbox_bpf.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698