[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") |
| 6 | |
| 7 | declare_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 | |
| 21 | group("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 | |
| 37 | source_set("sandbox_linux_test_utils") { |
| 38 | sources = [ |
| 39 | "tests/sandbox_test_runner.cc", |
| 40 | "tests/sandbox_test_runner.h", |
| 41 | "tests/sandbox_test_runner_function_pointer.cc", |
| 42 | "tests/sandbox_test_runner_function_pointer.h", |
| 43 | "tests/test_utils.cc", |
| 44 | "tests/test_utils.h", |
| 45 | "tests/unit_tests.cc", |
| 46 | "tests/unit_tests.h", |
| 47 | ] |
| 48 | |
| 49 | deps = [ |
| 50 | "//testing/gtest", |
| 51 | ] |
| 52 | |
| 53 | if (use_seccomp_bpf) { |
| 54 | sources += [ |
| 55 | "seccomp-bpf/bpf_tester_compatibility_delegate.h", |
| 56 | "seccomp-bpf/bpf_tests.h", |
| 57 | "seccomp-bpf/sandbox_bpf_test_runner.cc", |
| 58 | "seccomp-bpf/sandbox_bpf_test_runner.h", |
| 59 | ] |
| 60 | deps += [ |
| 61 | ":seccomp_bpf", |
| 62 | ] |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | # The main sandboxing test target. |
| 67 | test("sandbox_linux_unittests") { |
| 68 | sources = [ |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 69 | "services/broker_process_unittest.cc", |
| 70 | "services/scoped_process_unittest.cc", |
| 71 | "services/thread_helpers_unittests.cc", |
| 72 | "services/yama_unittests.cc", |
[email protected] | 232f6e11 | 2014-06-27 07:51:38 | [diff] [blame] | 73 | "tests/main.cc", |
| 74 | "tests/scoped_temporary_file.cc", |
| 75 | "tests/scoped_temporary_file.h", |
| 76 | "tests/scoped_temporary_file_unittest.cc", |
| 77 | "tests/unit_tests_unittest.cc", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 78 | ] |
| 79 | |
| 80 | deps = [ |
| 81 | ":sandbox", |
| 82 | ":sandbox_linux_test_utils", |
| 83 | "//base", |
| 84 | "//base/test:test_support", |
| 85 | "//testing/gtest", |
| 86 | ] |
| 87 | |
| 88 | if (compile_suid_client) { |
| 89 | sources += [ |
| 90 | "suid/client/setuid_sandbox_client_unittest.cc", |
| 91 | ] |
| 92 | } |
| 93 | if (use_seccomp_bpf) { |
| 94 | sources += [ |
[email protected] | fb75e2a | 2014-07-17 07:24:58 | [diff] [blame] | 95 | "bpf_dsl/bpf_dsl_unittest.cc", |
| 96 | "bpf_dsl/cons_unittest.cc", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 97 | "seccomp-bpf-helpers/baseline_policy_unittest.cc", |
| 98 | "seccomp-bpf/bpf_tests_unittest.cc", |
| 99 | "seccomp-bpf/codegen_unittest.cc", |
| 100 | "seccomp-bpf/errorcode_unittest.cc", |
| 101 | "seccomp-bpf/sandbox_bpf_unittest.cc", |
| 102 | "seccomp-bpf/syscall_iterator_unittest.cc", |
| 103 | "seccomp-bpf/syscall_unittest.cc", |
| 104 | ] |
| 105 | } |
| 106 | if (compile_credentials) { |
| 107 | sources += [ |
| 108 | "services/credentials_unittest.cc", |
| 109 | "services/unix_domain_socket_unittest.cc", |
| 110 | ] |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | # TODO(GYP) Android version of this test. |
| 115 | # { |
| 116 | # # This target is the shared library used by Android APK (i.e. |
| 117 | # # JNI-friendly) tests. |
| 118 | # "target_name": "sandbox_linux_jni_unittests", |
| 119 | # "includes": [ |
| 120 | # "sandbox_linux_test_sources.gypi", |
| 121 | # ], |
| 122 | # "type": "shared_library", |
| 123 | # "conditions": [ |
| 124 | # [ "OS == "android"", { |
| 125 | # "dependencies": [ |
| 126 | # "../testing/android/native_test.gyp:native_test_native_code", |
| 127 | # ], |
| 128 | # }], |
| 129 | # ], |
| 130 | # }, |
| 131 | |
| 132 | component("seccomp_bpf") { |
| 133 | sources = [ |
[email protected] | fb75e2a | 2014-07-17 07:24:58 | [diff] [blame] | 134 | "bpf_dsl/bpf_dsl.cc", |
| 135 | "bpf_dsl/bpf_dsl.h", |
| 136 | "bpf_dsl/cons.h", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 137 | "seccomp-bpf/basicblock.cc", |
| 138 | "seccomp-bpf/basicblock.h", |
| 139 | "seccomp-bpf/codegen.cc", |
| 140 | "seccomp-bpf/codegen.h", |
| 141 | "seccomp-bpf/die.cc", |
| 142 | "seccomp-bpf/die.h", |
| 143 | "seccomp-bpf/errorcode.cc", |
| 144 | "seccomp-bpf/errorcode.h", |
| 145 | "seccomp-bpf/instruction.h", |
| 146 | "seccomp-bpf/linux_seccomp.h", |
| 147 | "seccomp-bpf/sandbox_bpf.cc", |
| 148 | "seccomp-bpf/sandbox_bpf.h", |
| 149 | "seccomp-bpf/sandbox_bpf_compatibility_policy.h", |
| 150 | "seccomp-bpf/sandbox_bpf_policy.cc", |
| 151 | "seccomp-bpf/sandbox_bpf_policy.h", |
| 152 | "seccomp-bpf/syscall.cc", |
| 153 | "seccomp-bpf/syscall.h", |
| 154 | "seccomp-bpf/syscall_iterator.cc", |
| 155 | "seccomp-bpf/syscall_iterator.h", |
| 156 | "seccomp-bpf/trap.cc", |
| 157 | "seccomp-bpf/trap.h", |
| 158 | "seccomp-bpf/verifier.cc", |
| 159 | "seccomp-bpf/verifier.h", |
| 160 | ] |
| 161 | defines = [ "SANDBOX_IMPLEMENTATION" ] |
| 162 | |
| 163 | deps = [ |
| 164 | ":sandbox_services_headers", |
| 165 | "//base", |
| 166 | ] |
| 167 | } |
| 168 | |
| 169 | component("seccomp_bpf_helpers") { |
| 170 | sources = [ |
| 171 | "seccomp-bpf-helpers/baseline_policy.cc", |
| 172 | "seccomp-bpf-helpers/baseline_policy.h", |
| 173 | "seccomp-bpf-helpers/sigsys_handlers.cc", |
| 174 | "seccomp-bpf-helpers/sigsys_handlers.h", |
| 175 | "seccomp-bpf-helpers/syscall_parameters_restrictions.cc", |
| 176 | "seccomp-bpf-helpers/syscall_parameters_restrictions.h", |
| 177 | "seccomp-bpf-helpers/syscall_sets.cc", |
| 178 | "seccomp-bpf-helpers/syscall_sets.h", |
| 179 | ] |
| 180 | defines = [ "SANDBOX_IMPLEMENTATION" ] |
| 181 | |
| 182 | deps = [ |
| 183 | "//base", |
| 184 | ":seccomp_bpf", |
| 185 | ] |
| 186 | } |
| 187 | |
| 188 | if (compile_seccomp_bpf_demo) { |
| 189 | # A demonstration program for the seccomp-bpf sandbox. |
| 190 | executable("seccomp_bpf_demo") { |
| 191 | sources = [ |
| 192 | "seccomp-bpf/demo.cc", |
| 193 | ] |
| 194 | deps = [ |
| 195 | ":seccomp_bpf", |
| 196 | ] |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | # The setuid sandbox for Linux. |
| 201 | executable("chrome_sandbox") { |
| 202 | sources = [ |
| 203 | "suid/common/sandbox.h", |
| 204 | "suid/common/suid_unsafe_environment_variables.h", |
| 205 | "suid/linux_util.c", |
| 206 | "suid/linux_util.h", |
| 207 | "suid/process_util.h", |
| 208 | "suid/process_util_linux.c", |
| 209 | "suid/sandbox.c", |
| 210 | ] |
| 211 | |
| 212 | cflags = [ |
| 213 | # For ULLONG_MAX |
| 214 | "-std=gnu99", |
| 215 | # These files have a suspicious comparison. |
| 216 | # TODO fix this and re-enable this warning. |
| 217 | "-Wno-sign-compare", |
| 218 | ] |
| 219 | } |
| 220 | |
| 221 | component("sandbox_services") { |
| 222 | sources = [ |
| 223 | "services/broker_process.cc", |
| 224 | "services/broker_process.h", |
| 225 | "services/init_process_reaper.cc", |
| 226 | "services/init_process_reaper.h", |
| 227 | "services/scoped_process.cc", |
| 228 | "services/scoped_process.h", |
| 229 | "services/thread_helpers.cc", |
| 230 | "services/thread_helpers.h", |
| 231 | "services/yama.h", |
| 232 | "services/yama.cc", |
| 233 | ] |
| 234 | |
| 235 | defines = [ "SANDBOX_IMPLEMENTATION" ] |
| 236 | |
| 237 | if (compile_credentials) { |
| 238 | sources += [ |
| 239 | "services/credentials.cc", |
| 240 | "services/credentials.h", |
| 241 | ] |
| 242 | # For capabilities.cc. |
| 243 | configs += [ "//build/config/linux:libcap" ] |
| 244 | } |
| 245 | |
| 246 | deps = [ |
| 247 | "//base", |
| 248 | ] |
| 249 | } |
| 250 | |
| 251 | source_set("sandbox_services_headers") { |
| 252 | sources = [ |
| 253 | "services/android_arm_ucontext.h", |
leecam | e6f6b73 | 2014-08-24 23:38:09 | [diff] [blame^] | 254 | "services/android_arm64_ucontext.h", |
[email protected] | 9de395e4 | 2014-06-04 22:25:28 | [diff] [blame] | 255 | "services/android_futex.h", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 256 | "services/android_ucontext.h", |
| 257 | "services/android_i386_ucontext.h", |
| 258 | "services/arm_linux_syscalls.h", |
leecam | e6f6b73 | 2014-08-24 23:38:09 | [diff] [blame^] | 259 | "services/arm64_linux_syscalls.h", |
[email protected] | 75cd8f0 | 2014-05-29 20:56:02 | [diff] [blame] | 260 | "services/linux_syscalls.h", |
| 261 | "services/x86_32_linux_syscalls.h", |
| 262 | "services/x86_64_linux_syscalls.h", |
| 263 | ] |
| 264 | } |
| 265 | |
| 266 | # We make this its own target so that it does not interfere with our tests. |
| 267 | source_set("libc_urandom_override") { |
| 268 | sources = [ |
| 269 | "services/libc_urandom_override.cc", |
| 270 | "services/libc_urandom_override.h", |
| 271 | ] |
| 272 | deps = [ |
| 273 | "//base", |
| 274 | ] |
| 275 | } |
| 276 | |
| 277 | component("suid_sandbox_client") { |
| 278 | sources = [ |
| 279 | "suid/common/sandbox.h", |
| 280 | "suid/common/suid_unsafe_environment_variables.h", |
| 281 | "suid/client/setuid_sandbox_client.cc", |
| 282 | "suid/client/setuid_sandbox_client.h", |
| 283 | ] |
| 284 | defines = [ "SANDBOX_IMPLEMENTATION" ] |
| 285 | |
| 286 | deps = [ |
| 287 | ":sandbox_services", |
| 288 | "//base", |
| 289 | ] |
| 290 | } |
| 291 | |
| 292 | if (is_android) { |
| 293 | # TODO(GYP) enable this. Needs an android_strip wrapper python script. |
| 294 | #action("sandbox_linux_unittests_stripped") { |
| 295 | # script = "android_stip.py" |
| 296 | # |
| 297 | # in_file = "$root_out_dir/sandbox_linux_unittests" |
| 298 | # |
| 299 | # out_file = "$root_out_dir/sandbox_linux_unittests_stripped" |
| 300 | # outputs = [ out_file ] |
| 301 | # |
| 302 | # args = [ |
| 303 | # rebase_path(in_file, root_build_dir), |
| 304 | # "-o", rebase_path(out_file, root_build_dir), |
| 305 | # ] |
| 306 | # |
| 307 | # deps = [ |
| 308 | # ":sandbox_linux_unittests", |
| 309 | # ] |
| 310 | #} |
| 311 | |
| 312 | # TODO(GYP) convert this. |
| 313 | # { |
| 314 | # 'target_name': 'sandbox_linux_jni_unittests_apk', |
| 315 | # 'type': 'none', |
| 316 | # 'variables': { |
| 317 | # 'test_suite_name': 'sandbox_linux_jni_unittests', |
| 318 | # }, |
| 319 | # 'dependencies': [ |
| 320 | # 'sandbox_linux_jni_unittests', |
| 321 | # ], |
| 322 | # 'includes': [ '../../build/apk_test.gypi' ], |
| 323 | # } |
| 324 | } |