[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 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. |
| 4 | |
| 5 | import("//build/config/features.gni") |
qsr | fb5251d1 | 2015-01-21 15:57:22 | [diff] [blame] | 6 | import("//testing/test.gni") |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 7 | |
| 8 | declare_args() { |
| 9 | compile_suid_client = is_linux |
| 10 | |
| 11 | compile_credentials = is_linux |
| 12 | |
| 13 | compile_seccomp_bpf_demo = |
scottmg | 34fb7e5 | 2014-12-03 23:27:24 | [diff] [blame] | 14 | is_linux && (cpu_arch == "x86" || cpu_arch == "x64") |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 15 | } |
| 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 | |
| 22 | group("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 | |
| 38 | source_set("sandbox_linux_test_utils") { |
Brett Wilson | 0c8745a | 2014-09-08 22:59:49 | [diff] [blame] | 39 | testonly = true |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 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 | ] |
| 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 | ] |
scottmg | 34fb7e5 | 2014-12-03 23:27:24 | [diff] [blame] | 62 | deps += [ ":seccomp_bpf" ] |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
| 66 | # The main sandboxing test target. |
| 67 | test("sandbox_linux_unittests") { |
| 68 | sources = [ |
jln | b14fc80 | 2015-02-12 05:32:11 | [diff] [blame^] | 69 | "services/proc_util_unittest.cc", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 70 | "services/scoped_process_unittest.cc", |
jln | c420f0d | 2014-11-22 01:12:09 | [diff] [blame] | 71 | "services/syscall_wrappers_unittest.cc", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 72 | "services/thread_helpers_unittests.cc", |
| 73 | "services/yama_unittests.cc", |
leecam | ad78f42 | 2014-11-26 22:08:45 | [diff] [blame] | 74 | "syscall_broker/broker_file_permission_unittest.cc", |
jln | 70c42c20 | 2014-11-01 00:59:57 | [diff] [blame] | 75 | "syscall_broker/broker_process_unittest.cc", |
[email protected] | 232f6e11 | 2014-06-27 07:51:38 | [diff] [blame] | 76 | "tests/main.cc", |
| 77 | "tests/scoped_temporary_file.cc", |
| 78 | "tests/scoped_temporary_file.h", |
| 79 | "tests/scoped_temporary_file_unittest.cc", |
jln | c420f0d | 2014-11-22 01:12:09 | [diff] [blame] | 80 | "tests/test_utils_unittest.cc", |
[email protected] | 232f6e11 | 2014-06-27 07:51:38 | [diff] [blame] | 81 | "tests/unit_tests_unittest.cc", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 82 | ] |
| 83 | |
| 84 | deps = [ |
| 85 | ":sandbox", |
| 86 | ":sandbox_linux_test_utils", |
| 87 | "//base", |
| 88 | "//base/test:test_support", |
| 89 | "//testing/gtest", |
| 90 | ] |
| 91 | |
Brett Wilson | 7306753 | 2014-09-12 22:24:14 | [diff] [blame] | 92 | if (is_linux) { |
| 93 | # Don't use this on Android. |
| 94 | libs = [ "rt" ] |
| 95 | } |
Brett Wilson | e3934435 | 2014-09-12 21:07:26 | [diff] [blame] | 96 | |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 97 | if (compile_suid_client) { |
mdempsky | 3cc942a | 2015-02-05 03:29:25 | [diff] [blame] | 98 | sources += [ |
| 99 | "suid/client/setuid_sandbox_client_unittest.cc", |
| 100 | "suid/client/setuid_sandbox_host_unittest.cc", |
| 101 | ] |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 102 | } |
| 103 | if (use_seccomp_bpf) { |
| 104 | sources += [ |
[email protected] | fb75e2a | 2014-07-17 07:24:58 | [diff] [blame] | 105 | "bpf_dsl/bpf_dsl_unittest.cc", |
mdempsky | b80b1f5 | 2015-02-05 00:54:35 | [diff] [blame] | 106 | "bpf_dsl/codegen_unittest.cc", |
[email protected] | fb75e2a | 2014-07-17 07:24:58 | [diff] [blame] | 107 | "bpf_dsl/cons_unittest.cc", |
mdempsky | ce4c9f1 | 2015-02-05 06:23:05 | [diff] [blame] | 108 | "bpf_dsl/syscall_set_unittest.cc", |
jln | aedcc3e | 2015-02-12 03:18:10 | [diff] [blame] | 109 | "integration_tests/bpf_dsl_seccomp_unittest.cc", |
| 110 | "integration_tests/seccomp_broker_process_unittest.cc", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 111 | "seccomp-bpf-helpers/baseline_policy_unittest.cc", |
jln | fcdfb10 | 2014-09-12 02:47:44 | [diff] [blame] | 112 | "seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 113 | "seccomp-bpf/bpf_tests_unittest.cc", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 114 | "seccomp-bpf/errorcode_unittest.cc", |
jln | a29d0a3 | 2014-11-26 22:38:35 | [diff] [blame] | 115 | "seccomp-bpf/sandbox_bpf_unittest.cc", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 116 | "seccomp-bpf/syscall_unittest.cc", |
| 117 | ] |
| 118 | } |
| 119 | if (compile_credentials) { |
| 120 | sources += [ |
jln | aedcc3e | 2015-02-12 03:18:10 | [diff] [blame] | 121 | "integration_tests/namespace_unix_domain_socket_unittest.cc", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 122 | "services/credentials_unittest.cc", |
rickyz | 8f235da | 2015-02-03 07:26:19 | [diff] [blame] | 123 | "services/namespace_sandbox_unittest.cc", |
rickyz | 41fb145 | 2015-01-27 03:57:58 | [diff] [blame] | 124 | "services/namespace_utils_unittest.cc", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 125 | ] |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | # TODO(GYP) Android version of this test. |
| 130 | # { |
| 131 | # # This target is the shared library used by Android APK (i.e. |
| 132 | # # JNI-friendly) tests. |
| 133 | # "target_name": "sandbox_linux_jni_unittests", |
| 134 | # "includes": [ |
| 135 | # "sandbox_linux_test_sources.gypi", |
| 136 | # ], |
| 137 | # "type": "shared_library", |
| 138 | # "conditions": [ |
| 139 | # [ "OS == "android"", { |
| 140 | # "dependencies": [ |
| 141 | # "../testing/android/native_test.gyp:native_test_native_code", |
| 142 | # ], |
| 143 | # }], |
| 144 | # ], |
| 145 | # }, |
| 146 | |
| 147 | component("seccomp_bpf") { |
| 148 | sources = [ |
[email protected] | fb75e2a | 2014-07-17 07:24:58 | [diff] [blame] | 149 | "bpf_dsl/bpf_dsl.cc", |
| 150 | "bpf_dsl/bpf_dsl.h", |
mdempsky | c60a1c5 | 2014-10-24 23:07:10 | [diff] [blame] | 151 | "bpf_dsl/bpf_dsl_forward.h", |
mdempsky | fb10cce | 2014-10-14 17:56:44 | [diff] [blame] | 152 | "bpf_dsl/bpf_dsl_impl.h", |
mdempsky | b80b1f5 | 2015-02-05 00:54:35 | [diff] [blame] | 153 | "bpf_dsl/codegen.cc", |
| 154 | "bpf_dsl/codegen.h", |
[email protected] | fb75e2a | 2014-07-17 07:24:58 | [diff] [blame] | 155 | "bpf_dsl/cons.h", |
mdempsky | a41c404 | 2014-10-31 20:50:27 | [diff] [blame] | 156 | "bpf_dsl/dump_bpf.cc", |
| 157 | "bpf_dsl/dump_bpf.h", |
mdempsky | c60a1c5 | 2014-10-24 23:07:10 | [diff] [blame] | 158 | "bpf_dsl/policy.cc", |
| 159 | "bpf_dsl/policy.h", |
mdempsky | 27e78ad7 | 2014-10-16 16:49:54 | [diff] [blame] | 160 | "bpf_dsl/policy_compiler.cc", |
| 161 | "bpf_dsl/policy_compiler.h", |
mdempsky | ce4c9f1 | 2015-02-05 06:23:05 | [diff] [blame] | 162 | "bpf_dsl/syscall_set.cc", |
| 163 | "bpf_dsl/syscall_set.h", |
mdempsky | 27e78ad7 | 2014-10-16 16:49:54 | [diff] [blame] | 164 | "bpf_dsl/trap_registry.h", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 165 | "seccomp-bpf/die.cc", |
| 166 | "seccomp-bpf/die.h", |
| 167 | "seccomp-bpf/errorcode.cc", |
| 168 | "seccomp-bpf/errorcode.h", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 169 | "seccomp-bpf/linux_seccomp.h", |
| 170 | "seccomp-bpf/sandbox_bpf.cc", |
| 171 | "seccomp-bpf/sandbox_bpf.h", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 172 | "seccomp-bpf/syscall.cc", |
| 173 | "seccomp-bpf/syscall.h", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 174 | "seccomp-bpf/trap.cc", |
| 175 | "seccomp-bpf/trap.h", |
| 176 | "seccomp-bpf/verifier.cc", |
| 177 | "seccomp-bpf/verifier.h", |
| 178 | ] |
| 179 | defines = [ "SANDBOX_IMPLEMENTATION" ] |
| 180 | |
| 181 | deps = [ |
jln | bd4df41c | 2014-11-25 02:32:30 | [diff] [blame] | 182 | ":sandbox_services", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 183 | ":sandbox_services_headers", |
| 184 | "//base", |
| 185 | ] |
| 186 | } |
| 187 | |
| 188 | component("seccomp_bpf_helpers") { |
| 189 | sources = [ |
| 190 | "seccomp-bpf-helpers/baseline_policy.cc", |
| 191 | "seccomp-bpf-helpers/baseline_policy.h", |
| 192 | "seccomp-bpf-helpers/sigsys_handlers.cc", |
| 193 | "seccomp-bpf-helpers/sigsys_handlers.h", |
| 194 | "seccomp-bpf-helpers/syscall_parameters_restrictions.cc", |
| 195 | "seccomp-bpf-helpers/syscall_parameters_restrictions.h", |
| 196 | "seccomp-bpf-helpers/syscall_sets.cc", |
| 197 | "seccomp-bpf-helpers/syscall_sets.h", |
| 198 | ] |
| 199 | defines = [ "SANDBOX_IMPLEMENTATION" ] |
| 200 | |
| 201 | deps = [ |
| 202 | "//base", |
jamesr | 4359db7 | 2015-01-21 12:40:00 | [diff] [blame] | 203 | ":sandbox_services", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 204 | ":seccomp_bpf", |
| 205 | ] |
| 206 | } |
| 207 | |
James Robinson | 060f2e3 | 2014-09-10 22:31:37 | [diff] [blame] | 208 | if (is_linux) { |
scottmg | 34fb7e5 | 2014-12-03 23:27:24 | [diff] [blame] | 209 | # The setuid sandbox for Linux. |
James Robinson | 060f2e3 | 2014-09-10 22:31:37 | [diff] [blame] | 210 | executable("chrome_sandbox") { |
| 211 | sources = [ |
| 212 | "suid/common/sandbox.h", |
| 213 | "suid/common/suid_unsafe_environment_variables.h", |
James Robinson | 060f2e3 | 2014-09-10 22:31:37 | [diff] [blame] | 214 | "suid/process_util.h", |
| 215 | "suid/process_util_linux.c", |
| 216 | "suid/sandbox.c", |
| 217 | ] |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 218 | |
James Robinson | 060f2e3 | 2014-09-10 22:31:37 | [diff] [blame] | 219 | cflags = [ |
| 220 | # For ULLONG_MAX |
| 221 | "-std=gnu99", |
scottmg | 34fb7e5 | 2014-12-03 23:27:24 | [diff] [blame] | 222 | |
James Robinson | 060f2e3 | 2014-09-10 22:31:37 | [diff] [blame] | 223 | # These files have a suspicious comparison. |
| 224 | # TODO fix this and re-enable this warning. |
| 225 | "-Wno-sign-compare", |
| 226 | ] |
| 227 | } |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | component("sandbox_services") { |
| 231 | sources = [ |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 232 | "services/init_process_reaper.cc", |
| 233 | "services/init_process_reaper.h", |
jln | b14fc80 | 2015-02-12 05:32:11 | [diff] [blame^] | 234 | "services/proc_util.cc", |
| 235 | "services/proc_util.h", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 236 | "services/scoped_process.cc", |
| 237 | "services/scoped_process.h", |
jln | 610a4a61 | 2014-11-20 18:58:21 | [diff] [blame] | 238 | "services/syscall_wrappers.cc", |
| 239 | "services/syscall_wrappers.h", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 240 | "services/thread_helpers.cc", |
| 241 | "services/thread_helpers.h", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 242 | "services/yama.cc", |
jln | b14fc80 | 2015-02-12 05:32:11 | [diff] [blame^] | 243 | "services/yama.h", |
jln | 878dca3 | 2014-11-11 07:43:57 | [diff] [blame] | 244 | "syscall_broker/broker_channel.cc", |
| 245 | "syscall_broker/broker_channel.h", |
jln | 70c42c20 | 2014-11-01 00:59:57 | [diff] [blame] | 246 | "syscall_broker/broker_client.cc", |
| 247 | "syscall_broker/broker_client.h", |
| 248 | "syscall_broker/broker_common.h", |
leecam | ad78f42 | 2014-11-26 22:08:45 | [diff] [blame] | 249 | "syscall_broker/broker_file_permission.cc", |
| 250 | "syscall_broker/broker_file_permission.h", |
jln | 70c42c20 | 2014-11-01 00:59:57 | [diff] [blame] | 251 | "syscall_broker/broker_host.cc", |
| 252 | "syscall_broker/broker_host.h", |
| 253 | "syscall_broker/broker_policy.cc", |
| 254 | "syscall_broker/broker_policy.h", |
| 255 | "syscall_broker/broker_process.cc", |
| 256 | "syscall_broker/broker_process.h", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 257 | ] |
| 258 | |
| 259 | defines = [ "SANDBOX_IMPLEMENTATION" ] |
| 260 | |
| 261 | if (compile_credentials) { |
| 262 | sources += [ |
| 263 | "services/credentials.cc", |
| 264 | "services/credentials.h", |
rickyz | 8f235da | 2015-02-03 07:26:19 | [diff] [blame] | 265 | "services/namespace_sandbox.cc", |
| 266 | "services/namespace_sandbox.h", |
rickyz | 41fb145 | 2015-01-27 03:57:58 | [diff] [blame] | 267 | "services/namespace_utils.cc", |
| 268 | "services/namespace_utils.h", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 269 | ] |
scottmg | 34fb7e5 | 2014-12-03 23:27:24 | [diff] [blame] | 270 | |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 271 | # For capabilities.cc. |
| 272 | configs += [ "//build/config/linux:libcap" ] |
| 273 | } |
| 274 | |
| 275 | deps = [ |
| 276 | "//base", |
| 277 | ] |
| 278 | } |
| 279 | |
| 280 | source_set("sandbox_services_headers") { |
| 281 | sources = [ |
jln | aedcc3e | 2015-02-12 03:18:10 | [diff] [blame] | 282 | "system_headers/android_arm_ucontext.h", |
| 283 | "system_headers/android_arm64_ucontext.h", |
| 284 | "system_headers/android_futex.h", |
| 285 | "system_headers/android_ucontext.h", |
| 286 | "system_headers/android_i386_ucontext.h", |
| 287 | "system_headers/arm_linux_syscalls.h", |
| 288 | "system_headers/arm64_linux_syscalls.h", |
| 289 | "system_headers/linux_syscalls.h", |
| 290 | "system_headers/x86_32_linux_syscalls.h", |
| 291 | "system_headers/x86_64_linux_syscalls.h", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 292 | ] |
| 293 | } |
| 294 | |
| 295 | # We make this its own target so that it does not interfere with our tests. |
| 296 | source_set("libc_urandom_override") { |
| 297 | sources = [ |
| 298 | "services/libc_urandom_override.cc", |
| 299 | "services/libc_urandom_override.h", |
| 300 | ] |
| 301 | deps = [ |
| 302 | "//base", |
| 303 | ] |
| 304 | } |
| 305 | |
James Robinson | 060f2e3 | 2014-09-10 22:31:37 | [diff] [blame] | 306 | if (compile_suid_client) { |
| 307 | component("suid_sandbox_client") { |
| 308 | sources = [ |
| 309 | "suid/common/sandbox.h", |
| 310 | "suid/common/suid_unsafe_environment_variables.h", |
| 311 | "suid/client/setuid_sandbox_client.cc", |
| 312 | "suid/client/setuid_sandbox_client.h", |
mdempsky | 3cc942a | 2015-02-05 03:29:25 | [diff] [blame] | 313 | "suid/client/setuid_sandbox_host.cc", |
| 314 | "suid/client/setuid_sandbox_host.h", |
James Robinson | 060f2e3 | 2014-09-10 22:31:37 | [diff] [blame] | 315 | ] |
| 316 | defines = [ "SANDBOX_IMPLEMENTATION" ] |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 317 | |
James Robinson | 060f2e3 | 2014-09-10 22:31:37 | [diff] [blame] | 318 | deps = [ |
| 319 | ":sandbox_services", |
| 320 | "//base", |
| 321 | ] |
| 322 | } |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | if (is_android) { |
| 326 | # TODO(GYP) enable this. Needs an android_strip wrapper python script. |
| 327 | #action("sandbox_linux_unittests_stripped") { |
| 328 | # script = "android_stip.py" |
| 329 | # |
| 330 | # in_file = "$root_out_dir/sandbox_linux_unittests" |
| 331 | # |
| 332 | # out_file = "$root_out_dir/sandbox_linux_unittests_stripped" |
| 333 | # outputs = [ out_file ] |
| 334 | # |
| 335 | # args = [ |
| 336 | # rebase_path(in_file, root_build_dir), |
| 337 | # "-o", rebase_path(out_file, root_build_dir), |
| 338 | # ] |
| 339 | # |
| 340 | # deps = [ |
| 341 | # ":sandbox_linux_unittests", |
| 342 | # ] |
| 343 | #} |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 344 | # TODO(GYP) convert this. |
| 345 | # { |
| 346 | # 'target_name': 'sandbox_linux_jni_unittests_apk', |
| 347 | # 'type': 'none', |
| 348 | # 'variables': { |
| 349 | # 'test_suite_name': 'sandbox_linux_jni_unittests', |
| 350 | # }, |
| 351 | # 'dependencies': [ |
| 352 | # 'sandbox_linux_jni_unittests', |
| 353 | # ], |
| 354 | # 'includes': [ '../../build/apk_test.gypi' ], |
| 355 | # } |
| 356 | } |