blob: 0f8f86a43c5c45b487dd8283fe135034a8334a09 [file] [log] [blame]
[email protected]75cd8f02014-05-29 20:56:021# Copyright 2014 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/features.gni")
6
7declare_args() {
8 compile_suid_client = is_linux
9
10 compile_credentials = is_linux
11
12 compile_seccomp_bpf_demo =
13 (is_linux && (cpu_arch == "x86" || cpu_arch == "x64"))
14}
15
16# We have two principal targets: sandbox and sandbox_linux_unittests
17# All other targets are listed as dependencies.
18# There is one notable exception: for historical reasons, chrome_sandbox is
19# the setuid sandbox and is its own target.
20
21group("sandbox") {
22 deps = [
23 ":sandbox_services",
24 ]
25
26 if (compile_suid_client) {
27 deps += [ ":suid_sandbox_client" ]
28 }
29 if (use_seccomp_bpf) {
30 deps += [
31 ":seccomp_bpf",
32 ":seccomp_bpf_helpers",
33 ]
34 }
35}
36
37source_set("sandbox_linux_test_utils") {
Brett Wilson0c8745a2014-09-08 22:59:4938 testonly = true
[email protected]75cd8f02014-05-29 20:56:0239 sources = [
40 "tests/sandbox_test_runner.cc",
41 "tests/sandbox_test_runner.h",
42 "tests/sandbox_test_runner_function_pointer.cc",
43 "tests/sandbox_test_runner_function_pointer.h",
44 "tests/test_utils.cc",
45 "tests/test_utils.h",
46 "tests/unit_tests.cc",
47 "tests/unit_tests.h",
48 ]
49
50 deps = [
51 "//testing/gtest",
52 ]
53
54 if (use_seccomp_bpf) {
55 sources += [
56 "seccomp-bpf/bpf_tester_compatibility_delegate.h",
57 "seccomp-bpf/bpf_tests.h",
58 "seccomp-bpf/sandbox_bpf_test_runner.cc",
59 "seccomp-bpf/sandbox_bpf_test_runner.h",
60 ]
61 deps += [
62 ":seccomp_bpf",
63 ]
64 }
65}
66
67# The main sandboxing test target.
68test("sandbox_linux_unittests") {
69 sources = [
[email protected]75cd8f02014-05-29 20:56:0270 "services/scoped_process_unittest.cc",
jlnc420f0d2014-11-22 01:12:0971 "services/syscall_wrappers_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:0272 "services/thread_helpers_unittests.cc",
73 "services/yama_unittests.cc",
jln70c42c202014-11-01 00:59:5774 "syscall_broker/broker_process_unittest.cc",
[email protected]232f6e112014-06-27 07:51:3875 "tests/main.cc",
76 "tests/scoped_temporary_file.cc",
77 "tests/scoped_temporary_file.h",
78 "tests/scoped_temporary_file_unittest.cc",
jlnc420f0d2014-11-22 01:12:0979 "tests/test_utils_unittest.cc",
[email protected]232f6e112014-06-27 07:51:3880 "tests/unit_tests_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:0281 ]
82
83 deps = [
84 ":sandbox",
85 ":sandbox_linux_test_utils",
86 "//base",
87 "//base/test:test_support",
88 "//testing/gtest",
89 ]
90
Brett Wilson73067532014-09-12 22:24:1491 if (is_linux) {
92 # Don't use this on Android.
93 libs = [ "rt" ]
94 }
Brett Wilsone39344352014-09-12 21:07:2695
[email protected]75cd8f02014-05-29 20:56:0296 if (compile_suid_client) {
97 sources += [
98 "suid/client/setuid_sandbox_client_unittest.cc",
99 ]
100 }
101 if (use_seccomp_bpf) {
102 sources += [
mdempsky22aa66d2014-09-13 01:41:34103 "bpf_dsl/bpf_dsl_more_unittest.cc",
[email protected]fb75e2a2014-07-17 07:24:58104 "bpf_dsl/bpf_dsl_unittest.cc",
105 "bpf_dsl/cons_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02106 "seccomp-bpf-helpers/baseline_policy_unittest.cc",
jlnfcdfb102014-09-12 02:47:44107 "seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc",
[email protected]75cd8f02014-05-29 20:56:02108 "seccomp-bpf/bpf_tests_unittest.cc",
109 "seccomp-bpf/codegen_unittest.cc",
110 "seccomp-bpf/errorcode_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02111 "seccomp-bpf/syscall_iterator_unittest.cc",
112 "seccomp-bpf/syscall_unittest.cc",
113 ]
114 }
115 if (compile_credentials) {
116 sources += [
117 "services/credentials_unittest.cc",
118 "services/unix_domain_socket_unittest.cc",
119 ]
120 }
121}
122
123# TODO(GYP) Android version of this test.
124# {
125# # This target is the shared library used by Android APK (i.e.
126# # JNI-friendly) tests.
127# "target_name": "sandbox_linux_jni_unittests",
128# "includes": [
129# "sandbox_linux_test_sources.gypi",
130# ],
131# "type": "shared_library",
132# "conditions": [
133# [ "OS == "android"", {
134# "dependencies": [
135# "../testing/android/native_test.gyp:native_test_native_code",
136# ],
137# }],
138# ],
139# },
140
141component("seccomp_bpf") {
142 sources = [
[email protected]fb75e2a2014-07-17 07:24:58143 "bpf_dsl/bpf_dsl.cc",
144 "bpf_dsl/bpf_dsl.h",
mdempskyc60a1c52014-10-24 23:07:10145 "bpf_dsl/bpf_dsl_forward.h",
mdempskyfb10cce2014-10-14 17:56:44146 "bpf_dsl/bpf_dsl_impl.h",
[email protected]fb75e2a2014-07-17 07:24:58147 "bpf_dsl/cons.h",
mdempskya41c4042014-10-31 20:50:27148 "bpf_dsl/dump_bpf.cc",
149 "bpf_dsl/dump_bpf.h",
mdempskyc60a1c52014-10-24 23:07:10150 "bpf_dsl/policy.cc",
151 "bpf_dsl/policy.h",
mdempsky27e78ad72014-10-16 16:49:54152 "bpf_dsl/policy_compiler.cc",
153 "bpf_dsl/policy_compiler.h",
154 "bpf_dsl/trap_registry.h",
[email protected]75cd8f02014-05-29 20:56:02155 "seccomp-bpf/codegen.cc",
156 "seccomp-bpf/codegen.h",
157 "seccomp-bpf/die.cc",
158 "seccomp-bpf/die.h",
159 "seccomp-bpf/errorcode.cc",
160 "seccomp-bpf/errorcode.h",
[email protected]75cd8f02014-05-29 20:56:02161 "seccomp-bpf/linux_seccomp.h",
162 "seccomp-bpf/sandbox_bpf.cc",
163 "seccomp-bpf/sandbox_bpf.h",
[email protected]75cd8f02014-05-29 20:56:02164 "seccomp-bpf/syscall.cc",
165 "seccomp-bpf/syscall.h",
166 "seccomp-bpf/syscall_iterator.cc",
167 "seccomp-bpf/syscall_iterator.h",
168 "seccomp-bpf/trap.cc",
169 "seccomp-bpf/trap.h",
170 "seccomp-bpf/verifier.cc",
171 "seccomp-bpf/verifier.h",
172 ]
173 defines = [ "SANDBOX_IMPLEMENTATION" ]
174
175 deps = [
176 ":sandbox_services_headers",
177 "//base",
178 ]
179}
180
181component("seccomp_bpf_helpers") {
182 sources = [
183 "seccomp-bpf-helpers/baseline_policy.cc",
184 "seccomp-bpf-helpers/baseline_policy.h",
185 "seccomp-bpf-helpers/sigsys_handlers.cc",
186 "seccomp-bpf-helpers/sigsys_handlers.h",
187 "seccomp-bpf-helpers/syscall_parameters_restrictions.cc",
188 "seccomp-bpf-helpers/syscall_parameters_restrictions.h",
189 "seccomp-bpf-helpers/syscall_sets.cc",
190 "seccomp-bpf-helpers/syscall_sets.h",
191 ]
192 defines = [ "SANDBOX_IMPLEMENTATION" ]
193
194 deps = [
195 "//base",
196 ":seccomp_bpf",
197 ]
198}
199
James Robinson060f2e32014-09-10 22:31:37200if (is_linux) {
[email protected]75cd8f02014-05-29 20:56:02201# The setuid sandbox for Linux.
James Robinson060f2e32014-09-10 22:31:37202 executable("chrome_sandbox") {
203 sources = [
204 "suid/common/sandbox.h",
205 "suid/common/suid_unsafe_environment_variables.h",
James Robinson060f2e32014-09-10 22:31:37206 "suid/process_util.h",
207 "suid/process_util_linux.c",
208 "suid/sandbox.c",
209 ]
[email protected]75cd8f02014-05-29 20:56:02210
James Robinson060f2e32014-09-10 22:31:37211 cflags = [
212 # For ULLONG_MAX
213 "-std=gnu99",
214 # These files have a suspicious comparison.
215 # TODO fix this and re-enable this warning.
216 "-Wno-sign-compare",
217 ]
218 }
[email protected]75cd8f02014-05-29 20:56:02219}
220
221component("sandbox_services") {
222 sources = [
[email protected]75cd8f02014-05-29 20:56:02223 "services/init_process_reaper.cc",
224 "services/init_process_reaper.h",
225 "services/scoped_process.cc",
226 "services/scoped_process.h",
jln610a4a612014-11-20 18:58:21227 "services/syscall_wrappers.cc",
228 "services/syscall_wrappers.h",
[email protected]75cd8f02014-05-29 20:56:02229 "services/thread_helpers.cc",
230 "services/thread_helpers.h",
231 "services/yama.h",
232 "services/yama.cc",
jln878dca32014-11-11 07:43:57233 "syscall_broker/broker_channel.cc",
234 "syscall_broker/broker_channel.h",
jln70c42c202014-11-01 00:59:57235 "syscall_broker/broker_client.cc",
236 "syscall_broker/broker_client.h",
237 "syscall_broker/broker_common.h",
238 "syscall_broker/broker_host.cc",
239 "syscall_broker/broker_host.h",
240 "syscall_broker/broker_policy.cc",
241 "syscall_broker/broker_policy.h",
242 "syscall_broker/broker_process.cc",
243 "syscall_broker/broker_process.h",
[email protected]75cd8f02014-05-29 20:56:02244 ]
245
246 defines = [ "SANDBOX_IMPLEMENTATION" ]
247
248 if (compile_credentials) {
249 sources += [
250 "services/credentials.cc",
251 "services/credentials.h",
252 ]
253 # For capabilities.cc.
254 configs += [ "//build/config/linux:libcap" ]
255 }
256
257 deps = [
258 "//base",
259 ]
260}
261
262source_set("sandbox_services_headers") {
263 sources = [
264 "services/android_arm_ucontext.h",
leecame6f6b732014-08-24 23:38:09265 "services/android_arm64_ucontext.h",
[email protected]9de395e42014-06-04 22:25:28266 "services/android_futex.h",
[email protected]75cd8f02014-05-29 20:56:02267 "services/android_ucontext.h",
268 "services/android_i386_ucontext.h",
269 "services/arm_linux_syscalls.h",
leecame6f6b732014-08-24 23:38:09270 "services/arm64_linux_syscalls.h",
[email protected]75cd8f02014-05-29 20:56:02271 "services/linux_syscalls.h",
272 "services/x86_32_linux_syscalls.h",
273 "services/x86_64_linux_syscalls.h",
274 ]
275}
276
277# We make this its own target so that it does not interfere with our tests.
278source_set("libc_urandom_override") {
279 sources = [
280 "services/libc_urandom_override.cc",
281 "services/libc_urandom_override.h",
282 ]
283 deps = [
284 "//base",
285 ]
286}
287
James Robinson060f2e32014-09-10 22:31:37288if (compile_suid_client) {
289 component("suid_sandbox_client") {
290 sources = [
291 "suid/common/sandbox.h",
292 "suid/common/suid_unsafe_environment_variables.h",
293 "suid/client/setuid_sandbox_client.cc",
294 "suid/client/setuid_sandbox_client.h",
295 ]
296 defines = [ "SANDBOX_IMPLEMENTATION" ]
[email protected]75cd8f02014-05-29 20:56:02297
James Robinson060f2e32014-09-10 22:31:37298 deps = [
299 ":sandbox_services",
300 "//base",
301 ]
302 }
[email protected]75cd8f02014-05-29 20:56:02303}
304
305if (is_android) {
306 # TODO(GYP) enable this. Needs an android_strip wrapper python script.
307 #action("sandbox_linux_unittests_stripped") {
308 # script = "android_stip.py"
309 #
310 # in_file = "$root_out_dir/sandbox_linux_unittests"
311 #
312 # out_file = "$root_out_dir/sandbox_linux_unittests_stripped"
313 # outputs = [ out_file ]
314 #
315 # args = [
316 # rebase_path(in_file, root_build_dir),
317 # "-o", rebase_path(out_file, root_build_dir),
318 # ]
319 #
320 # deps = [
321 # ":sandbox_linux_unittests",
322 # ]
323 #}
324
325 # TODO(GYP) convert this.
326 # {
327 # 'target_name': 'sandbox_linux_jni_unittests_apk',
328 # 'type': 'none',
329 # 'variables': {
330 # 'test_suite_name': 'sandbox_linux_jni_unittests',
331 # },
332 # 'dependencies': [
333 # 'sandbox_linux_jni_unittests',
334 # ],
335 # 'includes': [ '../../build/apk_test.gypi' ],
336 # }
337}