blob: 764875351989828b0c7e98e0f8256bf68579a77e [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 =
13 (is_linux && (cpu_arch == "x86" || cpu_arch == "x64"))
14}
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 ]
61 deps += [
62 ":seccomp_bpf",
63 ]
64 }
65}
66
67# The main sandboxing test target.
68test("sandbox_linux_unittests") {
69 sources = [
[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) {
98 sources += [
99 "suid/client/setuid_sandbox_client_unittest.cc",
100 ]
101 }
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",
106 "bpf_dsl/cons_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02107 "seccomp-bpf-helpers/baseline_policy_unittest.cc",
jlnfcdfb102014-09-12 02:47:44108 "seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc",
[email protected]75cd8f02014-05-29 20:56:02109 "seccomp-bpf/bpf_tests_unittest.cc",
110 "seccomp-bpf/codegen_unittest.cc",
111 "seccomp-bpf/errorcode_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02112 "seccomp-bpf/syscall_iterator_unittest.cc",
113 "seccomp-bpf/syscall_unittest.cc",
114 ]
115 }
116 if (compile_credentials) {
117 sources += [
118 "services/credentials_unittest.cc",
hidehiko7349c252014-11-26 20:30:01119 "services/proc_util_unittest.cc",
[email protected]75cd8f02014-05-29 20:56:02120 "services/unix_domain_socket_unittest.cc",
121 ]
122 }
123}
124
125# TODO(GYP) Android version of this test.
126# {
127# # This target is the shared library used by Android APK (i.e.
128# # JNI-friendly) tests.
129# "target_name": "sandbox_linux_jni_unittests",
130# "includes": [
131# "sandbox_linux_test_sources.gypi",
132# ],
133# "type": "shared_library",
134# "conditions": [
135# [ "OS == "android"", {
136# "dependencies": [
137# "../testing/android/native_test.gyp:native_test_native_code",
138# ],
139# }],
140# ],
141# },
142
143component("seccomp_bpf") {
144 sources = [
[email protected]fb75e2a2014-07-17 07:24:58145 "bpf_dsl/bpf_dsl.cc",
146 "bpf_dsl/bpf_dsl.h",
mdempskyc60a1c52014-10-24 23:07:10147 "bpf_dsl/bpf_dsl_forward.h",
mdempskyfb10cce2014-10-14 17:56:44148 "bpf_dsl/bpf_dsl_impl.h",
[email protected]fb75e2a2014-07-17 07:24:58149 "bpf_dsl/cons.h",
mdempskya41c4042014-10-31 20:50:27150 "bpf_dsl/dump_bpf.cc",
151 "bpf_dsl/dump_bpf.h",
mdempskyc60a1c52014-10-24 23:07:10152 "bpf_dsl/policy.cc",
153 "bpf_dsl/policy.h",
mdempsky27e78ad72014-10-16 16:49:54154 "bpf_dsl/policy_compiler.cc",
155 "bpf_dsl/policy_compiler.h",
156 "bpf_dsl/trap_registry.h",
[email protected]75cd8f02014-05-29 20:56:02157 "seccomp-bpf/codegen.cc",
158 "seccomp-bpf/codegen.h",
159 "seccomp-bpf/die.cc",
160 "seccomp-bpf/die.h",
161 "seccomp-bpf/errorcode.cc",
162 "seccomp-bpf/errorcode.h",
[email protected]75cd8f02014-05-29 20:56:02163 "seccomp-bpf/linux_seccomp.h",
164 "seccomp-bpf/sandbox_bpf.cc",
165 "seccomp-bpf/sandbox_bpf.h",
[email protected]75cd8f02014-05-29 20:56:02166 "seccomp-bpf/syscall.cc",
167 "seccomp-bpf/syscall.h",
168 "seccomp-bpf/syscall_iterator.cc",
169 "seccomp-bpf/syscall_iterator.h",
170 "seccomp-bpf/trap.cc",
171 "seccomp-bpf/trap.h",
172 "seccomp-bpf/verifier.cc",
173 "seccomp-bpf/verifier.h",
174 ]
175 defines = [ "SANDBOX_IMPLEMENTATION" ]
176
177 deps = [
jlnbd4df41c2014-11-25 02:32:30178 ":sandbox_services",
[email protected]75cd8f02014-05-29 20:56:02179 ":sandbox_services_headers",
180 "//base",
181 ]
182}
183
184component("seccomp_bpf_helpers") {
185 sources = [
186 "seccomp-bpf-helpers/baseline_policy.cc",
187 "seccomp-bpf-helpers/baseline_policy.h",
188 "seccomp-bpf-helpers/sigsys_handlers.cc",
189 "seccomp-bpf-helpers/sigsys_handlers.h",
190 "seccomp-bpf-helpers/syscall_parameters_restrictions.cc",
191 "seccomp-bpf-helpers/syscall_parameters_restrictions.h",
192 "seccomp-bpf-helpers/syscall_sets.cc",
193 "seccomp-bpf-helpers/syscall_sets.h",
194 ]
195 defines = [ "SANDBOX_IMPLEMENTATION" ]
196
197 deps = [
198 "//base",
199 ":seccomp_bpf",
200 ]
201}
202
James Robinson060f2e32014-09-10 22:31:37203if (is_linux) {
[email protected]75cd8f02014-05-29 20:56:02204# 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",
217 # 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 ]
260 # For capabilities.cc.
261 configs += [ "//build/config/linux:libcap" ]
262 }
263
264 deps = [
265 "//base",
266 ]
267}
268
269source_set("sandbox_services_headers") {
270 sources = [
271 "services/android_arm_ucontext.h",
leecame6f6b732014-08-24 23:38:09272 "services/android_arm64_ucontext.h",
[email protected]9de395e42014-06-04 22:25:28273 "services/android_futex.h",
[email protected]75cd8f02014-05-29 20:56:02274 "services/android_ucontext.h",
275 "services/android_i386_ucontext.h",
276 "services/arm_linux_syscalls.h",
leecame6f6b732014-08-24 23:38:09277 "services/arm64_linux_syscalls.h",
[email protected]75cd8f02014-05-29 20:56:02278 "services/linux_syscalls.h",
279 "services/x86_32_linux_syscalls.h",
280 "services/x86_64_linux_syscalls.h",
281 ]
282}
283
284# We make this its own target so that it does not interfere with our tests.
285source_set("libc_urandom_override") {
286 sources = [
287 "services/libc_urandom_override.cc",
288 "services/libc_urandom_override.h",
289 ]
290 deps = [
291 "//base",
292 ]
293}
294
James Robinson060f2e32014-09-10 22:31:37295if (compile_suid_client) {
296 component("suid_sandbox_client") {
297 sources = [
298 "suid/common/sandbox.h",
299 "suid/common/suid_unsafe_environment_variables.h",
300 "suid/client/setuid_sandbox_client.cc",
301 "suid/client/setuid_sandbox_client.h",
302 ]
303 defines = [ "SANDBOX_IMPLEMENTATION" ]
[email protected]75cd8f02014-05-29 20:56:02304
James Robinson060f2e32014-09-10 22:31:37305 deps = [
306 ":sandbox_services",
307 "//base",
308 ]
309 }
[email protected]75cd8f02014-05-29 20:56:02310}
311
312if (is_android) {
313 # TODO(GYP) enable this. Needs an android_strip wrapper python script.
314 #action("sandbox_linux_unittests_stripped") {
315 # script = "android_stip.py"
316 #
317 # in_file = "$root_out_dir/sandbox_linux_unittests"
318 #
319 # out_file = "$root_out_dir/sandbox_linux_unittests_stripped"
320 # outputs = [ out_file ]
321 #
322 # args = [
323 # rebase_path(in_file, root_build_dir),
324 # "-o", rebase_path(out_file, root_build_dir),
325 # ]
326 #
327 # deps = [
328 # ":sandbox_linux_unittests",
329 # ]
330 #}
331
332 # 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}