blob: 120b4b7de9c2c1ed9a2e55f64862acd6234f9c43 [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) {
scottmg34fb7e52014-12-03 23:27:2497 sources += [ "suid/client/setuid_sandbox_client_unittest.cc" ]
[email protected]75cd8f02014-05-29 20:56:0298 }
99 if (use_seccomp_bpf) {
100 sources += [
mdempsky22aa66d2014-09-13 01:41:34101 "bpf_dsl/bpf_dsl_more_unittest.cc",
[email protected]fb75e2a2014-07-17 07:24:58102 "bpf_dsl/bpf_dsl_unittest.cc",
103 "bpf_dsl/cons_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02104 "seccomp-bpf-helpers/baseline_policy_unittest.cc",
jlnfcdfb102014-09-12 02:47:44105 "seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc",
[email protected]75cd8f02014-05-29 20:56:02106 "seccomp-bpf/bpf_tests_unittest.cc",
107 "seccomp-bpf/codegen_unittest.cc",
108 "seccomp-bpf/errorcode_unittest.cc",
jlna29d0a32014-11-26 22:38:35109 "seccomp-bpf/sandbox_bpf_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02110 "seccomp-bpf/syscall_iterator_unittest.cc",
111 "seccomp-bpf/syscall_unittest.cc",
112 ]
113 }
114 if (compile_credentials) {
115 sources += [
116 "services/credentials_unittest.cc",
rickyz41fb1452015-01-27 03:57:58117 "services/namespace_utils_unittest.cc",
hidehiko7349c252014-11-26 20:30:01118 "services/proc_util_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02119 "services/unix_domain_socket_unittest.cc",
120 ]
121 }
122}
123
124# TODO(GYP) Android version of this test.
125# {
126# # This target is the shared library used by Android APK (i.e.
127# # JNI-friendly) tests.
128# "target_name": "sandbox_linux_jni_unittests",
129# "includes": [
130# "sandbox_linux_test_sources.gypi",
131# ],
132# "type": "shared_library",
133# "conditions": [
134# [ "OS == "android"", {
135# "dependencies": [
136# "../testing/android/native_test.gyp:native_test_native_code",
137# ],
138# }],
139# ],
140# },
141
142component("seccomp_bpf") {
143 sources = [
[email protected]fb75e2a2014-07-17 07:24:58144 "bpf_dsl/bpf_dsl.cc",
145 "bpf_dsl/bpf_dsl.h",
mdempskyc60a1c52014-10-24 23:07:10146 "bpf_dsl/bpf_dsl_forward.h",
mdempskyfb10cce2014-10-14 17:56:44147 "bpf_dsl/bpf_dsl_impl.h",
[email protected]fb75e2a2014-07-17 07:24:58148 "bpf_dsl/cons.h",
mdempskya41c4042014-10-31 20:50:27149 "bpf_dsl/dump_bpf.cc",
150 "bpf_dsl/dump_bpf.h",
mdempskyc60a1c52014-10-24 23:07:10151 "bpf_dsl/policy.cc",
152 "bpf_dsl/policy.h",
mdempsky27e78ad72014-10-16 16:49:54153 "bpf_dsl/policy_compiler.cc",
154 "bpf_dsl/policy_compiler.h",
155 "bpf_dsl/trap_registry.h",
[email protected]75cd8f02014-05-29 20:56:02156 "seccomp-bpf/codegen.cc",
157 "seccomp-bpf/codegen.h",
158 "seccomp-bpf/die.cc",
159 "seccomp-bpf/die.h",
160 "seccomp-bpf/errorcode.cc",
161 "seccomp-bpf/errorcode.h",
[email protected]75cd8f02014-05-29 20:56:02162 "seccomp-bpf/linux_seccomp.h",
163 "seccomp-bpf/sandbox_bpf.cc",
164 "seccomp-bpf/sandbox_bpf.h",
[email protected]75cd8f02014-05-29 20:56:02165 "seccomp-bpf/syscall.cc",
166 "seccomp-bpf/syscall.h",
167 "seccomp-bpf/syscall_iterator.cc",
168 "seccomp-bpf/syscall_iterator.h",
169 "seccomp-bpf/trap.cc",
170 "seccomp-bpf/trap.h",
171 "seccomp-bpf/verifier.cc",
172 "seccomp-bpf/verifier.h",
173 ]
174 defines = [ "SANDBOX_IMPLEMENTATION" ]
175
176 deps = [
jlnbd4df41c2014-11-25 02:32:30177 ":sandbox_services",
[email protected]75cd8f02014-05-29 20:56:02178 ":sandbox_services_headers",
179 "//base",
180 ]
181}
182
183component("seccomp_bpf_helpers") {
184 sources = [
185 "seccomp-bpf-helpers/baseline_policy.cc",
186 "seccomp-bpf-helpers/baseline_policy.h",
187 "seccomp-bpf-helpers/sigsys_handlers.cc",
188 "seccomp-bpf-helpers/sigsys_handlers.h",
189 "seccomp-bpf-helpers/syscall_parameters_restrictions.cc",
190 "seccomp-bpf-helpers/syscall_parameters_restrictions.h",
191 "seccomp-bpf-helpers/syscall_sets.cc",
192 "seccomp-bpf-helpers/syscall_sets.h",
193 ]
194 defines = [ "SANDBOX_IMPLEMENTATION" ]
195
196 deps = [
197 "//base",
jamesr4359db72015-01-21 12:40:00198 ":sandbox_services",
[email protected]75cd8f02014-05-29 20:56:02199 ":seccomp_bpf",
200 ]
201}
202
James Robinson060f2e32014-09-10 22:31:37203if (is_linux) {
scottmg34fb7e52014-12-03 23:27:24204 # The setuid sandbox for Linux.
James Robinson060f2e32014-09-10 22:31:37205 executable("chrome_sandbox") {
206 sources = [
207 "suid/common/sandbox.h",
208 "suid/common/suid_unsafe_environment_variables.h",
James Robinson060f2e32014-09-10 22:31:37209 "suid/process_util.h",
210 "suid/process_util_linux.c",
211 "suid/sandbox.c",
212 ]
[email protected]75cd8f02014-05-29 20:56:02213
James Robinson060f2e32014-09-10 22:31:37214 cflags = [
215 # For ULLONG_MAX
216 "-std=gnu99",
scottmg34fb7e52014-12-03 23:27:24217
James Robinson060f2e32014-09-10 22:31:37218 # These files have a suspicious comparison.
219 # TODO fix this and re-enable this warning.
220 "-Wno-sign-compare",
221 ]
222 }
[email protected]75cd8f02014-05-29 20:56:02223}
224
225component("sandbox_services") {
226 sources = [
[email protected]75cd8f02014-05-29 20:56:02227 "services/init_process_reaper.cc",
228 "services/init_process_reaper.h",
229 "services/scoped_process.cc",
230 "services/scoped_process.h",
jln610a4a612014-11-20 18:58:21231 "services/syscall_wrappers.cc",
232 "services/syscall_wrappers.h",
[email protected]75cd8f02014-05-29 20:56:02233 "services/thread_helpers.cc",
234 "services/thread_helpers.h",
235 "services/yama.h",
236 "services/yama.cc",
jln878dca32014-11-11 07:43:57237 "syscall_broker/broker_channel.cc",
238 "syscall_broker/broker_channel.h",
jln70c42c202014-11-01 00:59:57239 "syscall_broker/broker_client.cc",
240 "syscall_broker/broker_client.h",
241 "syscall_broker/broker_common.h",
leecamad78f422014-11-26 22:08:45242 "syscall_broker/broker_file_permission.cc",
243 "syscall_broker/broker_file_permission.h",
jln70c42c202014-11-01 00:59:57244 "syscall_broker/broker_host.cc",
245 "syscall_broker/broker_host.h",
246 "syscall_broker/broker_policy.cc",
247 "syscall_broker/broker_policy.h",
248 "syscall_broker/broker_process.cc",
249 "syscall_broker/broker_process.h",
[email protected]75cd8f02014-05-29 20:56:02250 ]
251
252 defines = [ "SANDBOX_IMPLEMENTATION" ]
253
254 if (compile_credentials) {
255 sources += [
256 "services/credentials.cc",
257 "services/credentials.h",
rickyz41fb1452015-01-27 03:57:58258 "services/namespace_utils.cc",
259 "services/namespace_utils.h",
hidehiko7349c252014-11-26 20:30:01260 "services/proc_util.cc",
261 "services/proc_util.h",
[email protected]75cd8f02014-05-29 20:56:02262 ]
scottmg34fb7e52014-12-03 23:27:24263
[email protected]75cd8f02014-05-29 20:56:02264 # For capabilities.cc.
265 configs += [ "//build/config/linux:libcap" ]
266 }
267
268 deps = [
269 "//base",
270 ]
271}
272
273source_set("sandbox_services_headers") {
274 sources = [
275 "services/android_arm_ucontext.h",
leecame6f6b732014-08-24 23:38:09276 "services/android_arm64_ucontext.h",
[email protected]9de395e42014-06-04 22:25:28277 "services/android_futex.h",
[email protected]75cd8f02014-05-29 20:56:02278 "services/android_ucontext.h",
279 "services/android_i386_ucontext.h",
280 "services/arm_linux_syscalls.h",
leecame6f6b732014-08-24 23:38:09281 "services/arm64_linux_syscalls.h",
[email protected]75cd8f02014-05-29 20:56:02282 "services/linux_syscalls.h",
283 "services/x86_32_linux_syscalls.h",
284 "services/x86_64_linux_syscalls.h",
285 ]
286}
287
288# We make this its own target so that it does not interfere with our tests.
289source_set("libc_urandom_override") {
290 sources = [
291 "services/libc_urandom_override.cc",
292 "services/libc_urandom_override.h",
293 ]
294 deps = [
295 "//base",
296 ]
297}
298
James Robinson060f2e32014-09-10 22:31:37299if (compile_suid_client) {
300 component("suid_sandbox_client") {
301 sources = [
302 "suid/common/sandbox.h",
303 "suid/common/suid_unsafe_environment_variables.h",
304 "suid/client/setuid_sandbox_client.cc",
305 "suid/client/setuid_sandbox_client.h",
306 ]
307 defines = [ "SANDBOX_IMPLEMENTATION" ]
[email protected]75cd8f02014-05-29 20:56:02308
James Robinson060f2e32014-09-10 22:31:37309 deps = [
310 ":sandbox_services",
311 "//base",
312 ]
313 }
[email protected]75cd8f02014-05-29 20:56:02314}
315
316if (is_android) {
317 # TODO(GYP) enable this. Needs an android_strip wrapper python script.
318 #action("sandbox_linux_unittests_stripped") {
319 # script = "android_stip.py"
320 #
321 # in_file = "$root_out_dir/sandbox_linux_unittests"
322 #
323 # out_file = "$root_out_dir/sandbox_linux_unittests_stripped"
324 # outputs = [ out_file ]
325 #
326 # args = [
327 # rebase_path(in_file, root_build_dir),
328 # "-o", rebase_path(out_file, root_build_dir),
329 # ]
330 #
331 # deps = [
332 # ":sandbox_linux_unittests",
333 # ]
334 #}
[email protected]75cd8f02014-05-29 20:56:02335 # TODO(GYP) convert this.
336 # {
337 # 'target_name': 'sandbox_linux_jni_unittests_apk',
338 # 'type': 'none',
339 # 'variables': {
340 # 'test_suite_name': 'sandbox_linux_jni_unittests',
341 # },
342 # 'dependencies': [
343 # 'sandbox_linux_jni_unittests',
344 # ],
345 # 'includes': [ '../../build/apk_test.gypi' ],
346 # }
347}