blob: af3a95063997a2d9962978df5a17b444725c1eb0 [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")
6
7declare_args() {
8 compile_suid_client = is_linux
9
10 compile_credentials = is_linux
11
12 compile_seccomp_bpf_demo =
scottmg34fb7e52014-12-03 23:27:2413 is_linux && (cpu_arch == "x86" || cpu_arch == "x64")
[email protected]75cd8f02014-05-29 20:56:0214}
15
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.
20
21group("sandbox") {
22 deps = [
23 ":sandbox_services",
24 ]
25
26 if (compile_suid_client) {
27 deps += [ ":suid_sandbox_client" ]
28 }
29 if (use_seccomp_bpf) {
30 deps += [
31 ":seccomp_bpf",
32 ":seccomp_bpf_helpers",
33 ]
34 }
35}
36
37source_set("sandbox_linux_test_utils") {
Brett Wilson0c8745a2014-09-08 22:59:4938 testonly = true
[email protected]75cd8f02014-05-29 20:56:0239 sources = [
40 "tests/sandbox_test_runner.cc",
41 "tests/sandbox_test_runner.h",
42 "tests/sandbox_test_runner_function_pointer.cc",
43 "tests/sandbox_test_runner_function_pointer.h",
44 "tests/test_utils.cc",
45 "tests/test_utils.h",
46 "tests/unit_tests.cc",
47 "tests/unit_tests.h",
48 ]
49
50 deps = [
51 "//testing/gtest",
52 ]
53
54 if (use_seccomp_bpf) {
55 sources += [
56 "seccomp-bpf/bpf_tester_compatibility_delegate.h",
57 "seccomp-bpf/bpf_tests.h",
58 "seccomp-bpf/sandbox_bpf_test_runner.cc",
59 "seccomp-bpf/sandbox_bpf_test_runner.h",
60 ]
scottmg34fb7e52014-12-03 23:27:2461 deps += [ ":seccomp_bpf" ]
[email protected]75cd8f02014-05-29 20:56:0262 }
63}
64
65# The main sandboxing test target.
66test("sandbox_linux_unittests") {
67 sources = [
[email protected]75cd8f02014-05-29 20:56:0268 "services/scoped_process_unittest.cc",
jlnc420f0d2014-11-22 01:12:0969 "services/syscall_wrappers_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:0270 "services/thread_helpers_unittests.cc",
71 "services/yama_unittests.cc",
leecamad78f422014-11-26 22:08:4572 "syscall_broker/broker_file_permission_unittest.cc",
jln70c42c202014-11-01 00:59:5773 "syscall_broker/broker_process_unittest.cc",
[email protected]232f6e112014-06-27 07:51:3874 "tests/main.cc",
75 "tests/scoped_temporary_file.cc",
76 "tests/scoped_temporary_file.h",
77 "tests/scoped_temporary_file_unittest.cc",
jlnc420f0d2014-11-22 01:12:0978 "tests/test_utils_unittest.cc",
[email protected]232f6e112014-06-27 07:51:3879 "tests/unit_tests_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:0280 ]
81
82 deps = [
83 ":sandbox",
84 ":sandbox_linux_test_utils",
85 "//base",
86 "//base/test:test_support",
87 "//testing/gtest",
88 ]
89
Brett Wilson73067532014-09-12 22:24:1490 if (is_linux) {
91 # Don't use this on Android.
92 libs = [ "rt" ]
93 }
Brett Wilsone39344352014-09-12 21:07:2694
[email protected]75cd8f02014-05-29 20:56:0295 if (compile_suid_client) {
scottmg34fb7e52014-12-03 23:27:2496 sources += [ "suid/client/setuid_sandbox_client_unittest.cc" ]
[email protected]75cd8f02014-05-29 20:56:0297 }
98 if (use_seccomp_bpf) {
99 sources += [
mdempsky22aa66d2014-09-13 01:41:34100 "bpf_dsl/bpf_dsl_more_unittest.cc",
[email protected]fb75e2a2014-07-17 07:24:58101 "bpf_dsl/bpf_dsl_unittest.cc",
102 "bpf_dsl/cons_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02103 "seccomp-bpf-helpers/baseline_policy_unittest.cc",
jlnfcdfb102014-09-12 02:47:44104 "seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc",
[email protected]75cd8f02014-05-29 20:56:02105 "seccomp-bpf/bpf_tests_unittest.cc",
106 "seccomp-bpf/codegen_unittest.cc",
107 "seccomp-bpf/errorcode_unittest.cc",
jlna29d0a32014-11-26 22:38:35108 "seccomp-bpf/sandbox_bpf_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02109 "seccomp-bpf/syscall_iterator_unittest.cc",
110 "seccomp-bpf/syscall_unittest.cc",
111 ]
112 }
113 if (compile_credentials) {
114 sources += [
115 "services/credentials_unittest.cc",
hidehiko7349c252014-11-26 20:30:01116 "services/proc_util_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02117 "services/unix_domain_socket_unittest.cc",
118 ]
119 }
120}
121
122# TODO(GYP) Android version of this test.
123# {
124# # This target is the shared library used by Android APK (i.e.
125# # JNI-friendly) tests.
126# "target_name": "sandbox_linux_jni_unittests",
127# "includes": [
128# "sandbox_linux_test_sources.gypi",
129# ],
130# "type": "shared_library",
131# "conditions": [
132# [ "OS == "android"", {
133# "dependencies": [
134# "../testing/android/native_test.gyp:native_test_native_code",
135# ],
136# }],
137# ],
138# },
139
140component("seccomp_bpf") {
141 sources = [
[email protected]fb75e2a2014-07-17 07:24:58142 "bpf_dsl/bpf_dsl.cc",
143 "bpf_dsl/bpf_dsl.h",
mdempskyc60a1c52014-10-24 23:07:10144 "bpf_dsl/bpf_dsl_forward.h",
mdempskyfb10cce2014-10-14 17:56:44145 "bpf_dsl/bpf_dsl_impl.h",
[email protected]fb75e2a2014-07-17 07:24:58146 "bpf_dsl/cons.h",
mdempskya41c4042014-10-31 20:50:27147 "bpf_dsl/dump_bpf.cc",
148 "bpf_dsl/dump_bpf.h",
mdempskyc60a1c52014-10-24 23:07:10149 "bpf_dsl/policy.cc",
150 "bpf_dsl/policy.h",
mdempsky27e78ad72014-10-16 16:49:54151 "bpf_dsl/policy_compiler.cc",
152 "bpf_dsl/policy_compiler.h",
153 "bpf_dsl/trap_registry.h",
[email protected]75cd8f02014-05-29 20:56:02154 "seccomp-bpf/codegen.cc",
155 "seccomp-bpf/codegen.h",
156 "seccomp-bpf/die.cc",
157 "seccomp-bpf/die.h",
158 "seccomp-bpf/errorcode.cc",
159 "seccomp-bpf/errorcode.h",
[email protected]75cd8f02014-05-29 20:56:02160 "seccomp-bpf/linux_seccomp.h",
161 "seccomp-bpf/sandbox_bpf.cc",
162 "seccomp-bpf/sandbox_bpf.h",
[email protected]75cd8f02014-05-29 20:56:02163 "seccomp-bpf/syscall.cc",
164 "seccomp-bpf/syscall.h",
165 "seccomp-bpf/syscall_iterator.cc",
166 "seccomp-bpf/syscall_iterator.h",
167 "seccomp-bpf/trap.cc",
168 "seccomp-bpf/trap.h",
169 "seccomp-bpf/verifier.cc",
170 "seccomp-bpf/verifier.h",
171 ]
172 defines = [ "SANDBOX_IMPLEMENTATION" ]
173
174 deps = [
jlnbd4df41c2014-11-25 02:32:30175 ":sandbox_services",
[email protected]75cd8f02014-05-29 20:56:02176 ":sandbox_services_headers",
177 "//base",
178 ]
179}
180
181component("seccomp_bpf_helpers") {
182 sources = [
183 "seccomp-bpf-helpers/baseline_policy.cc",
184 "seccomp-bpf-helpers/baseline_policy.h",
185 "seccomp-bpf-helpers/sigsys_handlers.cc",
186 "seccomp-bpf-helpers/sigsys_handlers.h",
187 "seccomp-bpf-helpers/syscall_parameters_restrictions.cc",
188 "seccomp-bpf-helpers/syscall_parameters_restrictions.h",
189 "seccomp-bpf-helpers/syscall_sets.cc",
190 "seccomp-bpf-helpers/syscall_sets.h",
191 ]
192 defines = [ "SANDBOX_IMPLEMENTATION" ]
193
194 deps = [
195 "//base",
196 ":seccomp_bpf",
197 ]
198}
199
James Robinson060f2e32014-09-10 22:31:37200if (is_linux) {
scottmg34fb7e52014-12-03 23:27:24201 # The setuid sandbox for Linux.
James Robinson060f2e32014-09-10 22:31:37202 executable("chrome_sandbox") {
203 sources = [
204 "suid/common/sandbox.h",
205 "suid/common/suid_unsafe_environment_variables.h",
James Robinson060f2e32014-09-10 22:31:37206 "suid/process_util.h",
207 "suid/process_util_linux.c",
208 "suid/sandbox.c",
209 ]
[email protected]75cd8f02014-05-29 20:56:02210
James Robinson060f2e32014-09-10 22:31:37211 cflags = [
212 # For ULLONG_MAX
213 "-std=gnu99",
scottmg34fb7e52014-12-03 23:27:24214
James Robinson060f2e32014-09-10 22:31:37215 # These files have a suspicious comparison.
216 # TODO fix this and re-enable this warning.
217 "-Wno-sign-compare",
218 ]
219 }
[email protected]75cd8f02014-05-29 20:56:02220}
221
222component("sandbox_services") {
223 sources = [
[email protected]75cd8f02014-05-29 20:56:02224 "services/init_process_reaper.cc",
225 "services/init_process_reaper.h",
226 "services/scoped_process.cc",
227 "services/scoped_process.h",
jln610a4a612014-11-20 18:58:21228 "services/syscall_wrappers.cc",
229 "services/syscall_wrappers.h",
[email protected]75cd8f02014-05-29 20:56:02230 "services/thread_helpers.cc",
231 "services/thread_helpers.h",
232 "services/yama.h",
233 "services/yama.cc",
jln878dca32014-11-11 07:43:57234 "syscall_broker/broker_channel.cc",
235 "syscall_broker/broker_channel.h",
jln70c42c202014-11-01 00:59:57236 "syscall_broker/broker_client.cc",
237 "syscall_broker/broker_client.h",
238 "syscall_broker/broker_common.h",
leecamad78f422014-11-26 22:08:45239 "syscall_broker/broker_file_permission.cc",
240 "syscall_broker/broker_file_permission.h",
jln70c42c202014-11-01 00:59:57241 "syscall_broker/broker_host.cc",
242 "syscall_broker/broker_host.h",
243 "syscall_broker/broker_policy.cc",
244 "syscall_broker/broker_policy.h",
245 "syscall_broker/broker_process.cc",
246 "syscall_broker/broker_process.h",
[email protected]75cd8f02014-05-29 20:56:02247 ]
248
249 defines = [ "SANDBOX_IMPLEMENTATION" ]
250
251 if (compile_credentials) {
252 sources += [
253 "services/credentials.cc",
254 "services/credentials.h",
hidehiko7349c252014-11-26 20:30:01255 "services/proc_util.cc",
256 "services/proc_util.h",
[email protected]75cd8f02014-05-29 20:56:02257 ]
scottmg34fb7e52014-12-03 23:27:24258
[email protected]75cd8f02014-05-29 20:56:02259 # For capabilities.cc.
260 configs += [ "//build/config/linux:libcap" ]
261 }
262
263 deps = [
264 "//base",
265 ]
266}
267
268source_set("sandbox_services_headers") {
269 sources = [
270 "services/android_arm_ucontext.h",
leecame6f6b732014-08-24 23:38:09271 "services/android_arm64_ucontext.h",
[email protected]9de395e42014-06-04 22:25:28272 "services/android_futex.h",
[email protected]75cd8f02014-05-29 20:56:02273 "services/android_ucontext.h",
274 "services/android_i386_ucontext.h",
275 "services/arm_linux_syscalls.h",
leecame6f6b732014-08-24 23:38:09276 "services/arm64_linux_syscalls.h",
[email protected]75cd8f02014-05-29 20:56:02277 "services/linux_syscalls.h",
278 "services/x86_32_linux_syscalls.h",
279 "services/x86_64_linux_syscalls.h",
280 ]
281}
282
283# We make this its own target so that it does not interfere with our tests.
284source_set("libc_urandom_override") {
285 sources = [
286 "services/libc_urandom_override.cc",
287 "services/libc_urandom_override.h",
288 ]
289 deps = [
290 "//base",
291 ]
292}
293
James Robinson060f2e32014-09-10 22:31:37294if (compile_suid_client) {
295 component("suid_sandbox_client") {
296 sources = [
297 "suid/common/sandbox.h",
298 "suid/common/suid_unsafe_environment_variables.h",
299 "suid/client/setuid_sandbox_client.cc",
300 "suid/client/setuid_sandbox_client.h",
301 ]
302 defines = [ "SANDBOX_IMPLEMENTATION" ]
[email protected]75cd8f02014-05-29 20:56:02303
James Robinson060f2e32014-09-10 22:31:37304 deps = [
305 ":sandbox_services",
306 "//base",
307 ]
308 }
[email protected]75cd8f02014-05-29 20:56:02309}
310
311if (is_android) {
312 # TODO(GYP) enable this. Needs an android_strip wrapper python script.
313 #action("sandbox_linux_unittests_stripped") {
314 # script = "android_stip.py"
315 #
316 # in_file = "$root_out_dir/sandbox_linux_unittests"
317 #
318 # out_file = "$root_out_dir/sandbox_linux_unittests_stripped"
319 # outputs = [ out_file ]
320 #
321 # args = [
322 # rebase_path(in_file, root_build_dir),
323 # "-o", rebase_path(out_file, root_build_dir),
324 # ]
325 #
326 # deps = [
327 # ":sandbox_linux_unittests",
328 # ]
329 #}
[email protected]75cd8f02014-05-29 20:56:02330 # TODO(GYP) convert this.
331 # {
332 # 'target_name': 'sandbox_linux_jni_unittests_apk',
333 # 'type': 'none',
334 # 'variables': {
335 # 'test_suite_name': 'sandbox_linux_jni_unittests',
336 # },
337 # 'dependencies': [
338 # 'sandbox_linux_jni_unittests',
339 # ],
340 # 'includes': [ '../../build/apk_test.gypi' ],
341 # }
342}