blob: dd16cb2cdbb35b07335e6310fd515360716a9c65 [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 = [
[email protected]75cd8f02014-05-29 20:56:0269 "services/scoped_process_unittest.cc",
jlnc420f0d2014-11-22 01:12:0970 "services/syscall_wrappers_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:0271 "services/thread_helpers_unittests.cc",
72 "services/yama_unittests.cc",
leecamad78f422014-11-26 22:08:4573 "syscall_broker/broker_file_permission_unittest.cc",
jln70c42c202014-11-01 00:59:5774 "syscall_broker/broker_process_unittest.cc",
[email protected]232f6e112014-06-27 07:51:3875 "tests/main.cc",
76 "tests/scoped_temporary_file.cc",
77 "tests/scoped_temporary_file.h",
78 "tests/scoped_temporary_file_unittest.cc",
jlnc420f0d2014-11-22 01:12:0979 "tests/test_utils_unittest.cc",
[email protected]232f6e112014-06-27 07:51:3880 "tests/unit_tests_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:0281 ]
82
83 deps = [
84 ":sandbox",
85 ":sandbox_linux_test_utils",
86 "//base",
87 "//base/test:test_support",
88 "//testing/gtest",
89 ]
90
Brett Wilson73067532014-09-12 22:24:1491 if (is_linux) {
92 # Don't use this on Android.
93 libs = [ "rt" ]
94 }
Brett Wilsone39344352014-09-12 21:07:2695
[email protected]75cd8f02014-05-29 20:56:0296 if (compile_suid_client) {
mdempsky3cc942a2015-02-05 03:29:2597 sources += [
98 "suid/client/setuid_sandbox_client_unittest.cc",
99 "suid/client/setuid_sandbox_host_unittest.cc",
100 ]
[email protected]75cd8f02014-05-29 20:56:02101 }
102 if (use_seccomp_bpf) {
103 sources += [
mdempsky22aa66d2014-09-13 01:41:34104 "bpf_dsl/bpf_dsl_more_unittest.cc",
[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",
[email protected]75cd8f02014-05-29 20:56:02108 "seccomp-bpf-helpers/baseline_policy_unittest.cc",
jlnfcdfb102014-09-12 02:47:44109 "seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc",
[email protected]75cd8f02014-05-29 20:56:02110 "seccomp-bpf/bpf_tests_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02111 "seccomp-bpf/errorcode_unittest.cc",
jlna29d0a32014-11-26 22:38:35112 "seccomp-bpf/sandbox_bpf_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02113 "seccomp-bpf/syscall_iterator_unittest.cc",
114 "seccomp-bpf/syscall_unittest.cc",
115 ]
116 }
117 if (compile_credentials) {
118 sources += [
119 "services/credentials_unittest.cc",
rickyz8f235da2015-02-03 07:26:19120 "services/namespace_sandbox_unittest.cc",
rickyz41fb1452015-01-27 03:57:58121 "services/namespace_utils_unittest.cc",
hidehiko7349c252014-11-26 20:30:01122 "services/proc_util_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02123 "services/unix_domain_socket_unittest.cc",
124 ]
125 }
126}
127
128# TODO(GYP) Android version of this test.
129# {
130# # This target is the shared library used by Android APK (i.e.
131# # JNI-friendly) tests.
132# "target_name": "sandbox_linux_jni_unittests",
133# "includes": [
134# "sandbox_linux_test_sources.gypi",
135# ],
136# "type": "shared_library",
137# "conditions": [
138# [ "OS == "android"", {
139# "dependencies": [
140# "../testing/android/native_test.gyp:native_test_native_code",
141# ],
142# }],
143# ],
144# },
145
146component("seccomp_bpf") {
147 sources = [
[email protected]fb75e2a2014-07-17 07:24:58148 "bpf_dsl/bpf_dsl.cc",
149 "bpf_dsl/bpf_dsl.h",
mdempskyc60a1c52014-10-24 23:07:10150 "bpf_dsl/bpf_dsl_forward.h",
mdempskyfb10cce2014-10-14 17:56:44151 "bpf_dsl/bpf_dsl_impl.h",
mdempskyb80b1f52015-02-05 00:54:35152 "bpf_dsl/codegen.cc",
153 "bpf_dsl/codegen.h",
[email protected]fb75e2a2014-07-17 07:24:58154 "bpf_dsl/cons.h",
mdempskya41c4042014-10-31 20:50:27155 "bpf_dsl/dump_bpf.cc",
156 "bpf_dsl/dump_bpf.h",
mdempskyc60a1c52014-10-24 23:07:10157 "bpf_dsl/policy.cc",
158 "bpf_dsl/policy.h",
mdempsky27e78ad72014-10-16 16:49:54159 "bpf_dsl/policy_compiler.cc",
160 "bpf_dsl/policy_compiler.h",
161 "bpf_dsl/trap_registry.h",
[email protected]75cd8f02014-05-29 20:56:02162 "seccomp-bpf/die.cc",
163 "seccomp-bpf/die.h",
164 "seccomp-bpf/errorcode.cc",
165 "seccomp-bpf/errorcode.h",
[email protected]75cd8f02014-05-29 20:56:02166 "seccomp-bpf/linux_seccomp.h",
167 "seccomp-bpf/sandbox_bpf.cc",
168 "seccomp-bpf/sandbox_bpf.h",
[email protected]75cd8f02014-05-29 20:56:02169 "seccomp-bpf/syscall.cc",
170 "seccomp-bpf/syscall.h",
171 "seccomp-bpf/syscall_iterator.cc",
172 "seccomp-bpf/syscall_iterator.h",
173 "seccomp-bpf/trap.cc",
174 "seccomp-bpf/trap.h",
175 "seccomp-bpf/verifier.cc",
176 "seccomp-bpf/verifier.h",
177 ]
178 defines = [ "SANDBOX_IMPLEMENTATION" ]
179
180 deps = [
jlnbd4df41c2014-11-25 02:32:30181 ":sandbox_services",
[email protected]75cd8f02014-05-29 20:56:02182 ":sandbox_services_headers",
183 "//base",
184 ]
185}
186
187component("seccomp_bpf_helpers") {
188 sources = [
189 "seccomp-bpf-helpers/baseline_policy.cc",
190 "seccomp-bpf-helpers/baseline_policy.h",
191 "seccomp-bpf-helpers/sigsys_handlers.cc",
192 "seccomp-bpf-helpers/sigsys_handlers.h",
193 "seccomp-bpf-helpers/syscall_parameters_restrictions.cc",
194 "seccomp-bpf-helpers/syscall_parameters_restrictions.h",
195 "seccomp-bpf-helpers/syscall_sets.cc",
196 "seccomp-bpf-helpers/syscall_sets.h",
197 ]
198 defines = [ "SANDBOX_IMPLEMENTATION" ]
199
200 deps = [
201 "//base",
jamesr4359db72015-01-21 12:40:00202 ":sandbox_services",
[email protected]75cd8f02014-05-29 20:56:02203 ":seccomp_bpf",
204 ]
205}
206
James Robinson060f2e32014-09-10 22:31:37207if (is_linux) {
scottmg34fb7e52014-12-03 23:27:24208 # The setuid sandbox for Linux.
James Robinson060f2e32014-09-10 22:31:37209 executable("chrome_sandbox") {
210 sources = [
211 "suid/common/sandbox.h",
212 "suid/common/suid_unsafe_environment_variables.h",
James Robinson060f2e32014-09-10 22:31:37213 "suid/process_util.h",
214 "suid/process_util_linux.c",
215 "suid/sandbox.c",
216 ]
[email protected]75cd8f02014-05-29 20:56:02217
James Robinson060f2e32014-09-10 22:31:37218 cflags = [
219 # For ULLONG_MAX
220 "-std=gnu99",
scottmg34fb7e52014-12-03 23:27:24221
James Robinson060f2e32014-09-10 22:31:37222 # These files have a suspicious comparison.
223 # TODO fix this and re-enable this warning.
224 "-Wno-sign-compare",
225 ]
226 }
[email protected]75cd8f02014-05-29 20:56:02227}
228
229component("sandbox_services") {
230 sources = [
[email protected]75cd8f02014-05-29 20:56:02231 "services/init_process_reaper.cc",
232 "services/init_process_reaper.h",
233 "services/scoped_process.cc",
234 "services/scoped_process.h",
jln610a4a612014-11-20 18:58:21235 "services/syscall_wrappers.cc",
236 "services/syscall_wrappers.h",
[email protected]75cd8f02014-05-29 20:56:02237 "services/thread_helpers.cc",
238 "services/thread_helpers.h",
239 "services/yama.h",
240 "services/yama.cc",
jln878dca32014-11-11 07:43:57241 "syscall_broker/broker_channel.cc",
242 "syscall_broker/broker_channel.h",
jln70c42c202014-11-01 00:59:57243 "syscall_broker/broker_client.cc",
244 "syscall_broker/broker_client.h",
245 "syscall_broker/broker_common.h",
leecamad78f422014-11-26 22:08:45246 "syscall_broker/broker_file_permission.cc",
247 "syscall_broker/broker_file_permission.h",
jln70c42c202014-11-01 00:59:57248 "syscall_broker/broker_host.cc",
249 "syscall_broker/broker_host.h",
250 "syscall_broker/broker_policy.cc",
251 "syscall_broker/broker_policy.h",
252 "syscall_broker/broker_process.cc",
253 "syscall_broker/broker_process.h",
[email protected]75cd8f02014-05-29 20:56:02254 ]
255
256 defines = [ "SANDBOX_IMPLEMENTATION" ]
257
258 if (compile_credentials) {
259 sources += [
260 "services/credentials.cc",
261 "services/credentials.h",
rickyz8f235da2015-02-03 07:26:19262 "services/namespace_sandbox.cc",
263 "services/namespace_sandbox.h",
rickyz41fb1452015-01-27 03:57:58264 "services/namespace_utils.cc",
265 "services/namespace_utils.h",
hidehiko7349c252014-11-26 20:30:01266 "services/proc_util.cc",
267 "services/proc_util.h",
[email protected]75cd8f02014-05-29 20:56:02268 ]
scottmg34fb7e52014-12-03 23:27:24269
[email protected]75cd8f02014-05-29 20:56:02270 # For capabilities.cc.
271 configs += [ "//build/config/linux:libcap" ]
272 }
273
274 deps = [
275 "//base",
276 ]
277}
278
279source_set("sandbox_services_headers") {
280 sources = [
281 "services/android_arm_ucontext.h",
leecame6f6b732014-08-24 23:38:09282 "services/android_arm64_ucontext.h",
[email protected]9de395e42014-06-04 22:25:28283 "services/android_futex.h",
[email protected]75cd8f02014-05-29 20:56:02284 "services/android_ucontext.h",
285 "services/android_i386_ucontext.h",
286 "services/arm_linux_syscalls.h",
leecame6f6b732014-08-24 23:38:09287 "services/arm64_linux_syscalls.h",
[email protected]75cd8f02014-05-29 20:56:02288 "services/linux_syscalls.h",
289 "services/x86_32_linux_syscalls.h",
290 "services/x86_64_linux_syscalls.h",
291 ]
292}
293
294# We make this its own target so that it does not interfere with our tests.
295source_set("libc_urandom_override") {
296 sources = [
297 "services/libc_urandom_override.cc",
298 "services/libc_urandom_override.h",
299 ]
300 deps = [
301 "//base",
302 ]
303}
304
James Robinson060f2e32014-09-10 22:31:37305if (compile_suid_client) {
306 component("suid_sandbox_client") {
307 sources = [
308 "suid/common/sandbox.h",
309 "suid/common/suid_unsafe_environment_variables.h",
310 "suid/client/setuid_sandbox_client.cc",
311 "suid/client/setuid_sandbox_client.h",
mdempsky3cc942a2015-02-05 03:29:25312 "suid/client/setuid_sandbox_host.cc",
313 "suid/client/setuid_sandbox_host.h",
James Robinson060f2e32014-09-10 22:31:37314 ]
315 defines = [ "SANDBOX_IMPLEMENTATION" ]
[email protected]75cd8f02014-05-29 20:56:02316
James Robinson060f2e32014-09-10 22:31:37317 deps = [
318 ":sandbox_services",
319 "//base",
320 ]
321 }
[email protected]75cd8f02014-05-29 20:56:02322}
323
324if (is_android) {
325 # TODO(GYP) enable this. Needs an android_strip wrapper python script.
326 #action("sandbox_linux_unittests_stripped") {
327 # script = "android_stip.py"
328 #
329 # in_file = "$root_out_dir/sandbox_linux_unittests"
330 #
331 # out_file = "$root_out_dir/sandbox_linux_unittests_stripped"
332 # outputs = [ out_file ]
333 #
334 # args = [
335 # rebase_path(in_file, root_build_dir),
336 # "-o", rebase_path(out_file, root_build_dir),
337 # ]
338 #
339 # deps = [
340 # ":sandbox_linux_unittests",
341 # ]
342 #}
[email protected]75cd8f02014-05-29 20:56:02343 # TODO(GYP) convert this.
344 # {
345 # 'target_name': 'sandbox_linux_jni_unittests_apk',
346 # 'type': 'none',
347 # 'variables': {
348 # 'test_suite_name': 'sandbox_linux_jni_unittests',
349 # },
350 # 'dependencies': [
351 # 'sandbox_linux_jni_unittests',
352 # ],
353 # 'includes': [ '../../build/apk_test.gypi' ],
354 # }
355}