blob: aef08b29dbffae5bfcd789965c39d561db10cfa2 [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
Inseob Kimff2018f2024-04-17 09:48:43 +090045cc_defaults {
46 name: "selinux_policy_version",
47 cflags: ["-DSEPOLICY_VERSION=30"],
48}
Jeff Vander Stoepecd288f2019-02-15 12:18:15 -080049
yangbill3e345372020-04-15 13:55:47 +080050// For vts_treble_sys_prop_test
51filegroup {
52 name: "private_property_contexts",
53 srcs: ["private/property_contexts"],
54 visibility: [
55 "//test/vts-testcase/security/system_property",
56 ],
57}
Inseob Kime35b49b2021-02-18 19:15:41 +090058
Inseob Kima49e7242021-03-22 10:26:13 +090059se_build_files {
60 name: "se_build_files",
Inseob Kime35b49b2021-02-18 19:15:41 +090061 srcs: [
Inseob Kima49e7242021-03-22 10:26:13 +090062 "security_classes",
63 "initial_sids",
64 "access_vectors",
65 "global_macros",
66 "neverallow_macros",
67 "mls_macros",
68 "mls_decl",
69 "mls",
70 "policy_capabilities",
71 "te_macros",
72 "attributes",
73 "ioctl_defines",
74 "ioctl_macros",
75 "*.te",
76 "roles_decl",
77 "roles",
78 "users",
79 "initial_sid_contexts",
80 "fs_use",
81 "genfs_contexts",
82 "port_contexts",
Inseob Kime35b49b2021-02-18 19:15:41 +090083 ],
84}
85
Inseob Kim7cb20812021-12-16 16:52:14 +090086se_build_files {
87 name: "sepolicy_technical_debt",
88 srcs: ["technical_debt.cil"],
89}
90
Cole Faustac1f8152024-06-17 12:39:02 -070091phony {
Inseob Kim151562f2024-04-12 10:53:34 +090092 // Currently used only for aosp_cf_system_x86_64
93 // TODO(b/329208946): migrate selinux_policy_system to Soong
94 name: "selinux_policy_system_soong",
95 required: [
96 "plat_bug_map",
97 "plat_file_contexts",
98 "plat_hwservice_contexts",
99 "plat_keystore2_key_contexts",
100 "plat_mac_permissions.xml",
101 "plat_mapping_file",
102 "plat_property_contexts",
103 "plat_seapp_contexts",
104 "plat_sepolicy.cil",
Inseob Kim9b323082024-11-06 17:10:09 +0900105 "plat_sepolicy_genfs_202504.cil",
Inseob Kim151562f2024-04-12 10:53:34 +0900106 "plat_service_contexts",
107 "secilc",
Cole Faustac1f8152024-06-17 12:39:02 -0700108 "plat_29.0.cil",
109 "29.0.compat.cil",
110 "plat_30.0.cil",
111 "30.0.compat.cil",
112 "plat_31.0.cil",
113 "31.0.compat.cil",
114 "plat_32.0.cil",
115 "32.0.compat.cil",
116 "plat_33.0.cil",
117 "33.0.compat.cil",
118 "plat_34.0.cil",
119 "34.0.compat.cil",
120 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
121 "202404": [],
122 default: [
123 "plat_202404.cil",
124 "202404.compat.cil",
125 ],
126 }) + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
Cole Faustc22dece2024-06-20 12:58:34 -0700127 true: ["plat_sepolicy_and_mapping.sha256"],
Cole Faustac1f8152024-06-17 12:39:02 -0700128 default: [],
Nikita Ioffe48966b62024-10-22 14:01:17 +0000129 }) + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
130 true: ["plat_tee_service_contexts"],
131 default: [],
Cole Faustac1f8152024-06-17 12:39:02 -0700132 }),
Inseob Kim151562f2024-04-12 10:53:34 +0900133}
134
Inseob Kimff2018f2024-04-17 09:48:43 +0900135reqd_mask_policy = [":se_build_files{.reqd_mask}"]
136plat_public_policy = [":se_build_files{.plat_public}"]
137plat_private_policy = [":se_build_files{.plat_private}"]
138system_ext_public_policy = [":se_build_files{.system_ext_public}"]
Inseob Kim0a707fa2021-12-09 23:35:11 +0900139system_ext_private_policy = [":se_build_files{.system_ext_private}"]
Inseob Kimff2018f2024-04-17 09:48:43 +0900140product_public_policy = [":se_build_files{.product_public}"]
141product_private_policy = [":se_build_files{.product_private}"]
Inseob Kim0a707fa2021-12-09 23:35:11 +0900142
Inseob Kima49e7242021-03-22 10:26:13 +0900143// reqd_policy_mask - a policy.conf file which contains only the bare minimum
144// policy necessary to use checkpolicy.
145//
146// This bare-minimum policy needs to be present in all policy.conf files, but
147// should not necessarily be exported as part of the public policy.
148//
149// The rules generated by reqd_policy_mask will allow the compilation of public
150// policy and subsequent removal of CIL policy that should not be exported.
151se_policy_conf {
152 name: "reqd_policy_mask.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900153 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900154 srcs: reqd_mask_policy,
Inseob Kime35b49b2021-02-18 19:15:41 +0900155 installable: false,
156}
157
Inseob Kima49e7242021-03-22 10:26:13 +0900158se_policy_cil {
159 name: "reqd_policy_mask.cil",
160 src: ":reqd_policy_mask.conf",
161 secilc_check: false,
162 installable: false,
Inseob Kime35b49b2021-02-18 19:15:41 +0900163}
164
Inseob Kima49e7242021-03-22 10:26:13 +0900165// pub_policy - policy that will be exported to be a part of non-platform
166// policy corresponding to this platform version.
167//
168// This is a limited subset of policy that would not compile in checkpolicy on
169// its own.
170//
171// To get around this limitation, add only the required files from private
172// policy, which will generate CIL policy that will then be filtered out by the
173// reqd_policy_mask.
174//
175// There are three pub_policy.cil files below:
176// - pub_policy.cil: exported 'product', 'system_ext' and 'system' policy.
177// - system_ext_pub_policy.cil: exported 'system_ext' and 'system' policy.
178// - plat_pub_policy.cil: exported 'system' policy.
179//
180// Those above files will in turn be used to generate the following versioned cil files:
181// - product_mapping_file: the versioned, exported 'product' policy in product partition.
182// - system_ext_mapping_file: the versioned, exported 'system_ext' policy in system_ext partition.
183// - plat_mapping_file: the versioned, exported 'system' policy in system partition.
184// - plat_pub_versioned.cil: the versioned, exported 'product', 'system_ext' and 'system' policy
185// in vendor partition.
186//
187se_policy_conf {
188 name: "pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900189 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900190 srcs: plat_public_policy +
191 system_ext_public_policy +
192 product_public_policy +
193 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900194 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900195 installable: false,
196}
197
198se_policy_cil {
199 name: "pub_policy.cil",
200 src: ":pub_policy.conf",
201 filter_out: [":reqd_policy_mask.cil"],
202 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900203 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900204 installable: false,
205}
206
207se_policy_conf {
208 name: "system_ext_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900209 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900210 srcs: plat_public_policy +
211 system_ext_public_policy +
212 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900213 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900214 installable: false,
215}
216
217se_policy_cil {
218 name: "system_ext_pub_policy.cil",
219 src: ":system_ext_pub_policy.conf",
220 filter_out: [":reqd_policy_mask.cil"],
221 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900222 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900223 installable: false,
224}
225
226se_policy_conf {
227 name: "plat_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900228 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900229 srcs: plat_public_policy +
230 reqd_mask_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900231 installable: false,
232}
233
234se_policy_cil {
235 name: "plat_pub_policy.cil",
236 src: ":plat_pub_policy.conf",
237 filter_out: [":reqd_policy_mask.cil"],
238 secilc_check: false,
239 installable: false,
240}
241
242// plat_policy.conf - A combination of the private and public platform policy
243// which will ship with the device.
244//
245// The platform will always reflect the most recent platform version and is not
246// currently being attributized.
247se_policy_conf {
248 name: "plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900249 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900250 srcs: plat_public_policy +
251 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900252 installable: false,
253}
254
255se_policy_cil {
256 name: "plat_sepolicy.cil",
257 src: ":plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900258 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kima49e7242021-03-22 10:26:13 +0900259}
260
Inseob Kim6cc75f42021-04-29 13:53:20 +0000261// userdebug_plat_policy.conf - the userdebug version plat_sepolicy.cil
262se_policy_conf {
263 name: "userdebug_plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900264 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900265 srcs: plat_public_policy +
266 plat_private_policy,
Inseob Kim6cc75f42021-04-29 13:53:20 +0000267 build_variant: "userdebug",
268 installable: false,
269}
270
271se_policy_cil {
272 name: "userdebug_plat_sepolicy.cil",
273 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900274 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kim6cc75f42021-04-29 13:53:20 +0000275 debug_ramdisk: true,
Yi-Yo Chiang68478b12021-10-16 03:23:05 +0800276 dist: {
277 targets: ["droidcore"],
278 },
Inseob Kim6cc75f42021-04-29 13:53:20 +0000279}
280
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000281// A copy of the userdebug_plat_policy in GSI.
282soong_config_module_type {
283 name: "gsi_se_policy_cil",
284 module_type: "se_policy_cil",
285 config_namespace: "ANDROID",
286 bool_variables: [
287 "PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT",
288 ],
289 properties: [
290 "enabled",
291 "installable",
292 ],
293}
294
295gsi_se_policy_cil {
296 name: "system_ext_userdebug_plat_sepolicy.cil",
297 stem: "userdebug_plat_sepolicy.cil",
298 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900299 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000300 system_ext_specific: true,
301 enabled: false,
302 installable: false,
303 soong_config_variables: {
304 PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT: {
305 enabled: true,
306 installable: true,
307 },
308 },
309}
310
Inseob Kima49e7242021-03-22 10:26:13 +0900311// system_ext_policy.conf - A combination of the private and public system_ext
312// policy which will ship with the device. System_ext policy is not attributized
313se_policy_conf {
314 name: "system_ext_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900315 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900316 srcs: plat_public_policy +
317 plat_private_policy +
318 system_ext_public_policy +
319 system_ext_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900320 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900321 installable: false,
322}
323
324se_policy_cil {
325 name: "system_ext_sepolicy.cil",
326 src: ":system_ext_sepolicy.conf",
327 system_ext_specific: true,
328 filter_out: [":plat_sepolicy.cil"],
329 remove_line_marker: true,
330}
331
332// product_policy.conf - A combination of the private and public product policy
333// which will ship with the device. Product policy is not attributized
334se_policy_conf {
335 name: "product_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900336 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900337 srcs: plat_public_policy +
338 plat_private_policy +
339 system_ext_public_policy +
340 system_ext_private_policy +
341 product_public_policy +
342 product_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900343 product_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900344 installable: false,
345}
346
347se_policy_cil {
348 name: "product_sepolicy.cil",
349 src: ":product_sepolicy.conf",
350 product_specific: true,
Inseob Kimff2018f2024-04-17 09:48:43 +0900351 filter_out: [
352 ":plat_sepolicy.cil",
353 ":system_ext_sepolicy.cil",
354 ],
Inseob Kima49e7242021-03-22 10:26:13 +0900355 remove_line_marker: true,
356}
357
Inseob Kim039175b2021-03-25 15:37:34 +0900358// policy mapping files
359// auto-generate the mapping file for current platform policy, since it needs to
360// track platform policy development
361se_versioned_policy {
362 name: "plat_mapping_file",
363 base: ":plat_pub_policy.cil",
364 mapping: true,
365 version: "current",
366 relative_install_path: "mapping", // install to /system/etc/selinux/mapping
367}
368
369se_versioned_policy {
370 name: "system_ext_mapping_file",
371 base: ":system_ext_pub_policy.cil",
372 mapping: true,
373 version: "current",
374 filter_out: [":plat_mapping_file"],
375 relative_install_path: "mapping", // install to /system_ext/etc/selinux/mapping
376 system_ext_specific: true,
377}
378
379se_versioned_policy {
380 name: "product_mapping_file",
381 base: ":pub_policy.cil",
382 mapping: true,
383 version: "current",
Inseob Kimff2018f2024-04-17 09:48:43 +0900384 filter_out: [
385 ":plat_mapping_file",
386 ":system_ext_mapping_file",
387 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900388 relative_install_path: "mapping", // install to /product/etc/selinux/mapping
389 product_specific: true,
390}
391
Inseob Kim6c6aa012023-08-31 16:47:38 +0900392//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900393// vendor/odm sepolicy
Inseob Kim6c6aa012023-08-31 16:47:38 +0900394//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900395
Inseob Kim039175b2021-03-25 15:37:34 +0900396// plat_pub_versioned.cil - the exported platform policy associated with the version
397// that non-platform policy targets.
398se_versioned_policy {
399 name: "plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900400 base: ":pub_policy.cil",
401 target_policy: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900402 version: "vendor",
Inseob Kim039175b2021-03-25 15:37:34 +0900403 vendor: true,
404}
405
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900406// vendor_policy.cil - the vendor sepolicy. This needs attributization and to be combined
407// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
408// policy and the platform public policy files in order to use checkpolicy.
409se_policy_conf {
410 name: "vendor_sepolicy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900411 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900412 srcs: plat_public_policy +
413 system_ext_public_policy +
414 product_public_policy +
415 reqd_mask_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900416 ":se_build_files{.plat_vendor}",
417 ":se_build_files{.vendor}",
418 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900419 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900420 installable: false,
421}
422
423se_policy_cil {
424 name: "vendor_sepolicy.cil.raw",
425 src: ":vendor_sepolicy.conf",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900426 filter_out: [":reqd_policy_mask.cil"],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900427 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900428 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900429 installable: false,
430}
431
432se_versioned_policy {
433 name: "vendor_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900434 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900435 target_policy: ":vendor_sepolicy.cil.raw",
436 version: "vendor",
437 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900438 ":plat_sepolicy.cil",
439 ":system_ext_sepolicy.cil",
440 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900441 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900442 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900443 ],
444 filter_out: [":plat_pub_versioned.cil"],
445 vendor: true,
446}
447
448// odm_policy.cil - the odl sepolicy. This needs attributization and to be combined
449// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
450// policy and the platform public policy files in order to use checkpolicy.
451se_policy_conf {
452 name: "odm_sepolicy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900453 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900454 srcs: plat_public_policy +
455 system_ext_public_policy +
456 product_public_policy +
457 reqd_mask_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900458 ":se_build_files{.plat_vendor}",
459 ":se_build_files{.vendor}",
460 ":se_build_files{.odm}",
461 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900462 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900463 installable: false,
464}
465
466se_policy_cil {
467 name: "odm_sepolicy.cil.raw",
468 src: ":odm_sepolicy.conf",
469 filter_out: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900470 ":reqd_policy_mask.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900471 ":vendor_sepolicy.cil",
472 ],
473 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900474 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900475 installable: false,
476}
477
478se_versioned_policy {
479 name: "odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900480 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900481 target_policy: ":odm_sepolicy.cil.raw",
482 version: "vendor",
483 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900484 ":plat_sepolicy.cil",
485 ":system_ext_sepolicy.cil",
486 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900487 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900488 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900489 ":vendor_sepolicy.cil",
490 ],
Inseob Kimff2018f2024-04-17 09:48:43 +0900491 filter_out: [
492 ":plat_pub_versioned.cil",
493 ":vendor_sepolicy.cil",
494 ],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900495 device_specific: true,
496}
497
Inseob Kim039175b2021-03-25 15:37:34 +0900498//////////////////////////////////
499// Precompiled sepolicy is loaded if and only if:
500// - plat_sepolicy_and_mapping.sha256 equals
501// precompiled_sepolicy.plat_sepolicy_and_mapping.sha256
502// AND
503// - system_ext_sepolicy_and_mapping.sha256 equals
504// precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256
505// AND
506// - product_sepolicy_and_mapping.sha256 equals
507// precompiled_sepolicy.product_sepolicy_and_mapping.sha256
508// See system/core/init/selinux.cpp for details.
509//////////////////////////////////
Cole Faust30349e32024-10-22 16:31:06 -0700510java_genrule {
Inseob Kim039175b2021-03-25 15:37:34 +0900511 name: "plat_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900512 srcs: [
513 ":plat_sepolicy.cil",
514 ":plat_mapping_file",
515 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900516 out: ["plat_sepolicy_and_mapping.sha256"],
517 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
518}
519
520prebuilt_etc {
521 name: "plat_sepolicy_and_mapping.sha256",
522 filename: "plat_sepolicy_and_mapping.sha256",
523 src: ":plat_sepolicy_and_mapping.sha256_gen",
524 relative_install_path: "selinux",
525}
526
Cole Faust30349e32024-10-22 16:31:06 -0700527java_genrule {
Inseob Kim039175b2021-03-25 15:37:34 +0900528 name: "system_ext_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900529 srcs: [
530 ":system_ext_sepolicy.cil",
531 ":system_ext_mapping_file",
532 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900533 out: ["system_ext_sepolicy_and_mapping.sha256"],
534 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
535}
536
537prebuilt_etc {
538 name: "system_ext_sepolicy_and_mapping.sha256",
539 filename: "system_ext_sepolicy_and_mapping.sha256",
540 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
541 relative_install_path: "selinux",
542 system_ext_specific: true,
543}
544
Cole Faust30349e32024-10-22 16:31:06 -0700545java_genrule {
Inseob Kim039175b2021-03-25 15:37:34 +0900546 name: "product_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900547 srcs: [
548 ":product_sepolicy.cil",
549 ":product_mapping_file",
550 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900551 out: ["product_sepolicy_and_mapping.sha256"],
552 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
553}
554
555prebuilt_etc {
556 name: "product_sepolicy_and_mapping.sha256",
557 filename: "product_sepolicy_and_mapping.sha256",
558 src: ":product_sepolicy_and_mapping.sha256_gen",
559 relative_install_path: "selinux",
560 product_specific: true,
561}
562
Inseob Kim1c056b12021-04-30 00:11:43 +0900563sepolicy_vers {
564 name: "plat_sepolicy_vers.txt",
565 version: "vendor",
566 vendor: true,
567}
568
Inseob Kim9b323082024-11-06 17:10:09 +0900569genrule {
570 name: "genfs_labels_version.txt.gen",
571 out: ["genfs_labels_version.txt"],
572 cmd: select(soong_config_variable("ANDROID", "BOARD_GENFS_LABELS_VERSION"), {
573 any @ value: "echo " + value + " > $(out)",
574 default: "echo > $(out)",
575 }),
576}
577
578prebuilt_etc {
579 name: "genfs_labels_version.txt",
580 src: ":genfs_labels_version.txt.gen",
581 relative_install_path: "selinux",
582 vendor: true,
583}
584
Inseob Kim731182a2021-05-06 11:44:37 +0000585soong_config_module_type {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900586 name: "precompiled_sepolicy_prebuilts_defaults",
Inseob Kim731182a2021-05-06 11:44:37 +0000587 module_type: "prebuilt_defaults",
588 config_namespace: "ANDROID",
589 bool_variables: ["BOARD_USES_ODMIMAGE"],
Inseob Kimff2018f2024-04-17 09:48:43 +0900590 properties: [
591 "vendor",
592 "device_specific",
593 ],
Inseob Kim731182a2021-05-06 11:44:37 +0000594}
595
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900596precompiled_sepolicy_prebuilts_defaults {
597 name: "precompiled_sepolicy_prebuilts",
Inseob Kim731182a2021-05-06 11:44:37 +0000598 soong_config_variables: {
599 BOARD_USES_ODMIMAGE: {
600 device_specific: true,
601 conditions_default: {
602 vendor: true,
603 },
604 },
605 },
606}
607
608//////////////////////////////////
609// SHA-256 digest of the plat_sepolicy.cil and plat_mapping_file against
610// which precompiled_policy was built.
611//////////////////////////////////
612prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900613 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000614 name: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
615 filename: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
616 src: ":plat_sepolicy_and_mapping.sha256_gen",
617 relative_install_path: "selinux",
618}
619
620//////////////////////////////////
621// SHA-256 digest of the system_ext_sepolicy.cil and system_ext_mapping_file against
622// which precompiled_policy was built.
623//////////////////////////////////
624prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900625 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000626 name: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
627 filename: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
628 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
629 relative_install_path: "selinux",
630}
631
632//////////////////////////////////
633// SHA-256 digest of the product_sepolicy.cil and product_mapping_file against
634// which precompiled_policy was built.
635//////////////////////////////////
636prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900637 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000638 name: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
639 filename: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
640 src: ":product_sepolicy_and_mapping.sha256_gen",
641 relative_install_path: "selinux",
642}
643
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900644soong_config_module_type {
645 name: "precompiled_se_policy_binary",
646 module_type: "se_policy_binary",
647 config_namespace: "ANDROID",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900648 bool_variables: ["BOARD_USES_ODMIMAGE"],
Inseob Kimff2018f2024-04-17 09:48:43 +0900649 properties: [
650 "vendor",
651 "device_specific",
652 ],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900653}
654
Garfield Tand8c51f22023-10-02 14:17:04 -0700655filegroup {
656 name: "precompiled_sepolicy_srcs",
Cole Faust30349e32024-10-22 16:31:06 -0700657 device_common_srcs: [
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900658 ":plat_sepolicy.cil",
Sandro143988d2022-08-05 11:38:56 +0000659 ":plat_pub_versioned.cil",
660 ":system_ext_sepolicy.cil",
661 ":product_sepolicy.cil",
662 ":vendor_sepolicy.cil",
663 ":odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900664 ":plat_mapping_file",
665 ":system_ext_mapping_file",
666 ":product_mapping_file",
Sandro143988d2022-08-05 11:38:56 +0000667 ],
Inseob Kim9b323082024-11-06 17:10:09 +0900668 device_first_srcs: select(soong_config_variable("ANDROID", "BOARD_GENFS_LABELS_VERSION"), {
669 "202504": [":plat_sepolicy_genfs_202504.cil"],
670 default: [],
671 }),
Garfield Tand8c51f22023-10-02 14:17:04 -0700672 // Make precompiled_sepolicy_srcs as public so that OEMs have access to them.
673 // Useful when some partitions need to be bind mounted across VM boundaries.
674 visibility: ["//visibility:public"],
675}
676
677precompiled_se_policy_binary {
678 name: "precompiled_sepolicy",
679 srcs: [
680 ":precompiled_sepolicy_srcs",
681 ],
Sandro143988d2022-08-05 11:38:56 +0000682 soong_config_variables: {
683 BOARD_USES_ODMIMAGE: {
684 device_specific: true,
685 conditions_default: {
686 vendor: true,
687 },
688 },
Sandro143988d2022-08-05 11:38:56 +0000689 },
690 required: [
691 "sepolicy_neverallows",
Sandro143988d2022-08-05 11:38:56 +0000692 ],
693 dist: {
694 targets: ["base-sepolicy-files-for-mapping"],
695 },
696}
697
Inseob Kim5bbcd682021-12-28 14:57:03 +0900698// policy for recovery
699se_policy_conf {
700 name: "recovery_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900701 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900702 srcs: plat_public_policy +
703 plat_private_policy +
704 system_ext_public_policy +
705 system_ext_private_policy +
706 product_public_policy +
707 product_private_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900708 ":se_build_files{.plat_vendor}",
709 ":se_build_files{.vendor}",
710 ":se_build_files{.odm}",
711 ],
Inseob Kim5bbcd682021-12-28 14:57:03 +0900712 target_recovery: true,
713 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900714 recovery: true,
Inseob Kim5bbcd682021-12-28 14:57:03 +0900715}
716
717se_policy_cil {
718 name: "recovery_sepolicy.cil",
719 src: ":recovery_sepolicy.conf",
720 secilc_check: false, // will be done in se_policy_binary module
721 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900722 recovery: true,
Inseob Kim5bbcd682021-12-28 14:57:03 +0900723}
724
725se_policy_binary {
726 name: "sepolicy.recovery",
727 srcs: [":recovery_sepolicy.cil"],
728 stem: "sepolicy",
729 recovery: true,
730}
731
Inseob Kima49e7242021-03-22 10:26:13 +0900732//////////////////////////////////
733// SELinux policy embedded into CTS.
734// CTS checks neverallow rules of this policy against the policy of the device under test.
735//////////////////////////////////
736se_policy_conf {
737 name: "general_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900738 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900739 srcs: plat_public_policy +
740 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900741 build_variant: "user",
742 cts: true,
743 exclude_build_test: true,
Inseob Kim4b9929e2024-03-28 17:52:32 +0900744 dist: {
745 targets: ["sepolicy_finalize"],
746 },
Inseob Kima49e7242021-03-22 10:26:13 +0900747}
Inseob Kimd5816612021-09-15 03:01:05 +0000748
749//////////////////////////////////
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000750// Base system policy for treble sepolicy tests.
751// If system sepolicy is extended (e.g. by SoC vendors), their plat_pub_versioned.cil may differ
752// with system/sepolicy/prebuilts/api/{version}/plat_pub_versioned.cil. In that case,
753// BOARD_PLAT_PUB_VERSIONED_POLICY can be used to specify extended plat_pub_versioned.cil.
754// See treble_sepolicy_tests_for_release.mk for more details.
755//////////////////////////////////
756se_policy_conf {
757 name: "base_plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900758 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900759 srcs: plat_public_policy +
760 plat_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000761 build_variant: "user",
762 installable: false,
763}
764
765se_policy_cil {
766 name: "base_plat_sepolicy.cil",
767 src: ":base_plat_sepolicy.conf",
768 additional_cil_files: ["private/technical_debt.cil"],
769 installable: false,
770 secilc_check: false, // done by se_policy_binary
Inseob Kimd67c5a32025-01-17 10:39:42 +0900771 dist: {
772 targets: ["sepolicy_finalize"],
773 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000774}
775
776se_policy_binary {
777 name: "base_plat_sepolicy",
778 srcs: [":base_plat_sepolicy.cil"],
779 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900780 dist: {
781 targets: ["base-sepolicy-files-for-mapping"],
782 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000783}
784
785se_policy_conf {
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000786 name: "base_product_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900787 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900788 srcs: plat_public_policy +
789 plat_private_policy +
790 system_ext_public_policy +
791 system_ext_private_policy +
792 product_public_policy +
793 product_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000794 build_variant: "user",
795 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900796 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000797}
798
799se_policy_cil {
800 name: "base_product_sepolicy.cil",
801 src: ":base_product_sepolicy.conf",
802 additional_cil_files: ["private/technical_debt.cil"],
803 product_specific: true,
804 installable: false,
805 secilc_check: false, // done by se_policy_binary
806}
807
808se_policy_binary {
809 name: "base_product_sepolicy",
810 srcs: [":base_product_sepolicy.cil"],
811 product_specific: true,
812 installable: false,
813}
814
815se_policy_conf {
816 name: "base_plat_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900817 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900818 srcs: plat_public_policy +
819 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000820 build_variant: "user",
821 installable: false,
822}
823
824se_policy_cil {
825 name: "base_plat_pub_policy.cil",
826 src: ":base_plat_pub_policy.conf",
827 filter_out: [":reqd_policy_mask.cil"],
828 secilc_check: false,
829 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900830 dist: {
831 targets: ["base-sepolicy-files-for-mapping"],
832 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000833}
834
Inseob Kimd67c5a32025-01-17 10:39:42 +0900835se_versioned_policy {
836 name: "base_plat_mapping_file",
837 base: ":base_plat_pub_policy.cil",
838 mapping: true,
839 version: "current",
840 relative_install_path: "mapping", // install to /system/etc/selinux/mapping
841 dist: {
842 targets: ["sepolicy_finalize"],
843 },
844 installable: false,
845}
846
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000847se_policy_conf {
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000848 name: "base_product_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900849 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900850 srcs: plat_public_policy +
851 system_ext_public_policy +
852 product_public_policy +
853 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000854 build_variant: "user",
855 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900856 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000857}
858
859se_policy_cil {
860 name: "base_product_pub_policy.cil",
861 src: ":base_product_pub_policy.conf",
862 filter_out: [":reqd_policy_mask.cil"],
863 secilc_check: false,
864 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900865 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000866}
867
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800868// bug_map - Bug tracking information for selinux denials loaded by auditd.
Inseob Kim41964032022-04-22 07:50:22 +0900869se_build_files {
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800870 name: "bug_map_files",
871 srcs: ["bug_map"],
872}
873
874se_bug_map {
875 name: "plat_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900876 srcs: [":bug_map_files{.plat_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800877 stem: "bug_map",
878}
879
880se_bug_map {
881 name: "system_ext_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900882 srcs: [":bug_map_files{.system_ext_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800883 stem: "bug_map",
884 system_ext_specific: true,
885}
886
887se_bug_map {
888 name: "vendor_bug_map",
Inseob Kimff2018f2024-04-17 09:48:43 +0900889 srcs: [
890 ":bug_map_files{.vendor}",
891 ":bug_map_files{.plat_vendor}",
892 ],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800893 // Legacy file name of the vendor partition bug_map.
894 stem: "selinux_denial_metadata",
895 vendor: true,
896}
897
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900898se_neverallow_test {
899 name: "sepolicy_neverallows",
Inseob Kim085f22f2023-11-09 11:13:01 +0900900 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900901 srcs: plat_public_policy +
902 plat_private_policy +
903 system_ext_public_policy +
904 system_ext_private_policy +
905 product_public_policy +
Inseob Kim6c6aa012023-08-31 16:47:38 +0900906 product_private_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900907 ":se_build_files{.plat_vendor}",
908 ":se_build_files{.vendor}",
909 ":se_build_files{.odm}",
910 ],
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900911}
912
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000913//////////////////////////////////
Inseob Kimd5816612021-09-15 03:01:05 +0000914// se_freeze_test compares the plat sepolicy with the prebuilt sepolicy
915// Additional directories can be specified via Makefile variables:
916// SEPOLICY_FREEZE_TEST_EXTRA_DIRS and SEPOLICY_FREEZE_TEST_EXTRA_PREBUILT_DIRS.
917//////////////////////////////////
Inseob Kimb19ca8d2024-12-27 17:00:25 +0900918
Inseob Kimd4e49452025-01-17 10:43:25 +0900919FREEZE_TEST_BOARD_API_LEVEL = "202504"
Inseob Kimb19ca8d2024-12-27 17:00:25 +0900920
921se_policy_conf {
922 name: "base_plat_pub_policy_for_freeze_test.conf",
923 defaults: ["se_policy_conf_flags_defaults"],
924 srcs: plat_public_policy +
925 reqd_mask_policy,
926 build_variant: "user",
927 installable: false,
928 board_api_level: FREEZE_TEST_BOARD_API_LEVEL,
929}
930
931se_policy_cil {
932 name: "base_plat_pub_policy_for_freeze_test.cil",
933 src: ":base_plat_pub_policy_for_freeze_test.conf",
934 filter_out: [":reqd_policy_mask.cil"],
935 secilc_check: false,
936 installable: false,
937}
938
Inseob Kimd5816612021-09-15 03:01:05 +0000939se_freeze_test {
Inseob Kim36d9d392023-09-04 17:40:03 +0900940 name: "se_freeze_test",
Inseob Kimb19ca8d2024-12-27 17:00:25 +0900941 board_api_level: FREEZE_TEST_BOARD_API_LEVEL,
942 current_cil: ":base_plat_pub_policy_for_freeze_test.cil",
943 prebuilt_cil: ":" + FREEZE_TEST_BOARD_API_LEVEL + "_plat_pub_policy.cil",
Inseob Kimd5816612021-09-15 03:01:05 +0000944}
Inseob Kim61257ca2022-02-25 11:26:16 +0900945
946//////////////////////////////////
947// sepolicy_test checks various types of violations, which can't be easily done
948// by CIL itself. Refer tests/sepolicy_tests.py for more detail.
949//////////////////////////////////
Cole Faust30349e32024-10-22 16:31:06 -0700950java_genrule {
Inseob Kim61257ca2022-02-25 11:26:16 +0900951 name: "sepolicy_test",
952 srcs: [
953 ":plat_file_contexts",
954 ":vendor_file_contexts",
955 ":system_ext_file_contexts",
956 ":product_file_contexts",
957 ":odm_file_contexts",
958 ":precompiled_sepolicy",
959 ],
960 tools: ["sepolicy_tests"],
961 out: ["sepolicy_test"],
962 cmd: "$(location sepolicy_tests) " +
963 "-f $(location :plat_file_contexts) " +
964 "-f $(location :vendor_file_contexts) " +
965 "-f $(location :system_ext_file_contexts) " +
966 "-f $(location :product_file_contexts) " +
967 "-f $(location :odm_file_contexts) " +
968 "-p $(location :precompiled_sepolicy) && " +
969 "touch $(out)",
970}
Inseob Kim3a9d91c2023-09-27 17:39:07 +0900971
972//////////////////////////////////
973// TestDevTypeViolations can't run on old devices (V or before)
974//////////////////////////////////
975
976soong_config_module_type {
977 name: "dev_type_test_genrule",
Cole Faust30349e32024-10-22 16:31:06 -0700978 module_type: "java_genrule",
Inseob Kim3a9d91c2023-09-27 17:39:07 +0900979 config_namespace: "ANDROID",
980 bool_variables: ["CHECK_DEV_TYPE_VIOLATIONS"],
981 properties: ["cmd"],
982}
983
984dev_type_test_genrule {
985 name: "sepolicy_dev_type_test",
986 srcs: [
987 ":plat_file_contexts",
988 ":vendor_file_contexts",
989 ":system_ext_file_contexts",
990 ":product_file_contexts",
991 ":odm_file_contexts",
992 ":precompiled_sepolicy",
993 ],
994 tools: ["sepolicy_tests"],
995 out: ["sepolicy_dev_type_test"],
996 soong_config_variables: {
997 CHECK_DEV_TYPE_VIOLATIONS: {
998 cmd: "$(location sepolicy_tests) " +
999 "-f $(location :plat_file_contexts) " +
1000 "-f $(location :vendor_file_contexts) " +
1001 "-f $(location :system_ext_file_contexts) " +
1002 "-f $(location :product_file_contexts) " +
1003 "-f $(location :odm_file_contexts) " +
1004 "-p $(location :precompiled_sepolicy) " +
1005 "-t TestDevTypeViolations && " +
1006 "touch $(out)",
1007 conditions_default: {
1008 cmd: "touch $(out)",
1009 },
1010 },
1011 },
1012}
kellyhung08f7c992024-09-18 03:34:53 +00001013
1014phony {
1015 name: "selinux_policy_system_ext",
1016 required: [
1017 //"ifdef HAS_SYSTEM_EXT_PUBLIC_SEPOLICY" check included in system_ext_pub_policy.cil
1018 "system_ext_mapping_file",
1019 //"ifdef HAS_SYSTEM_EXT_SEPOLICY" check included in .cil
1020 "system_ext_sepolicy.cil",
1021 ] + [
1022 //"ifdef HAS_SYSTEM_EXT_SEPOLICY" check included in .cil
1023 "system_ext_29.0.cil",
1024 "system_ext_30.0.cil",
1025 "system_ext_31.0.cil",
1026 "system_ext_32.0.cil",
1027 "system_ext_33.0.cil",
1028 "system_ext_34.0.cil",
1029 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1030 "202404": [],
1031 default: [
1032 "system_ext_202404.cil",
1033 ],
1034 }) +
1035 select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1036 true: ["system_ext_sepolicy_and_mapping.sha256"],
1037 default: [],
1038 }) + [
1039 "system_ext_file_contexts",
1040 "system_ext_file_contexts_test",
1041 "system_ext_keystore2_key_contexts",
1042 "system_ext_hwservice_contexts",
1043 "system_ext_hwservice_contexts_test",
1044 "system_ext_property_contexts",
1045 "system_ext_property_contexts_test",
1046 "system_ext_seapp_contexts",
1047 "system_ext_service_contexts",
1048 "system_ext_service_contexts_test",
1049 "system_ext_mac_permissions.xml",
1050 "system_ext_bug_map",
1051 // $(addprefix system_ext_,$(addsuffix .compat.cil,$(PLATFORM_SEPOLICY_COMPAT_VERSIONS))) \
1052 "system_ext_29.0.compat.cil",
1053 "system_ext_30.0.compat.cil",
1054 "system_ext_31.0.compat.cil",
1055 "system_ext_32.0.compat.cil",
1056 "system_ext_33.0.compat.cil",
1057 "system_ext_34.0.compat.cil",
1058 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1059 "202404": [],
1060 default: [
1061 "system_ext_202404.compat.cil",
1062 ],
Nikita Ioffe48966b62024-10-22 14:01:17 +00001063 }) + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
1064 true: ["system_ext_tee_service_contexts"],
1065 default: [],
kellyhung08f7c992024-09-18 03:34:53 +00001066 }),
Spandan Das80252082024-10-17 21:58:34 +00001067 system_ext_specific: true,
kellyhung08f7c992024-09-18 03:34:53 +00001068}
kellyhung14081902024-09-18 04:59:54 +00001069
1070phony {
1071 name: "selinux_policy_product",
1072 required: [
1073 "product_mapping_file",
1074 "product_sepolicy.cil",
1075 // "ifdef HAS_PRODUCT_PUBLIC_SEPOLICY" check included in .cil
1076 "product_29.0.cil",
1077 "product_30.0.cil",
1078 "product_31.0.cil",
1079 "product_32.0.cil",
1080 "product_33.0.cil",
1081 "product_34.0.cil",
1082 "product_file_contexts",
1083 // "ifdef HAS_PRODUCT_SEPOLICY_DIR" in Android.mk can be ignored.
1084 "product_file_contexts_test",
1085 "product_keystore2_key_contexts",
1086 "product_hwservice_contexts",
1087 "product_hwservice_contexts_test",
1088 "product_property_contexts",
1089 "product_property_contexts_test",
1090 "product_seapp_contexts",
1091 "product_service_contexts",
1092 "product_service_contexts_test",
1093 "product_mac_permissions.xml",
1094 ] + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1095 true: ["product_sepolicy_and_mapping.sha256"],
1096 default: [],
1097 }) + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1098 "202404": [],
1099 default: [
1100 "product_202404.cil",
1101 ],
Nikita Ioffe48966b62024-10-22 14:01:17 +00001102 }) + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
1103 true: ["product_tee_service_contexts"],
1104 default: [],
kellyhung14081902024-09-18 04:59:54 +00001105 }),
Spandan Das155cc2f2024-10-18 22:27:25 +00001106 product_specific: true,
kellyhung14081902024-09-18 04:59:54 +00001107}
kellyhunga07b3712024-09-25 03:31:09 +00001108
1109phony {
1110 name: "selinux_policy_nonsystem",
1111 required: [
Spandan Das62656052024-11-01 18:37:13 +00001112 "selinux_policy_system_ext",
1113 "selinux_policy_product",
1114 "selinux_policy_vendor",
1115 "selinux_policy_odm",
1116 // Builds an additional userdebug sepolicy into the debug ramdisk.
1117 "userdebug_plat_sepolicy.cil",
1118 ],
1119}
1120
1121phony {
1122 name: "selinux_policy_vendor",
1123 required: [
Inseob Kim9b323082024-11-06 17:10:09 +09001124 "genfs_labels_version.txt",
kellyhunga07b3712024-09-25 03:31:09 +00001125 "plat_pub_versioned.cil",
1126 "vendor_sepolicy.cil",
1127 "plat_sepolicy_vers.txt",
1128 "vendor_file_contexts",
1129 "vendor_file_contexts_test",
1130 "vendor_keystore2_key_contexts",
1131 "vendor_mac_permissions.xml",
1132 "vendor_property_contexts",
1133 "vendor_property_contexts_test",
1134 "vendor_seapp_contexts",
1135 "vendor_service_contexts",
1136 "vendor_service_contexts_test",
1137 "vendor_hwservice_contexts",
1138 "vendor_hwservice_contexts_test",
1139 "vendor_bug_map",
1140 "vndservice_contexts",
1141 "vndservice_contexts_test",
Nikita Ioffe48966b62024-10-22 14:01:17 +00001142 ] + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
1143 true: ["vendor_tee_service_contexts"],
1144 default: [],
1145 }),
Spandan Das62656052024-11-01 18:37:13 +00001146 vendor: true,
1147}
1148
1149phony {
1150 name: "selinux_policy_odm",
1151 required: [
kellyhunga07b3712024-09-25 03:31:09 +00001152 "odm_sepolicy.cil",
1153 "odm_file_contexts",
1154 "odm_file_contexts_test",
1155 "odm_seapp_contexts",
1156 "odm_property_contexts",
1157 "odm_property_contexts_test",
1158 "odm_service_contexts",
1159 "odm_service_contexts_test",
1160 "odm_hwservice_contexts",
1161 "odm_hwservice_contexts_test",
1162 "odm_mac_permissions.xml",
kellyhunga07b3712024-09-25 03:31:09 +00001163 ] + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1164 true: [
1165 "precompiled_sepolicy",
1166 "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
1167 "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
1168 "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
1169 ],
1170 default: [],
1171 }),
Spandan Das62656052024-11-01 18:37:13 +00001172 device_specific: true,
kellyhunga07b3712024-09-25 03:31:09 +00001173}
kellyhung0c9edb32024-07-15 11:06:26 +00001174
1175phony {
1176 name: "selinux_policy_system",
1177 required: [
1178 "29.0.compat.cil",
1179 "30.0.compat.cil",
1180 "31.0.compat.cil",
1181 "32.0.compat.cil",
1182 "33.0.compat.cil",
1183 "34.0.compat.cil",
1184 "build_sepolicy",
1185 "fuzzer_bindings_test",
1186 "plat_29.0.cil",
1187 "plat_30.0.cil",
1188 "plat_31.0.cil",
1189 "plat_32.0.cil",
1190 "plat_33.0.cil",
1191 "plat_34.0.cil",
1192 "plat_bug_map",
1193 "plat_file_contexts",
1194 "plat_file_contexts_data_test",
1195 "plat_file_contexts_test",
1196 "plat_hwservice_contexts",
1197 "plat_hwservice_contexts_test",
1198 "plat_keystore2_key_contexts",
1199 "plat_mac_permissions.xml",
1200 "plat_mapping_file",
1201 "plat_property_contexts",
1202 "plat_property_contexts_test",
1203 "plat_seapp_contexts",
1204 "plat_sepolicy.cil",
Inseob Kim9b323082024-11-06 17:10:09 +09001205 "plat_sepolicy_genfs_202504.cil",
kellyhung0c9edb32024-07-15 11:06:26 +00001206 "plat_service_contexts",
1207 "plat_service_contexts_test",
1208 "searchpolicy",
1209 "secilc",
1210 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1211 "202404": [],
1212 default: [
1213 "202404.compat.cil",
1214 "plat_202404.cil",
1215 ],
1216 }) + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1217 true: ["plat_sepolicy_and_mapping.sha256"],
1218 default: [],
1219 }) + select((
1220 soong_config_variable("ANDROID", "ASAN_ENABLED"),
1221 product_variable("selinux_ignore_neverallows"),
1222 ), {
1223 (true, true): [
1224 ],
1225 (default, default): [
1226 "sepolicy_compat_test",
1227 "sepolicy_test",
1228 "sepolicy_dev_type_test",
1229 "treble_sepolicy_tests_29.0",
1230 "treble_sepolicy_tests_30.0",
1231 "treble_sepolicy_tests_31.0",
1232 "treble_sepolicy_tests_32.0",
1233 "treble_sepolicy_tests_33.0",
1234 "treble_sepolicy_tests_34.0",
1235 ],
1236 }) + select((
1237 soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"),
1238 soong_config_variable("ANDROID", "ASAN_ENABLED"),
1239 product_variable("selinux_ignore_neverallows"),
1240 ), {
1241 ("202404", true, true): [],
1242 (default, true, true): [],
1243 (default, default, default): [
1244 "treble_sepolicy_tests_202404",
1245 ],
1246 }) + select(soong_config_variable("ANDROID", "RELEASE_BOARD_API_LEVEL_FROZEN"), {
1247 true: ["se_freeze_test"],
1248 default: [],
Nikita Ioffe48966b62024-10-22 14:01:17 +00001249 }) + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
1250 true: ["plat_tee_service_contexts"],
1251 default: [],
kellyhung0c9edb32024-07-15 11:06:26 +00001252 }),
1253}
kellyhungee97d9c2024-10-03 00:54:38 +00001254
1255phony {
1256 name: "selinux_policy",
1257 required: [
1258 // Runs checkfc against merged service_contexts files
1259 "merged_hwservice_contexts_test",
1260 "merged_service_contexts_test",
1261 "selinux_policy_nonsystem",
1262 "selinux_policy_system",
1263 ],
1264}
1265
1266// selinux_policy is a main goal and triggers lots of tests.
1267// Most tests are FAKE modules, so aren'triggered on normal builds. (e.g. 'm')
1268// By setting as droidcore's dependency, tests will run on normal builds.
1269phony_rule {
1270 name: "droidcore",
1271 phony_deps: ["selinux_policy"],
1272}
kellyhung8659c152024-10-07 21:37:14 +00001273
1274//-----------------------------------------------------------------------------
1275// TODO - remove this. Keep around until we get the filesystem creation stuff
1276// taken care of.
1277//
1278// The file_contexts.bin is built in the following way:
1279// 1. Collect all file_contexts files in THIS repository and process them with
1280// m4 into a tmp file called file_contexts.local.tmp.
1281// 2. Collect all device specific file_contexts files and process them with m4
1282// into a tmp file called file_contexts.device.tmp.
1283// 3. Run checkfc -e (allow no device fc entries ie empty) and fc_sort on
1284// file_contexts.device.tmp and output to file_contexts.device.sorted.tmp.
1285// 4. Concatenate file_contexts.local.tmp and file_contexts.device.sorted.tmp
1286// into file_contexts.concat.tmp.
1287// 5. Run checkfc and sefcontext_compile on file_contexts.concat.tmp to produce
1288// file_contexts.bin.
1289//
1290// Note: That a newline file is placed between each file_context file found to
1291// ensure a proper build when an fc file is missing an ending newline.
1292//---
1293// 1. Collect all file_contexts files in THIS repository and process them with
1294// m4 into a tmp file called file_contexts.local.tmp.
Cole Faust30349e32024-10-22 16:31:06 -07001295java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001296 name: "file_contexts.local.tmp",
1297 srcs: [
1298 ":plat_file_contexts",
1299 ":system_ext_file_contexts",
1300 ":product_file_contexts",
1301 ],
1302 tools: [
1303 "m4",
1304 ],
1305 out: ["file_contexts.local.tmp"],
1306 cmd: "$(location m4) --fatal-warnings " +
1307 "-s $(in) > $(out)",
1308}
1309
1310// 2. Collect all device specific file_contexts files and process them with m4
1311// into a tmp file called file_contexts.device.tmp.
1312PRIVATE_ADDITIONAL_M4DEFS = select(soong_config_variable("ANDROID", "ADDITIONAL_M4DEFS"), {
1313 any @ m4defs: m4defs,
1314 default: "",
1315})
Cole Faust30349e32024-10-22 16:31:06 -07001316java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001317 name: "file_contexts.device.tmp",
1318 srcs: [
1319 ":vendor_file_contexts",
1320 ":odm_file_contexts",
1321 ],
1322 tools: [
1323 "m4",
1324 ],
1325 out: ["file_contexts.device.tmp"],
1326 cmd: "$(location m4) --fatal-warnings " +
1327 "-s " + PRIVATE_ADDITIONAL_M4DEFS +
1328 " $(in) > $(out)",
1329}
1330
1331// 3. Run checkfc -e (allow no device fc entries ie empty) and fc_sort on
1332// file_contexts.device.tmp and output to file_contexts.device.sorted.tmp.
Cole Faust30349e32024-10-22 16:31:06 -07001333java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001334 name: "file_contexts.device.sorted.tmp",
1335 srcs: [
1336 ":file_contexts.device.tmp",
1337 ":precompiled_sepolicy",
1338 ],
1339 tools: [
1340 "checkfc",
1341 "fc_sort",
1342 ],
1343 out: ["file_contexts.device.sorted.tmp"],
1344 cmd: "$(location checkfc) " +
1345 "-e $(location :precompiled_sepolicy) " +
1346 "$(location :file_contexts.device.tmp) && " +
1347 "$(location fc_sort) " +
1348 "-i $(location :file_contexts.device.tmp) " +
1349 "-o $(out)",
1350}
1351
1352// 4. Concatenate file_contexts.local.tmp and file_contexts.device.sorted.tmp
1353// into file_contexts.concat.tmp.
Cole Faust30349e32024-10-22 16:31:06 -07001354java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001355 name: "file_contexts.concat.tmp",
1356 srcs: [
1357 ":file_contexts.local.tmp",
1358 ":file_contexts.device.sorted.tmp",
1359 ],
1360 tools: [
1361 "m4",
1362 ],
1363 out: ["file_contexts.concat.tmp"],
1364 cmd: "$(location m4) --fatal-warnings " +
1365 "-s $(location :file_contexts.local.tmp) " +
1366 "$(location :file_contexts.device.sorted.tmp) > $(out)",
1367}
1368
1369// 5. Run checkfc and sefcontext_compile on file_contexts.concat.tmp to produce
1370// file_contexts.bin.
Cole Faust30349e32024-10-22 16:31:06 -07001371java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001372 name: "file_contexts_bin_gen",
1373 srcs: [
1374 ":file_contexts.concat.tmp",
1375 ":precompiled_sepolicy",
1376 ],
1377 tools: [
1378 "checkfc",
1379 "sefcontext_compile",
1380 ],
1381 out: ["file_contexts.bin"],
1382 cmd: "$(location checkfc) " +
1383 "$(location :precompiled_sepolicy) " +
1384 "$(location :file_contexts.concat.tmp) && " +
1385 "$(location sefcontext_compile) " +
1386 "-o $(out) $(location :file_contexts.concat.tmp)",
1387}
1388
1389prebuilt_etc {
1390 name: "file_contexts.bin",
1391 src: ":file_contexts_bin_gen",
1392}