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/syscall_set_unittest.cc",
121 "integration_tests/bpf_dsl_seccomp_unittest.cc",
122 "integration_tests/seccomp_broker_process_unittest.cc",
123 "seccomp-bpf-helpers/baseline_policy_unittest.cc",
124 "seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc",
125 "seccomp-bpf/bpf_tests_unittest.cc",
126 "seccomp-bpf/errorcode_unittest.cc",
127 "seccomp-bpf/sandbox_bpf_unittest.cc",
128 "seccomp-bpf/syscall_unittest.cc",
129 "seccomp-bpf/trap_unittest.cc",
132 if (compile_credentials) {
134 "integration_tests/namespace_unix_domain_socket_unittest.cc",
135 "services/credentials_unittest.cc",
136 "services/namespace_utils_unittest.cc",
139 if (use_base_test_suite) {
140 # Tests that use advanced features not available in stock GTest.
141 sources += [ "services/namespace_sandbox_unittest.cc" ]
144 # For credentials_unittest.cc
145 configs += [ "//build/config/linux:libcap" ]
149 # TODO(GYP): Delete this after we've converted everything to GN.
150 # The _run targets exist only for compatibility w/ GYP.
151 group("sandbox_linux_unittests_run") {
154 ":sandbox_linux_unittests",
158 # The main sandboxing test target.
159 test("sandbox_linux_unittests") {
161 ":sandbox_linux_unittests_sources",
165 # This target is the shared library used by Android APK (i.e.
166 # JNI-friendly) tests.
167 shared_library("sandbox_linux_jni_unittests") {
170 ":sandbox_linux_unittests_sources",
173 deps += [ "//testing/android/native_test:native_test_native_code" ]
177 component("seccomp_bpf") {
179 "bpf_dsl/bpf_dsl.cc",
181 "bpf_dsl/bpf_dsl_forward.h",
182 "bpf_dsl/bpf_dsl_impl.h",
183 "bpf_dsl/codegen.cc",
186 "bpf_dsl/dump_bpf.cc",
187 "bpf_dsl/dump_bpf.h",
188 "bpf_dsl/linux_syscall_ranges.h",
191 "bpf_dsl/policy_compiler.cc",
192 "bpf_dsl/policy_compiler.h",
193 "bpf_dsl/seccomp_macros.h",
194 "bpf_dsl/syscall_set.cc",
195 "bpf_dsl/syscall_set.h",
196 "bpf_dsl/trap_registry.h",
197 "bpf_dsl/verifier.cc",
198 "bpf_dsl/verifier.h",
199 "seccomp-bpf/die.cc",
201 "seccomp-bpf/errorcode.cc",
202 "seccomp-bpf/errorcode.h",
203 "seccomp-bpf/sandbox_bpf.cc",
204 "seccomp-bpf/sandbox_bpf.h",
205 "seccomp-bpf/syscall.cc",
206 "seccomp-bpf/syscall.h",
207 "seccomp-bpf/trap.cc",
208 "seccomp-bpf/trap.h",
210 defines = [ "SANDBOX_IMPLEMENTATION" ]
214 ":sandbox_services_headers",
219 component("seccomp_bpf_helpers") {
221 "seccomp-bpf-helpers/baseline_policy.cc",
222 "seccomp-bpf-helpers/baseline_policy.h",
223 "seccomp-bpf-helpers/sigsys_handlers.cc",
224 "seccomp-bpf-helpers/sigsys_handlers.h",
225 "seccomp-bpf-helpers/syscall_parameters_restrictions.cc",
226 "seccomp-bpf-helpers/syscall_parameters_restrictions.h",
227 "seccomp-bpf-helpers/syscall_sets.cc",
228 "seccomp-bpf-helpers/syscall_sets.h",
230 defines = [ "SANDBOX_IMPLEMENTATION" ]
240 # The setuid sandbox for Linux.
241 executable("chrome_sandbox") {
243 "suid/common/sandbox.h",
244 "suid/common/suid_unsafe_environment_variables.h",
245 "suid/process_util.h",
246 "suid/process_util_linux.c",
254 # These files have a suspicious comparison.
255 # TODO fix this and re-enable this warning.
261 component("sandbox_services") {
263 "services/init_process_reaper.cc",
264 "services/init_process_reaper.h",
265 "services/proc_util.cc",
266 "services/proc_util.h",
267 "services/resource_limits.cc",
268 "services/resource_limits.h",
269 "services/scoped_process.cc",
270 "services/scoped_process.h",
271 "services/syscall_wrappers.cc",
272 "services/syscall_wrappers.h",
273 "services/thread_helpers.cc",
274 "services/thread_helpers.h",
277 "syscall_broker/broker_channel.cc",
278 "syscall_broker/broker_channel.h",
279 "syscall_broker/broker_client.cc",
280 "syscall_broker/broker_client.h",
281 "syscall_broker/broker_common.h",
282 "syscall_broker/broker_file_permission.cc",
283 "syscall_broker/broker_file_permission.h",
284 "syscall_broker/broker_host.cc",
285 "syscall_broker/broker_host.h",
286 "syscall_broker/broker_policy.cc",
287 "syscall_broker/broker_policy.h",
288 "syscall_broker/broker_process.cc",
289 "syscall_broker/broker_process.h",
292 defines = [ "SANDBOX_IMPLEMENTATION" ]
298 if (compile_credentials) {
300 "services/credentials.cc",
301 "services/credentials.h",
302 "services/namespace_sandbox.cc",
303 "services/namespace_sandbox.h",
304 "services/namespace_utils.cc",
305 "services/namespace_utils.h",
308 deps += [ ":sandbox_services_headers" ]
312 source_set("sandbox_services_headers") {
314 "system_headers/arm64_linux_syscalls.h",
315 "system_headers/arm64_linux_ucontext.h",
316 "system_headers/arm_linux_syscalls.h",
317 "system_headers/arm_linux_ucontext.h",
318 "system_headers/i386_linux_ucontext.h",
319 "system_headers/linux_futex.h",
320 "system_headers/linux_seccomp.h",
321 "system_headers/linux_signal.h",
322 "system_headers/linux_syscalls.h",
323 "system_headers/linux_time.h",
324 "system_headers/linux_ucontext.h",
325 "system_headers/x86_32_linux_syscalls.h",
326 "system_headers/x86_64_linux_syscalls.h",
330 # We make this its own target so that it does not interfere with our tests.
331 source_set("libc_urandom_override") {
333 "services/libc_urandom_override.cc",
334 "services/libc_urandom_override.h",
341 if (compile_suid_client) {
342 component("suid_sandbox_client") {
344 "suid/client/setuid_sandbox_client.cc",
345 "suid/client/setuid_sandbox_client.h",
346 "suid/client/setuid_sandbox_host.cc",
347 "suid/client/setuid_sandbox_host.h",
348 "suid/common/sandbox.h",
349 "suid/common/suid_unsafe_environment_variables.h",
351 defines = [ "SANDBOX_IMPLEMENTATION" ]
361 # TODO(GYP) enable this. Needs an android_strip wrapper python script.
362 #action("sandbox_linux_unittests_stripped") {
363 # script = "android_stip.py"
365 # in_file = "$root_out_dir/sandbox_linux_unittests"
367 # out_file = "$root_out_dir/sandbox_linux_unittests_stripped"
368 # outputs = [ out_file ]
371 # rebase_path(in_file, root_build_dir),
372 # "-o", rebase_path(out_file, root_build_dir),
376 # ":sandbox_linux_unittests",
379 # TODO(GYP) convert this.
381 # 'target_name': 'sandbox_linux_jni_unittests_apk',
384 # 'test_suite_name': 'sandbox_linux_jni_unittests',
387 # 'sandbox_linux_jni_unittests',
389 # 'includes': [ '../../build/apk_test.gypi' ],