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 compile_seccomp_bpf_demo =
14 is_linux && (cpu_arch == "x86" || cpu_arch == "x64")
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" ]
66 # The main sandboxing test target.
67 test("sandbox_linux_unittests") {
69 "services/proc_util_unittest.cc",
70 "services/resource_limits_unittests.cc",
71 "services/scoped_process_unittest.cc",
72 "services/syscall_wrappers_unittest.cc",
73 "services/thread_helpers_unittests.cc",
74 "services/yama_unittests.cc",
75 "syscall_broker/broker_file_permission_unittest.cc",
76 "syscall_broker/broker_process_unittest.cc",
78 "tests/scoped_temporary_file.cc",
79 "tests/scoped_temporary_file.h",
80 "tests/scoped_temporary_file_unittest.cc",
81 "tests/test_utils_unittest.cc",
82 "tests/unit_tests_unittest.cc",
87 ":sandbox_linux_test_utils",
89 "//base/test:test_support",
94 # Don't use this on Android.
98 if (compile_suid_client) {
100 "suid/client/setuid_sandbox_client_unittest.cc",
101 "suid/client/setuid_sandbox_host_unittest.cc",
104 if (use_seccomp_bpf) {
106 "bpf_dsl/bpf_dsl_unittest.cc",
107 "bpf_dsl/codegen_unittest.cc",
108 "bpf_dsl/cons_unittest.cc",
109 "bpf_dsl/syscall_set_unittest.cc",
110 "integration_tests/bpf_dsl_seccomp_unittest.cc",
111 "integration_tests/seccomp_broker_process_unittest.cc",
112 "seccomp-bpf-helpers/baseline_policy_unittest.cc",
113 "seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc",
114 "seccomp-bpf/bpf_tests_unittest.cc",
115 "seccomp-bpf/errorcode_unittest.cc",
116 "seccomp-bpf/sandbox_bpf_unittest.cc",
117 "seccomp-bpf/syscall_unittest.cc",
120 if (compile_credentials) {
122 "integration_tests/namespace_unix_domain_socket_unittest.cc",
123 "services/credentials_unittest.cc",
124 "services/namespace_sandbox_unittest.cc",
125 "services/namespace_utils_unittest.cc",
130 # TODO(GYP) Android version of this test.
132 # # This target is the shared library used by Android APK (i.e.
133 # # JNI-friendly) tests.
134 # "target_name": "sandbox_linux_jni_unittests",
136 # "sandbox_linux_test_sources.gypi",
138 # "type": "shared_library",
140 # [ "OS == "android"", {
142 # "../testing/android/native_test.gyp:native_test_native_code",
148 component("seccomp_bpf") {
150 "bpf_dsl/bpf_dsl.cc",
152 "bpf_dsl/bpf_dsl_forward.h",
153 "bpf_dsl/bpf_dsl_impl.h",
154 "bpf_dsl/codegen.cc",
157 "bpf_dsl/dump_bpf.cc",
158 "bpf_dsl/dump_bpf.h",
159 "bpf_dsl/linux_syscall_ranges.h",
162 "bpf_dsl/policy_compiler.cc",
163 "bpf_dsl/policy_compiler.h",
164 "bpf_dsl/seccomp_macros.h",
165 "bpf_dsl/syscall_set.cc",
166 "bpf_dsl/syscall_set.h",
167 "bpf_dsl/trap_registry.h",
168 "seccomp-bpf/die.cc",
170 "seccomp-bpf/errorcode.cc",
171 "seccomp-bpf/errorcode.h",
172 "seccomp-bpf/sandbox_bpf.cc",
173 "seccomp-bpf/sandbox_bpf.h",
174 "seccomp-bpf/syscall.cc",
175 "seccomp-bpf/syscall.h",
176 "seccomp-bpf/trap.cc",
177 "seccomp-bpf/trap.h",
178 "seccomp-bpf/verifier.cc",
179 "seccomp-bpf/verifier.h",
181 defines = [ "SANDBOX_IMPLEMENTATION" ]
185 ":sandbox_services_headers",
190 component("seccomp_bpf_helpers") {
192 "seccomp-bpf-helpers/baseline_policy.cc",
193 "seccomp-bpf-helpers/baseline_policy.h",
194 "seccomp-bpf-helpers/sigsys_handlers.cc",
195 "seccomp-bpf-helpers/sigsys_handlers.h",
196 "seccomp-bpf-helpers/syscall_parameters_restrictions.cc",
197 "seccomp-bpf-helpers/syscall_parameters_restrictions.h",
198 "seccomp-bpf-helpers/syscall_sets.cc",
199 "seccomp-bpf-helpers/syscall_sets.h",
201 defines = [ "SANDBOX_IMPLEMENTATION" ]
211 # The setuid sandbox for Linux.
212 executable("chrome_sandbox") {
214 "suid/common/sandbox.h",
215 "suid/common/suid_unsafe_environment_variables.h",
216 "suid/process_util.h",
217 "suid/process_util_linux.c",
225 # These files have a suspicious comparison.
226 # TODO fix this and re-enable this warning.
232 component("sandbox_services") {
234 "services/init_process_reaper.cc",
235 "services/init_process_reaper.h",
236 "services/proc_util.cc",
237 "services/proc_util.h",
238 "services/resource_limits.cc",
239 "services/resource_limits.h",
240 "services/scoped_process.cc",
241 "services/scoped_process.h",
242 "services/syscall_wrappers.cc",
243 "services/syscall_wrappers.h",
244 "services/thread_helpers.cc",
245 "services/thread_helpers.h",
248 "syscall_broker/broker_channel.cc",
249 "syscall_broker/broker_channel.h",
250 "syscall_broker/broker_client.cc",
251 "syscall_broker/broker_client.h",
252 "syscall_broker/broker_common.h",
253 "syscall_broker/broker_file_permission.cc",
254 "syscall_broker/broker_file_permission.h",
255 "syscall_broker/broker_host.cc",
256 "syscall_broker/broker_host.h",
257 "syscall_broker/broker_policy.cc",
258 "syscall_broker/broker_policy.h",
259 "syscall_broker/broker_process.cc",
260 "syscall_broker/broker_process.h",
263 defines = [ "SANDBOX_IMPLEMENTATION" ]
265 if (compile_credentials) {
267 "services/credentials.cc",
268 "services/credentials.h",
269 "services/namespace_sandbox.cc",
270 "services/namespace_sandbox.h",
271 "services/namespace_utils.cc",
272 "services/namespace_utils.h",
275 # For capabilities.cc.
276 configs += [ "//build/config/linux:libcap" ]
284 source_set("sandbox_services_headers") {
286 "system_headers/android_arm64_ucontext.h",
287 "system_headers/android_arm_ucontext.h",
288 "system_headers/android_futex.h",
289 "system_headers/android_i386_ucontext.h",
290 "system_headers/android_ucontext.h",
291 "system_headers/arm64_linux_syscalls.h",
292 "system_headers/arm_linux_syscalls.h",
293 "system_headers/linux_seccomp.h",
294 "system_headers/linux_syscalls.h",
295 "system_headers/x86_32_linux_syscalls.h",
296 "system_headers/x86_64_linux_syscalls.h",
300 # We make this its own target so that it does not interfere with our tests.
301 source_set("libc_urandom_override") {
303 "services/libc_urandom_override.cc",
304 "services/libc_urandom_override.h",
311 if (compile_suid_client) {
312 component("suid_sandbox_client") {
314 "suid/common/sandbox.h",
315 "suid/common/suid_unsafe_environment_variables.h",
316 "suid/client/setuid_sandbox_client.cc",
317 "suid/client/setuid_sandbox_client.h",
318 "suid/client/setuid_sandbox_host.cc",
319 "suid/client/setuid_sandbox_host.h",
321 defines = [ "SANDBOX_IMPLEMENTATION" ]
331 # TODO(GYP) enable this. Needs an android_strip wrapper python script.
332 #action("sandbox_linux_unittests_stripped") {
333 # script = "android_stip.py"
335 # in_file = "$root_out_dir/sandbox_linux_unittests"
337 # out_file = "$root_out_dir/sandbox_linux_unittests_stripped"
338 # outputs = [ out_file ]
341 # rebase_path(in_file, root_build_dir),
342 # "-o", rebase_path(out_file, root_build_dir),
346 # ":sandbox_linux_unittests",
349 # TODO(GYP) convert this.
351 # 'target_name': 'sandbox_linux_jni_unittests_apk',
354 # 'test_suite_name': 'sandbox_linux_jni_unittests',
357 # 'sandbox_linux_jni_unittests',
359 # 'includes': [ '../../build/apk_test.gypi' ],