blob: e98cdad836b255d57c542eff9c0634f9809fb518 [file] [log] [blame]
Dan Willemsen2acbec52017-09-14 17:28:36 -07001// 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// =========================================================
Bob Badour5f579b82021-02-12 21:18:40 -080017package {
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
Dan Willemsen2acbec52017-09-14 17:28:36 -070053libminijailSrcFiles = [
54 "bpf.c",
55 "libminijail.c",
56 "signal_handler.c",
57 "syscall_filter.c",
58 "syscall_wrapper.c",
59 "system.c",
60 "util.c",
61]
62
63unittestSrcFiles = [
64 "testrunner.cc",
65]
66
67minijailCommonLibraries = ["libcap"]
68
69cc_defaults {
70 name: "libminijail_flags",
71 cflags: [
Luis Hector Chavezc3e17722018-10-16 20:43:12 -070072 "-D_FILE_OFFSET_BITS=64",
Mike Frysinger916c6c32018-09-27 14:17:53 -040073 "-DALLOW_DEBUG_LOGGING",
Nicole Anderson-Aubcc8cfd2020-11-10 20:33:27 +000074 "-DALLOW_DUPLICATE_SYSCALLS",
Allen Webbee876072019-02-21 10:56:21 -080075 "-DDEFAULT_PIVOT_ROOT=\"/var/empty\"",
Dan Willemsen2acbec52017-09-14 17:28:36 -070076 "-Wall",
77 "-Werror",
78 ],
Mike Frysinger32a3b692021-04-17 10:23:54 -040079 c_std: "gnu11",
Dan Willemsen2acbec52017-09-14 17:28:36 -070080 target: {
81 darwin: {
82 enabled: false,
83 },
84 },
85}
86
87// Static library for generated code.
88// =========================================================
89cc_object {
90 name: "libminijail_gen_syscall_obj",
91 vendor_available: true,
Justin Yuned25bf32020-11-11 18:21:21 +090092 product_available: true,
Jiyong Park85e7a262018-05-24 14:09:04 +090093 recovery_available: true,
Martin Stjernholma74925e2020-04-08 01:02:51 +010094 header_libs: ["libc_headers"], // TODO(b/153662223): Clean this up.
Dan Willemsen2acbec52017-09-14 17:28:36 -070095 srcs: ["gen_syscalls.c"],
96 cflags: [
97 "-dD",
98 "-E",
Chih-Hung Hsiehed6a82e2017-10-04 10:54:11 -070099 "-Wall",
100 "-Werror",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700101 ],
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900102 apex_available: [
103 "//apex_available:platform",
104 "com.android.adbd",
105 "com.android.media.swcodec",
Jiyong Park1081a942020-12-07 15:09:28 +0900106 "com.android.virt",
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900107 ],
Jooyung Han42b623b2020-04-16 18:48:30 +0900108 min_sdk_version: "29",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700109}
110
111cc_genrule {
112 name: "libminijail_gen_syscall",
113 vendor_available: true,
Justin Yuned25bf32020-11-11 18:21:21 +0900114 product_available: true,
Jiyong Park85e7a262018-05-24 14:09:04 +0900115 recovery_available: true,
Dan Willemsen2acbec52017-09-14 17:28:36 -0700116 tool_files: ["gen_syscalls.sh"],
117 cmd: "$(location gen_syscalls.sh) $(in) $(out)",
118 srcs: [":libminijail_gen_syscall_obj"],
119 out: ["libsyscalls.c"],
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900120 apex_available: [
121 "//apex_available:platform",
122 "com.android.adbd",
123 "com.android.media.swcodec",
Jiyong Park1081a942020-12-07 15:09:28 +0900124 "com.android.virt",
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900125 ],
Dan Willemsen2acbec52017-09-14 17:28:36 -0700126}
127
128cc_object {
129 name: "libminijail_gen_constants_obj",
130 vendor_available: true,
Justin Yuned25bf32020-11-11 18:21:21 +0900131 product_available: true,
Jiyong Park85e7a262018-05-24 14:09:04 +0900132 recovery_available: true,
Martin Stjernholma74925e2020-04-08 01:02:51 +0100133 header_libs: ["libc_headers"], // TODO(b/153662223): Clean this up.
Dan Willemsen2acbec52017-09-14 17:28:36 -0700134 srcs: ["gen_constants.c"],
135 cflags: [
136 "-dD",
137 "-E",
Chih-Hung Hsiehed6a82e2017-10-04 10:54:11 -0700138 "-Wall",
139 "-Werror",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700140 ],
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900141 apex_available: [
142 "//apex_available:platform",
143 "com.android.adbd",
144 "com.android.media.swcodec",
Jiyong Park1081a942020-12-07 15:09:28 +0900145 "com.android.virt",
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900146 ],
Jooyung Han42b623b2020-04-16 18:48:30 +0900147 min_sdk_version: "29",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700148}
149
150cc_genrule {
151 name: "libminijail_gen_constants",
152 vendor_available: true,
Justin Yuned25bf32020-11-11 18:21:21 +0900153 product_available: true,
Jiyong Park85e7a262018-05-24 14:09:04 +0900154 recovery_available: true,
Dan Willemsen2acbec52017-09-14 17:28:36 -0700155 tool_files: ["gen_constants.sh"],
156 cmd: "$(location gen_constants.sh) $(in) $(out)",
157 srcs: [":libminijail_gen_constants_obj"],
158 out: ["libconstants.c"],
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900159 apex_available: [
160 "//apex_available:platform",
161 "com.android.adbd",
162 "com.android.media.swcodec",
Jiyong Park1081a942020-12-07 15:09:28 +0900163 "com.android.virt",
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900164 ],
Dan Willemsen2acbec52017-09-14 17:28:36 -0700165}
166
167cc_library_static {
168 name: "libminijail_generated",
169 vendor_available: true,
Justin Yuned25bf32020-11-11 18:21:21 +0900170 product_available: true,
Jiyong Park85e7a262018-05-24 14:09:04 +0900171 recovery_available: true,
Dan Willemsen2acbec52017-09-14 17:28:36 -0700172 defaults: ["libminijail_flags"],
173 host_supported: true,
174
175 target: {
176 android: {
177 generated_sources: [
178 "libminijail_gen_syscall",
179 "libminijail_gen_constants",
180 ],
181 },
182 host: {
183 srcs: [
184 "linux-x86/libconstants.gen.c",
185 "linux-x86/libsyscalls.gen.c",
186 ],
187 },
188 },
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900189 apex_available: [
190 "//apex_available:platform",
191 "com.android.adbd",
192 "com.android.media.swcodec",
Jiyong Park1081a942020-12-07 15:09:28 +0900193 "com.android.virt",
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900194 ],
Jooyung Han42b623b2020-04-16 18:48:30 +0900195 min_sdk_version: "29",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700196}
197
Luis Hector Chavezc90ec152019-12-13 09:12:33 -0800198cc_object {
199 name: "libminijail_gen_constants_llvmir",
200 vendor_available: true,
Justin Yuned25bf32020-11-11 18:21:21 +0900201 product_available: true,
Luis Hector Chavezc90ec152019-12-13 09:12:33 -0800202 recovery_available: true,
203 host_supported: true,
Martin Stjernholma74925e2020-04-08 01:02:51 +0100204 header_libs: ["libc_headers"], // TODO(b/153662223): Clean this up.
Luis Hector Chavezc90ec152019-12-13 09:12:33 -0800205 cflags: [
206 "-S",
207 "-O0",
208 "-emit-llvm",
209 ],
210
211 target: {
212 android: {
213 generated_sources: ["libminijail_gen_constants"],
214 },
215 host: {
216 srcs: ["linux-x86/libconstants.gen.c"],
217 },
218 },
219}
220
221cc_object {
222 name: "libminijail_gen_syscall_llvmir",
223 vendor_available: true,
Justin Yuned25bf32020-11-11 18:21:21 +0900224 product_available: true,
Luis Hector Chavezc90ec152019-12-13 09:12:33 -0800225 recovery_available: true,
226 host_supported: true,
Martin Stjernholma74925e2020-04-08 01:02:51 +0100227 header_libs: ["libc_headers"], // TODO(b/153662223): Clean this up.
Luis Hector Chavezc90ec152019-12-13 09:12:33 -0800228 cflags: [
229 "-S",
230 "-O0",
231 "-emit-llvm",
232 ],
233
234 target: {
235 android: {
236 generated_sources: ["libminijail_gen_syscall"],
237 },
238 host: {
239 srcs: ["linux-x86/libsyscalls.gen.c"],
240 },
241 },
242}
243
Dan Willemsen2acbec52017-09-14 17:28:36 -0700244// libminijail shared and static library for target.
245// =========================================================
246cc_library {
247 name: "libminijail",
Luis Hector Chavez413af652018-04-19 20:15:13 -0700248 host_supported: true,
Logan Chien9460f602017-11-21 20:32:45 +0800249
Dan Willemsen2acbec52017-09-14 17:28:36 -0700250 vendor_available: true,
Justin Yuned25bf32020-11-11 18:21:21 +0900251 product_available: true,
Jiyong Park85e7a262018-05-24 14:09:04 +0900252 recovery_available: true,
Logan Chien9460f602017-11-21 20:32:45 +0800253 vndk: {
254 enabled: true,
255 },
256
Dan Willemsen2acbec52017-09-14 17:28:36 -0700257 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: ["."],
Luis Hector Chavez413af652018-04-19 20:15:13 -0700269
270 target: {
271 host: {
272 cflags: [
273 "-DPRELOADPATH=\"/invalidminijailpreload.so\"",
274 ],
275 },
276 },
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900277 apex_available: [
278 "//apex_available:platform",
279 "com.android.adbd",
280 "com.android.media.swcodec",
Jiyong Park1081a942020-12-07 15:09:28 +0900281 "com.android.virt",
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900282 ],
Jooyung Han42b623b2020-04-16 18:48:30 +0900283 min_sdk_version: "29",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700284}
285
286// Example ASan-ified libminijail shared library for target.
287// Commented out since it's only needed for local debugging.
288// =========================================================
289//cc_library_shared {
290// name: "libminijail_asan",
291// defaults: ["libminijail_flags"],
292//
293// sanitize: {
294// address: true,
295// },
296// relative_install_path: "asan",
297// srcs: libminijailSrcFiles,
298//
299// static_libs: ["libminijail_generated"],
300// shared_libs: minijailCommonLibraries,
301// export_include_dirs: ["."],
302//}
303
304// libminijail native unit tests using gtest.
305//
306// For a device, run with:
307// adb shell /data/nativetest/libminijail_unittest_gtest/libminijail_unittest_gtest
308//
309// For host, run with:
310// out/host/linux-x86/nativetest(64)/libminijail_unittest_gtest/libminijail_unittest_gtest
311// =========================================================
312cc_test {
313 name: "libminijail_unittest_gtest",
314 defaults: ["libminijail_flags"],
315 // TODO(b/31395668): Re-enable once the seccomp(2) syscall becomes available.
316 //host_supported: true
317
318 srcs: libminijailSrcFiles + ["libminijail_unittest.cc"] + unittestSrcFiles,
319
320 static_libs: ["libminijail_generated"],
321 shared_libs: minijailCommonLibraries,
322
323 target: {
324 android: {
325 cflags: ["-Wno-writable-strings"],
326 test_suites: ["device-tests"],
327 },
328 host: {
329 cflags: ["-DPRELOADPATH=\"/invalid\""],
330 },
331 },
332}
333
334// Syscall filtering native unit tests using gtest.
335//
336// For a device, run with:
337// adb shell /data/nativetest/syscall_filter_unittest_gtest/syscall_filter_unittest_gtest
338//
339// For host, run with:
340// out/host/linux-x86/nativetest(64)/syscall_filter_unittest_gtest/syscall_filter_unittest_gtest
341// =========================================================
342cc_test {
343 name: "syscall_filter_unittest_gtest",
344 defaults: ["libminijail_flags"],
345 host_supported: true,
346
347 srcs: [
348 "bpf.c",
349 "syscall_filter.c",
Luis Héctor Chávez01b628c2021-01-03 05:46:57 -0800350 "syscall_wrapper.c",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700351 "util.c",
352 "syscall_filter_unittest.cc",
353 ] + unittestSrcFiles,
354
355 static_libs: ["libminijail_generated"],
356 shared_libs: minijailCommonLibraries,
357
358 target: {
359 android: {
360 test_suites: ["device-tests"],
361 },
362 },
Julien Desprez28fd8402021-02-10 11:01:17 -0800363 test_options: {
364 unit_test: true,
365 },
366 data: ["test/*"],
Dan Willemsen2acbec52017-09-14 17:28:36 -0700367}
368
369// System functionality unit tests using gtest.
370//
371// For a device, run with:
Jorge Lucangeli Obes1ed75bc2018-01-25 14:06:42 -0500372// adb shell /data/nativetest/mj_system_unittest_gtest/mj_system_unittest_gtest
Dan Willemsen2acbec52017-09-14 17:28:36 -0700373//
374// For host, run with:
Jorge Lucangeli Obes1ed75bc2018-01-25 14:06:42 -0500375// out/host/linux-x86/nativetest(64)/mj_system_unittest_gtest/mj_system_unittest_gtest
Dan Willemsen2acbec52017-09-14 17:28:36 -0700376// =========================================================
377cc_test {
Jorge Lucangeli Obes1ed75bc2018-01-25 14:06:42 -0500378 name: "mj_system_unittest_gtest",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700379 defaults: ["libminijail_flags"],
380 host_supported: true,
381
382 srcs: [
Luis Héctor Chávez01b628c2021-01-03 05:46:57 -0800383 "syscall_wrapper.c",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700384 "system.c",
385 "util.c",
386 "system_unittest.cc",
387 ] + unittestSrcFiles,
388
389 static_libs: ["libminijail_generated"],
390 shared_libs: minijailCommonLibraries,
391
392 target: {
393 android: {
394 test_suites: ["device-tests"],
395 },
396 },
397}
398
Mike Frysinger32c39922018-01-17 17:09:54 -0500399// Utility functionality unit tests using gtest.
400//
401// For a device, run with:
Jorge Lucangeli Obes1ed75bc2018-01-25 14:06:42 -0500402// adb shell /data/nativetest/mj_util_unittest_gtest/mj_util_unittest_gtest
Mike Frysinger32c39922018-01-17 17:09:54 -0500403//
404// For host, run with:
Jorge Lucangeli Obes1ed75bc2018-01-25 14:06:42 -0500405// out/host/linux-x86/nativetest(64)/mj_util_unittest_gtest/mj_util_unittest_gtest
Mike Frysinger32c39922018-01-17 17:09:54 -0500406// =========================================================
407cc_test {
Jorge Lucangeli Obes1ed75bc2018-01-25 14:06:42 -0500408 name: "mj_util_unittest_gtest",
Mike Frysinger32c39922018-01-17 17:09:54 -0500409 defaults: ["libminijail_flags"],
410 host_supported: true,
411
412 srcs: [
413 "util.c",
414 "util_unittest.cc",
415 ] + unittestSrcFiles,
416
417 static_libs: ["libminijail_generated"],
418 shared_libs: minijailCommonLibraries,
419
420 target: {
421 android: {
422 test_suites: ["device-tests"],
423 },
424 },
425}
426
Mike Frysinger4d2a81e2018-01-22 16:43:33 -0500427// Utility functionality unit tests using gtest.
428//
429// For a device, run with:
430// adb shell /data/nativetest/minijail0_cli_unittest_gtest/minijail0_cli_unittest_gtest
431//
432// For host, run with:
433// out/host/linux-x86/nativetest(64)/minijail0_cli_unittest_gtest/minijail0_cli_unittest_gtest
434// =========================================================
435cc_test {
436 name: "minijail0_cli_unittest_gtest",
437 defaults: ["libminijail_flags"],
438 host_supported: true,
439
440 cflags: [
441 "-DPRELOADPATH=\"/invalid\"",
442 ],
443 srcs: libminijailSrcFiles + [
444 "elfparse.c",
445 "minijail0_cli.c",
446 "minijail0_cli_unittest.cc",
447 ] + unittestSrcFiles,
448
449 static_libs: ["libminijail_generated"],
450 shared_libs: minijailCommonLibraries,
451
452 target: {
453 android: {
454 test_suites: ["device-tests"],
455 },
456 },
457}
458
Dan Willemsen2acbec52017-09-14 17:28:36 -0700459// libminijail_test executable for brillo_Minijail test.
460// =========================================================
461cc_test {
462 name: "libminijail_test",
463 defaults: ["libminijail_flags"],
464 test_suites: ["device-tests"],
465
466 gtest: false,
467
468 srcs: ["test/libminijail_test.cpp"],
469
470 shared_libs: [
471 "libbase",
472 "libminijail",
473 ],
474}
475
476// libminijail usage example.
477// =========================================================
478cc_binary {
479 name: "drop_privs",
480 defaults: ["libminijail_flags"],
481
482 // Don't build with ASan, but leave commented out for easy local debugging.
483 // sanitize: { address: true, },
484 srcs: ["examples/drop_privs.cpp"],
485
486 shared_libs: [
487 "libbase",
488 "libminijail",
489 ],
490}
491
492// minijail0 executable.
493// This is not currently used on Brillo/Android,
494// but it's convenient to be able to build it.
495// =========================================================
496cc_binary {
497 name: "minijail0",
498 defaults: ["libminijail_flags"],
Luis Hector Chavez413af652018-04-19 20:15:13 -0700499 host_supported: true,
Dan Willemsen2acbec52017-09-14 17:28:36 -0700500
501 cflags: [
Dan Willemsen2acbec52017-09-14 17:28:36 -0700502 "-DPRELOADPATH=\"/invalidminijailpreload.so\"",
503 ],
504 srcs: [
505 "elfparse.c",
506 "minijail0.c",
Mike Frysinger5ef22ca2018-01-20 13:42:10 -0500507 "minijail0_cli.c",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700508 ],
509
510 static_libs: ["libminijail_generated"],
511 shared_libs: minijailCommonLibraries + ["libminijail"],
512}
Lingfeng Yanga111f542020-02-20 08:50:39 -0800513
Yo Chiang81df0662020-07-25 19:40:44 +0800514rust_defaults {
515 name: "libminijail_rust_defaults",
516 target: {
517 darwin: {
518 enabled: false,
519 },
520 },
521}
522
Andrew Walbran9bd40192020-06-05 14:44:30 +0100523// This target was generated by cargo2android.py --run --device, with some
524// manual fixes.
Andrew Walbran7f5b63b2020-07-21 14:30:42 +0100525rust_library {
Lingfeng Yanga111f542020-02-20 08:50:39 -0800526 name: "libminijail_sys",
Yo Chiang81df0662020-07-25 19:40:44 +0800527 defaults: ["libminijail_rust_defaults"],
Andrew Walbran9bd40192020-06-05 14:44:30 +0100528 host_supported: true,
Lingfeng Yanga111f542020-02-20 08:50:39 -0800529 crate_name: "minijail_sys",
Allen Webb96dd14e2020-06-17 08:33:50 -0700530 srcs: ["rust/minijail-sys/lib.rs"],
Lingfeng Yanga111f542020-02-20 08:50:39 -0800531 edition: "2018",
Andrew Walbran7f5b63b2020-07-21 14:30:42 +0100532 rustlibs: [
Lingfeng Yanga111f542020-02-20 08:50:39 -0800533 "liblibc",
534 ],
Lingfeng Yanga111f542020-02-20 08:50:39 -0800535 shared_libs: [
536 "libcap",
Alistair Delva54fa7322020-08-24 13:01:05 -0700537 "libminijail",
Lingfeng Yanga111f542020-02-20 08:50:39 -0800538 ],
Jiyong Park1081a942020-12-07 15:09:28 +0900539 apex_available: [
540 "//apex_available:platform",
541 "com.android.virt",
542 ],
Lingfeng Yanga111f542020-02-20 08:50:39 -0800543}
Alistair Delva9072fad2020-07-20 22:57:57 -0700544
545// This target was generated by cargo2android.py --run --device, with some
546// manual fixes.
Andrew Walbran7f5b63b2020-07-21 14:30:42 +0100547rust_library {
Alistair Delva9072fad2020-07-20 22:57:57 -0700548 name: "libminijail_rust",
Yo Chiang81df0662020-07-25 19:40:44 +0800549 defaults: ["libminijail_rust_defaults"],
Alistair Delva9072fad2020-07-20 22:57:57 -0700550 host_supported: true,
551 crate_name: "minijail",
552 srcs: ["rust/minijail/src/lib.rs"],
553 edition: "2018",
Andrew Walbran7f5b63b2020-07-21 14:30:42 +0100554 rustlibs: [
Alistair Delva9072fad2020-07-20 22:57:57 -0700555 "liblibc",
556 "libminijail_sys",
557 ],
Jiyong Park1081a942020-12-07 15:09:28 +0900558 apex_available: [
559 "//apex_available:platform",
560 "com.android.virt",
561 ],
Alistair Delva9072fad2020-07-20 22:57:57 -0700562}