Roll src/third_party/skia c877a71:fa77eb1
[chromium-blink-merge.git] / sandbox / linux / BUILD.gn
blobccb186a2891653e756417e76f2d248dff5ed6f13
1 # 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.
5 import("//build/config/features.gni")
6 import("//testing/test.gni")
8 declare_args() {
9   compile_suid_client = is_linux
11   compile_credentials = is_linux
13   compile_seccomp_bpf_demo =
14       is_linux && (current_cpu == "x86" || current_cpu == "x64")
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.
22 group("sandbox") {
23   deps = [
24     ":sandbox_services",
25   ]
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   }
38 source_set("sandbox_linux_test_utils") {
39   testonly = true
40   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   ]
51   deps = [
52     "//testing/gtest",
53   ]
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     ]
62     deps += [ ":seccomp_bpf" ]
63   }
66 # Sources shared by sandbox_linux_unittests and sandbox_linux_jni_unittests.
67 source_set("sandbox_linux_unittests_sources") {
68   testonly = true
70   sources = [
71     "services/proc_util_unittest.cc",
72     "services/resource_limits_unittests.cc",
73     "services/scoped_process_unittest.cc",
74     "services/syscall_wrappers_unittest.cc",
75     "services/thread_helpers_unittests.cc",
76     "services/yama_unittests.cc",
77     "syscall_broker/broker_file_permission_unittest.cc",
78     "syscall_broker/broker_process_unittest.cc",
79     "tests/main.cc",
80     "tests/scoped_temporary_file.cc",
81     "tests/scoped_temporary_file.h",
82     "tests/scoped_temporary_file_unittest.cc",
83     "tests/test_utils_unittest.cc",
84     "tests/unit_tests_unittest.cc",
85   ]
87   deps = [
88     ":sandbox",
89     ":sandbox_linux_test_utils",
90     "//base",
91     "//base/test:test_support",
92     "//testing/gtest",
93   ]
95   if (is_linux) {
96     # Don't use this on Android.
97     libs = [ "rt" ]
98   }
100   if (compile_suid_client) {
101     sources += [
102       "suid/client/setuid_sandbox_client_unittest.cc",
103       "suid/client/setuid_sandbox_host_unittest.cc",
104     ]
105   }
106   if (use_seccomp_bpf) {
107     sources += [
108       "bpf_dsl/bpf_dsl_unittest.cc",
109       "bpf_dsl/codegen_unittest.cc",
110       "bpf_dsl/cons_unittest.cc",
111       "bpf_dsl/syscall_set_unittest.cc",
112       "integration_tests/bpf_dsl_seccomp_unittest.cc",
113       "integration_tests/seccomp_broker_process_unittest.cc",
114       "seccomp-bpf-helpers/baseline_policy_unittest.cc",
115       "seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc",
116       "seccomp-bpf/bpf_tests_unittest.cc",
117       "seccomp-bpf/errorcode_unittest.cc",
118       "seccomp-bpf/sandbox_bpf_unittest.cc",
119       "seccomp-bpf/syscall_unittest.cc",
120     ]
121   }
122   if (compile_credentials) {
123     sources += [
124       "integration_tests/namespace_unix_domain_socket_unittest.cc",
125       "services/credentials_unittest.cc",
126       "services/namespace_sandbox_unittest.cc",
127       "services/namespace_utils_unittest.cc",
128     ]
129   }
132 # The main sandboxing test target.
133 test("sandbox_linux_unittests") {
134   deps = [
135     ":sandbox_linux_unittests_sources",
136   ]
139 # This target is the shared library used by Android APK (i.e.
140 # JNI-friendly) tests.
141 shared_library("sandbox_linux_jni_unittests") {
142   testonly = true
143   deps = [
144     ":sandbox_linux_unittests_sources",
145   ]
146   if (is_android) {
147     deps += [ "//testing/android:native_test_native_code" ]
148   }
151 component("seccomp_bpf") {
152   sources = [
153     "bpf_dsl/bpf_dsl.cc",
154     "bpf_dsl/bpf_dsl.h",
155     "bpf_dsl/bpf_dsl_forward.h",
156     "bpf_dsl/bpf_dsl_impl.h",
157     "bpf_dsl/codegen.cc",
158     "bpf_dsl/codegen.h",
159     "bpf_dsl/cons.h",
160     "bpf_dsl/dump_bpf.cc",
161     "bpf_dsl/dump_bpf.h",
162     "bpf_dsl/linux_syscall_ranges.h",
163     "bpf_dsl/policy.cc",
164     "bpf_dsl/policy.h",
165     "bpf_dsl/policy_compiler.cc",
166     "bpf_dsl/policy_compiler.h",
167     "bpf_dsl/seccomp_macros.h",
168     "bpf_dsl/syscall_set.cc",
169     "bpf_dsl/syscall_set.h",
170     "bpf_dsl/trap_registry.h",
171     "seccomp-bpf/die.cc",
172     "seccomp-bpf/die.h",
173     "seccomp-bpf/errorcode.cc",
174     "seccomp-bpf/errorcode.h",
175     "seccomp-bpf/sandbox_bpf.cc",
176     "seccomp-bpf/sandbox_bpf.h",
177     "seccomp-bpf/syscall.cc",
178     "seccomp-bpf/syscall.h",
179     "seccomp-bpf/trap.cc",
180     "seccomp-bpf/trap.h",
181     "seccomp-bpf/verifier.cc",
182     "seccomp-bpf/verifier.h",
183   ]
184   defines = [ "SANDBOX_IMPLEMENTATION" ]
186   deps = [
187     ":sandbox_services",
188     ":sandbox_services_headers",
189     "//base",
190   ]
193 component("seccomp_bpf_helpers") {
194   sources = [
195     "seccomp-bpf-helpers/baseline_policy.cc",
196     "seccomp-bpf-helpers/baseline_policy.h",
197     "seccomp-bpf-helpers/sigsys_handlers.cc",
198     "seccomp-bpf-helpers/sigsys_handlers.h",
199     "seccomp-bpf-helpers/syscall_parameters_restrictions.cc",
200     "seccomp-bpf-helpers/syscall_parameters_restrictions.h",
201     "seccomp-bpf-helpers/syscall_sets.cc",
202     "seccomp-bpf-helpers/syscall_sets.h",
203   ]
204   defines = [ "SANDBOX_IMPLEMENTATION" ]
206   deps = [
207     "//base",
208     ":sandbox_services",
209     ":seccomp_bpf",
210   ]
213 if (is_linux) {
214   # The setuid sandbox for Linux.
215   executable("chrome_sandbox") {
216     sources = [
217       "suid/common/sandbox.h",
218       "suid/common/suid_unsafe_environment_variables.h",
219       "suid/process_util.h",
220       "suid/process_util_linux.c",
221       "suid/sandbox.c",
222     ]
224     cflags = [
225       # For ULLONG_MAX
226       "-std=gnu99",
228       # These files have a suspicious comparison.
229       # TODO fix this and re-enable this warning.
230       "-Wno-sign-compare",
231     ]
232   }
235 component("sandbox_services") {
236   sources = [
237     "services/init_process_reaper.cc",
238     "services/init_process_reaper.h",
239     "services/proc_util.cc",
240     "services/proc_util.h",
241     "services/resource_limits.cc",
242     "services/resource_limits.h",
243     "services/scoped_process.cc",
244     "services/scoped_process.h",
245     "services/syscall_wrappers.cc",
246     "services/syscall_wrappers.h",
247     "services/thread_helpers.cc",
248     "services/thread_helpers.h",
249     "services/yama.cc",
250     "services/yama.h",
251     "syscall_broker/broker_channel.cc",
252     "syscall_broker/broker_channel.h",
253     "syscall_broker/broker_client.cc",
254     "syscall_broker/broker_client.h",
255     "syscall_broker/broker_common.h",
256     "syscall_broker/broker_file_permission.cc",
257     "syscall_broker/broker_file_permission.h",
258     "syscall_broker/broker_host.cc",
259     "syscall_broker/broker_host.h",
260     "syscall_broker/broker_policy.cc",
261     "syscall_broker/broker_policy.h",
262     "syscall_broker/broker_process.cc",
263     "syscall_broker/broker_process.h",
264   ]
266   defines = [ "SANDBOX_IMPLEMENTATION" ]
268   if (compile_credentials) {
269     sources += [
270       "services/credentials.cc",
271       "services/credentials.h",
272       "services/namespace_sandbox.cc",
273       "services/namespace_sandbox.h",
274       "services/namespace_utils.cc",
275       "services/namespace_utils.h",
276     ]
278     # For capabilities.cc.
279     configs += [ "//build/config/linux:libcap" ]
280   }
282   deps = [
283     "//base",
284   ]
287 source_set("sandbox_services_headers") {
288   sources = [
289     "system_headers/android_arm64_ucontext.h",
290     "system_headers/android_arm_ucontext.h",
291     "system_headers/android_futex.h",
292     "system_headers/android_i386_ucontext.h",
293     "system_headers/android_ucontext.h",
294     "system_headers/arm64_linux_syscalls.h",
295     "system_headers/arm_linux_syscalls.h",
296     "system_headers/linux_seccomp.h",
297     "system_headers/linux_syscalls.h",
298     "system_headers/x86_32_linux_syscalls.h",
299     "system_headers/x86_64_linux_syscalls.h",
300   ]
303 # We make this its own target so that it does not interfere with our tests.
304 source_set("libc_urandom_override") {
305   sources = [
306     "services/libc_urandom_override.cc",
307     "services/libc_urandom_override.h",
308   ]
309   deps = [
310     "//base",
311   ]
314 if (compile_suid_client) {
315   component("suid_sandbox_client") {
316     sources = [
317       "suid/client/setuid_sandbox_client.cc",
318       "suid/client/setuid_sandbox_client.h",
319       "suid/client/setuid_sandbox_host.cc",
320       "suid/client/setuid_sandbox_host.h",
321       "suid/common/sandbox.h",
322       "suid/common/suid_unsafe_environment_variables.h",
323     ]
324     defines = [ "SANDBOX_IMPLEMENTATION" ]
326     deps = [
327       ":sandbox_services",
328       "//base",
329     ]
330   }
333 if (is_android) {
334   # TODO(GYP) enable this. Needs an android_strip wrapper python script.
335   #action("sandbox_linux_unittests_stripped") {
336   #  script = "android_stip.py"
337   #
338   #  in_file = "$root_out_dir/sandbox_linux_unittests"
339   #
340   #  out_file = "$root_out_dir/sandbox_linux_unittests_stripped"
341   #  outputs = [ out_file ]
342   #
343   #  args = [
344   #    rebase_path(in_file, root_build_dir),
345   #    "-o", rebase_path(out_file, root_build_dir),
346   #  ]
347   #
348   #  deps = [
349   #    ":sandbox_linux_unittests",
350   #  ]
351   #}
352   # TODO(GYP) convert this.
353   #      {
354   #      'target_name': 'sandbox_linux_jni_unittests_apk',
355   #      'type': 'none',
356   #      'variables': {
357   #        'test_suite_name': 'sandbox_linux_jni_unittests',
358   #      },
359   #      'dependencies': [
360   #        'sandbox_linux_jni_unittests',
361   #      ],
362   #      'includes': [ '../../build/apk_test.gypi' ],
363   #      }