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

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

Issue 10827223: Add basic ARM support to the seccomp-bpf sandbox. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address jln's comments. Created 8 years, 4 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 | « sandbox/linux/sandbox_linux.gypi ('k') | sandbox/linux/seccomp-bpf/sandbox_bpf.cc » ('j') | 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 #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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 // Impose some reasonable maximum BPF program size. Realistically, the 77 // Impose some reasonable maximum BPF program size. Realistically, the
78 // kernel probably has much lower limits. But by limiting to less than 78 // kernel probably has much lower limits. But by limiting to less than
79 // 30 bits, we can ease requirements on some of our data types. 79 // 30 bits, we can ease requirements on some of our data types.
80 #define SECCOMP_MAX_PROGRAM_SIZE (1<<30) 80 #define SECCOMP_MAX_PROGRAM_SIZE (1<<30)
81 81
82 #if defined(__i386__) 82 #if defined(__i386__)
83 #define MIN_SYSCALL 0u 83 #define MIN_SYSCALL 0u
84 #define MAX_SYSCALL 1024u 84 #define MAX_SYSCALL 1024u
85 #define SECCOMP_ARCH AUDIT_ARCH_I386 85 #define SECCOMP_ARCH AUDIT_ARCH_I386
86 #define REG_RESULT REG_EAX 86
87 #define REG_SYSCALL REG_EAX 87 #define SECCOMP_REG(_ctx, _reg) ((_ctx)->uc_mcontext.gregs[(_reg)])
88 #define REG_IP REG_EIP 88 #define SECCOMP_RESULT(_ctx) SECCOMP_REG(_ctx, REG_EAX)
89 #define REG_PARM1 REG_EBX 89 #define SECCOMP_SYSCALL(_ctx) SECCOMP_REG(_ctx, REG_EAX)
90 #define REG_PARM2 REG_ECX 90 #define SECCOMP_IP(_ctx) SECCOMP_REG(_ctx, REG_EIP)
91 #define REG_PARM3 REG_EDX 91 #define SECCOMP_PARM1(_ctx) SECCOMP_REG(_ctx, REG_EBX)
92 #define REG_PARM4 REG_ESI 92 #define SECCOMP_PARM2(_ctx) SECCOMP_REG(_ctx, REG_ECX)
93 #define REG_PARM5 REG_EDI 93 #define SECCOMP_PARM3(_ctx) SECCOMP_REG(_ctx, REG_EDX)
94 #define REG_PARM6 REG_EBP 94 #define SECCOMP_PARM4(_ctx) SECCOMP_REG(_ctx, REG_ESI)
95 #define SECCOMP_PARM5(_ctx) SECCOMP_REG(_ctx, REG_EDI)
96 #define SECCOMP_PARM6(_ctx) SECCOMP_REG(_ctx, REG_EBP)
97
95 #elif defined(__x86_64__) 98 #elif defined(__x86_64__)
96 #define MIN_SYSCALL 0u 99 #define MIN_SYSCALL 0u
97 #define MAX_SYSCALL 1024u 100 #define MAX_SYSCALL 1024u
98 #define SECCOMP_ARCH AUDIT_ARCH_X86_64 101 #define SECCOMP_ARCH AUDIT_ARCH_X86_64
99 #define REG_RESULT REG_RAX 102
100 #define REG_SYSCALL REG_RAX 103 #define SECCOMP_REG(_ctx, _reg) ((_ctx)->uc_mcontext.gregs[(_reg)])
101 #define REG_IP REG_RIP 104 #define SECCOMP_RESULT(_ctx) SECCOMP_REG(_ctx, REG_RAX)
102 #define REG_PARM1 REG_RDI 105 #define SECCOMP_SYSCALL(_ctx) SECCOMP_REG(_ctx, REG_RAX)
103 #define REG_PARM2 REG_RSI 106 #define SECCOMP_IP(_ctx) SECCOMP_REG(_ctx, REG_RIP)
104 #define REG_PARM3 REG_RDX 107 #define SECCOMP_PARM1(_ctx) SECCOMP_REG(_ctx, REG_RDI)
105 #define REG_PARM4 REG_R10 108 #define SECCOMP_PARM2(_ctx) SECCOMP_REG(_ctx, REG_RSI)
106 #define REG_PARM5 REG_R8 109 #define SECCOMP_PARM3(_ctx) SECCOMP_REG(_ctx, REG_RDX)
107 #define REG_PARM6 REG_R9 110 #define SECCOMP_PARM4(_ctx) SECCOMP_REG(_ctx, REG_R10)
111 #define SECCOMP_PARM5(_ctx) SECCOMP_REG(_ctx, REG_R8)
112 #define SECCOMP_PARM6(_ctx) SECCOMP_REG(_ctx, REG_R9)
113
114 #elif defined(__arm__) && (defined(__thumb__) || defined(__ARM_EABI__))
115 // ARM EABI includes "ARM private" system calls starting at |__ARM_NR_BASE|,
116 // and a "ghost syscall private to the kernel", cmpxchg,
117 // at |__ARM_NR_BASE+0x00fff0|.
118 // See </arch/arm/include/asm/unistd.h> in the Linux kernel.
119 #define MIN_SYSCALL ((unsigned int)__NR_SYSCALL_BASE)
120 #define MAX_SYSCALL ((unsigned int)__ARM_NR_BASE + 0x00ffffu)
121 // <linux/audit.h> includes <linux/elf-em.h>, which does not define EM_ARM.
122 // <linux/elf.h> only includes <asm/elf.h> if we're in the kernel.
123 # if !defined(EM_ARM)
124 # define EM_ARM 40
125 # endif
126 #define SECCOMP_ARCH AUDIT_ARCH_ARM
127
128 // ARM sigcontext_t is different from i386/x86_64.
129 // See </arch/arm/include/asm/sigcontext.h> in the Linux kernel.
130 #define SECCOMP_REG(_ctx, _reg) ((_ctx)->uc_mcontext.arm_##_reg)
131 // ARM EABI syscall convention.
132 #define SECCOMP_RESULT(_ctx) SECCOMP_REG(_ctx, r0)
133 #define SECCOMP_SYSCALL(_ctx) SECCOMP_REG(_ctx, r7)
134 #define SECCOMP_IP(_ctx) SECCOMP_REG(_ctx, pc)
135 #define SECCOMP_PARM1(_ctx) SECCOMP_REG(_ctx, r0)
136 #define SECCOMP_PARM2(_ctx) SECCOMP_REG(_ctx, r1)
137 #define SECCOMP_PARM3(_ctx) SECCOMP_REG(_ctx, r2)
138 #define SECCOMP_PARM4(_ctx) SECCOMP_REG(_ctx, r3)
139 #define SECCOMP_PARM5(_ctx) SECCOMP_REG(_ctx, r4)
140 #define SECCOMP_PARM6(_ctx) SECCOMP_REG(_ctx, r5)
141
108 #else 142 #else
109 #error Unsupported target platform 143 #error Unsupported target platform
144
110 #endif 145 #endif
111 146
112 struct arch_seccomp_data { 147 struct arch_seccomp_data {
113 int nr; 148 int nr;
114 uint32_t arch; 149 uint32_t arch;
115 uint64_t instruction_pointer; 150 uint64_t instruction_pointer;
116 uint64_t args[6]; 151 uint64_t args[6];
117 }; 152 };
118 153
119 struct arch_sigsys { 154 struct arch_sigsys {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 static Traps *traps_; 409 static Traps *traps_;
375 static TrapIds trapIds_; 410 static TrapIds trapIds_;
376 static ErrorCode *trapArray_; 411 static ErrorCode *trapArray_;
377 static size_t trapArraySize_; 412 static size_t trapArraySize_;
378 DISALLOW_IMPLICIT_CONSTRUCTORS(Sandbox); 413 DISALLOW_IMPLICIT_CONSTRUCTORS(Sandbox);
379 }; 414 };
380 415
381 } // namespace 416 } // namespace
382 417
383 #endif // SANDBOX_BPF_H__ 418 #endif // SANDBOX_BPF_H__
OLDNEW
« no previous file with comments | « sandbox/linux/sandbox_linux.gypi ('k') | sandbox/linux/seccomp-bpf/sandbox_bpf.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698