blob: 4c16e14647022c315e04c370c07f25dda240ed23 [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 ],
79 target: {
80 darwin: {
81 enabled: false,
82 },
83 },
84}
85
86// Static library for generated code.
87// =========================================================
88cc_object {
89 name: "libminijail_gen_syscall_obj",
90 vendor_available: true,
Justin Yuned25bf32020-11-11 18:21:21 +090091 product_available: true,
Jiyong Park85e7a262018-05-24 14:09:04 +090092 recovery_available: true,
Martin Stjernholma74925e2020-04-08 01:02:51 +010093 header_libs: ["libc_headers"], // TODO(b/153662223): Clean this up.
Dan Willemsen2acbec52017-09-14 17:28:36 -070094 srcs: ["gen_syscalls.c"],
95 cflags: [
96 "-dD",
97 "-E",
Chih-Hung Hsiehed6a82e2017-10-04 10:54:11 -070098 "-Wall",
99 "-Werror",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700100 ],
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900101 apex_available: [
102 "//apex_available:platform",
103 "com.android.adbd",
104 "com.android.media.swcodec",
Jiyong Park1081a942020-12-07 15:09:28 +0900105 "com.android.virt",
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900106 ],
Jooyung Han42b623b2020-04-16 18:48:30 +0900107 min_sdk_version: "29",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700108}
109
110cc_genrule {
111 name: "libminijail_gen_syscall",
112 vendor_available: true,
Justin Yuned25bf32020-11-11 18:21:21 +0900113 product_available: true,
Jiyong Park85e7a262018-05-24 14:09:04 +0900114 recovery_available: true,
Dan Willemsen2acbec52017-09-14 17:28:36 -0700115 tool_files: ["gen_syscalls.sh"],
116 cmd: "$(location gen_syscalls.sh) $(in) $(out)",
117 srcs: [":libminijail_gen_syscall_obj"],
118 out: ["libsyscalls.c"],
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900119 apex_available: [
120 "//apex_available:platform",
121 "com.android.adbd",
122 "com.android.media.swcodec",
Jiyong Park1081a942020-12-07 15:09:28 +0900123 "com.android.virt",
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900124 ],
Dan Willemsen2acbec52017-09-14 17:28:36 -0700125}
126
127cc_object {
128 name: "libminijail_gen_constants_obj",
129 vendor_available: true,
Justin Yuned25bf32020-11-11 18:21:21 +0900130 product_available: true,
Jiyong Park85e7a262018-05-24 14:09:04 +0900131 recovery_available: true,
Martin Stjernholma74925e2020-04-08 01:02:51 +0100132 header_libs: ["libc_headers"], // TODO(b/153662223): Clean this up.
Dan Willemsen2acbec52017-09-14 17:28:36 -0700133 srcs: ["gen_constants.c"],
134 cflags: [
135 "-dD",
136 "-E",
Chih-Hung Hsiehed6a82e2017-10-04 10:54:11 -0700137 "-Wall",
138 "-Werror",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700139 ],
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900140 apex_available: [
141 "//apex_available:platform",
142 "com.android.adbd",
143 "com.android.media.swcodec",
Jiyong Park1081a942020-12-07 15:09:28 +0900144 "com.android.virt",
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900145 ],
Jooyung Han42b623b2020-04-16 18:48:30 +0900146 min_sdk_version: "29",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700147}
148
149cc_genrule {
150 name: "libminijail_gen_constants",
151 vendor_available: true,
Justin Yuned25bf32020-11-11 18:21:21 +0900152 product_available: true,
Jiyong Park85e7a262018-05-24 14:09:04 +0900153 recovery_available: true,
Dan Willemsen2acbec52017-09-14 17:28:36 -0700154 tool_files: ["gen_constants.sh"],
155 cmd: "$(location gen_constants.sh) $(in) $(out)",
156 srcs: [":libminijail_gen_constants_obj"],
157 out: ["libconstants.c"],
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900158 apex_available: [
159 "//apex_available:platform",
160 "com.android.adbd",
161 "com.android.media.swcodec",
Jiyong Park1081a942020-12-07 15:09:28 +0900162 "com.android.virt",
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900163 ],
Dan Willemsen2acbec52017-09-14 17:28:36 -0700164}
165
166cc_library_static {
167 name: "libminijail_generated",
168 vendor_available: true,
Justin Yuned25bf32020-11-11 18:21:21 +0900169 product_available: true,
Jiyong Park85e7a262018-05-24 14:09:04 +0900170 recovery_available: true,
Dan Willemsen2acbec52017-09-14 17:28:36 -0700171 defaults: ["libminijail_flags"],
172 host_supported: true,
173
174 target: {
175 android: {
176 generated_sources: [
177 "libminijail_gen_syscall",
178 "libminijail_gen_constants",
179 ],
180 },
181 host: {
182 srcs: [
183 "linux-x86/libconstants.gen.c",
184 "linux-x86/libsyscalls.gen.c",
185 ],
186 },
187 },
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900188 apex_available: [
189 "//apex_available:platform",
190 "com.android.adbd",
191 "com.android.media.swcodec",
Jiyong Park1081a942020-12-07 15:09:28 +0900192 "com.android.virt",
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900193 ],
Jooyung Han42b623b2020-04-16 18:48:30 +0900194 min_sdk_version: "29",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700195}
196
Luis Hector Chavezc90ec152019-12-13 09:12:33 -0800197cc_object {
198 name: "libminijail_gen_constants_llvmir",
199 vendor_available: true,
Justin Yuned25bf32020-11-11 18:21:21 +0900200 product_available: true,
Luis Hector Chavezc90ec152019-12-13 09:12:33 -0800201 recovery_available: true,
202 host_supported: true,
Martin Stjernholma74925e2020-04-08 01:02:51 +0100203 header_libs: ["libc_headers"], // TODO(b/153662223): Clean this up.
Luis Hector Chavezc90ec152019-12-13 09:12:33 -0800204 cflags: [
205 "-S",
206 "-O0",
207 "-emit-llvm",
208 ],
209
210 target: {
211 android: {
212 generated_sources: ["libminijail_gen_constants"],
213 },
214 host: {
215 srcs: ["linux-x86/libconstants.gen.c"],
216 },
217 },
218}
219
220cc_object {
221 name: "libminijail_gen_syscall_llvmir",
222 vendor_available: true,
Justin Yuned25bf32020-11-11 18:21:21 +0900223 product_available: true,
Luis Hector Chavezc90ec152019-12-13 09:12:33 -0800224 recovery_available: true,
225 host_supported: true,
Martin Stjernholma74925e2020-04-08 01:02:51 +0100226 header_libs: ["libc_headers"], // TODO(b/153662223): Clean this up.
Luis Hector Chavezc90ec152019-12-13 09:12:33 -0800227 cflags: [
228 "-S",
229 "-O0",
230 "-emit-llvm",
231 ],
232
233 target: {
234 android: {
235 generated_sources: ["libminijail_gen_syscall"],
236 },
237 host: {
238 srcs: ["linux-x86/libsyscalls.gen.c"],
239 },
240 },
241}
242
Dan Willemsen2acbec52017-09-14 17:28:36 -0700243// libminijail shared and static library for target.
244// =========================================================
245cc_library {
246 name: "libminijail",
Luis Hector Chavez413af652018-04-19 20:15:13 -0700247 host_supported: true,
Logan Chien9460f602017-11-21 20:32:45 +0800248
Dan Willemsen2acbec52017-09-14 17:28:36 -0700249 vendor_available: true,
Justin Yuned25bf32020-11-11 18:21:21 +0900250 product_available: true,
Jiyong Park85e7a262018-05-24 14:09:04 +0900251 recovery_available: true,
Logan Chien9460f602017-11-21 20:32:45 +0800252 vndk: {
253 enabled: true,
254 },
255
Dan Willemsen2acbec52017-09-14 17:28:36 -0700256 defaults: ["libminijail_flags"],
257
258 srcs: libminijailSrcFiles,
259
260 static: {
261 whole_static_libs: ["libminijail_generated"] + minijailCommonLibraries,
262 },
263 shared: {
264 static_libs: ["libminijail_generated"],
265 shared_libs: minijailCommonLibraries,
266 },
267 export_include_dirs: ["."],
Luis Hector Chavez413af652018-04-19 20:15:13 -0700268
269 target: {
270 host: {
271 cflags: [
272 "-DPRELOADPATH=\"/invalidminijailpreload.so\"",
273 ],
274 },
275 },
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900276 apex_available: [
277 "//apex_available:platform",
278 "com.android.adbd",
279 "com.android.media.swcodec",
Jiyong Park1081a942020-12-07 15:09:28 +0900280 "com.android.virt",
Jiyong Parke3a5cae2020-04-08 22:37:24 +0900281 ],
Jooyung Han42b623b2020-04-16 18:48:30 +0900282 min_sdk_version: "29",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700283}
284
285// Example ASan-ified libminijail shared library for target.
286// Commented out since it's only needed for local debugging.
287// =========================================================
288//cc_library_shared {
289// name: "libminijail_asan",
290// defaults: ["libminijail_flags"],
291//
292// sanitize: {
293// address: true,
294// },
295// relative_install_path: "asan",
296// srcs: libminijailSrcFiles,
297//
298// static_libs: ["libminijail_generated"],
299// shared_libs: minijailCommonLibraries,
300// export_include_dirs: ["."],
301//}
302
303// libminijail native unit tests using gtest.
304//
305// For a device, run with:
306// adb shell /data/nativetest/libminijail_unittest_gtest/libminijail_unittest_gtest
307//
308// For host, run with:
309// out/host/linux-x86/nativetest(64)/libminijail_unittest_gtest/libminijail_unittest_gtest
310// =========================================================
311cc_test {
312 name: "libminijail_unittest_gtest",
313 defaults: ["libminijail_flags"],
314 // TODO(b/31395668): Re-enable once the seccomp(2) syscall becomes available.
315 //host_supported: true
316
317 srcs: libminijailSrcFiles + ["libminijail_unittest.cc"] + unittestSrcFiles,
318
319 static_libs: ["libminijail_generated"],
320 shared_libs: minijailCommonLibraries,
321
322 target: {
323 android: {
324 cflags: ["-Wno-writable-strings"],
325 test_suites: ["device-tests"],
326 },
327 host: {
328 cflags: ["-DPRELOADPATH=\"/invalid\""],
329 },
330 },
331}
332
333// Syscall filtering native unit tests using gtest.
334//
335// For a device, run with:
336// adb shell /data/nativetest/syscall_filter_unittest_gtest/syscall_filter_unittest_gtest
337//
338// For host, run with:
339// out/host/linux-x86/nativetest(64)/syscall_filter_unittest_gtest/syscall_filter_unittest_gtest
340// =========================================================
341cc_test {
342 name: "syscall_filter_unittest_gtest",
343 defaults: ["libminijail_flags"],
344 host_supported: true,
345
346 srcs: [
347 "bpf.c",
348 "syscall_filter.c",
Luis Héctor Chávez01b628c2021-01-03 05:46:57 -0800349 "syscall_wrapper.c",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700350 "util.c",
351 "syscall_filter_unittest.cc",
352 ] + unittestSrcFiles,
353
354 static_libs: ["libminijail_generated"],
355 shared_libs: minijailCommonLibraries,
356
357 target: {
358 android: {
359 test_suites: ["device-tests"],
360 },
361 },
362}
363
364// System functionality unit tests using gtest.
365//
366// For a device, run with:
Jorge Lucangeli Obes1ed75bc2018-01-25 14:06:42 -0500367// adb shell /data/nativetest/mj_system_unittest_gtest/mj_system_unittest_gtest
Dan Willemsen2acbec52017-09-14 17:28:36 -0700368//
369// For host, run with:
Jorge Lucangeli Obes1ed75bc2018-01-25 14:06:42 -0500370// out/host/linux-x86/nativetest(64)/mj_system_unittest_gtest/mj_system_unittest_gtest
Dan Willemsen2acbec52017-09-14 17:28:36 -0700371// =========================================================
372cc_test {
Jorge Lucangeli Obes1ed75bc2018-01-25 14:06:42 -0500373 name: "mj_system_unittest_gtest",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700374 defaults: ["libminijail_flags"],
375 host_supported: true,
376
377 srcs: [
Luis Héctor Chávez01b628c2021-01-03 05:46:57 -0800378 "syscall_wrapper.c",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700379 "system.c",
380 "util.c",
381 "system_unittest.cc",
382 ] + unittestSrcFiles,
383
384 static_libs: ["libminijail_generated"],
385 shared_libs: minijailCommonLibraries,
386
387 target: {
388 android: {
389 test_suites: ["device-tests"],
390 },
391 },
392}
393
Mike Frysinger32c39922018-01-17 17:09:54 -0500394// Utility functionality unit tests using gtest.
395//
396// For a device, run with:
Jorge Lucangeli Obes1ed75bc2018-01-25 14:06:42 -0500397// adb shell /data/nativetest/mj_util_unittest_gtest/mj_util_unittest_gtest
Mike Frysinger32c39922018-01-17 17:09:54 -0500398//
399// For host, run with:
Jorge Lucangeli Obes1ed75bc2018-01-25 14:06:42 -0500400// out/host/linux-x86/nativetest(64)/mj_util_unittest_gtest/mj_util_unittest_gtest
Mike Frysinger32c39922018-01-17 17:09:54 -0500401// =========================================================
402cc_test {
Jorge Lucangeli Obes1ed75bc2018-01-25 14:06:42 -0500403 name: "mj_util_unittest_gtest",
Mike Frysinger32c39922018-01-17 17:09:54 -0500404 defaults: ["libminijail_flags"],
405 host_supported: true,
406
407 srcs: [
408 "util.c",
409 "util_unittest.cc",
410 ] + unittestSrcFiles,
411
412 static_libs: ["libminijail_generated"],
413 shared_libs: minijailCommonLibraries,
414
415 target: {
416 android: {
417 test_suites: ["device-tests"],
418 },
419 },
420}
421
Mike Frysinger4d2a81e2018-01-22 16:43:33 -0500422// Utility functionality unit tests using gtest.
423//
424// For a device, run with:
425// adb shell /data/nativetest/minijail0_cli_unittest_gtest/minijail0_cli_unittest_gtest
426//
427// For host, run with:
428// out/host/linux-x86/nativetest(64)/minijail0_cli_unittest_gtest/minijail0_cli_unittest_gtest
429// =========================================================
430cc_test {
431 name: "minijail0_cli_unittest_gtest",
432 defaults: ["libminijail_flags"],
433 host_supported: true,
434
435 cflags: [
436 "-DPRELOADPATH=\"/invalid\"",
437 ],
438 srcs: libminijailSrcFiles + [
439 "elfparse.c",
440 "minijail0_cli.c",
441 "minijail0_cli_unittest.cc",
442 ] + unittestSrcFiles,
443
444 static_libs: ["libminijail_generated"],
445 shared_libs: minijailCommonLibraries,
446
447 target: {
448 android: {
449 test_suites: ["device-tests"],
450 },
451 },
452}
453
Dan Willemsen2acbec52017-09-14 17:28:36 -0700454// libminijail_test executable for brillo_Minijail test.
455// =========================================================
456cc_test {
457 name: "libminijail_test",
458 defaults: ["libminijail_flags"],
459 test_suites: ["device-tests"],
460
461 gtest: false,
462
463 srcs: ["test/libminijail_test.cpp"],
464
465 shared_libs: [
466 "libbase",
467 "libminijail",
468 ],
469}
470
471// libminijail usage example.
472// =========================================================
473cc_binary {
474 name: "drop_privs",
475 defaults: ["libminijail_flags"],
476
477 // Don't build with ASan, but leave commented out for easy local debugging.
478 // sanitize: { address: true, },
479 srcs: ["examples/drop_privs.cpp"],
480
481 shared_libs: [
482 "libbase",
483 "libminijail",
484 ],
485}
486
487// minijail0 executable.
488// This is not currently used on Brillo/Android,
489// but it's convenient to be able to build it.
490// =========================================================
491cc_binary {
492 name: "minijail0",
493 defaults: ["libminijail_flags"],
Luis Hector Chavez413af652018-04-19 20:15:13 -0700494 host_supported: true,
Dan Willemsen2acbec52017-09-14 17:28:36 -0700495
496 cflags: [
Dan Willemsen2acbec52017-09-14 17:28:36 -0700497 "-DPRELOADPATH=\"/invalidminijailpreload.so\"",
498 ],
499 srcs: [
500 "elfparse.c",
501 "minijail0.c",
Mike Frysinger5ef22ca2018-01-20 13:42:10 -0500502 "minijail0_cli.c",
Dan Willemsen2acbec52017-09-14 17:28:36 -0700503 ],
504
505 static_libs: ["libminijail_generated"],
506 shared_libs: minijailCommonLibraries + ["libminijail"],
507}
Lingfeng Yanga111f542020-02-20 08:50:39 -0800508
Yo Chiang81df0662020-07-25 19:40:44 +0800509rust_defaults {
510 name: "libminijail_rust_defaults",
511 target: {
512 darwin: {
513 enabled: false,
514 },
515 },
516}
517
Andrew Walbran9bd40192020-06-05 14:44:30 +0100518// This target was generated by cargo2android.py --run --device, with some
519// manual fixes.
Andrew Walbran7f5b63b2020-07-21 14:30:42 +0100520rust_library {
Lingfeng Yanga111f542020-02-20 08:50:39 -0800521 name: "libminijail_sys",
Yo Chiang81df0662020-07-25 19:40:44 +0800522 defaults: ["libminijail_rust_defaults"],
Andrew Walbran9bd40192020-06-05 14:44:30 +0100523 host_supported: true,
Lingfeng Yanga111f542020-02-20 08:50:39 -0800524 crate_name: "minijail_sys",
Allen Webb96dd14e2020-06-17 08:33:50 -0700525 srcs: ["rust/minijail-sys/lib.rs"],
Lingfeng Yanga111f542020-02-20 08:50:39 -0800526 edition: "2018",
Andrew Walbran7f5b63b2020-07-21 14:30:42 +0100527 rustlibs: [
Lingfeng Yanga111f542020-02-20 08:50:39 -0800528 "liblibc",
529 ],
Lingfeng Yanga111f542020-02-20 08:50:39 -0800530 shared_libs: [
531 "libcap",
Alistair Delva54fa7322020-08-24 13:01:05 -0700532 "libminijail",
Lingfeng Yanga111f542020-02-20 08:50:39 -0800533 ],
Jiyong Park1081a942020-12-07 15:09:28 +0900534 apex_available: [
535 "//apex_available:platform",
536 "com.android.virt",
537 ],
Lingfeng Yanga111f542020-02-20 08:50:39 -0800538}
Alistair Delva9072fad2020-07-20 22:57:57 -0700539
540// This target was generated by cargo2android.py --run --device, with some
541// manual fixes.
Andrew Walbran7f5b63b2020-07-21 14:30:42 +0100542rust_library {
Alistair Delva9072fad2020-07-20 22:57:57 -0700543 name: "libminijail_rust",
Yo Chiang81df0662020-07-25 19:40:44 +0800544 defaults: ["libminijail_rust_defaults"],
Alistair Delva9072fad2020-07-20 22:57:57 -0700545 host_supported: true,
546 crate_name: "minijail",
547 srcs: ["rust/minijail/src/lib.rs"],
548 edition: "2018",
Andrew Walbran7f5b63b2020-07-21 14:30:42 +0100549 rustlibs: [
Alistair Delva9072fad2020-07-20 22:57:57 -0700550 "liblibc",
551 "libminijail_sys",
552 ],
Jiyong Park1081a942020-12-07 15:09:28 +0900553 apex_available: [
554 "//apex_available:platform",
555 "com.android.virt",
556 ],
Alistair Delva9072fad2020-07-20 22:57:57 -0700557}