1// Copyright (C) 2015 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// Common variables. 16// ========================================================= 17package { 18 default_applicable_licenses: ["external_minijail_license"], 19} 20 21// Added automatically by a large-scale-change that took the approach of 22// 'apply every license found to every target'. While this makes sure we respect 23// every license restriction, it may not be entirely correct. 24// 25// e.g. GPL in an MIT project might only apply to the contrib/ directory. 26// 27// Please consider splitting the single license below into multiple licenses, 28// taking care not to lose any license_kind information, and overriding the 29// default license using the 'licenses: [...]' property on targets as needed. 30// 31// For unused files, consider creating a 'fileGroup' with "//visibility:private" 32// to attach the license to, and including a comment whether the files may be 33// used in the current project. 34// 35// large-scale-change included anything that looked like it might be a license 36// text as a license_text. e.g. LICENSE, NOTICE, COPYING etc. 37// 38// Please consider removing redundant or irrelevant files from 'license_text:'. 39// See: http://go/android-license-faq 40license { 41 name: "external_minijail_license", 42 visibility: [":__subpackages__"], 43 license_kinds: [ 44 "SPDX-license-identifier-Apache-2.0", 45 "SPDX-license-identifier-BSD", 46 ], 47 license_text: [ 48 "LICENSE", 49 "NOTICE", 50 ], 51} 52 53libminijailSrcFiles = [ 54 "bpf.c", 55 "landlock_util.c", 56 "libminijail.c", 57 "signal_handler.c", 58 "syscall_filter.c", 59 "syscall_wrapper.c", 60 "system.c", 61 "util.c", 62] 63 64unittestSrcFiles = [ 65 "testrunner.cc", 66 "test_util.cc", 67] 68 69minijailCommonLibraries = ["libcap"] 70 71cc_defaults { 72 name: "libminijail_flags", 73 cflags: [ 74 "-D_FILE_OFFSET_BITS=64", 75 "-DALLOW_DEBUG_LOGGING", 76 "-DALLOW_DUPLICATE_SYSCALLS", 77 "-DDEFAULT_PIVOT_ROOT=\"/var/empty\"", 78 "-DBINDMOUNT_ALLOWED_PREFIXES=\"\"", 79 "-Wall", 80 "-Werror", 81 ], 82 target: { 83 darwin: { 84 enabled: false, 85 }, 86 }, 87} 88 89// Static library for generated code. 90// ========================================================= 91cc_object { 92 name: "libminijail_gen_syscall_obj", 93 vendor_available: true, 94 product_available: true, 95 recovery_available: true, 96 srcs: ["gen_syscalls.c"], 97 cflags: [ 98 "-dD", 99 "-E", 100 "-Wall", 101 "-Werror", 102 ], 103 apex_available: [ 104 "//apex_available:platform", 105 "com.android.adbd", 106 "com.android.compos", 107 "com.android.media.swcodec", 108 "com.android.virt", 109 ], 110 min_sdk_version: "29", 111} 112 113cc_genrule { 114 name: "libminijail_gen_syscall", 115 vendor_available: true, 116 product_available: true, 117 recovery_available: true, 118 tool_files: ["gen_syscalls.sh"], 119 cmd: "$(location gen_syscalls.sh) $(in) $(out)", 120 srcs: [":libminijail_gen_syscall_obj"], 121 out: ["libsyscalls.c"], 122 apex_available: [ 123 "//apex_available:platform", 124 "com.android.adbd", 125 "com.android.compos", 126 "com.android.media.swcodec", 127 "com.android.virt", 128 ], 129} 130 131cc_object { 132 name: "libminijail_gen_constants_obj", 133 vendor_available: true, 134 product_available: true, 135 recovery_available: true, 136 srcs: ["gen_constants.c"], 137 cflags: [ 138 "-dD", 139 "-E", 140 "-Wall", 141 "-Werror", 142 ], 143 apex_available: [ 144 "//apex_available:platform", 145 "com.android.adbd", 146 "com.android.compos", 147 "com.android.media.swcodec", 148 "com.android.virt", 149 ], 150 min_sdk_version: "29", 151} 152 153cc_genrule { 154 name: "libminijail_gen_constants", 155 vendor_available: true, 156 product_available: true, 157 recovery_available: true, 158 tool_files: ["gen_constants.sh"], 159 cmd: "$(location gen_constants.sh) $(in) $(out)", 160 srcs: [":libminijail_gen_constants_obj"], 161 out: ["libconstants.c"], 162 apex_available: [ 163 "//apex_available:platform", 164 "com.android.adbd", 165 "com.android.compos", 166 "com.android.media.swcodec", 167 "com.android.virt", 168 ], 169} 170 171cc_library_static { 172 name: "libminijail_generated", 173 vendor_available: true, 174 product_available: true, 175 recovery_available: true, 176 defaults: ["libminijail_flags"], 177 host_supported: true, 178 179 target: { 180 android: { 181 generated_sources: [ 182 "libminijail_gen_syscall", 183 "libminijail_gen_constants", 184 ], 185 }, 186 host: { 187 srcs: [ 188 "linux-x86/libconstants.gen.c", 189 "linux-x86/libsyscalls.gen.c", 190 ], 191 }, 192 }, 193 apex_available: [ 194 "//apex_available:platform", 195 "com.android.adbd", 196 "com.android.compos", 197 "com.android.media.swcodec", 198 "com.android.virt", 199 ], 200 min_sdk_version: "29", 201} 202 203cc_object { 204 name: "libminijail_gen_constants_llvmir", 205 vendor_available: true, 206 product_available: true, 207 recovery_available: true, 208 host_supported: true, 209 cflags: [ 210 "-S", 211 "-O0", 212 "-emit-llvm", 213 ], 214 215 target: { 216 android: { 217 generated_sources: ["libminijail_gen_constants"], 218 }, 219 host: { 220 srcs: ["linux-x86/libconstants.gen.c"], 221 }, 222 }, 223} 224 225cc_object { 226 name: "libminijail_gen_syscall_llvmir", 227 vendor_available: true, 228 product_available: true, 229 recovery_available: true, 230 host_supported: true, 231 cflags: [ 232 "-S", 233 "-O0", 234 "-emit-llvm", 235 ], 236 237 target: { 238 android: { 239 generated_sources: ["libminijail_gen_syscall"], 240 }, 241 host: { 242 srcs: ["linux-x86/libsyscalls.gen.c"], 243 }, 244 }, 245} 246 247// libminijail shared and static library for target. 248// ========================================================= 249cc_library { 250 name: "libminijail", 251 host_supported: true, 252 253 vendor_available: true, 254 product_available: true, 255 recovery_available: true, 256 257 defaults: ["libminijail_flags"], 258 259 srcs: libminijailSrcFiles, 260 261 static: { 262 whole_static_libs: ["libminijail_generated"] + minijailCommonLibraries, 263 }, 264 shared: { 265 static_libs: ["libminijail_generated"], 266 shared_libs: minijailCommonLibraries, 267 }, 268 export_include_dirs: ["."], 269 270 target: { 271 host: { 272 cflags: [ 273 "-DPRELOADPATH=\"/invalidminijailpreload.so\"", 274 ], 275 }, 276 }, 277 apex_available: [ 278 "//apex_available:platform", 279 "com.android.adbd", 280 "com.android.compos", 281 "com.android.media.swcodec", 282 "com.android.virt", 283 ], 284 min_sdk_version: "29", 285} 286 287// Example ASan-ified libminijail shared library for target. 288// Commented out since it's only needed for local debugging. 289// ========================================================= 290//cc_library_shared { 291// name: "libminijail_asan", 292// defaults: ["libminijail_flags"], 293// 294// sanitize: { 295// address: true, 296// }, 297// relative_install_path: "asan", 298// srcs: libminijailSrcFiles, 299// 300// static_libs: ["libminijail_generated"], 301// shared_libs: minijailCommonLibraries, 302// export_include_dirs: ["."], 303//} 304 305// libminijail native unit tests using gtest. 306// 307// For a device, run with: 308// adb shell /data/nativetest/libminijail_unittest_gtest/libminijail_unittest_gtest 309// 310// For host, run with: 311// out/host/linux-x86/nativetest(64)/libminijail_unittest_gtest/libminijail_unittest_gtest 312// ========================================================= 313cc_test { 314 name: "libminijail_unittest_gtest", 315 defaults: ["libminijail_flags"], 316 // TODO(b/31395668): Re-enable once the seccomp(2) syscall becomes available. 317 //host_supported: true 318 319 srcs: libminijailSrcFiles + ["libminijail_unittest.cc"] + unittestSrcFiles, 320 321 static_libs: ["libminijail_generated"], 322 shared_libs: minijailCommonLibraries, 323 324 target: { 325 android: { 326 cflags: ["-Wno-writable-strings"], 327 test_suites: ["device-tests"], 328 }, 329 host: { 330 cflags: ["-DPRELOADPATH=\"/invalid\""], 331 }, 332 }, 333} 334 335// Syscall filtering native unit tests using gtest. 336// 337// For a device, run with: 338// adb shell /data/nativetest/syscall_filter_unittest_gtest/syscall_filter_unittest_gtest 339// 340// For host, run with: 341// out/host/linux-x86/nativetest(64)/syscall_filter_unittest_gtest/syscall_filter_unittest_gtest 342// ========================================================= 343cc_test { 344 name: "syscall_filter_unittest_gtest", 345 defaults: ["libminijail_flags"], 346 host_supported: true, 347 348 srcs: [ 349 "bpf.c", 350 "syscall_filter.c", 351 "syscall_wrapper.c", 352 "util.c", 353 "syscall_filter_unittest.cc", 354 ] + unittestSrcFiles, 355 356 static_libs: ["libminijail_generated"], 357 shared_libs: minijailCommonLibraries, 358 359 target: { 360 android: { 361 test_suites: ["device-tests"], 362 }, 363 }, 364 test_options: { 365 unit_test: true, 366 }, 367 data: ["test/*"], 368} 369 370// System functionality unit tests using gtest. 371// 372// For a device, run with: 373// adb shell /data/nativetest/mj_system_unittest_gtest/mj_system_unittest_gtest 374// 375// For host, run with: 376// out/host/linux-x86/nativetest(64)/mj_system_unittest_gtest/mj_system_unittest_gtest 377// ========================================================= 378cc_test { 379 name: "mj_system_unittest_gtest", 380 defaults: ["libminijail_flags"], 381 host_supported: true, 382 383 srcs: [ 384 "syscall_wrapper.c", 385 "system.c", 386 "util.c", 387 "system_unittest.cc", 388 ] + unittestSrcFiles, 389 390 static_libs: ["libminijail_generated"], 391 shared_libs: minijailCommonLibraries, 392 393 target: { 394 android: { 395 test_suites: ["device-tests"], 396 }, 397 }, 398} 399 400// Utility functionality unit tests using gtest. 401// 402// For a device, run with: 403// adb shell /data/nativetest/mj_util_unittest_gtest/mj_util_unittest_gtest 404// 405// For host, run with: 406// out/host/linux-x86/nativetest(64)/mj_util_unittest_gtest/mj_util_unittest_gtest 407// ========================================================= 408cc_test { 409 name: "mj_util_unittest_gtest", 410 defaults: ["libminijail_flags"], 411 host_supported: true, 412 413 srcs: [ 414 "util.c", 415 "util_unittest.cc", 416 ] + unittestSrcFiles, 417 418 static_libs: ["libminijail_generated"], 419 shared_libs: minijailCommonLibraries, 420 421 target: { 422 android: { 423 test_suites: ["device-tests"], 424 }, 425 }, 426} 427 428// Utility functionality unit tests using gtest. 429// 430// For a device, run with: 431// adb shell /data/nativetest/minijail0_cli_unittest_gtest/minijail0_cli_unittest_gtest 432// 433// For host, run with: 434// out/host/linux-x86/nativetest(64)/minijail0_cli_unittest_gtest/minijail0_cli_unittest_gtest 435// ========================================================= 436cc_test { 437 name: "minijail0_cli_unittest_gtest", 438 defaults: ["libminijail_flags"], 439 host_supported: true, 440 441 cflags: [ 442 "-DPRELOADPATH=\"/invalid\"", 443 ], 444 srcs: libminijailSrcFiles + [ 445 "config_parser.c", 446 "elfparse.c", 447 "minijail0_cli.c", 448 "minijail0_cli_unittest.cc", 449 ] + unittestSrcFiles, 450 451 static_libs: ["libminijail_generated"], 452 shared_libs: minijailCommonLibraries, 453 454 target: { 455 android: { 456 test_suites: ["device-tests"], 457 }, 458 }, 459 data: ["test/*"], 460 test_options: { 461 tags: ["no-remote"], 462 } 463} 464 465 466// Configuration file parser functionality unit tests using gtest. 467// 468// For a device, run with: 469// adb shell /data/nativetest/config_parser_unittest_gtest/config_parser_unittest_gtest 470// 471// For host, run with: 472// out/host/linux-x86/nativetest(64)/config_parser_unittest_gtest/config_parser_unittest_gtest 473// ========================================================= 474cc_test { 475 name: "config_parser_unittest_gtest", 476 defaults: ["libminijail_flags"], 477 host_supported: true, 478 479 srcs: [ 480 "config_parser.c", 481 "util.c", 482 "config_parser_unittest.cc", 483 ] + unittestSrcFiles, 484 485 static_libs: ["libminijail_generated"], 486 shared_libs: minijailCommonLibraries, 487 488 target: { 489 android: { 490 test_suites: ["device-tests"], 491 }, 492 }, 493 test_options: { 494 unit_test: true, 495 }, 496 data: ["test/*"], 497} 498 499// libminijail_test executable for brillo_Minijail test. 500// ========================================================= 501cc_test { 502 name: "libminijail_test", 503 defaults: ["libminijail_flags"], 504 test_suites: ["device-tests"], 505 506 gtest: false, 507 508 srcs: ["test/libminijail_test.cpp"], 509 510 shared_libs: [ 511 "libbase", 512 "libminijail", 513 ], 514} 515 516// libminijail usage example. 517// ========================================================= 518cc_binary { 519 name: "drop_privs", 520 defaults: ["libminijail_flags"], 521 522 // Don't build with ASan, but leave commented out for easy local debugging. 523 // sanitize: { address: true, }, 524 srcs: ["examples/drop_privs.cpp"], 525 526 shared_libs: [ 527 "libbase", 528 "libminijail", 529 ], 530} 531 532// minijail0 executable. 533// This is not currently used on Brillo/Android, 534// but it's convenient to be able to build it. 535// ========================================================= 536cc_binary { 537 name: "minijail0", 538 defaults: ["libminijail_flags"], 539 host_supported: true, 540 541 cflags: [ 542 "-DPRELOADPATH=\"/invalidminijailpreload.so\"", 543 ], 544 srcs: [ 545 "config_parser.c", 546 "elfparse.c", 547 "minijail0.c", 548 "minijail0_cli.c", 549 ], 550 551 static_libs: ["libminijail_generated"], 552 shared_libs: minijailCommonLibraries + ["libminijail"], 553} 554