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")
8 compile_suid_client = is_linux
10 compile_credentials = is_linux
12 compile_seccomp_bpf_demo =
13 (is_linux && (cpu_arch == "x86" || cpu_arch == "x64"))
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.
26 if (compile_suid_client) {
27 deps += [ ":suid_sandbox_client" ]
29 if (use_seccomp_bpf) {
32 ":seccomp_bpf_helpers",
37 source_set("sandbox_linux_test_utils") {
39 "tests/sandbox_test_runner.cc",
40 "tests/sandbox_test_runner.h",
41 "tests/sandbox_test_runner_function_pointer.cc",
42 "tests/sandbox_test_runner_function_pointer.h",
43 "tests/test_utils.cc",
45 "tests/unit_tests.cc",
53 if (use_seccomp_bpf) {
55 "seccomp-bpf/bpf_tester_compatibility_delegate.h",
56 "seccomp-bpf/bpf_tests.h",
57 "seccomp-bpf/sandbox_bpf_test_runner.cc",
58 "seccomp-bpf/sandbox_bpf_test_runner.h",
66 # The main sandboxing test target.
67 test("sandbox_linux_unittests") {
69 "services/broker_process_unittest.cc",
70 "services/scoped_process_unittest.cc",
71 "services/thread_helpers_unittests.cc",
72 "services/yama_unittests.cc",
74 "tests/scoped_temporary_file.cc",
75 "tests/scoped_temporary_file.h",
76 "tests/scoped_temporary_file_unittest.cc",
77 "tests/unit_tests_unittest.cc",
82 ":sandbox_linux_test_utils",
84 "//base/test:test_support",
88 if (compile_suid_client) {
90 "suid/client/setuid_sandbox_client_unittest.cc",
93 if (use_seccomp_bpf) {
95 "seccomp-bpf-helpers/baseline_policy_unittest.cc",
96 "seccomp-bpf/bpf_tests_unittest.cc",
97 "seccomp-bpf/codegen_unittest.cc",
98 "seccomp-bpf/errorcode_unittest.cc",
99 "seccomp-bpf/sandbox_bpf_unittest.cc",
100 "seccomp-bpf/syscall_iterator_unittest.cc",
101 "seccomp-bpf/syscall_unittest.cc",
104 if (compile_credentials) {
106 "services/credentials_unittest.cc",
107 "services/unix_domain_socket_unittest.cc",
112 # TODO(GYP) Android version of this test.
114 # # This target is the shared library used by Android APK (i.e.
115 # # JNI-friendly) tests.
116 # "target_name": "sandbox_linux_jni_unittests",
118 # "sandbox_linux_test_sources.gypi",
120 # "type": "shared_library",
122 # [ "OS == "android"", {
124 # "../testing/android/native_test.gyp:native_test_native_code",
130 component("seccomp_bpf") {
132 "seccomp-bpf/basicblock.cc",
133 "seccomp-bpf/basicblock.h",
134 "seccomp-bpf/codegen.cc",
135 "seccomp-bpf/codegen.h",
136 "seccomp-bpf/die.cc",
138 "seccomp-bpf/errorcode.cc",
139 "seccomp-bpf/errorcode.h",
140 "seccomp-bpf/instruction.h",
141 "seccomp-bpf/linux_seccomp.h",
142 "seccomp-bpf/sandbox_bpf.cc",
143 "seccomp-bpf/sandbox_bpf.h",
144 "seccomp-bpf/sandbox_bpf_compatibility_policy.h",
145 "seccomp-bpf/sandbox_bpf_policy.cc",
146 "seccomp-bpf/sandbox_bpf_policy.h",
147 "seccomp-bpf/syscall.cc",
148 "seccomp-bpf/syscall.h",
149 "seccomp-bpf/syscall_iterator.cc",
150 "seccomp-bpf/syscall_iterator.h",
151 "seccomp-bpf/trap.cc",
152 "seccomp-bpf/trap.h",
153 "seccomp-bpf/verifier.cc",
154 "seccomp-bpf/verifier.h",
156 defines = [ "SANDBOX_IMPLEMENTATION" ]
159 ":sandbox_services_headers",
164 component("seccomp_bpf_helpers") {
166 "seccomp-bpf-helpers/baseline_policy.cc",
167 "seccomp-bpf-helpers/baseline_policy.h",
168 "seccomp-bpf-helpers/sigsys_handlers.cc",
169 "seccomp-bpf-helpers/sigsys_handlers.h",
170 "seccomp-bpf-helpers/syscall_parameters_restrictions.cc",
171 "seccomp-bpf-helpers/syscall_parameters_restrictions.h",
172 "seccomp-bpf-helpers/syscall_sets.cc",
173 "seccomp-bpf-helpers/syscall_sets.h",
175 defines = [ "SANDBOX_IMPLEMENTATION" ]
183 if (compile_seccomp_bpf_demo) {
184 # A demonstration program for the seccomp-bpf sandbox.
185 executable("seccomp_bpf_demo") {
187 "seccomp-bpf/demo.cc",
195 # The setuid sandbox for Linux.
196 executable("chrome_sandbox") {
198 "suid/common/sandbox.h",
199 "suid/common/suid_unsafe_environment_variables.h",
202 "suid/process_util.h",
203 "suid/process_util_linux.c",
210 # These files have a suspicious comparison.
211 # TODO fix this and re-enable this warning.
216 component("sandbox_services") {
218 "services/broker_process.cc",
219 "services/broker_process.h",
220 "services/init_process_reaper.cc",
221 "services/init_process_reaper.h",
222 "services/scoped_process.cc",
223 "services/scoped_process.h",
224 "services/thread_helpers.cc",
225 "services/thread_helpers.h",
230 defines = [ "SANDBOX_IMPLEMENTATION" ]
232 if (compile_credentials) {
234 "services/credentials.cc",
235 "services/credentials.h",
237 # For capabilities.cc.
238 configs += [ "//build/config/linux:libcap" ]
246 source_set("sandbox_services_headers") {
248 "services/android_arm_ucontext.h",
249 "services/android_futex.h",
250 "services/android_ucontext.h",
251 "services/android_i386_ucontext.h",
252 "services/arm_linux_syscalls.h",
253 "services/linux_syscalls.h",
254 "services/x86_32_linux_syscalls.h",
255 "services/x86_64_linux_syscalls.h",
259 # We make this its own target so that it does not interfere with our tests.
260 source_set("libc_urandom_override") {
262 "services/libc_urandom_override.cc",
263 "services/libc_urandom_override.h",
270 component("suid_sandbox_client") {
272 "suid/common/sandbox.h",
273 "suid/common/suid_unsafe_environment_variables.h",
274 "suid/client/setuid_sandbox_client.cc",
275 "suid/client/setuid_sandbox_client.h",
277 defines = [ "SANDBOX_IMPLEMENTATION" ]
286 # TODO(GYP) enable this. Needs an android_strip wrapper python script.
287 #action("sandbox_linux_unittests_stripped") {
288 # script = "android_stip.py"
290 # in_file = "$root_out_dir/sandbox_linux_unittests"
292 # out_file = "$root_out_dir/sandbox_linux_unittests_stripped"
293 # outputs = [ out_file ]
296 # rebase_path(in_file, root_build_dir),
297 # "-o", rebase_path(out_file, root_build_dir),
301 # ":sandbox_linux_unittests",
305 # TODO(GYP) convert this.
307 # 'target_name': 'sandbox_linux_jni_unittests_apk',
310 # 'test_suite_name': 'sandbox_linux_jni_unittests',
313 # 'sandbox_linux_jni_unittests',
315 # 'includes': [ '../../build/apk_test.gypi' ],