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
3 # found in the LICENSE file.
5 import("//build/config/features.gni")
6 import("//testing/test.gni")
9 compile_suid_client = is_linux
11 compile_credentials = is_linux
13 # On Android, use plain GTest.
14 use_base_test_suite = is_linux
17 # We have two principal targets: sandbox and sandbox_linux_unittests
18 # All other targets are listed as dependencies.
19 # There is one notable exception: for historical reasons, chrome_sandbox is
20 # the setuid sandbox and is its own target.
27 if (compile_suid_client) {
28 deps += [ ":suid_sandbox_client" ]
30 if (use_seccomp_bpf) {
33 ":seccomp_bpf_helpers",
38 source_set("sandbox_linux_test_utils") {
41 "tests/sandbox_test_runner.cc",
42 "tests/sandbox_test_runner.h",
43 "tests/sandbox_test_runner_function_pointer.cc",
44 "tests/sandbox_test_runner_function_pointer.h",
45 "tests/test_utils.cc",
47 "tests/unit_tests.cc",
55 if (use_seccomp_bpf) {
57 "seccomp-bpf/bpf_tester_compatibility_delegate.h",
58 "seccomp-bpf/bpf_tests.h",
59 "seccomp-bpf/sandbox_bpf_test_runner.cc",
60 "seccomp-bpf/sandbox_bpf_test_runner.h",
62 deps += [ ":seccomp_bpf" ]
65 if (use_base_test_suite) {
66 deps += [ "//base/test:test_support" ]
67 defines = [ "SANDBOX_USES_BASE_TEST_SUITE" ]
71 # Sources shared by sandbox_linux_unittests and sandbox_linux_jni_unittests.
72 source_set("sandbox_linux_unittests_sources") {
76 "services/proc_util_unittest.cc",
77 "services/resource_limits_unittests.cc",
78 "services/scoped_process_unittest.cc",
79 "services/syscall_wrappers_unittest.cc",
80 "services/thread_helpers_unittests.cc",
81 "services/yama_unittests.cc",
82 "syscall_broker/broker_file_permission_unittest.cc",
83 "syscall_broker/broker_process_unittest.cc",
85 "tests/scoped_temporary_file.cc",
86 "tests/scoped_temporary_file.h",
87 "tests/scoped_temporary_file_unittest.cc",
88 "tests/test_utils_unittest.cc",
89 "tests/unit_tests_unittest.cc",
94 ":sandbox_linux_test_utils",
99 if (use_base_test_suite) {
100 deps += [ "//base/test:test_support" ]
101 defines = [ "SANDBOX_USES_BASE_TEST_SUITE" ]
105 # Don't use this on Android.
109 if (compile_suid_client) {
111 "suid/client/setuid_sandbox_client_unittest.cc",
112 "suid/client/setuid_sandbox_host_unittest.cc",
115 if (use_seccomp_bpf) {
117 "bpf_dsl/bpf_dsl_unittest.cc",
118 "bpf_dsl/codegen_unittest.cc",
119 "bpf_dsl/cons_unittest.cc",
120 "bpf_dsl/errorcode_unittest.cc",
121 "bpf_dsl/syscall_set_unittest.cc",
122 "bpf_dsl/test_trap_registry.cc",
123 "bpf_dsl/test_trap_registry.h",
124 "bpf_dsl/test_trap_registry_unittest.cc",
125 "integration_tests/bpf_dsl_seccomp_unittest.cc",
126 "integration_tests/seccomp_broker_process_unittest.cc",
127 "seccomp-bpf-helpers/baseline_policy_unittest.cc",
128 "seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc",
129 "seccomp-bpf/bpf_tests_unittest.cc",
130 "seccomp-bpf/sandbox_bpf_unittest.cc",
131 "seccomp-bpf/syscall_unittest.cc",
132 "seccomp-bpf/trap_unittest.cc",
134 deps += [ ":bpf_dsl_golden" ]
136 if (compile_credentials) {
138 "integration_tests/namespace_unix_domain_socket_unittest.cc",
139 "services/credentials_unittest.cc",
140 "services/namespace_utils_unittest.cc",
143 if (use_base_test_suite) {
144 # Tests that use advanced features not available in stock GTest.
145 sources += [ "services/namespace_sandbox_unittest.cc" ]
148 # For credentials_unittest.cc
149 configs += [ "//build/config/linux:libcap" ]
153 action("bpf_dsl_golden") {
154 script = "bpf_dsl/golden/generate.py"
156 "bpf_dsl/golden/i386/ArgSizePolicy.txt",
157 "bpf_dsl/golden/i386/BasicPolicy.txt",
158 "bpf_dsl/golden/i386/ElseIfPolicy.txt",
159 "bpf_dsl/golden/i386/MaskingPolicy.txt",
160 "bpf_dsl/golden/i386/MoreBooleanLogicPolicy.txt",
161 "bpf_dsl/golden/i386/NegativeConstantsPolicy.txt",
162 "bpf_dsl/golden/i386/SwitchPolicy.txt",
163 "bpf_dsl/golden/x86-64/ArgSizePolicy.txt",
164 "bpf_dsl/golden/x86-64/BasicPolicy.txt",
165 "bpf_dsl/golden/x86-64/BooleanLogicPolicy.txt",
166 "bpf_dsl/golden/x86-64/ElseIfPolicy.txt",
167 "bpf_dsl/golden/x86-64/MaskingPolicy.txt",
168 "bpf_dsl/golden/x86-64/MoreBooleanLogicPolicy.txt",
169 "bpf_dsl/golden/x86-64/NegativeConstantsPolicy.txt",
170 "bpf_dsl/golden/x86-64/SwitchPolicy.txt",
173 "$target_gen_dir/bpf_dsl/golden/golden_files.h",
176 rebase_path(outputs, root_build_dir) + rebase_path(inputs, root_build_dir)
179 # TODO(GYP): Delete this after we've converted everything to GN.
180 # The _run targets exist only for compatibility w/ GYP.
181 group("sandbox_linux_unittests_run") {
184 ":sandbox_linux_unittests",
188 # The main sandboxing test target.
189 test("sandbox_linux_unittests") {
191 ":sandbox_linux_unittests_sources",
195 # This target is the shared library used by Android APK (i.e.
196 # JNI-friendly) tests.
197 shared_library("sandbox_linux_jni_unittests") {
200 ":sandbox_linux_unittests_sources",
203 deps += [ "//testing/android/native_test:native_test_native_code" ]
207 component("seccomp_bpf") {
209 "bpf_dsl/bpf_dsl.cc",
211 "bpf_dsl/bpf_dsl_forward.h",
212 "bpf_dsl/bpf_dsl_impl.h",
213 "bpf_dsl/codegen.cc",
216 "bpf_dsl/dump_bpf.cc",
217 "bpf_dsl/dump_bpf.h",
218 "bpf_dsl/errorcode.cc",
219 "bpf_dsl/errorcode.h",
220 "bpf_dsl/linux_syscall_ranges.h",
223 "bpf_dsl/policy_compiler.cc",
224 "bpf_dsl/policy_compiler.h",
225 "bpf_dsl/seccomp_macros.h",
226 "bpf_dsl/syscall_set.cc",
227 "bpf_dsl/syscall_set.h",
228 "bpf_dsl/trap_registry.h",
229 "bpf_dsl/verifier.cc",
230 "bpf_dsl/verifier.h",
231 "seccomp-bpf/die.cc",
233 "seccomp-bpf/sandbox_bpf.cc",
234 "seccomp-bpf/sandbox_bpf.h",
235 "seccomp-bpf/syscall.cc",
236 "seccomp-bpf/syscall.h",
237 "seccomp-bpf/trap.cc",
238 "seccomp-bpf/trap.h",
240 defines = [ "SANDBOX_IMPLEMENTATION" ]
244 ":sandbox_services_headers",
249 component("seccomp_bpf_helpers") {
251 "seccomp-bpf-helpers/baseline_policy.cc",
252 "seccomp-bpf-helpers/baseline_policy.h",
253 "seccomp-bpf-helpers/sigsys_handlers.cc",
254 "seccomp-bpf-helpers/sigsys_handlers.h",
255 "seccomp-bpf-helpers/syscall_parameters_restrictions.cc",
256 "seccomp-bpf-helpers/syscall_parameters_restrictions.h",
257 "seccomp-bpf-helpers/syscall_sets.cc",
258 "seccomp-bpf-helpers/syscall_sets.h",
260 defines = [ "SANDBOX_IMPLEMENTATION" ]
270 # The setuid sandbox for Linux.
271 executable("chrome_sandbox") {
273 "suid/common/sandbox.h",
274 "suid/common/suid_unsafe_environment_variables.h",
275 "suid/process_util.h",
276 "suid/process_util_linux.c",
284 # These files have a suspicious comparison.
285 # TODO fix this and re-enable this warning.
291 component("sandbox_services") {
293 "services/init_process_reaper.cc",
294 "services/init_process_reaper.h",
295 "services/proc_util.cc",
296 "services/proc_util.h",
297 "services/resource_limits.cc",
298 "services/resource_limits.h",
299 "services/scoped_process.cc",
300 "services/scoped_process.h",
301 "services/syscall_wrappers.cc",
302 "services/syscall_wrappers.h",
303 "services/thread_helpers.cc",
304 "services/thread_helpers.h",
307 "syscall_broker/broker_channel.cc",
308 "syscall_broker/broker_channel.h",
309 "syscall_broker/broker_client.cc",
310 "syscall_broker/broker_client.h",
311 "syscall_broker/broker_common.h",
312 "syscall_broker/broker_file_permission.cc",
313 "syscall_broker/broker_file_permission.h",
314 "syscall_broker/broker_host.cc",
315 "syscall_broker/broker_host.h",
316 "syscall_broker/broker_policy.cc",
317 "syscall_broker/broker_policy.h",
318 "syscall_broker/broker_process.cc",
319 "syscall_broker/broker_process.h",
322 defines = [ "SANDBOX_IMPLEMENTATION" ]
328 if (compile_credentials) {
330 "services/credentials.cc",
331 "services/credentials.h",
332 "services/namespace_sandbox.cc",
333 "services/namespace_sandbox.h",
334 "services/namespace_utils.cc",
335 "services/namespace_utils.h",
338 deps += [ ":sandbox_services_headers" ]
342 source_set("sandbox_services_headers") {
344 "system_headers/arm64_linux_syscalls.h",
345 "system_headers/arm64_linux_ucontext.h",
346 "system_headers/arm_linux_syscalls.h",
347 "system_headers/arm_linux_ucontext.h",
348 "system_headers/i386_linux_ucontext.h",
349 "system_headers/linux_futex.h",
350 "system_headers/linux_seccomp.h",
351 "system_headers/linux_signal.h",
352 "system_headers/linux_syscalls.h",
353 "system_headers/linux_time.h",
354 "system_headers/linux_ucontext.h",
355 "system_headers/x86_32_linux_syscalls.h",
356 "system_headers/x86_64_linux_syscalls.h",
360 # We make this its own target so that it does not interfere with our tests.
361 source_set("libc_urandom_override") {
363 "services/libc_urandom_override.cc",
364 "services/libc_urandom_override.h",
371 if (compile_suid_client) {
372 component("suid_sandbox_client") {
374 "suid/client/setuid_sandbox_client.cc",
375 "suid/client/setuid_sandbox_client.h",
376 "suid/client/setuid_sandbox_host.cc",
377 "suid/client/setuid_sandbox_host.h",
378 "suid/common/sandbox.h",
379 "suid/common/suid_unsafe_environment_variables.h",
381 defines = [ "SANDBOX_IMPLEMENTATION" ]
391 # TODO(GYP) enable this. Needs an android_strip wrapper python script.
392 #action("sandbox_linux_unittests_stripped") {
393 # script = "android_stip.py"
395 # in_file = "$root_out_dir/sandbox_linux_unittests"
397 # out_file = "$root_out_dir/sandbox_linux_unittests_stripped"
398 # outputs = [ out_file ]
401 # rebase_path(in_file, root_build_dir),
402 # "-o", rebase_path(out_file, root_build_dir),
406 # ":sandbox_linux_unittests",
409 # TODO(GYP) convert this.
411 # 'target_name': 'sandbox_linux_jni_unittests_apk',
414 # 'test_suite_name': 'sandbox_linux_jni_unittests',
417 # 'sandbox_linux_jni_unittests',
419 # 'includes': [ '../../build/apk_test.gypi' ],