blob: b5cfcdb948086e30aea6db2f49443a2c1bcaed11 [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",
hidehiko7349c252014-11-26 20:30:01117 "services/proc_util_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02118 "services/unix_domain_socket_unittest.cc",
119 ]
120 }
121}
122
123# TODO(GYP) Android version of this test.
124# {
125# # This target is the shared library used by Android APK (i.e.
126# # JNI-friendly) tests.
127# "target_name": "sandbox_linux_jni_unittests",
128# "includes": [
129# "sandbox_linux_test_sources.gypi",
130# ],
131# "type": "shared_library",
132# "conditions": [
133# [ "OS == "android"", {
134# "dependencies": [
135# "../testing/android/native_test.gyp:native_test_native_code",
136# ],
137# }],
138# ],
139# },
140
141component("seccomp_bpf") {
142 sources = [
[email protected]fb75e2a2014-07-17 07:24:58143 "bpf_dsl/bpf_dsl.cc",
144 "bpf_dsl/bpf_dsl.h",
mdempskyc60a1c52014-10-24 23:07:10145 "bpf_dsl/bpf_dsl_forward.h",
mdempskyfb10cce2014-10-14 17:56:44146 "bpf_dsl/bpf_dsl_impl.h",
[email protected]fb75e2a2014-07-17 07:24:58147 "bpf_dsl/cons.h",
mdempskya41c4042014-10-31 20:50:27148 "bpf_dsl/dump_bpf.cc",
149 "bpf_dsl/dump_bpf.h",
mdempskyc60a1c52014-10-24 23:07:10150 "bpf_dsl/policy.cc",
151 "bpf_dsl/policy.h",
mdempsky27e78ad72014-10-16 16:49:54152 "bpf_dsl/policy_compiler.cc",
153 "bpf_dsl/policy_compiler.h",
154 "bpf_dsl/trap_registry.h",
[email protected]75cd8f02014-05-29 20:56:02155 "seccomp-bpf/codegen.cc",
156 "seccomp-bpf/codegen.h",
157 "seccomp-bpf/die.cc",
158 "seccomp-bpf/die.h",
159 "seccomp-bpf/errorcode.cc",
160 "seccomp-bpf/errorcode.h",
[email protected]75cd8f02014-05-29 20:56:02161 "seccomp-bpf/linux_seccomp.h",
162 "seccomp-bpf/sandbox_bpf.cc",
163 "seccomp-bpf/sandbox_bpf.h",
[email protected]75cd8f02014-05-29 20:56:02164 "seccomp-bpf/syscall.cc",
165 "seccomp-bpf/syscall.h",
166 "seccomp-bpf/syscall_iterator.cc",
167 "seccomp-bpf/syscall_iterator.h",
168 "seccomp-bpf/trap.cc",
169 "seccomp-bpf/trap.h",
170 "seccomp-bpf/verifier.cc",
171 "seccomp-bpf/verifier.h",
172 ]
173 defines = [ "SANDBOX_IMPLEMENTATION" ]
174
175 deps = [
jlnbd4df41c2014-11-25 02:32:30176 ":sandbox_services",
[email protected]75cd8f02014-05-29 20:56:02177 ":sandbox_services_headers",
178 "//base",
179 ]
180}
181
182component("seccomp_bpf_helpers") {
183 sources = [
184 "seccomp-bpf-helpers/baseline_policy.cc",
185 "seccomp-bpf-helpers/baseline_policy.h",
186 "seccomp-bpf-helpers/sigsys_handlers.cc",
187 "seccomp-bpf-helpers/sigsys_handlers.h",
188 "seccomp-bpf-helpers/syscall_parameters_restrictions.cc",
189 "seccomp-bpf-helpers/syscall_parameters_restrictions.h",
190 "seccomp-bpf-helpers/syscall_sets.cc",
191 "seccomp-bpf-helpers/syscall_sets.h",
192 ]
193 defines = [ "SANDBOX_IMPLEMENTATION" ]
194
195 deps = [
196 "//base",
jamesr4359db72015-01-21 12:40:00197 ":sandbox_services",
[email protected]75cd8f02014-05-29 20:56:02198 ":seccomp_bpf",
199 ]
200}
201
James Robinson060f2e32014-09-10 22:31:37202if (is_linux) {
scottmg34fb7e52014-12-03 23:27:24203 # The setuid sandbox for Linux.
James Robinson060f2e32014-09-10 22:31:37204 executable("chrome_sandbox") {
205 sources = [
206 "suid/common/sandbox.h",
207 "suid/common/suid_unsafe_environment_variables.h",
James Robinson060f2e32014-09-10 22:31:37208 "suid/process_util.h",
209 "suid/process_util_linux.c",
210 "suid/sandbox.c",
211 ]
[email protected]75cd8f02014-05-29 20:56:02212
James Robinson060f2e32014-09-10 22:31:37213 cflags = [
214 # For ULLONG_MAX
215 "-std=gnu99",
scottmg34fb7e52014-12-03 23:27:24216
James Robinson060f2e32014-09-10 22:31:37217 # These files have a suspicious comparison.
218 # TODO fix this and re-enable this warning.
219 "-Wno-sign-compare",
220 ]
221 }
[email protected]75cd8f02014-05-29 20:56:02222}
223
224component("sandbox_services") {
225 sources = [
[email protected]75cd8f02014-05-29 20:56:02226 "services/init_process_reaper.cc",
227 "services/init_process_reaper.h",
228 "services/scoped_process.cc",
229 "services/scoped_process.h",
jln610a4a612014-11-20 18:58:21230 "services/syscall_wrappers.cc",
231 "services/syscall_wrappers.h",
[email protected]75cd8f02014-05-29 20:56:02232 "services/thread_helpers.cc",
233 "services/thread_helpers.h",
234 "services/yama.h",
235 "services/yama.cc",
jln878dca32014-11-11 07:43:57236 "syscall_broker/broker_channel.cc",
237 "syscall_broker/broker_channel.h",
jln70c42c202014-11-01 00:59:57238 "syscall_broker/broker_client.cc",
239 "syscall_broker/broker_client.h",
240 "syscall_broker/broker_common.h",
leecamad78f422014-11-26 22:08:45241 "syscall_broker/broker_file_permission.cc",
242 "syscall_broker/broker_file_permission.h",
jln70c42c202014-11-01 00:59:57243 "syscall_broker/broker_host.cc",
244 "syscall_broker/broker_host.h",
245 "syscall_broker/broker_policy.cc",
246 "syscall_broker/broker_policy.h",
247 "syscall_broker/broker_process.cc",
248 "syscall_broker/broker_process.h",
[email protected]75cd8f02014-05-29 20:56:02249 ]
250
251 defines = [ "SANDBOX_IMPLEMENTATION" ]
252
253 if (compile_credentials) {
254 sources += [
255 "services/credentials.cc",
256 "services/credentials.h",
hidehiko7349c252014-11-26 20:30:01257 "services/proc_util.cc",
258 "services/proc_util.h",
[email protected]75cd8f02014-05-29 20:56:02259 ]
scottmg34fb7e52014-12-03 23:27:24260
[email protected]75cd8f02014-05-29 20:56:02261 # For capabilities.cc.
262 configs += [ "//build/config/linux:libcap" ]
263 }
264
265 deps = [
266 "//base",
267 ]
268}
269
270source_set("sandbox_services_headers") {
271 sources = [
272 "services/android_arm_ucontext.h",
leecame6f6b732014-08-24 23:38:09273 "services/android_arm64_ucontext.h",
[email protected]9de395e42014-06-04 22:25:28274 "services/android_futex.h",
[email protected]75cd8f02014-05-29 20:56:02275 "services/android_ucontext.h",
276 "services/android_i386_ucontext.h",
277 "services/arm_linux_syscalls.h",
leecame6f6b732014-08-24 23:38:09278 "services/arm64_linux_syscalls.h",
[email protected]75cd8f02014-05-29 20:56:02279 "services/linux_syscalls.h",
280 "services/x86_32_linux_syscalls.h",
281 "services/x86_64_linux_syscalls.h",
282 ]
283}
284
285# We make this its own target so that it does not interfere with our tests.
286source_set("libc_urandom_override") {
287 sources = [
288 "services/libc_urandom_override.cc",
289 "services/libc_urandom_override.h",
290 ]
291 deps = [
292 "//base",
293 ]
294}
295
James Robinson060f2e32014-09-10 22:31:37296if (compile_suid_client) {
297 component("suid_sandbox_client") {
298 sources = [
299 "suid/common/sandbox.h",
300 "suid/common/suid_unsafe_environment_variables.h",
301 "suid/client/setuid_sandbox_client.cc",
302 "suid/client/setuid_sandbox_client.h",
303 ]
304 defines = [ "SANDBOX_IMPLEMENTATION" ]
[email protected]75cd8f02014-05-29 20:56:02305
James Robinson060f2e32014-09-10 22:31:37306 deps = [
307 ":sandbox_services",
308 "//base",
309 ]
310 }
[email protected]75cd8f02014-05-29 20:56:02311}
312
313if (is_android) {
314 # TODO(GYP) enable this. Needs an android_strip wrapper python script.
315 #action("sandbox_linux_unittests_stripped") {
316 # script = "android_stip.py"
317 #
318 # in_file = "$root_out_dir/sandbox_linux_unittests"
319 #
320 # out_file = "$root_out_dir/sandbox_linux_unittests_stripped"
321 # outputs = [ out_file ]
322 #
323 # args = [
324 # rebase_path(in_file, root_build_dir),
325 # "-o", rebase_path(out_file, root_build_dir),
326 # ]
327 #
328 # deps = [
329 # ":sandbox_linux_unittests",
330 # ]
331 #}
[email protected]75cd8f02014-05-29 20:56:02332 # TODO(GYP) convert this.
333 # {
334 # 'target_name': 'sandbox_linux_jni_unittests_apk',
335 # 'type': 'none',
336 # 'variables': {
337 # 'test_suite_name': 'sandbox_linux_jni_unittests',
338 # },
339 # 'dependencies': [
340 # 'sandbox_linux_jni_unittests',
341 # ],
342 # 'includes': [ '../../build/apk_test.gypi' ],
343 # }
344}