blob: 677c0146e3aa40fb778070d75e3b816067a8b2b4 [file] [log] [blame]
Tri Voa5cfd3e2018-03-22 11:35:02 -07001// Copyright (C) 2018 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
Bob Badour601ebb42021-02-03 23:07:40 -080015package {
16 default_applicable_licenses: ["system_sepolicy_license"],
17}
18
19// Added automatically by a large-scale-change that took the approach of
20// 'apply every license found to every target'. While this makes sure we respect
21// every license restriction, it may not be entirely correct.
22//
23// e.g. GPL in an MIT project might only apply to the contrib/ directory.
24//
25// Please consider splitting the single license below into multiple licenses,
26// taking care not to lose any license_kind information, and overriding the
27// default license using the 'licenses: [...]' property on targets as needed.
28//
29// For unused files, consider creating a 'filegroup' with "//visibility:private"
30// to attach the license to, and including a comment whether the files may be
31// used in the current project.
32// http://go/android-license-faq
33license {
34 name: "system_sepolicy_license",
35 visibility: [":__subpackages__"],
36 license_kinds: [
37 "SPDX-license-identifier-Apache-2.0",
38 "legacy_unencumbered",
39 ],
40 license_text: [
41 "NOTICE",
42 ],
43}
44
Jeff Vander Stoepecd288f2019-02-15 12:18:15 -080045cc_defaults { name: "selinux_policy_version", cflags: ["-DSEPOLICY_VERSION=30"], }
46
yangbill3e345372020-04-15 13:55:47 +080047// For vts_treble_sys_prop_test
48filegroup {
49 name: "private_property_contexts",
50 srcs: ["private/property_contexts"],
51 visibility: [
52 "//test/vts-testcase/security/system_property",
53 ],
54}
Inseob Kime35b49b2021-02-18 19:15:41 +090055
Inseob Kima49e7242021-03-22 10:26:13 +090056se_build_files {
57 name: "se_build_files",
Inseob Kime35b49b2021-02-18 19:15:41 +090058 srcs: [
Inseob Kima49e7242021-03-22 10:26:13 +090059 "security_classes",
60 "initial_sids",
61 "access_vectors",
62 "global_macros",
63 "neverallow_macros",
64 "mls_macros",
65 "mls_decl",
66 "mls",
67 "policy_capabilities",
68 "te_macros",
69 "attributes",
70 "ioctl_defines",
71 "ioctl_macros",
72 "*.te",
73 "roles_decl",
74 "roles",
75 "users",
76 "initial_sid_contexts",
77 "fs_use",
78 "genfs_contexts",
79 "port_contexts",
Inseob Kime35b49b2021-02-18 19:15:41 +090080 ],
81}
82
Inseob Kim7cb20812021-12-16 16:52:14 +090083se_build_files {
84 name: "sepolicy_technical_debt",
85 srcs: ["technical_debt.cil"],
86}
87
Inseob Kim0a707fa2021-12-09 23:35:11 +090088reqd_mask_policy = [":se_build_files{.reqd_mask}"]
89plat_public_policy = [":se_build_files{.plat_public}"]
90plat_private_policy = [":se_build_files{.plat_private}"]
91system_ext_public_policy = [":se_build_files{.system_ext_public}"]
92system_ext_private_policy = [":se_build_files{.system_ext_private}"]
93product_public_policy = [":se_build_files{.product_public}"]
94product_private_policy = [":se_build_files{.product_private}"]
95
Inseob Kima49e7242021-03-22 10:26:13 +090096// reqd_policy_mask - a policy.conf file which contains only the bare minimum
97// policy necessary to use checkpolicy.
98//
99// This bare-minimum policy needs to be present in all policy.conf files, but
100// should not necessarily be exported as part of the public policy.
101//
102// The rules generated by reqd_policy_mask will allow the compilation of public
103// policy and subsequent removal of CIL policy that should not be exported.
104se_policy_conf {
105 name: "reqd_policy_mask.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900106 srcs: reqd_mask_policy,
Inseob Kime35b49b2021-02-18 19:15:41 +0900107 installable: false,
108}
109
Inseob Kima49e7242021-03-22 10:26:13 +0900110se_policy_cil {
111 name: "reqd_policy_mask.cil",
112 src: ":reqd_policy_mask.conf",
113 secilc_check: false,
114 installable: false,
Inseob Kime35b49b2021-02-18 19:15:41 +0900115}
116
Inseob Kima49e7242021-03-22 10:26:13 +0900117// pub_policy - policy that will be exported to be a part of non-platform
118// policy corresponding to this platform version.
119//
120// This is a limited subset of policy that would not compile in checkpolicy on
121// its own.
122//
123// To get around this limitation, add only the required files from private
124// policy, which will generate CIL policy that will then be filtered out by the
125// reqd_policy_mask.
126//
127// There are three pub_policy.cil files below:
128// - pub_policy.cil: exported 'product', 'system_ext' and 'system' policy.
129// - system_ext_pub_policy.cil: exported 'system_ext' and 'system' policy.
130// - plat_pub_policy.cil: exported 'system' policy.
131//
132// Those above files will in turn be used to generate the following versioned cil files:
133// - product_mapping_file: the versioned, exported 'product' policy in product partition.
134// - system_ext_mapping_file: the versioned, exported 'system_ext' policy in system_ext partition.
135// - plat_mapping_file: the versioned, exported 'system' policy in system partition.
136// - plat_pub_versioned.cil: the versioned, exported 'product', 'system_ext' and 'system' policy
137// in vendor partition.
138//
139se_policy_conf {
140 name: "pub_policy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900141 srcs: plat_public_policy +
142 system_ext_public_policy +
143 product_public_policy +
144 reqd_mask_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900145 installable: false,
146}
147
148se_policy_cil {
149 name: "pub_policy.cil",
150 src: ":pub_policy.conf",
151 filter_out: [":reqd_policy_mask.cil"],
152 secilc_check: false,
153 installable: false,
154}
155
156se_policy_conf {
157 name: "system_ext_pub_policy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900158 srcs: plat_public_policy +
159 system_ext_public_policy +
160 reqd_mask_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900161 installable: false,
162}
163
164se_policy_cil {
165 name: "system_ext_pub_policy.cil",
166 src: ":system_ext_pub_policy.conf",
167 filter_out: [":reqd_policy_mask.cil"],
168 secilc_check: false,
169 installable: false,
170}
171
172se_policy_conf {
173 name: "plat_pub_policy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900174 srcs: plat_public_policy +
175 reqd_mask_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900176 installable: false,
177}
178
179se_policy_cil {
180 name: "plat_pub_policy.cil",
181 src: ":plat_pub_policy.conf",
182 filter_out: [":reqd_policy_mask.cil"],
183 secilc_check: false,
184 installable: false,
185}
186
187// plat_policy.conf - A combination of the private and public platform policy
188// which will ship with the device.
189//
190// The platform will always reflect the most recent platform version and is not
191// currently being attributized.
192se_policy_conf {
193 name: "plat_sepolicy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900194 srcs: plat_public_policy +
195 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900196 installable: false,
197}
198
199se_policy_cil {
200 name: "plat_sepolicy.cil",
201 src: ":plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900202 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kima49e7242021-03-22 10:26:13 +0900203}
204
Lokesh Gidra1269a172022-08-01 17:20:38 +0000205
Jeff Vander Stoepf9348b52021-12-14 13:32:12 +0100206se_policy_conf {
207 name: "apex_sepolicy-33.conf",
Lokesh Gidra1269a172022-08-01 17:20:38 +0000208 srcs: plat_public_policy + plat_private_policy + ["com.android.sepolicy/33/*.te"],
Jeff Vander Stoepf9348b52021-12-14 13:32:12 +0100209 installable: false,
210}
211
212se_policy_cil {
213 name: "apex_sepolicy-33.cil",
214 src: ":apex_sepolicy-33.conf",
Lokesh Gidra1269a172022-08-01 17:20:38 +0000215 filter_out: [":plat_sepolicy.cil"],
Jeff Vander Stoepf9348b52021-12-14 13:32:12 +0100216 installable: false,
217 stem: "apex_sepolicy.cil",
218}
219
Sandro143988d2022-08-05 11:38:56 +0000220se_policy_cil {
221 name: "decompiled_sepolicy-without_apex.cil",
222 src: ":precompiled_sepolicy-without_apex",
223 decompile_binary: true,
224}
225
226se_policy_cil {
227 name: "apex_sepolicy-decompiled.cil",
228 src: ":precompiled_sepolicy",
229 decompile_binary: true,
230 filter_out: [":decompiled_sepolicy-without_apex.cil"],
231 additional_cil_files: ["com.android.sepolicy/33/definitions/definitions.cil"],
232 secilc_check: false,
233}
234
Inseob Kim6cc75f42021-04-29 13:53:20 +0000235// userdebug_plat_policy.conf - the userdebug version plat_sepolicy.cil
236se_policy_conf {
237 name: "userdebug_plat_sepolicy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900238 srcs: plat_public_policy +
239 plat_private_policy,
Inseob Kim6cc75f42021-04-29 13:53:20 +0000240 build_variant: "userdebug",
241 installable: false,
242}
243
244se_policy_cil {
245 name: "userdebug_plat_sepolicy.cil",
246 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900247 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kim6cc75f42021-04-29 13:53:20 +0000248 debug_ramdisk: true,
Yi-Yo Chiang68478b12021-10-16 03:23:05 +0800249 dist: {
250 targets: ["droidcore"],
251 },
Inseob Kim6cc75f42021-04-29 13:53:20 +0000252}
253
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000254// A copy of the userdebug_plat_policy in GSI.
255soong_config_module_type {
256 name: "gsi_se_policy_cil",
257 module_type: "se_policy_cil",
258 config_namespace: "ANDROID",
259 bool_variables: [
260 "PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT",
261 ],
262 properties: [
263 "enabled",
264 "installable",
265 ],
266}
267
268gsi_se_policy_cil {
269 name: "system_ext_userdebug_plat_sepolicy.cil",
270 stem: "userdebug_plat_sepolicy.cil",
271 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900272 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000273 system_ext_specific: true,
274 enabled: false,
275 installable: false,
276 soong_config_variables: {
277 PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT: {
278 enabled: true,
279 installable: true,
280 },
281 },
282}
283
Inseob Kima49e7242021-03-22 10:26:13 +0900284// system_ext_policy.conf - A combination of the private and public system_ext
285// policy which will ship with the device. System_ext policy is not attributized
286se_policy_conf {
287 name: "system_ext_sepolicy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900288 srcs: plat_public_policy +
289 plat_private_policy +
290 system_ext_public_policy +
291 system_ext_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900292 installable: false,
293}
294
295se_policy_cil {
296 name: "system_ext_sepolicy.cil",
297 src: ":system_ext_sepolicy.conf",
298 system_ext_specific: true,
299 filter_out: [":plat_sepolicy.cil"],
300 remove_line_marker: true,
301}
302
303// product_policy.conf - A combination of the private and public product policy
304// which will ship with the device. Product policy is not attributized
305se_policy_conf {
306 name: "product_sepolicy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900307 srcs: plat_public_policy +
308 plat_private_policy +
309 system_ext_public_policy +
310 system_ext_private_policy +
311 product_public_policy +
312 product_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900313 installable: false,
314}
315
316se_policy_cil {
317 name: "product_sepolicy.cil",
318 src: ":product_sepolicy.conf",
319 product_specific: true,
320 filter_out: [":plat_sepolicy.cil", ":system_ext_sepolicy.cil"],
321 remove_line_marker: true,
322}
323
Inseob Kim039175b2021-03-25 15:37:34 +0900324// policy mapping files
325// auto-generate the mapping file for current platform policy, since it needs to
326// track platform policy development
327se_versioned_policy {
328 name: "plat_mapping_file",
329 base: ":plat_pub_policy.cil",
330 mapping: true,
331 version: "current",
332 relative_install_path: "mapping", // install to /system/etc/selinux/mapping
333}
334
335se_versioned_policy {
336 name: "system_ext_mapping_file",
337 base: ":system_ext_pub_policy.cil",
338 mapping: true,
339 version: "current",
340 filter_out: [":plat_mapping_file"],
341 relative_install_path: "mapping", // install to /system_ext/etc/selinux/mapping
342 system_ext_specific: true,
343}
344
345se_versioned_policy {
346 name: "product_mapping_file",
347 base: ":pub_policy.cil",
348 mapping: true,
349 version: "current",
350 filter_out: [":plat_mapping_file", ":system_ext_mapping_file"],
351 relative_install_path: "mapping", // install to /product/etc/selinux/mapping
352 product_specific: true,
353}
354
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900355// vendor/odm sepolicy
356//
357// If BOARD_SEPOLICY_VERS is set to a value other than PLATFORM_SEPOLICY_VERSION,
358// policy files of platform (system, system_ext, product) can't be mixed with
359// policy files of vendor (vendor, odm). If it's the case, platform policies and
360// vendor policies are separately built. More specifically,
361//
362// - Platform policy files needed to build vendor policies, such as plat_policy,
363// plat_mapping_cil, plat_pub_policy, reqd_policy_mask, are built from the
364// prebuilts (copy of platform policy files of version BOARD_SEPOLICY_VERS).
365//
366// - sepolicy_neverallows only checks platform policies, and a new module
367// sepolicy_neverallows_vendor checks vendor policies.
368//
369// - neverallow checks are turned off while compiling precompiled_sepolicy
370// module and sepolicy module.
371//
372// - Vendor policies are not checked on the compat test (compat.mk).
373//
374// In such scenario, we can grab platform policy files from the prebuilts/api
375// directory. But we need more than that: prebuilts of system_ext, product,
376// system/sepolicy/reqd_mask, and system/sepolicy/vendor. The following
377// variables are introduced to specify such prebuilts.
378//
379// - BOARD_REQD_MASK_POLICY (prebuilt of system/sepolicy/reqd_mask)
380// - BOARD_PLAT_VENDOR_POLICY (prebuilt of system/sepolicy/vendor)
381// - BOARD_SYSTEM_EXT_PUBLIC_PREBUILT_DIRS (prebuilt of system_ext public)
382// - BOARD_SYSTEM_EXT_PRIVATE_PREBUILT_DIRS (prebuilt of system_ext private)
383// - BOARD_PRODUCT_PUBLIC_PREBUILT_DIRS (prebuilt of product public)
384// - BOARD_PRODUCT_PRIVATE_PREBUILT_DIRS (prebuilt of product private)
385//
386// Vendors are responsible for copying policy files from the old version of the
387// source tree as prebuilts, and for setting BOARD_*_POLICY variables so they
388// can be used to build vendor policies.
389//
390// To support both mixed build and normal build, platform policy files are
391// indirectly referred as {.(partition)_(scope)_for_vendor}. They will be equal
392// to {.(partition)_scope)} if BOARD_SEPOLICY_VERS == PLATFORM_SEPOLICY_VERSION.
393// Otherwise, they will be equal to the Makefile variables above.
394
395plat_public_policies_for_vendor = [
396 ":se_build_files{.plat_public_for_vendor}",
397 ":se_build_files{.system_ext_public_for_vendor}",
398 ":se_build_files{.product_public_for_vendor}",
399 ":se_build_files{.reqd_mask_for_vendor}",
400]
401
402plat_policies_for_vendor = [
403 ":se_build_files{.plat_public_for_vendor}",
404 ":se_build_files{.plat_private_for_vendor}",
405 ":se_build_files{.system_ext_public_for_vendor}",
406 ":se_build_files{.system_ext_private_for_vendor}",
407 ":se_build_files{.product_public_for_vendor}",
408 ":se_build_files{.product_private_for_vendor}",
409]
410
411se_policy_conf {
412 name: "plat_policy_for_vendor.conf",
413 srcs: plat_policies_for_vendor,
414 installable: false,
415}
416
417se_policy_cil {
418 name: "plat_policy_for_vendor.cil",
419 src: ":plat_policy_for_vendor.conf",
420 additional_cil_files: [":sepolicy_technical_debt{.plat_private_for_vendor}"],
421 installable: false,
422}
423
424se_policy_conf {
425 name: "reqd_policy_mask_for_vendor.conf",
426 srcs: [":se_build_files{.reqd_mask_for_vendor}"],
427 installable: false,
428}
429
430se_policy_cil {
431 name: "reqd_policy_mask_for_vendor.cil",
432 src: ":reqd_policy_mask_for_vendor.conf",
433 secilc_check: false,
434 installable: false,
435}
436
437se_policy_conf {
438 name: "pub_policy_for_vendor.conf",
439 srcs: plat_public_policies_for_vendor,
440 installable: false,
441}
442
443se_policy_cil {
444 name: "pub_policy_for_vendor.cil",
445 src: ":pub_policy_for_vendor.conf",
446 filter_out: [":reqd_policy_mask_for_vendor.cil"],
447 secilc_check: false,
448 installable: false,
449}
450
451se_versioned_policy {
452 name: "plat_mapping_file_for_vendor",
453 base: ":pub_policy_for_vendor.cil",
454 mapping: true,
455 version: "vendor",
456 installable: false,
457}
458
Inseob Kim039175b2021-03-25 15:37:34 +0900459// plat_pub_versioned.cil - the exported platform policy associated with the version
460// that non-platform policy targets.
461se_versioned_policy {
462 name: "plat_pub_versioned.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900463 base: ":pub_policy_for_vendor.cil",
464 target_policy: ":pub_policy_for_vendor.cil",
465 version: "vendor",
Inseob Kim039175b2021-03-25 15:37:34 +0900466 vendor: true,
467}
468
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900469// vendor_policy.cil - the vendor sepolicy. This needs attributization and to be combined
470// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
471// policy and the platform public policy files in order to use checkpolicy.
472se_policy_conf {
473 name: "vendor_sepolicy.conf",
474 srcs: plat_public_policies_for_vendor + [
475 ":se_build_files{.plat_vendor_for_vendor}",
476 ":se_build_files{.vendor}",
477 ],
478 installable: false,
479}
480
481se_policy_cil {
482 name: "vendor_sepolicy.cil.raw",
483 src: ":vendor_sepolicy.conf",
484 filter_out: [":reqd_policy_mask_for_vendor.cil"],
485 secilc_check: false, // will be done in se_versioned_policy module
486 installable: false,
487}
488
489se_versioned_policy {
490 name: "vendor_sepolicy.cil",
491 base: ":pub_policy_for_vendor.cil",
492 target_policy: ":vendor_sepolicy.cil.raw",
493 version: "vendor",
494 dependent_cils: [
495 ":plat_policy_for_vendor.cil",
496 ":plat_pub_versioned.cil",
497 ":plat_mapping_file_for_vendor",
498 ],
499 filter_out: [":plat_pub_versioned.cil"],
500 vendor: true,
501}
502
503// odm_policy.cil - the odl sepolicy. This needs attributization and to be combined
504// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
505// policy and the platform public policy files in order to use checkpolicy.
506se_policy_conf {
507 name: "odm_sepolicy.conf",
508 srcs: plat_public_policies_for_vendor + [
509 ":se_build_files{.plat_vendor_for_vendor}",
510 ":se_build_files{.vendor}",
511 ":se_build_files{.odm}",
512 ],
513 installable: false,
514}
515
516se_policy_cil {
517 name: "odm_sepolicy.cil.raw",
518 src: ":odm_sepolicy.conf",
519 filter_out: [
520 ":reqd_policy_mask_for_vendor.cil",
521 ":vendor_sepolicy.cil",
522 ],
523 secilc_check: false, // will be done in se_versioned_policy module
524 installable: false,
525}
526
527se_versioned_policy {
528 name: "odm_sepolicy.cil",
529 base: ":pub_policy_for_vendor.cil",
530 target_policy: ":odm_sepolicy.cil.raw",
531 version: "vendor",
532 dependent_cils: [
533 ":plat_policy_for_vendor.cil",
534 ":plat_pub_versioned.cil",
535 ":plat_mapping_file_for_vendor",
536 ":vendor_sepolicy.cil",
537 ],
538 filter_out: [":plat_pub_versioned.cil", ":vendor_sepolicy.cil"],
539 device_specific: true,
540}
541
Inseob Kim039175b2021-03-25 15:37:34 +0900542//////////////////////////////////
543// Precompiled sepolicy is loaded if and only if:
544// - plat_sepolicy_and_mapping.sha256 equals
545// precompiled_sepolicy.plat_sepolicy_and_mapping.sha256
546// AND
547// - system_ext_sepolicy_and_mapping.sha256 equals
548// precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256
549// AND
550// - product_sepolicy_and_mapping.sha256 equals
551// precompiled_sepolicy.product_sepolicy_and_mapping.sha256
Jeff Vander Stoepf9348b52021-12-14 13:32:12 +0100552// AND
553// - apex_sepolicy.sha256 equals
554// precompiled_sepolicy.apex_sepolicy.sha256
Inseob Kim039175b2021-03-25 15:37:34 +0900555// See system/core/init/selinux.cpp for details.
556//////////////////////////////////
557genrule {
558 name: "plat_sepolicy_and_mapping.sha256_gen",
559 srcs: [":plat_sepolicy.cil", ":plat_mapping_file"],
560 out: ["plat_sepolicy_and_mapping.sha256"],
561 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
562}
563
564prebuilt_etc {
565 name: "plat_sepolicy_and_mapping.sha256",
566 filename: "plat_sepolicy_and_mapping.sha256",
567 src: ":plat_sepolicy_and_mapping.sha256_gen",
568 relative_install_path: "selinux",
569}
570
571genrule {
Jeff Vander Stoepf9348b52021-12-14 13:32:12 +0100572 name: "apex_sepolicy.sha256_gen",
573 srcs: [":apex_sepolicy-33.cil"],
574 out: ["apex_sepolicy.sha256"],
575 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
576}
577
578prebuilt_etc {
579 name: "apex_sepolicy.sha256",
580 filename: "apex_sepolicy.sha256",
581 src: ":apex_sepolicy.sha256_gen",
582 installable: false,
583}
584
585genrule {
Inseob Kim039175b2021-03-25 15:37:34 +0900586 name: "system_ext_sepolicy_and_mapping.sha256_gen",
587 srcs: [":system_ext_sepolicy.cil", ":system_ext_mapping_file"],
588 out: ["system_ext_sepolicy_and_mapping.sha256"],
589 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
590}
591
592prebuilt_etc {
593 name: "system_ext_sepolicy_and_mapping.sha256",
594 filename: "system_ext_sepolicy_and_mapping.sha256",
595 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
596 relative_install_path: "selinux",
597 system_ext_specific: true,
598}
599
600genrule {
601 name: "product_sepolicy_and_mapping.sha256_gen",
602 srcs: [":product_sepolicy.cil", ":product_mapping_file"],
603 out: ["product_sepolicy_and_mapping.sha256"],
604 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
605}
606
607prebuilt_etc {
608 name: "product_sepolicy_and_mapping.sha256",
609 filename: "product_sepolicy_and_mapping.sha256",
610 src: ":product_sepolicy_and_mapping.sha256_gen",
611 relative_install_path: "selinux",
612 product_specific: true,
613}
614
Inseob Kim1c056b12021-04-30 00:11:43 +0900615sepolicy_vers {
616 name: "plat_sepolicy_vers.txt",
617 version: "vendor",
618 vendor: true,
619}
620
Inseob Kim731182a2021-05-06 11:44:37 +0000621soong_config_module_type {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900622 name: "precompiled_sepolicy_prebuilts_defaults",
Inseob Kim731182a2021-05-06 11:44:37 +0000623 module_type: "prebuilt_defaults",
624 config_namespace: "ANDROID",
625 bool_variables: ["BOARD_USES_ODMIMAGE"],
626 properties: ["vendor", "device_specific"],
627}
628
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900629precompiled_sepolicy_prebuilts_defaults {
630 name: "precompiled_sepolicy_prebuilts",
Inseob Kim731182a2021-05-06 11:44:37 +0000631 soong_config_variables: {
632 BOARD_USES_ODMIMAGE: {
633 device_specific: true,
634 conditions_default: {
635 vendor: true,
636 },
637 },
638 },
639}
640
641//////////////////////////////////
642// SHA-256 digest of the plat_sepolicy.cil and plat_mapping_file against
643// which precompiled_policy was built.
644//////////////////////////////////
645prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900646 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000647 name: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
648 filename: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
649 src: ":plat_sepolicy_and_mapping.sha256_gen",
650 relative_install_path: "selinux",
651}
652
653//////////////////////////////////
Jeff Vander Stoepf9348b52021-12-14 13:32:12 +0100654// SHA-256 digest of the apex_sepolicy.cil against which precompiled_policy
655// was built.
656//////////////////////////////////
657prebuilt_etc {
658 defaults: ["precompiled_sepolicy_prebuilts"],
659 name: "precompiled_sepolicy.apex_sepolicy.sha256",
660 filename: "precompiled_sepolicy.apex_sepolicy.sha256",
661 src: ":apex_sepolicy.sha256_gen",
662 relative_install_path: "selinux",
663}
664
665//////////////////////////////////
Inseob Kim731182a2021-05-06 11:44:37 +0000666// SHA-256 digest of the system_ext_sepolicy.cil and system_ext_mapping_file against
667// which precompiled_policy was built.
668//////////////////////////////////
669prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900670 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000671 name: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
672 filename: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
673 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
674 relative_install_path: "selinux",
675}
676
677//////////////////////////////////
678// SHA-256 digest of the product_sepolicy.cil and product_mapping_file against
679// which precompiled_policy was built.
680//////////////////////////////////
681prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900682 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000683 name: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
684 filename: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
685 src: ":product_sepolicy_and_mapping.sha256_gen",
686 relative_install_path: "selinux",
687}
688
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900689soong_config_module_type {
690 name: "precompiled_se_policy_binary",
691 module_type: "se_policy_binary",
692 config_namespace: "ANDROID",
693 bool_variables: ["BOARD_USES_ODMIMAGE", "IS_TARGET_MIXED_SEPOLICY"],
694 value_variables: ["MIXED_SEPOLICY_VERSION"],
695 properties: ["vendor", "device_specific", "srcs", "ignore_neverallow"],
696}
697
698precompiled_se_policy_binary {
699 name: "precompiled_sepolicy",
700 srcs: [
701 ":plat_sepolicy.cil",
Jeff Vander Stoepf9348b52021-12-14 13:32:12 +0100702 ":apex_sepolicy-33.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900703 ":plat_pub_versioned.cil",
704 ":system_ext_sepolicy.cil",
705 ":product_sepolicy.cil",
706 ":vendor_sepolicy.cil",
707 ":odm_sepolicy.cil",
708 ],
709 soong_config_variables: {
710 BOARD_USES_ODMIMAGE: {
711 device_specific: true,
712 conditions_default: {
713 vendor: true,
714 },
715 },
716 IS_TARGET_MIXED_SEPOLICY: {
717 ignore_neverallow: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900718 },
719 MIXED_SEPOLICY_VERSION: {
720 srcs: [
721 ":plat_%s.cil",
722 ":system_ext_%s.cil",
723 ":product_%s.cil",
724 ],
725 conditions_default: {
726 srcs: [
727 ":plat_mapping_file",
728 ":system_ext_mapping_file",
729 ":product_mapping_file",
730 ],
731 },
732 },
733 },
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900734 required: [
735 "sepolicy_neverallows",
736 "sepolicy_neverallows_vendor",
737 ],
Inseob Kimeec39192022-01-21 11:47:54 +0900738 dist: {
739 targets: ["base-sepolicy-files-for-mapping"],
740 },
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900741}
Inseob Kim731182a2021-05-06 11:44:37 +0000742
Sandro143988d2022-08-05 11:38:56 +0000743precompiled_se_policy_binary {
744 name: "precompiled_sepolicy-without_apex",
745 srcs: [
746 ":plat_sepolicy.cil",
747 ":plat_pub_versioned.cil",
748 ":system_ext_sepolicy.cil",
749 ":product_sepolicy.cil",
750 ":vendor_sepolicy.cil",
751 ":odm_sepolicy.cil",
752 ],
753 soong_config_variables: {
754 BOARD_USES_ODMIMAGE: {
755 device_specific: true,
756 conditions_default: {
757 vendor: true,
758 },
759 },
760 IS_TARGET_MIXED_SEPOLICY: {
761 ignore_neverallow: true,
762 },
763 MIXED_SEPOLICY_VERSION: {
764 srcs: [
765 ":plat_%s.cil",
766 ":system_ext_%s.cil",
767 ":product_%s.cil",
768 ],
769 conditions_default: {
770 srcs: [
771 ":plat_mapping_file",
772 ":system_ext_mapping_file",
773 ":product_mapping_file",
774 ],
775 },
776 },
777 },
778 required: [
779 "sepolicy_neverallows",
780 "sepolicy_neverallows_vendor",
781 ],
782 dist: {
783 targets: ["base-sepolicy-files-for-mapping"],
784 },
785}
786
Inseob Kim5bbcd682021-12-28 14:57:03 +0900787// policy for recovery
788se_policy_conf {
789 name: "recovery_sepolicy.conf",
790 srcs: plat_policies_for_vendor + [
791 ":se_build_files{.plat_vendor_for_vendor}",
792 ":se_build_files{.vendor}",
793 ":se_build_files{.odm}",
794 ],
795 target_recovery: true,
796 installable: false,
797}
798
799se_policy_cil {
800 name: "recovery_sepolicy.cil",
801 src: ":recovery_sepolicy.conf",
802 secilc_check: false, // will be done in se_policy_binary module
803 installable: false,
804}
805
806se_policy_binary {
807 name: "sepolicy.recovery",
808 srcs: [":recovery_sepolicy.cil"],
809 stem: "sepolicy",
810 recovery: true,
811}
812
Inseob Kima49e7242021-03-22 10:26:13 +0900813//////////////////////////////////
814// SELinux policy embedded into CTS.
815// CTS checks neverallow rules of this policy against the policy of the device under test.
816//////////////////////////////////
817se_policy_conf {
818 name: "general_sepolicy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900819 srcs: plat_public_policy +
820 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900821 build_variant: "user",
822 cts: true,
823 exclude_build_test: true,
824}
Inseob Kimd5816612021-09-15 03:01:05 +0000825
826//////////////////////////////////
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000827// Base system policy for treble sepolicy tests.
828// If system sepolicy is extended (e.g. by SoC vendors), their plat_pub_versioned.cil may differ
829// with system/sepolicy/prebuilts/api/{version}/plat_pub_versioned.cil. In that case,
830// BOARD_PLAT_PUB_VERSIONED_POLICY can be used to specify extended plat_pub_versioned.cil.
831// See treble_sepolicy_tests_for_release.mk for more details.
832//////////////////////////////////
833se_policy_conf {
834 name: "base_plat_sepolicy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900835 srcs: plat_public_policy +
836 plat_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000837 build_variant: "user",
838 installable: false,
839}
840
841se_policy_cil {
842 name: "base_plat_sepolicy.cil",
843 src: ":base_plat_sepolicy.conf",
844 additional_cil_files: ["private/technical_debt.cil"],
845 installable: false,
846 secilc_check: false, // done by se_policy_binary
847}
848
849se_policy_binary {
850 name: "base_plat_sepolicy",
851 srcs: [":base_plat_sepolicy.cil"],
852 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900853 dist: {
854 targets: ["base-sepolicy-files-for-mapping"],
855 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000856}
857
858se_policy_conf {
859 name: "base_system_ext_sepolicy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900860 srcs: plat_public_policy +
861 plat_private_policy +
862 system_ext_public_policy +
863 system_ext_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000864 build_variant: "user",
865 installable: false,
866}
867
868se_policy_cil {
869 name: "base_system_ext_sepolicy.cil",
870 src: ":base_system_ext_sepolicy.conf",
871 additional_cil_files: ["private/technical_debt.cil"],
872 system_ext_specific: true,
873 installable: false,
874 secilc_check: false, // done by se_policy_binary
875}
876
877se_policy_binary {
878 name: "base_system_ext_sepolicy",
879 srcs: [":base_system_ext_sepolicy.cil"],
880 system_ext_specific: true,
881 installable: false,
882}
883
884se_policy_conf {
885 name: "base_product_sepolicy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900886 srcs: plat_public_policy +
887 plat_private_policy +
888 system_ext_public_policy +
889 system_ext_private_policy +
890 product_public_policy +
891 product_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000892 build_variant: "user",
893 installable: false,
894}
895
896se_policy_cil {
897 name: "base_product_sepolicy.cil",
898 src: ":base_product_sepolicy.conf",
899 additional_cil_files: ["private/technical_debt.cil"],
900 product_specific: true,
901 installable: false,
902 secilc_check: false, // done by se_policy_binary
903}
904
905se_policy_binary {
906 name: "base_product_sepolicy",
907 srcs: [":base_product_sepolicy.cil"],
908 product_specific: true,
909 installable: false,
910}
911
912se_policy_conf {
913 name: "base_plat_pub_policy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900914 srcs: plat_public_policy +
915 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000916 build_variant: "user",
917 installable: false,
918}
919
920se_policy_cil {
921 name: "base_plat_pub_policy.cil",
922 src: ":base_plat_pub_policy.conf",
923 filter_out: [":reqd_policy_mask.cil"],
924 secilc_check: false,
925 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900926 dist: {
927 targets: ["base-sepolicy-files-for-mapping"],
928 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000929}
930
931se_policy_conf {
932 name: "base_system_ext_pub_policy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900933 srcs: plat_public_policy +
934 system_ext_public_policy +
935 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000936 build_variant: "user",
937 installable: false,
938}
939
940se_policy_cil {
941 name: "base_system_ext_pub_policy.cil",
942 src: ":base_system_ext_pub_policy.conf",
943 filter_out: [":reqd_policy_mask.cil"],
944 secilc_check: false,
945 installable: false,
946}
947
948se_policy_conf {
949 name: "base_product_pub_policy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900950 srcs: plat_public_policy +
951 system_ext_public_policy +
952 product_public_policy +
953 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000954 build_variant: "user",
955 installable: false,
956}
957
958se_policy_cil {
959 name: "base_product_pub_policy.cil",
960 src: ":base_product_pub_policy.conf",
961 filter_out: [":reqd_policy_mask.cil"],
962 secilc_check: false,
963 installable: false,
964}
965
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800966// bug_map - Bug tracking information for selinux denials loaded by auditd.
Inseob Kim41964032022-04-22 07:50:22 +0900967se_build_files {
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800968 name: "bug_map_files",
969 srcs: ["bug_map"],
970}
971
972se_bug_map {
973 name: "plat_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900974 srcs: [":bug_map_files{.plat_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800975 stem: "bug_map",
976}
977
978se_bug_map {
979 name: "system_ext_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900980 srcs: [":bug_map_files{.system_ext_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800981 stem: "bug_map",
982 system_ext_specific: true,
983}
984
985se_bug_map {
986 name: "vendor_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900987 srcs: [":bug_map_files{.vendor}", ":bug_map_files{.plat_vendor_for_vendor}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800988 // Legacy file name of the vendor partition bug_map.
989 stem: "selinux_denial_metadata",
990 vendor: true,
991}
992
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900993se_neverallow_test {
994 name: "sepolicy_neverallows",
995 srcs: plat_public_policy +
996 plat_private_policy +
997 system_ext_public_policy +
998 system_ext_private_policy +
999 product_public_policy +
1000 product_private_policy,
1001}
1002
1003se_neverallow_test {
1004 name: "sepolicy_neverallows_vendor",
1005 srcs: plat_policies_for_vendor + [
1006 ":se_build_files{.plat_vendor_for_vendor}",
1007 ":se_build_files{.vendor}",
1008 ":se_build_files{.odm}",
1009 ],
1010}
1011
Inseob Kim4d90b7e2021-09-27 13:43:01 +00001012//////////////////////////////////
Inseob Kimd5816612021-09-15 03:01:05 +00001013// se_freeze_test compares the plat sepolicy with the prebuilt sepolicy
1014// Additional directories can be specified via Makefile variables:
1015// SEPOLICY_FREEZE_TEST_EXTRA_DIRS and SEPOLICY_FREEZE_TEST_EXTRA_PREBUILT_DIRS.
1016//////////////////////////////////
1017se_freeze_test {
1018 name: "sepolicy_freeze_test",
1019}
Inseob Kim61257ca2022-02-25 11:26:16 +09001020
1021//////////////////////////////////
1022// sepolicy_test checks various types of violations, which can't be easily done
1023// by CIL itself. Refer tests/sepolicy_tests.py for more detail.
1024//////////////////////////////////
1025genrule {
1026 name: "sepolicy_test",
1027 srcs: [
1028 ":plat_file_contexts",
1029 ":vendor_file_contexts",
1030 ":system_ext_file_contexts",
1031 ":product_file_contexts",
1032 ":odm_file_contexts",
1033 ":precompiled_sepolicy",
1034 ],
1035 tools: ["sepolicy_tests"],
1036 out: ["sepolicy_test"],
1037 cmd: "$(location sepolicy_tests) " +
1038 "-f $(location :plat_file_contexts) " +
1039 "-f $(location :vendor_file_contexts) " +
1040 "-f $(location :system_ext_file_contexts) " +
1041 "-f $(location :product_file_contexts) " +
1042 "-f $(location :odm_file_contexts) " +
1043 "-p $(location :precompiled_sepolicy) && " +
1044 "touch $(out)",
1045}