• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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        "-Wno-unused-command-line-argument",
103    ],
104    apex_available: [
105        "//apex_available:platform",
106        "com.android.adbd",
107        "com.android.compos",
108        "com.android.media.swcodec",
109        "com.android.virt",
110    ],
111    min_sdk_version: "29",
112}
113
114cc_genrule {
115    name: "libminijail_gen_syscall",
116    vendor_available: true,
117    product_available: true,
118    recovery_available: true,
119    tool_files: ["gen_syscalls.sh"],
120    cmd: "$(location gen_syscalls.sh) $(in) $(out)",
121    srcs: [":libminijail_gen_syscall_obj"],
122    out: ["libsyscalls.c"],
123    apex_available: [
124        "//apex_available:platform",
125        "com.android.adbd",
126        "com.android.compos",
127        "com.android.media.swcodec",
128        "com.android.virt",
129    ],
130}
131
132cc_object {
133    name: "libminijail_gen_constants_obj",
134    vendor_available: true,
135    product_available: true,
136    recovery_available: true,
137    srcs: ["gen_constants.c"],
138    cflags: [
139        "-dD",
140        "-E",
141        "-Wall",
142        "-Werror",
143        "-Wno-unused-command-line-argument",
144    ],
145    apex_available: [
146        "//apex_available:platform",
147        "com.android.adbd",
148        "com.android.compos",
149        "com.android.media.swcodec",
150        "com.android.virt",
151    ],
152    min_sdk_version: "29",
153}
154
155cc_genrule {
156    name: "libminijail_gen_constants",
157    vendor_available: true,
158    product_available: true,
159    recovery_available: true,
160    tool_files: ["gen_constants.sh"],
161    cmd: "$(location gen_constants.sh) $(in) $(out)",
162    srcs: [":libminijail_gen_constants_obj"],
163    out: ["libconstants.c"],
164    apex_available: [
165        "//apex_available:platform",
166        "com.android.adbd",
167        "com.android.compos",
168        "com.android.media.swcodec",
169        "com.android.virt",
170    ],
171}
172
173cc_library_static {
174    name: "libminijail_generated",
175    vendor_available: true,
176    product_available: true,
177    recovery_available: true,
178    defaults: ["libminijail_flags"],
179    host_supported: true,
180
181    target: {
182        android: {
183            generated_sources: [
184                "libminijail_gen_syscall",
185                "libminijail_gen_constants",
186            ],
187        },
188        host: {
189            srcs: [
190                "linux-x86/libconstants.gen.c",
191                "linux-x86/libsyscalls.gen.c",
192            ],
193        },
194    },
195    apex_available: [
196        "//apex_available:platform",
197        "com.android.adbd",
198        "com.android.compos",
199        "com.android.media.swcodec",
200        "com.android.virt",
201    ],
202    min_sdk_version: "29",
203}
204
205cc_object {
206    name: "libminijail_gen_constants_llvmir",
207    vendor_available: true,
208    product_available: true,
209    recovery_available: true,
210    host_supported: true,
211    cflags: [
212        "-S",
213        "-O0",
214        "-emit-llvm",
215        "-Wno-unused-command-line-argument",
216    ],
217
218    target: {
219        android: {
220            generated_sources: ["libminijail_gen_constants"],
221        },
222        host: {
223            srcs: ["linux-x86/libconstants.gen.c"],
224        },
225    },
226}
227
228cc_object {
229    name: "libminijail_gen_syscall_llvmir",
230    vendor_available: true,
231    product_available: true,
232    recovery_available: true,
233    host_supported: true,
234    cflags: [
235        "-S",
236        "-O0",
237        "-emit-llvm",
238        "-Wno-unused-command-line-argument",
239    ],
240
241    target: {
242        android: {
243            generated_sources: ["libminijail_gen_syscall"],
244        },
245        host: {
246            srcs: ["linux-x86/libsyscalls.gen.c"],
247        },
248    },
249}
250
251// libminijail shared and static library for target.
252// =========================================================
253cc_library {
254    name: "libminijail",
255    host_supported: true,
256
257    vendor_available: true,
258    product_available: true,
259    recovery_available: true,
260
261    defaults: ["libminijail_flags"],
262
263    srcs: libminijailSrcFiles,
264
265    static: {
266        whole_static_libs: ["libminijail_generated"] + minijailCommonLibraries,
267    },
268    shared: {
269        static_libs: ["libminijail_generated"],
270        shared_libs: minijailCommonLibraries,
271    },
272    export_include_dirs: ["."],
273
274    target: {
275        host: {
276            cflags: [
277                "-DPRELOADPATH=\"/invalidminijailpreload.so\"",
278            ],
279        },
280    },
281    apex_available: [
282        "//apex_available:platform",
283        "com.android.adbd",
284        "com.android.compos",
285        "com.android.media.swcodec",
286        "com.android.virt",
287    ],
288    min_sdk_version: "29",
289}
290
291// Example ASan-ified libminijail shared library for target.
292// Commented out since it's only needed for local debugging.
293// =========================================================
294//cc_library_shared {
295//    name: "libminijail_asan",
296//    defaults: ["libminijail_flags"],
297//
298//    sanitize: {
299//        address: true,
300//    },
301//    relative_install_path: "asan",
302//    srcs: libminijailSrcFiles,
303//
304//    static_libs: ["libminijail_generated"],
305//    shared_libs: minijailCommonLibraries,
306//    export_include_dirs: ["."],
307//}
308
309// libminijail native unit tests using gtest.
310//
311// For a device, run with:
312// adb shell /data/nativetest/libminijail_unittest_gtest/libminijail_unittest_gtest
313//
314// For host, run with:
315// out/host/linux-x86/nativetest(64)/libminijail_unittest_gtest/libminijail_unittest_gtest
316// =========================================================
317cc_test {
318    name: "libminijail_unittest_gtest",
319    defaults: ["libminijail_flags"],
320    // TODO(b/31395668): Re-enable once the seccomp(2) syscall becomes available.
321    //host_supported: true
322
323    srcs: libminijailSrcFiles + ["libminijail_unittest.cc"] + unittestSrcFiles,
324
325    static_libs: ["libminijail_generated"],
326    shared_libs: minijailCommonLibraries,
327
328    target: {
329        android: {
330            cflags: ["-Wno-writable-strings"],
331            test_suites: ["device-tests"],
332        },
333        host: {
334            cflags: ["-DPRELOADPATH=\"/invalid\""],
335        },
336    },
337}
338
339// Syscall filtering native unit tests using gtest.
340//
341// For a device, run with:
342// adb shell /data/nativetest/syscall_filter_unittest_gtest/syscall_filter_unittest_gtest
343//
344// For host, run with:
345// out/host/linux-x86/nativetest(64)/syscall_filter_unittest_gtest/syscall_filter_unittest_gtest
346// =========================================================
347cc_test {
348    name: "syscall_filter_unittest_gtest",
349    defaults: ["libminijail_flags"],
350    host_supported: true,
351
352    srcs: [
353        "bpf.c",
354        "syscall_filter.c",
355        "syscall_wrapper.c",
356        "util.c",
357        "syscall_filter_unittest.cc",
358    ] + unittestSrcFiles,
359
360    static_libs: ["libminijail_generated"],
361    shared_libs: minijailCommonLibraries,
362
363    target: {
364        android: {
365            test_suites: ["device-tests"],
366        },
367    },
368    test_options: {
369        unit_test: true,
370    },
371    data: ["test/*"],
372}
373
374// System functionality unit tests using gtest.
375//
376// For a device, run with:
377// adb shell /data/nativetest/mj_system_unittest_gtest/mj_system_unittest_gtest
378//
379// For host, run with:
380// out/host/linux-x86/nativetest(64)/mj_system_unittest_gtest/mj_system_unittest_gtest
381// =========================================================
382cc_test {
383    name: "mj_system_unittest_gtest",
384    defaults: ["libminijail_flags"],
385    host_supported: true,
386
387    srcs: [
388        "syscall_wrapper.c",
389        "system.c",
390        "util.c",
391        "system_unittest.cc",
392    ] + unittestSrcFiles,
393
394    static_libs: ["libminijail_generated"],
395    shared_libs: minijailCommonLibraries,
396
397    target: {
398        android: {
399            test_suites: ["device-tests"],
400        },
401    },
402}
403
404// Utility functionality unit tests using gtest.
405//
406// For a device, run with:
407// adb shell /data/nativetest/mj_util_unittest_gtest/mj_util_unittest_gtest
408//
409// For host, run with:
410// out/host/linux-x86/nativetest(64)/mj_util_unittest_gtest/mj_util_unittest_gtest
411// =========================================================
412cc_test {
413    name: "mj_util_unittest_gtest",
414    defaults: ["libminijail_flags"],
415    host_supported: true,
416
417    srcs: [
418        "util.c",
419        "util_unittest.cc",
420    ] + unittestSrcFiles,
421
422    static_libs: ["libminijail_generated"],
423    shared_libs: minijailCommonLibraries,
424
425    target: {
426        android: {
427            test_suites: ["device-tests"],
428        },
429    },
430}
431
432// Utility functionality unit tests using gtest.
433//
434// For a device, run with:
435// adb shell /data/nativetest/minijail0_cli_unittest_gtest/minijail0_cli_unittest_gtest
436//
437// For host, run with:
438// out/host/linux-x86/nativetest(64)/minijail0_cli_unittest_gtest/minijail0_cli_unittest_gtest
439// =========================================================
440cc_test {
441    name: "minijail0_cli_unittest_gtest",
442    defaults: ["libminijail_flags"],
443    host_supported: true,
444
445    cflags: [
446        "-DPRELOADPATH=\"/invalid\"",
447    ],
448    srcs: libminijailSrcFiles + [
449        "config_parser.c",
450        "elfparse.c",
451        "minijail0_cli.c",
452        "minijail0_cli_unittest.cc",
453    ] + unittestSrcFiles,
454
455    static_libs: ["libminijail_generated"],
456    shared_libs: minijailCommonLibraries,
457
458    target: {
459        android: {
460            test_suites: ["device-tests"],
461        },
462    },
463    data: ["test/*"],
464    test_options: {
465        tags: ["no-remote"],
466    }
467}
468
469
470// Configuration file parser functionality unit tests using gtest.
471//
472// For a device, run with:
473// adb shell /data/nativetest/config_parser_unittest_gtest/config_parser_unittest_gtest
474//
475// For host, run with:
476// out/host/linux-x86/nativetest(64)/config_parser_unittest_gtest/config_parser_unittest_gtest
477// =========================================================
478cc_test {
479    name: "config_parser_unittest_gtest",
480    defaults: ["libminijail_flags"],
481    host_supported: true,
482
483    srcs: [
484        "config_parser.c",
485        "util.c",
486        "config_parser_unittest.cc",
487    ] + unittestSrcFiles,
488
489    static_libs: ["libminijail_generated"],
490    shared_libs: minijailCommonLibraries,
491
492    target: {
493        android: {
494            test_suites: ["device-tests"],
495        },
496    },
497    test_options: {
498        unit_test: true,
499    },
500    data: ["test/*"],
501}
502
503// libminijail_test executable for brillo_Minijail test.
504// =========================================================
505cc_test {
506    name: "libminijail_test",
507    defaults: ["libminijail_flags"],
508    test_suites: ["device-tests"],
509
510    gtest: false,
511
512    srcs: ["test/libminijail_test.cpp"],
513
514    shared_libs: [
515        "libbase",
516        "libminijail",
517    ],
518}
519
520// libminijail usage example.
521// =========================================================
522cc_binary {
523    name: "drop_privs",
524    defaults: ["libminijail_flags"],
525
526    // Don't build with ASan, but leave commented out for easy local debugging.
527    // sanitize: { address: true, },
528    srcs: ["examples/drop_privs.cpp"],
529
530    shared_libs: [
531        "libbase",
532        "libminijail",
533    ],
534}
535
536// minijail0 executable.
537// This is not currently used on Brillo/Android,
538// but it's convenient to be able to build it.
539// =========================================================
540cc_binary {
541    name: "minijail0",
542    defaults: ["libminijail_flags"],
543    host_supported: true,
544
545    cflags: [
546        "-DPRELOADPATH=\"/invalidminijailpreload.so\"",
547    ],
548    srcs: [
549        "config_parser.c",
550        "elfparse.c",
551        "minijail0.c",
552        "minijail0_cli.c",
553    ],
554
555    static_libs: ["libminijail_generated"],
556    shared_libs: minijailCommonLibraries + ["libminijail"],
557}
558