blob: ed4e69722386852495a8116e58daaa6b49680ccf [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")
qsrfb5251d12015-01-21 15:57:226import("//testing/test.gni")
[email protected]75cd8f02014-05-29 20:56:027
8declare_args() {
9 compile_suid_client = is_linux
10
11 compile_credentials = is_linux
12
13 compile_seccomp_bpf_demo =
scottmg34fb7e52014-12-03 23:27:2414 is_linux && (cpu_arch == "x86" || cpu_arch == "x64")
[email protected]75cd8f02014-05-29 20:56:0215}
16
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.
21
22group("sandbox") {
23 deps = [
24 ":sandbox_services",
25 ]
26
27 if (compile_suid_client) {
28 deps += [ ":suid_sandbox_client" ]
29 }
30 if (use_seccomp_bpf) {
31 deps += [
32 ":seccomp_bpf",
33 ":seccomp_bpf_helpers",
34 ]
35 }
36}
37
38source_set("sandbox_linux_test_utils") {
Brett Wilson0c8745a2014-09-08 22:59:4939 testonly = true
[email protected]75cd8f02014-05-29 20:56:0240 sources = [
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",
46 "tests/test_utils.h",
47 "tests/unit_tests.cc",
48 "tests/unit_tests.h",
49 ]
50
51 deps = [
52 "//testing/gtest",
53 ]
54
55 if (use_seccomp_bpf) {
56 sources += [
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",
61 ]
scottmg34fb7e52014-12-03 23:27:2462 deps += [ ":seccomp_bpf" ]
[email protected]75cd8f02014-05-29 20:56:0263 }
64}
65
66# The main sandboxing test target.
67test("sandbox_linux_unittests") {
68 sources = [
jlnb14fc802015-02-12 05:32:1169 "services/proc_util_unittest.cc",
[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",
leecamad78f422014-11-26 22:08:4574 "syscall_broker/broker_file_permission_unittest.cc",
jln70c42c202014-11-01 00:59:5775 "syscall_broker/broker_process_unittest.cc",
[email protected]232f6e112014-06-27 07:51:3876 "tests/main.cc",
77 "tests/scoped_temporary_file.cc",
78 "tests/scoped_temporary_file.h",
79 "tests/scoped_temporary_file_unittest.cc",
jlnc420f0d2014-11-22 01:12:0980 "tests/test_utils_unittest.cc",
[email protected]232f6e112014-06-27 07:51:3881 "tests/unit_tests_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:0282 ]
83
84 deps = [
85 ":sandbox",
86 ":sandbox_linux_test_utils",
87 "//base",
88 "//base/test:test_support",
89 "//testing/gtest",
90 ]
91
Brett Wilson73067532014-09-12 22:24:1492 if (is_linux) {
93 # Don't use this on Android.
94 libs = [ "rt" ]
95 }
Brett Wilsone39344352014-09-12 21:07:2696
[email protected]75cd8f02014-05-29 20:56:0297 if (compile_suid_client) {
mdempsky3cc942a2015-02-05 03:29:2598 sources += [
99 "suid/client/setuid_sandbox_client_unittest.cc",
100 "suid/client/setuid_sandbox_host_unittest.cc",
101 ]
[email protected]75cd8f02014-05-29 20:56:02102 }
103 if (use_seccomp_bpf) {
104 sources += [
[email protected]fb75e2a2014-07-17 07:24:58105 "bpf_dsl/bpf_dsl_unittest.cc",
mdempskyb80b1f52015-02-05 00:54:35106 "bpf_dsl/codegen_unittest.cc",
[email protected]fb75e2a2014-07-17 07:24:58107 "bpf_dsl/cons_unittest.cc",
mdempskyce4c9f12015-02-05 06:23:05108 "bpf_dsl/syscall_set_unittest.cc",
jlnaedcc3e2015-02-12 03:18:10109 "integration_tests/bpf_dsl_seccomp_unittest.cc",
110 "integration_tests/seccomp_broker_process_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02111 "seccomp-bpf-helpers/baseline_policy_unittest.cc",
jlnfcdfb102014-09-12 02:47:44112 "seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc",
[email protected]75cd8f02014-05-29 20:56:02113 "seccomp-bpf/bpf_tests_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02114 "seccomp-bpf/errorcode_unittest.cc",
jlna29d0a32014-11-26 22:38:35115 "seccomp-bpf/sandbox_bpf_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02116 "seccomp-bpf/syscall_unittest.cc",
117 ]
118 }
119 if (compile_credentials) {
120 sources += [
jlnaedcc3e2015-02-12 03:18:10121 "integration_tests/namespace_unix_domain_socket_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02122 "services/credentials_unittest.cc",
rickyz8f235da2015-02-03 07:26:19123 "services/namespace_sandbox_unittest.cc",
rickyz41fb1452015-01-27 03:57:58124 "services/namespace_utils_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02125 ]
126 }
127}
128
129# TODO(GYP) Android version of this test.
130# {
131# # This target is the shared library used by Android APK (i.e.
132# # JNI-friendly) tests.
133# "target_name": "sandbox_linux_jni_unittests",
134# "includes": [
135# "sandbox_linux_test_sources.gypi",
136# ],
137# "type": "shared_library",
138# "conditions": [
139# [ "OS == "android"", {
140# "dependencies": [
141# "../testing/android/native_test.gyp:native_test_native_code",
142# ],
143# }],
144# ],
145# },
146
147component("seccomp_bpf") {
148 sources = [
[email protected]fb75e2a2014-07-17 07:24:58149 "bpf_dsl/bpf_dsl.cc",
150 "bpf_dsl/bpf_dsl.h",
mdempskyc60a1c52014-10-24 23:07:10151 "bpf_dsl/bpf_dsl_forward.h",
mdempskyfb10cce2014-10-14 17:56:44152 "bpf_dsl/bpf_dsl_impl.h",
mdempskyb80b1f52015-02-05 00:54:35153 "bpf_dsl/codegen.cc",
154 "bpf_dsl/codegen.h",
[email protected]fb75e2a2014-07-17 07:24:58155 "bpf_dsl/cons.h",
mdempskya41c4042014-10-31 20:50:27156 "bpf_dsl/dump_bpf.cc",
157 "bpf_dsl/dump_bpf.h",
mdempskyc60a1c52014-10-24 23:07:10158 "bpf_dsl/policy.cc",
159 "bpf_dsl/policy.h",
mdempsky27e78ad72014-10-16 16:49:54160 "bpf_dsl/policy_compiler.cc",
161 "bpf_dsl/policy_compiler.h",
mdempskyce4c9f12015-02-05 06:23:05162 "bpf_dsl/syscall_set.cc",
163 "bpf_dsl/syscall_set.h",
mdempsky27e78ad72014-10-16 16:49:54164 "bpf_dsl/trap_registry.h",
[email protected]75cd8f02014-05-29 20:56:02165 "seccomp-bpf/die.cc",
166 "seccomp-bpf/die.h",
167 "seccomp-bpf/errorcode.cc",
168 "seccomp-bpf/errorcode.h",
[email protected]75cd8f02014-05-29 20:56:02169 "seccomp-bpf/linux_seccomp.h",
170 "seccomp-bpf/sandbox_bpf.cc",
171 "seccomp-bpf/sandbox_bpf.h",
[email protected]75cd8f02014-05-29 20:56:02172 "seccomp-bpf/syscall.cc",
173 "seccomp-bpf/syscall.h",
[email protected]75cd8f02014-05-29 20:56:02174 "seccomp-bpf/trap.cc",
175 "seccomp-bpf/trap.h",
176 "seccomp-bpf/verifier.cc",
177 "seccomp-bpf/verifier.h",
178 ]
179 defines = [ "SANDBOX_IMPLEMENTATION" ]
180
181 deps = [
jlnbd4df41c2014-11-25 02:32:30182 ":sandbox_services",
[email protected]75cd8f02014-05-29 20:56:02183 ":sandbox_services_headers",
184 "//base",
185 ]
186}
187
188component("seccomp_bpf_helpers") {
189 sources = [
190 "seccomp-bpf-helpers/baseline_policy.cc",
191 "seccomp-bpf-helpers/baseline_policy.h",
192 "seccomp-bpf-helpers/sigsys_handlers.cc",
193 "seccomp-bpf-helpers/sigsys_handlers.h",
194 "seccomp-bpf-helpers/syscall_parameters_restrictions.cc",
195 "seccomp-bpf-helpers/syscall_parameters_restrictions.h",
196 "seccomp-bpf-helpers/syscall_sets.cc",
197 "seccomp-bpf-helpers/syscall_sets.h",
198 ]
199 defines = [ "SANDBOX_IMPLEMENTATION" ]
200
201 deps = [
202 "//base",
jamesr4359db72015-01-21 12:40:00203 ":sandbox_services",
[email protected]75cd8f02014-05-29 20:56:02204 ":seccomp_bpf",
205 ]
206}
207
James Robinson060f2e32014-09-10 22:31:37208if (is_linux) {
scottmg34fb7e52014-12-03 23:27:24209 # The setuid sandbox for Linux.
James Robinson060f2e32014-09-10 22:31:37210 executable("chrome_sandbox") {
211 sources = [
212 "suid/common/sandbox.h",
213 "suid/common/suid_unsafe_environment_variables.h",
James Robinson060f2e32014-09-10 22:31:37214 "suid/process_util.h",
215 "suid/process_util_linux.c",
216 "suid/sandbox.c",
217 ]
[email protected]75cd8f02014-05-29 20:56:02218
James Robinson060f2e32014-09-10 22:31:37219 cflags = [
220 # For ULLONG_MAX
221 "-std=gnu99",
scottmg34fb7e52014-12-03 23:27:24222
James Robinson060f2e32014-09-10 22:31:37223 # These files have a suspicious comparison.
224 # TODO fix this and re-enable this warning.
225 "-Wno-sign-compare",
226 ]
227 }
[email protected]75cd8f02014-05-29 20:56:02228}
229
230component("sandbox_services") {
231 sources = [
[email protected]75cd8f02014-05-29 20:56:02232 "services/init_process_reaper.cc",
233 "services/init_process_reaper.h",
jlnb14fc802015-02-12 05:32:11234 "services/proc_util.cc",
235 "services/proc_util.h",
[email protected]75cd8f02014-05-29 20:56:02236 "services/scoped_process.cc",
237 "services/scoped_process.h",
jln610a4a612014-11-20 18:58:21238 "services/syscall_wrappers.cc",
239 "services/syscall_wrappers.h",
[email protected]75cd8f02014-05-29 20:56:02240 "services/thread_helpers.cc",
241 "services/thread_helpers.h",
[email protected]75cd8f02014-05-29 20:56:02242 "services/yama.cc",
jlnb14fc802015-02-12 05:32:11243 "services/yama.h",
jln878dca32014-11-11 07:43:57244 "syscall_broker/broker_channel.cc",
245 "syscall_broker/broker_channel.h",
jln70c42c202014-11-01 00:59:57246 "syscall_broker/broker_client.cc",
247 "syscall_broker/broker_client.h",
248 "syscall_broker/broker_common.h",
leecamad78f422014-11-26 22:08:45249 "syscall_broker/broker_file_permission.cc",
250 "syscall_broker/broker_file_permission.h",
jln70c42c202014-11-01 00:59:57251 "syscall_broker/broker_host.cc",
252 "syscall_broker/broker_host.h",
253 "syscall_broker/broker_policy.cc",
254 "syscall_broker/broker_policy.h",
255 "syscall_broker/broker_process.cc",
256 "syscall_broker/broker_process.h",
[email protected]75cd8f02014-05-29 20:56:02257 ]
258
259 defines = [ "SANDBOX_IMPLEMENTATION" ]
260
261 if (compile_credentials) {
262 sources += [
263 "services/credentials.cc",
264 "services/credentials.h",
rickyz8f235da2015-02-03 07:26:19265 "services/namespace_sandbox.cc",
266 "services/namespace_sandbox.h",
rickyz41fb1452015-01-27 03:57:58267 "services/namespace_utils.cc",
268 "services/namespace_utils.h",
[email protected]75cd8f02014-05-29 20:56:02269 ]
scottmg34fb7e52014-12-03 23:27:24270
[email protected]75cd8f02014-05-29 20:56:02271 # For capabilities.cc.
272 configs += [ "//build/config/linux:libcap" ]
273 }
274
275 deps = [
276 "//base",
277 ]
278}
279
280source_set("sandbox_services_headers") {
281 sources = [
jlnaedcc3e2015-02-12 03:18:10282 "system_headers/android_arm_ucontext.h",
283 "system_headers/android_arm64_ucontext.h",
284 "system_headers/android_futex.h",
285 "system_headers/android_ucontext.h",
286 "system_headers/android_i386_ucontext.h",
287 "system_headers/arm_linux_syscalls.h",
288 "system_headers/arm64_linux_syscalls.h",
289 "system_headers/linux_syscalls.h",
290 "system_headers/x86_32_linux_syscalls.h",
291 "system_headers/x86_64_linux_syscalls.h",
[email protected]75cd8f02014-05-29 20:56:02292 ]
293}
294
295# We make this its own target so that it does not interfere with our tests.
296source_set("libc_urandom_override") {
297 sources = [
298 "services/libc_urandom_override.cc",
299 "services/libc_urandom_override.h",
300 ]
301 deps = [
302 "//base",
303 ]
304}
305
James Robinson060f2e32014-09-10 22:31:37306if (compile_suid_client) {
307 component("suid_sandbox_client") {
308 sources = [
309 "suid/common/sandbox.h",
310 "suid/common/suid_unsafe_environment_variables.h",
311 "suid/client/setuid_sandbox_client.cc",
312 "suid/client/setuid_sandbox_client.h",
mdempsky3cc942a2015-02-05 03:29:25313 "suid/client/setuid_sandbox_host.cc",
314 "suid/client/setuid_sandbox_host.h",
James Robinson060f2e32014-09-10 22:31:37315 ]
316 defines = [ "SANDBOX_IMPLEMENTATION" ]
[email protected]75cd8f02014-05-29 20:56:02317
James Robinson060f2e32014-09-10 22:31:37318 deps = [
319 ":sandbox_services",
320 "//base",
321 ]
322 }
[email protected]75cd8f02014-05-29 20:56:02323}
324
325if (is_android) {
326 # TODO(GYP) enable this. Needs an android_strip wrapper python script.
327 #action("sandbox_linux_unittests_stripped") {
328 # script = "android_stip.py"
329 #
330 # in_file = "$root_out_dir/sandbox_linux_unittests"
331 #
332 # out_file = "$root_out_dir/sandbox_linux_unittests_stripped"
333 # outputs = [ out_file ]
334 #
335 # args = [
336 # rebase_path(in_file, root_build_dir),
337 # "-o", rebase_path(out_file, root_build_dir),
338 # ]
339 #
340 # deps = [
341 # ":sandbox_linux_unittests",
342 # ]
343 #}
[email protected]75cd8f02014-05-29 20:56:02344 # TODO(GYP) convert this.
345 # {
346 # 'target_name': 'sandbox_linux_jni_unittests_apk',
347 # 'type': 'none',
348 # 'variables': {
349 # 'test_suite_name': 'sandbox_linux_jni_unittests',
350 # },
351 # 'dependencies': [
352 # 'sandbox_linux_jni_unittests',
353 # ],
354 # 'includes': [ '../../build/apk_test.gypi' ],
355 # }
356}