blob: 44f064ed9b61d26bc493a0f00135d5fa60035e4d [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 Kim4b951e92025-01-23 10:41:03 +0900106 "plat_sepolicy_genfs_202604.cil",
Inseob Kim151562f2024-04-12 10:53:34 +0900107 "plat_service_contexts",
108 "secilc",
Cole Faustac1f8152024-06-17 12:39:02 -0700109 "plat_29.0.cil",
110 "29.0.compat.cil",
111 "plat_30.0.cil",
112 "30.0.compat.cil",
113 "plat_31.0.cil",
114 "31.0.compat.cil",
115 "plat_32.0.cil",
116 "32.0.compat.cil",
117 "plat_33.0.cil",
118 "33.0.compat.cil",
119 "plat_34.0.cil",
120 "34.0.compat.cil",
121 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
122 "202404": [],
123 default: [
124 "plat_202404.cil",
125 "202404.compat.cil",
126 ],
Inseob Kime468a372025-01-22 17:19:44 +0900127 }) + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
128 // TODO(b/391513934): clean up once we can simplify complex select statements.
129 "202404": [],
130 "202504": [],
131 default: [
132 "plat_202504.cil",
133 "202504.compat.cil",
134 ],
Cole Faustac1f8152024-06-17 12:39:02 -0700135 }) + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
Cole Faustc22dece2024-06-20 12:58:34 -0700136 true: ["plat_sepolicy_and_mapping.sha256"],
Cole Faustac1f8152024-06-17 12:39:02 -0700137 default: [],
Nikita Ioffe48966b62024-10-22 14:01:17 +0000138 }) + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
139 true: ["plat_tee_service_contexts"],
140 default: [],
Cole Faustac1f8152024-06-17 12:39:02 -0700141 }),
Inseob Kim151562f2024-04-12 10:53:34 +0900142}
143
Inseob Kimff2018f2024-04-17 09:48:43 +0900144reqd_mask_policy = [":se_build_files{.reqd_mask}"]
145plat_public_policy = [":se_build_files{.plat_public}"]
146plat_private_policy = [":se_build_files{.plat_private}"]
147system_ext_public_policy = [":se_build_files{.system_ext_public}"]
Inseob Kim0a707fa2021-12-09 23:35:11 +0900148system_ext_private_policy = [":se_build_files{.system_ext_private}"]
Inseob Kimff2018f2024-04-17 09:48:43 +0900149product_public_policy = [":se_build_files{.product_public}"]
150product_private_policy = [":se_build_files{.product_private}"]
Inseob Kim0a707fa2021-12-09 23:35:11 +0900151
Inseob Kima49e7242021-03-22 10:26:13 +0900152// reqd_policy_mask - a policy.conf file which contains only the bare minimum
153// policy necessary to use checkpolicy.
154//
155// This bare-minimum policy needs to be present in all policy.conf files, but
156// should not necessarily be exported as part of the public policy.
157//
158// The rules generated by reqd_policy_mask will allow the compilation of public
159// policy and subsequent removal of CIL policy that should not be exported.
160se_policy_conf {
161 name: "reqd_policy_mask.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900162 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900163 srcs: reqd_mask_policy,
Inseob Kime35b49b2021-02-18 19:15:41 +0900164 installable: false,
165}
166
Inseob Kima49e7242021-03-22 10:26:13 +0900167se_policy_cil {
168 name: "reqd_policy_mask.cil",
169 src: ":reqd_policy_mask.conf",
170 secilc_check: false,
171 installable: false,
Inseob Kime35b49b2021-02-18 19:15:41 +0900172}
173
Inseob Kima49e7242021-03-22 10:26:13 +0900174// pub_policy - policy that will be exported to be a part of non-platform
175// policy corresponding to this platform version.
176//
177// This is a limited subset of policy that would not compile in checkpolicy on
178// its own.
179//
180// To get around this limitation, add only the required files from private
181// policy, which will generate CIL policy that will then be filtered out by the
182// reqd_policy_mask.
183//
184// There are three pub_policy.cil files below:
185// - pub_policy.cil: exported 'product', 'system_ext' and 'system' policy.
186// - system_ext_pub_policy.cil: exported 'system_ext' and 'system' policy.
187// - plat_pub_policy.cil: exported 'system' policy.
188//
189// Those above files will in turn be used to generate the following versioned cil files:
190// - product_mapping_file: the versioned, exported 'product' policy in product partition.
191// - system_ext_mapping_file: the versioned, exported 'system_ext' policy in system_ext partition.
192// - plat_mapping_file: the versioned, exported 'system' policy in system partition.
193// - plat_pub_versioned.cil: the versioned, exported 'product', 'system_ext' and 'system' policy
194// in vendor partition.
195//
196se_policy_conf {
197 name: "pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900198 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900199 srcs: plat_public_policy +
200 system_ext_public_policy +
201 product_public_policy +
202 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900203 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900204 installable: false,
205}
206
207se_policy_cil {
208 name: "pub_policy.cil",
209 src: ":pub_policy.conf",
210 filter_out: [":reqd_policy_mask.cil"],
211 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900212 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900213 installable: false,
214}
215
216se_policy_conf {
217 name: "system_ext_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900218 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900219 srcs: plat_public_policy +
220 system_ext_public_policy +
221 reqd_mask_policy,
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_cil {
227 name: "system_ext_pub_policy.cil",
228 src: ":system_ext_pub_policy.conf",
229 filter_out: [":reqd_policy_mask.cil"],
230 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900231 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900232 installable: false,
233}
234
235se_policy_conf {
236 name: "plat_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900237 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900238 srcs: plat_public_policy +
239 reqd_mask_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900240 installable: false,
241}
242
243se_policy_cil {
244 name: "plat_pub_policy.cil",
245 src: ":plat_pub_policy.conf",
246 filter_out: [":reqd_policy_mask.cil"],
247 secilc_check: false,
248 installable: false,
249}
250
251// plat_policy.conf - A combination of the private and public platform policy
252// which will ship with the device.
253//
254// The platform will always reflect the most recent platform version and is not
255// currently being attributized.
256se_policy_conf {
257 name: "plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900258 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900259 srcs: plat_public_policy +
260 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900261 installable: false,
262}
263
264se_policy_cil {
265 name: "plat_sepolicy.cil",
266 src: ":plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900267 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kima49e7242021-03-22 10:26:13 +0900268}
269
Inseob Kim6cc75f42021-04-29 13:53:20 +0000270// userdebug_plat_policy.conf - the userdebug version plat_sepolicy.cil
271se_policy_conf {
272 name: "userdebug_plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900273 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900274 srcs: plat_public_policy +
275 plat_private_policy,
Inseob Kim6cc75f42021-04-29 13:53:20 +0000276 build_variant: "userdebug",
277 installable: false,
278}
279
280se_policy_cil {
281 name: "userdebug_plat_sepolicy.cil",
282 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900283 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kim6cc75f42021-04-29 13:53:20 +0000284 debug_ramdisk: true,
Yi-Yo Chiang68478b12021-10-16 03:23:05 +0800285 dist: {
286 targets: ["droidcore"],
287 },
Inseob Kim6cc75f42021-04-29 13:53:20 +0000288}
289
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000290// A copy of the userdebug_plat_policy in GSI.
291soong_config_module_type {
292 name: "gsi_se_policy_cil",
293 module_type: "se_policy_cil",
294 config_namespace: "ANDROID",
295 bool_variables: [
296 "PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT",
297 ],
298 properties: [
299 "enabled",
300 "installable",
301 ],
302}
303
304gsi_se_policy_cil {
305 name: "system_ext_userdebug_plat_sepolicy.cil",
306 stem: "userdebug_plat_sepolicy.cil",
307 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900308 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000309 system_ext_specific: true,
310 enabled: false,
311 installable: false,
312 soong_config_variables: {
313 PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT: {
314 enabled: true,
315 installable: true,
316 },
317 },
318}
319
Inseob Kima49e7242021-03-22 10:26:13 +0900320// system_ext_policy.conf - A combination of the private and public system_ext
321// policy which will ship with the device. System_ext policy is not attributized
322se_policy_conf {
323 name: "system_ext_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900324 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900325 srcs: plat_public_policy +
326 plat_private_policy +
327 system_ext_public_policy +
328 system_ext_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900329 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900330 installable: false,
331}
332
333se_policy_cil {
334 name: "system_ext_sepolicy.cil",
335 src: ":system_ext_sepolicy.conf",
336 system_ext_specific: true,
337 filter_out: [":plat_sepolicy.cil"],
338 remove_line_marker: true,
339}
340
341// product_policy.conf - A combination of the private and public product policy
342// which will ship with the device. Product policy is not attributized
343se_policy_conf {
344 name: "product_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900345 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900346 srcs: plat_public_policy +
347 plat_private_policy +
348 system_ext_public_policy +
349 system_ext_private_policy +
350 product_public_policy +
351 product_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900352 product_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900353 installable: false,
354}
355
356se_policy_cil {
357 name: "product_sepolicy.cil",
358 src: ":product_sepolicy.conf",
359 product_specific: true,
Inseob Kimff2018f2024-04-17 09:48:43 +0900360 filter_out: [
361 ":plat_sepolicy.cil",
362 ":system_ext_sepolicy.cil",
363 ],
Inseob Kima49e7242021-03-22 10:26:13 +0900364 remove_line_marker: true,
365}
366
Inseob Kim039175b2021-03-25 15:37:34 +0900367// policy mapping files
368// auto-generate the mapping file for current platform policy, since it needs to
369// track platform policy development
370se_versioned_policy {
371 name: "plat_mapping_file",
372 base: ":plat_pub_policy.cil",
373 mapping: true,
374 version: "current",
375 relative_install_path: "mapping", // install to /system/etc/selinux/mapping
376}
377
378se_versioned_policy {
379 name: "system_ext_mapping_file",
380 base: ":system_ext_pub_policy.cil",
381 mapping: true,
382 version: "current",
383 filter_out: [":plat_mapping_file"],
384 relative_install_path: "mapping", // install to /system_ext/etc/selinux/mapping
385 system_ext_specific: true,
386}
387
388se_versioned_policy {
389 name: "product_mapping_file",
390 base: ":pub_policy.cil",
391 mapping: true,
392 version: "current",
Inseob Kimff2018f2024-04-17 09:48:43 +0900393 filter_out: [
394 ":plat_mapping_file",
395 ":system_ext_mapping_file",
396 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900397 relative_install_path: "mapping", // install to /product/etc/selinux/mapping
398 product_specific: true,
399}
400
Inseob Kim6c6aa012023-08-31 16:47:38 +0900401//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900402// vendor/odm sepolicy
Inseob Kim6c6aa012023-08-31 16:47:38 +0900403//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900404
Inseob Kim039175b2021-03-25 15:37:34 +0900405// plat_pub_versioned.cil - the exported platform policy associated with the version
406// that non-platform policy targets.
407se_versioned_policy {
408 name: "plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900409 base: ":pub_policy.cil",
410 target_policy: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900411 version: "vendor",
Inseob Kim039175b2021-03-25 15:37:34 +0900412 vendor: true,
413}
414
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900415// vendor_policy.cil - the vendor sepolicy. This needs attributization and to be combined
416// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
417// policy and the platform public policy files in order to use checkpolicy.
418se_policy_conf {
419 name: "vendor_sepolicy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900420 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900421 srcs: plat_public_policy +
422 system_ext_public_policy +
423 product_public_policy +
424 reqd_mask_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900425 ":se_build_files{.plat_vendor}",
426 ":se_build_files{.vendor}",
427 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900428 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900429 installable: false,
430}
431
432se_policy_cil {
433 name: "vendor_sepolicy.cil.raw",
434 src: ":vendor_sepolicy.conf",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900435 filter_out: [":reqd_policy_mask.cil"],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900436 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900437 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900438 installable: false,
439}
440
441se_versioned_policy {
442 name: "vendor_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900443 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900444 target_policy: ":vendor_sepolicy.cil.raw",
445 version: "vendor",
446 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900447 ":plat_sepolicy.cil",
448 ":system_ext_sepolicy.cil",
449 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900450 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900451 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900452 ],
453 filter_out: [":plat_pub_versioned.cil"],
454 vendor: true,
455}
456
457// odm_policy.cil - the odl sepolicy. This needs attributization and to be combined
458// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
459// policy and the platform public policy files in order to use checkpolicy.
460se_policy_conf {
461 name: "odm_sepolicy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900462 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900463 srcs: plat_public_policy +
464 system_ext_public_policy +
465 product_public_policy +
466 reqd_mask_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900467 ":se_build_files{.plat_vendor}",
468 ":se_build_files{.vendor}",
469 ":se_build_files{.odm}",
470 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900471 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900472 installable: false,
473}
474
475se_policy_cil {
476 name: "odm_sepolicy.cil.raw",
477 src: ":odm_sepolicy.conf",
478 filter_out: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900479 ":reqd_policy_mask.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900480 ":vendor_sepolicy.cil",
481 ],
482 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900483 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900484 installable: false,
485}
486
487se_versioned_policy {
488 name: "odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900489 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900490 target_policy: ":odm_sepolicy.cil.raw",
491 version: "vendor",
492 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900493 ":plat_sepolicy.cil",
494 ":system_ext_sepolicy.cil",
495 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900496 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900497 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900498 ":vendor_sepolicy.cil",
499 ],
Inseob Kimff2018f2024-04-17 09:48:43 +0900500 filter_out: [
501 ":plat_pub_versioned.cil",
502 ":vendor_sepolicy.cil",
503 ],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900504 device_specific: true,
505}
506
Inseob Kim039175b2021-03-25 15:37:34 +0900507//////////////////////////////////
508// Precompiled sepolicy is loaded if and only if:
509// - plat_sepolicy_and_mapping.sha256 equals
510// precompiled_sepolicy.plat_sepolicy_and_mapping.sha256
511// AND
512// - system_ext_sepolicy_and_mapping.sha256 equals
513// precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256
514// AND
515// - product_sepolicy_and_mapping.sha256 equals
516// precompiled_sepolicy.product_sepolicy_and_mapping.sha256
517// See system/core/init/selinux.cpp for details.
518//////////////////////////////////
Cole Faust30349e32024-10-22 16:31:06 -0700519java_genrule {
Inseob Kim039175b2021-03-25 15:37:34 +0900520 name: "plat_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900521 srcs: [
522 ":plat_sepolicy.cil",
523 ":plat_mapping_file",
524 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900525 out: ["plat_sepolicy_and_mapping.sha256"],
526 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
527}
528
529prebuilt_etc {
530 name: "plat_sepolicy_and_mapping.sha256",
531 filename: "plat_sepolicy_and_mapping.sha256",
532 src: ":plat_sepolicy_and_mapping.sha256_gen",
533 relative_install_path: "selinux",
534}
535
Cole Faust30349e32024-10-22 16:31:06 -0700536java_genrule {
Inseob Kim039175b2021-03-25 15:37:34 +0900537 name: "system_ext_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900538 srcs: [
539 ":system_ext_sepolicy.cil",
540 ":system_ext_mapping_file",
541 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900542 out: ["system_ext_sepolicy_and_mapping.sha256"],
543 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
544}
545
546prebuilt_etc {
547 name: "system_ext_sepolicy_and_mapping.sha256",
548 filename: "system_ext_sepolicy_and_mapping.sha256",
549 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
550 relative_install_path: "selinux",
551 system_ext_specific: true,
552}
553
Cole Faust30349e32024-10-22 16:31:06 -0700554java_genrule {
Inseob Kim039175b2021-03-25 15:37:34 +0900555 name: "product_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900556 srcs: [
557 ":product_sepolicy.cil",
558 ":product_mapping_file",
559 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900560 out: ["product_sepolicy_and_mapping.sha256"],
561 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
562}
563
564prebuilt_etc {
565 name: "product_sepolicy_and_mapping.sha256",
566 filename: "product_sepolicy_and_mapping.sha256",
567 src: ":product_sepolicy_and_mapping.sha256_gen",
568 relative_install_path: "selinux",
569 product_specific: true,
570}
571
Inseob Kim1c056b12021-04-30 00:11:43 +0900572sepolicy_vers {
573 name: "plat_sepolicy_vers.txt",
574 version: "vendor",
575 vendor: true,
576}
577
Inseob Kim9b323082024-11-06 17:10:09 +0900578genrule {
579 name: "genfs_labels_version.txt.gen",
580 out: ["genfs_labels_version.txt"],
581 cmd: select(soong_config_variable("ANDROID", "BOARD_GENFS_LABELS_VERSION"), {
582 any @ value: "echo " + value + " > $(out)",
583 default: "echo > $(out)",
584 }),
585}
586
587prebuilt_etc {
588 name: "genfs_labels_version.txt",
589 src: ":genfs_labels_version.txt.gen",
590 relative_install_path: "selinux",
591 vendor: true,
592}
593
Inseob Kim731182a2021-05-06 11:44:37 +0000594soong_config_module_type {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900595 name: "precompiled_sepolicy_prebuilts_defaults",
Inseob Kim731182a2021-05-06 11:44:37 +0000596 module_type: "prebuilt_defaults",
597 config_namespace: "ANDROID",
598 bool_variables: ["BOARD_USES_ODMIMAGE"],
Inseob Kimff2018f2024-04-17 09:48:43 +0900599 properties: [
600 "vendor",
601 "device_specific",
602 ],
Inseob Kim731182a2021-05-06 11:44:37 +0000603}
604
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900605precompiled_sepolicy_prebuilts_defaults {
606 name: "precompiled_sepolicy_prebuilts",
Inseob Kim731182a2021-05-06 11:44:37 +0000607 soong_config_variables: {
608 BOARD_USES_ODMIMAGE: {
609 device_specific: true,
610 conditions_default: {
611 vendor: true,
612 },
613 },
614 },
615}
616
617//////////////////////////////////
618// SHA-256 digest of the plat_sepolicy.cil and plat_mapping_file against
619// which precompiled_policy was built.
620//////////////////////////////////
621prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900622 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000623 name: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
624 filename: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
625 src: ":plat_sepolicy_and_mapping.sha256_gen",
626 relative_install_path: "selinux",
627}
628
629//////////////////////////////////
630// SHA-256 digest of the system_ext_sepolicy.cil and system_ext_mapping_file against
631// which precompiled_policy was built.
632//////////////////////////////////
633prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900634 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000635 name: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
636 filename: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
637 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
638 relative_install_path: "selinux",
639}
640
641//////////////////////////////////
642// SHA-256 digest of the product_sepolicy.cil and product_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.product_sepolicy_and_mapping.sha256",
648 filename: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
649 src: ":product_sepolicy_and_mapping.sha256_gen",
650 relative_install_path: "selinux",
651}
652
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900653soong_config_module_type {
654 name: "precompiled_se_policy_binary",
655 module_type: "se_policy_binary",
656 config_namespace: "ANDROID",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900657 bool_variables: ["BOARD_USES_ODMIMAGE"],
Inseob Kimff2018f2024-04-17 09:48:43 +0900658 properties: [
659 "vendor",
660 "device_specific",
661 ],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900662}
663
Garfield Tand8c51f22023-10-02 14:17:04 -0700664filegroup {
665 name: "precompiled_sepolicy_srcs",
Cole Faust30349e32024-10-22 16:31:06 -0700666 device_common_srcs: [
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900667 ":plat_sepolicy.cil",
Sandro143988d2022-08-05 11:38:56 +0000668 ":plat_pub_versioned.cil",
669 ":system_ext_sepolicy.cil",
670 ":product_sepolicy.cil",
671 ":vendor_sepolicy.cil",
672 ":odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900673 ":plat_mapping_file",
674 ":system_ext_mapping_file",
675 ":product_mapping_file",
Sandro143988d2022-08-05 11:38:56 +0000676 ],
Inseob Kim9b323082024-11-06 17:10:09 +0900677 device_first_srcs: select(soong_config_variable("ANDROID", "BOARD_GENFS_LABELS_VERSION"), {
Inseob Kim4b951e92025-01-23 10:41:03 +0900678 "202404": [],
679 any @ ver: [":plat_sepolicy_genfs_" + ver + ".cil"],
Inseob Kim9b323082024-11-06 17:10:09 +0900680 default: [],
681 }),
Garfield Tand8c51f22023-10-02 14:17:04 -0700682 // Make precompiled_sepolicy_srcs as public so that OEMs have access to them.
683 // Useful when some partitions need to be bind mounted across VM boundaries.
684 visibility: ["//visibility:public"],
685}
686
687precompiled_se_policy_binary {
688 name: "precompiled_sepolicy",
689 srcs: [
690 ":precompiled_sepolicy_srcs",
691 ],
Sandro143988d2022-08-05 11:38:56 +0000692 soong_config_variables: {
693 BOARD_USES_ODMIMAGE: {
694 device_specific: true,
695 conditions_default: {
696 vendor: true,
697 },
698 },
Sandro143988d2022-08-05 11:38:56 +0000699 },
700 required: [
701 "sepolicy_neverallows",
Sandro143988d2022-08-05 11:38:56 +0000702 ],
703 dist: {
704 targets: ["base-sepolicy-files-for-mapping"],
705 },
706}
707
Inseob Kim5bbcd682021-12-28 14:57:03 +0900708// policy for recovery
709se_policy_conf {
710 name: "recovery_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900711 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900712 srcs: plat_public_policy +
713 plat_private_policy +
714 system_ext_public_policy +
715 system_ext_private_policy +
716 product_public_policy +
717 product_private_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900718 ":se_build_files{.plat_vendor}",
719 ":se_build_files{.vendor}",
720 ":se_build_files{.odm}",
721 ],
Inseob Kim5bbcd682021-12-28 14:57:03 +0900722 target_recovery: true,
723 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900724 recovery: true,
Inseob Kim5bbcd682021-12-28 14:57:03 +0900725}
726
727se_policy_cil {
728 name: "recovery_sepolicy.cil",
729 src: ":recovery_sepolicy.conf",
730 secilc_check: false, // will be done in se_policy_binary module
731 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900732 recovery: true,
Inseob Kim5bbcd682021-12-28 14:57:03 +0900733}
734
735se_policy_binary {
736 name: "sepolicy.recovery",
737 srcs: [":recovery_sepolicy.cil"],
738 stem: "sepolicy",
739 recovery: true,
740}
741
Inseob Kima49e7242021-03-22 10:26:13 +0900742//////////////////////////////////
743// SELinux policy embedded into CTS.
744// CTS checks neverallow rules of this policy against the policy of the device under test.
745//////////////////////////////////
746se_policy_conf {
747 name: "general_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900748 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900749 srcs: plat_public_policy +
750 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900751 build_variant: "user",
752 cts: true,
753 exclude_build_test: true,
Inseob Kim4b9929e2024-03-28 17:52:32 +0900754 dist: {
755 targets: ["sepolicy_finalize"],
756 },
Inseob Kima49e7242021-03-22 10:26:13 +0900757}
Inseob Kimd5816612021-09-15 03:01:05 +0000758
759//////////////////////////////////
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000760// Base system policy for treble sepolicy tests.
761// If system sepolicy is extended (e.g. by SoC vendors), their plat_pub_versioned.cil may differ
762// with system/sepolicy/prebuilts/api/{version}/plat_pub_versioned.cil. In that case,
763// BOARD_PLAT_PUB_VERSIONED_POLICY can be used to specify extended plat_pub_versioned.cil.
764// See treble_sepolicy_tests_for_release.mk for more details.
765//////////////////////////////////
766se_policy_conf {
767 name: "base_plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900768 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900769 srcs: plat_public_policy +
770 plat_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000771 build_variant: "user",
772 installable: false,
773}
774
775se_policy_cil {
776 name: "base_plat_sepolicy.cil",
777 src: ":base_plat_sepolicy.conf",
778 additional_cil_files: ["private/technical_debt.cil"],
779 installable: false,
780 secilc_check: false, // done by se_policy_binary
Inseob Kimd67c5a32025-01-17 10:39:42 +0900781 dist: {
782 targets: ["sepolicy_finalize"],
783 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000784}
785
786se_policy_binary {
787 name: "base_plat_sepolicy",
788 srcs: [":base_plat_sepolicy.cil"],
789 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900790 dist: {
791 targets: ["base-sepolicy-files-for-mapping"],
792 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000793}
794
795se_policy_conf {
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000796 name: "base_product_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900797 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900798 srcs: plat_public_policy +
799 plat_private_policy +
800 system_ext_public_policy +
801 system_ext_private_policy +
802 product_public_policy +
803 product_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000804 build_variant: "user",
805 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900806 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000807}
808
809se_policy_cil {
810 name: "base_product_sepolicy.cil",
811 src: ":base_product_sepolicy.conf",
812 additional_cil_files: ["private/technical_debt.cil"],
813 product_specific: true,
814 installable: false,
815 secilc_check: false, // done by se_policy_binary
816}
817
818se_policy_binary {
819 name: "base_product_sepolicy",
820 srcs: [":base_product_sepolicy.cil"],
821 product_specific: true,
822 installable: false,
823}
824
825se_policy_conf {
826 name: "base_plat_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900827 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900828 srcs: plat_public_policy +
829 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000830 build_variant: "user",
831 installable: false,
832}
833
834se_policy_cil {
835 name: "base_plat_pub_policy.cil",
836 src: ":base_plat_pub_policy.conf",
837 filter_out: [":reqd_policy_mask.cil"],
838 secilc_check: false,
839 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900840 dist: {
841 targets: ["base-sepolicy-files-for-mapping"],
842 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000843}
844
Inseob Kimd67c5a32025-01-17 10:39:42 +0900845se_versioned_policy {
846 name: "base_plat_mapping_file",
847 base: ":base_plat_pub_policy.cil",
848 mapping: true,
849 version: "current",
850 relative_install_path: "mapping", // install to /system/etc/selinux/mapping
851 dist: {
852 targets: ["sepolicy_finalize"],
853 },
854 installable: false,
855}
856
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000857se_policy_conf {
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000858 name: "base_product_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900859 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900860 srcs: plat_public_policy +
861 system_ext_public_policy +
862 product_public_policy +
863 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000864 build_variant: "user",
865 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900866 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000867}
868
869se_policy_cil {
870 name: "base_product_pub_policy.cil",
871 src: ":base_product_pub_policy.conf",
872 filter_out: [":reqd_policy_mask.cil"],
873 secilc_check: false,
874 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900875 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000876}
877
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800878// bug_map - Bug tracking information for selinux denials loaded by auditd.
Inseob Kim41964032022-04-22 07:50:22 +0900879se_build_files {
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800880 name: "bug_map_files",
881 srcs: ["bug_map"],
882}
883
884se_bug_map {
885 name: "plat_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900886 srcs: [":bug_map_files{.plat_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800887 stem: "bug_map",
888}
889
890se_bug_map {
891 name: "system_ext_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900892 srcs: [":bug_map_files{.system_ext_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800893 stem: "bug_map",
894 system_ext_specific: true,
895}
896
897se_bug_map {
898 name: "vendor_bug_map",
Inseob Kimff2018f2024-04-17 09:48:43 +0900899 srcs: [
900 ":bug_map_files{.vendor}",
901 ":bug_map_files{.plat_vendor}",
902 ],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800903 // Legacy file name of the vendor partition bug_map.
904 stem: "selinux_denial_metadata",
905 vendor: true,
906}
907
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900908se_neverallow_test {
909 name: "sepolicy_neverallows",
Inseob Kim085f22f2023-11-09 11:13:01 +0900910 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900911 srcs: plat_public_policy +
912 plat_private_policy +
913 system_ext_public_policy +
914 system_ext_private_policy +
915 product_public_policy +
Inseob Kim6c6aa012023-08-31 16:47:38 +0900916 product_private_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900917 ":se_build_files{.plat_vendor}",
918 ":se_build_files{.vendor}",
919 ":se_build_files{.odm}",
920 ],
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900921}
922
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000923//////////////////////////////////
Inseob Kimd5816612021-09-15 03:01:05 +0000924// se_freeze_test compares the plat sepolicy with the prebuilt sepolicy
925// Additional directories can be specified via Makefile variables:
926// SEPOLICY_FREEZE_TEST_EXTRA_DIRS and SEPOLICY_FREEZE_TEST_EXTRA_PREBUILT_DIRS.
927//////////////////////////////////
Inseob Kimb19ca8d2024-12-27 17:00:25 +0900928
Inseob Kimd4e49452025-01-17 10:43:25 +0900929FREEZE_TEST_BOARD_API_LEVEL = "202504"
Inseob Kimb19ca8d2024-12-27 17:00:25 +0900930
931se_policy_conf {
932 name: "base_plat_pub_policy_for_freeze_test.conf",
933 defaults: ["se_policy_conf_flags_defaults"],
934 srcs: plat_public_policy +
935 reqd_mask_policy,
936 build_variant: "user",
937 installable: false,
938 board_api_level: FREEZE_TEST_BOARD_API_LEVEL,
939}
940
941se_policy_cil {
942 name: "base_plat_pub_policy_for_freeze_test.cil",
943 src: ":base_plat_pub_policy_for_freeze_test.conf",
944 filter_out: [":reqd_policy_mask.cil"],
945 secilc_check: false,
946 installable: false,
947}
948
Inseob Kimd5816612021-09-15 03:01:05 +0000949se_freeze_test {
Inseob Kim36d9d392023-09-04 17:40:03 +0900950 name: "se_freeze_test",
Inseob Kimb19ca8d2024-12-27 17:00:25 +0900951 board_api_level: FREEZE_TEST_BOARD_API_LEVEL,
952 current_cil: ":base_plat_pub_policy_for_freeze_test.cil",
953 prebuilt_cil: ":" + FREEZE_TEST_BOARD_API_LEVEL + "_plat_pub_policy.cil",
Inseob Kimd5816612021-09-15 03:01:05 +0000954}
Inseob Kim61257ca2022-02-25 11:26:16 +0900955
956//////////////////////////////////
957// sepolicy_test checks various types of violations, which can't be easily done
958// by CIL itself. Refer tests/sepolicy_tests.py for more detail.
959//////////////////////////////////
Cole Faust30349e32024-10-22 16:31:06 -0700960java_genrule {
Inseob Kim61257ca2022-02-25 11:26:16 +0900961 name: "sepolicy_test",
962 srcs: [
963 ":plat_file_contexts",
964 ":vendor_file_contexts",
965 ":system_ext_file_contexts",
966 ":product_file_contexts",
967 ":odm_file_contexts",
968 ":precompiled_sepolicy",
969 ],
970 tools: ["sepolicy_tests"],
971 out: ["sepolicy_test"],
972 cmd: "$(location sepolicy_tests) " +
973 "-f $(location :plat_file_contexts) " +
974 "-f $(location :vendor_file_contexts) " +
975 "-f $(location :system_ext_file_contexts) " +
976 "-f $(location :product_file_contexts) " +
977 "-f $(location :odm_file_contexts) " +
978 "-p $(location :precompiled_sepolicy) && " +
979 "touch $(out)",
980}
Inseob Kim3a9d91c2023-09-27 17:39:07 +0900981
982//////////////////////////////////
983// TestDevTypeViolations can't run on old devices (V or before)
984//////////////////////////////////
985
986soong_config_module_type {
987 name: "dev_type_test_genrule",
Cole Faust30349e32024-10-22 16:31:06 -0700988 module_type: "java_genrule",
Inseob Kim3a9d91c2023-09-27 17:39:07 +0900989 config_namespace: "ANDROID",
990 bool_variables: ["CHECK_DEV_TYPE_VIOLATIONS"],
991 properties: ["cmd"],
992}
993
994dev_type_test_genrule {
995 name: "sepolicy_dev_type_test",
996 srcs: [
997 ":plat_file_contexts",
998 ":vendor_file_contexts",
999 ":system_ext_file_contexts",
1000 ":product_file_contexts",
1001 ":odm_file_contexts",
1002 ":precompiled_sepolicy",
1003 ],
1004 tools: ["sepolicy_tests"],
1005 out: ["sepolicy_dev_type_test"],
1006 soong_config_variables: {
1007 CHECK_DEV_TYPE_VIOLATIONS: {
1008 cmd: "$(location sepolicy_tests) " +
1009 "-f $(location :plat_file_contexts) " +
1010 "-f $(location :vendor_file_contexts) " +
1011 "-f $(location :system_ext_file_contexts) " +
1012 "-f $(location :product_file_contexts) " +
1013 "-f $(location :odm_file_contexts) " +
1014 "-p $(location :precompiled_sepolicy) " +
1015 "-t TestDevTypeViolations && " +
1016 "touch $(out)",
1017 conditions_default: {
1018 cmd: "touch $(out)",
1019 },
1020 },
1021 },
1022}
kellyhung08f7c992024-09-18 03:34:53 +00001023
1024phony {
1025 name: "selinux_policy_system_ext",
1026 required: [
1027 //"ifdef HAS_SYSTEM_EXT_PUBLIC_SEPOLICY" check included in system_ext_pub_policy.cil
1028 "system_ext_mapping_file",
1029 //"ifdef HAS_SYSTEM_EXT_SEPOLICY" check included in .cil
1030 "system_ext_sepolicy.cil",
1031 ] + [
1032 //"ifdef HAS_SYSTEM_EXT_SEPOLICY" check included in .cil
1033 "system_ext_29.0.cil",
1034 "system_ext_30.0.cil",
1035 "system_ext_31.0.cil",
1036 "system_ext_32.0.cil",
1037 "system_ext_33.0.cil",
1038 "system_ext_34.0.cil",
1039 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1040 "202404": [],
1041 default: [
1042 "system_ext_202404.cil",
1043 ],
Inseob Kime468a372025-01-22 17:19:44 +09001044 }) + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1045 // TODO(b/391513934): clean up once we can simplify complex select statements.
1046 "202404": [],
1047 "202504": [],
1048 default: [
1049 "system_ext_202504.cil",
1050 ],
kellyhung08f7c992024-09-18 03:34:53 +00001051 }) +
1052 select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1053 true: ["system_ext_sepolicy_and_mapping.sha256"],
1054 default: [],
1055 }) + [
1056 "system_ext_file_contexts",
1057 "system_ext_file_contexts_test",
1058 "system_ext_keystore2_key_contexts",
1059 "system_ext_hwservice_contexts",
1060 "system_ext_hwservice_contexts_test",
1061 "system_ext_property_contexts",
1062 "system_ext_property_contexts_test",
1063 "system_ext_seapp_contexts",
1064 "system_ext_service_contexts",
1065 "system_ext_service_contexts_test",
1066 "system_ext_mac_permissions.xml",
1067 "system_ext_bug_map",
1068 // $(addprefix system_ext_,$(addsuffix .compat.cil,$(PLATFORM_SEPOLICY_COMPAT_VERSIONS))) \
1069 "system_ext_29.0.compat.cil",
1070 "system_ext_30.0.compat.cil",
1071 "system_ext_31.0.compat.cil",
1072 "system_ext_32.0.compat.cil",
1073 "system_ext_33.0.compat.cil",
1074 "system_ext_34.0.compat.cil",
1075 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1076 "202404": [],
1077 default: [
1078 "system_ext_202404.compat.cil",
1079 ],
Inseob Kime468a372025-01-22 17:19:44 +09001080 }) + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1081 // TODO(b/391513934): clean up once we can simplify complex select statements.
1082 "202404": [],
1083 "202504": [],
1084 default: [
1085 "system_ext_202504.compat.cil",
1086 ],
Nikita Ioffe48966b62024-10-22 14:01:17 +00001087 }) + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
1088 true: ["system_ext_tee_service_contexts"],
1089 default: [],
kellyhung08f7c992024-09-18 03:34:53 +00001090 }),
Spandan Das80252082024-10-17 21:58:34 +00001091 system_ext_specific: true,
kellyhung08f7c992024-09-18 03:34:53 +00001092}
kellyhung14081902024-09-18 04:59:54 +00001093
1094phony {
1095 name: "selinux_policy_product",
1096 required: [
1097 "product_mapping_file",
1098 "product_sepolicy.cil",
1099 // "ifdef HAS_PRODUCT_PUBLIC_SEPOLICY" check included in .cil
1100 "product_29.0.cil",
1101 "product_30.0.cil",
1102 "product_31.0.cil",
1103 "product_32.0.cil",
1104 "product_33.0.cil",
1105 "product_34.0.cil",
1106 "product_file_contexts",
1107 // "ifdef HAS_PRODUCT_SEPOLICY_DIR" in Android.mk can be ignored.
1108 "product_file_contexts_test",
1109 "product_keystore2_key_contexts",
1110 "product_hwservice_contexts",
1111 "product_hwservice_contexts_test",
1112 "product_property_contexts",
1113 "product_property_contexts_test",
1114 "product_seapp_contexts",
1115 "product_service_contexts",
1116 "product_service_contexts_test",
1117 "product_mac_permissions.xml",
1118 ] + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1119 true: ["product_sepolicy_and_mapping.sha256"],
1120 default: [],
1121 }) + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1122 "202404": [],
1123 default: [
1124 "product_202404.cil",
1125 ],
Inseob Kime468a372025-01-22 17:19:44 +09001126 }) + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1127 // TODO(b/391513934): clean up once we can simplify complex select statements.
1128 "202404": [],
1129 "202504": [],
1130 default: [
1131 "product_202504.cil",
1132 ],
Nikita Ioffe48966b62024-10-22 14:01:17 +00001133 }) + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
1134 true: ["product_tee_service_contexts"],
1135 default: [],
kellyhung14081902024-09-18 04:59:54 +00001136 }),
Spandan Das155cc2f2024-10-18 22:27:25 +00001137 product_specific: true,
kellyhung14081902024-09-18 04:59:54 +00001138}
kellyhunga07b3712024-09-25 03:31:09 +00001139
1140phony {
1141 name: "selinux_policy_nonsystem",
1142 required: [
Spandan Das62656052024-11-01 18:37:13 +00001143 "selinux_policy_system_ext",
1144 "selinux_policy_product",
1145 "selinux_policy_vendor",
1146 "selinux_policy_odm",
1147 // Builds an additional userdebug sepolicy into the debug ramdisk.
1148 "userdebug_plat_sepolicy.cil",
1149 ],
1150}
1151
1152phony {
1153 name: "selinux_policy_vendor",
1154 required: [
Inseob Kim9b323082024-11-06 17:10:09 +09001155 "genfs_labels_version.txt",
kellyhunga07b3712024-09-25 03:31:09 +00001156 "plat_pub_versioned.cil",
1157 "vendor_sepolicy.cil",
1158 "plat_sepolicy_vers.txt",
1159 "vendor_file_contexts",
1160 "vendor_file_contexts_test",
1161 "vendor_keystore2_key_contexts",
1162 "vendor_mac_permissions.xml",
1163 "vendor_property_contexts",
1164 "vendor_property_contexts_test",
1165 "vendor_seapp_contexts",
1166 "vendor_service_contexts",
1167 "vendor_service_contexts_test",
1168 "vendor_hwservice_contexts",
1169 "vendor_hwservice_contexts_test",
1170 "vendor_bug_map",
1171 "vndservice_contexts",
1172 "vndservice_contexts_test",
Nikita Ioffe48966b62024-10-22 14:01:17 +00001173 ] + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
1174 true: ["vendor_tee_service_contexts"],
1175 default: [],
1176 }),
Spandan Das62656052024-11-01 18:37:13 +00001177 vendor: true,
1178}
1179
1180phony {
1181 name: "selinux_policy_odm",
1182 required: [
kellyhunga07b3712024-09-25 03:31:09 +00001183 "odm_sepolicy.cil",
1184 "odm_file_contexts",
1185 "odm_file_contexts_test",
1186 "odm_seapp_contexts",
1187 "odm_property_contexts",
1188 "odm_property_contexts_test",
1189 "odm_service_contexts",
1190 "odm_service_contexts_test",
1191 "odm_hwservice_contexts",
1192 "odm_hwservice_contexts_test",
1193 "odm_mac_permissions.xml",
kellyhunga07b3712024-09-25 03:31:09 +00001194 ] + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1195 true: [
1196 "precompiled_sepolicy",
1197 "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
1198 "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
1199 "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
1200 ],
1201 default: [],
1202 }),
Spandan Das62656052024-11-01 18:37:13 +00001203 device_specific: true,
kellyhunga07b3712024-09-25 03:31:09 +00001204}
kellyhung0c9edb32024-07-15 11:06:26 +00001205
1206phony {
1207 name: "selinux_policy_system",
1208 required: [
1209 "29.0.compat.cil",
1210 "30.0.compat.cil",
1211 "31.0.compat.cil",
1212 "32.0.compat.cil",
1213 "33.0.compat.cil",
1214 "34.0.compat.cil",
1215 "build_sepolicy",
1216 "fuzzer_bindings_test",
1217 "plat_29.0.cil",
1218 "plat_30.0.cil",
1219 "plat_31.0.cil",
1220 "plat_32.0.cil",
1221 "plat_33.0.cil",
1222 "plat_34.0.cil",
1223 "plat_bug_map",
1224 "plat_file_contexts",
1225 "plat_file_contexts_data_test",
1226 "plat_file_contexts_test",
1227 "plat_hwservice_contexts",
1228 "plat_hwservice_contexts_test",
1229 "plat_keystore2_key_contexts",
1230 "plat_mac_permissions.xml",
1231 "plat_mapping_file",
1232 "plat_property_contexts",
1233 "plat_property_contexts_test",
1234 "plat_seapp_contexts",
1235 "plat_sepolicy.cil",
Inseob Kim9b323082024-11-06 17:10:09 +09001236 "plat_sepolicy_genfs_202504.cil",
Inseob Kim4b951e92025-01-23 10:41:03 +09001237 "plat_sepolicy_genfs_202604.cil",
kellyhung0c9edb32024-07-15 11:06:26 +00001238 "plat_service_contexts",
1239 "plat_service_contexts_test",
1240 "searchpolicy",
1241 "secilc",
1242 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1243 "202404": [],
1244 default: [
1245 "202404.compat.cil",
1246 "plat_202404.cil",
1247 ],
Inseob Kime468a372025-01-22 17:19:44 +09001248 }) + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1249 // TODO(b/391513934): clean up once we can simplify complex select statements.
1250 "202404": [],
1251 "202504": [],
1252 default: [
1253 "202504.compat.cil",
1254 "plat_202504.cil",
1255 ],
kellyhung0c9edb32024-07-15 11:06:26 +00001256 }) + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1257 true: ["plat_sepolicy_and_mapping.sha256"],
1258 default: [],
1259 }) + select((
1260 soong_config_variable("ANDROID", "ASAN_ENABLED"),
1261 product_variable("selinux_ignore_neverallows"),
1262 ), {
1263 (true, true): [
1264 ],
1265 (default, default): [
1266 "sepolicy_compat_test",
1267 "sepolicy_test",
1268 "sepolicy_dev_type_test",
1269 "treble_sepolicy_tests_29.0",
1270 "treble_sepolicy_tests_30.0",
1271 "treble_sepolicy_tests_31.0",
1272 "treble_sepolicy_tests_32.0",
1273 "treble_sepolicy_tests_33.0",
1274 "treble_sepolicy_tests_34.0",
1275 ],
1276 }) + select((
1277 soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"),
1278 soong_config_variable("ANDROID", "ASAN_ENABLED"),
1279 product_variable("selinux_ignore_neverallows"),
1280 ), {
1281 ("202404", true, true): [],
1282 (default, true, true): [],
1283 (default, default, default): [
1284 "treble_sepolicy_tests_202404",
1285 ],
Inseob Kime468a372025-01-22 17:19:44 +09001286 }) + select((
1287 soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"),
1288 soong_config_variable("ANDROID", "ASAN_ENABLED"),
1289 product_variable("selinux_ignore_neverallows"),
1290 ), {
1291 ("202404", default, default): [], // TODO(b/391513934): clean up once we can simplify complex select statements.
1292 ("202504", true, true): [],
1293 (default, true, true): [],
1294 (default, default, default): [
1295 "treble_sepolicy_tests_202504",
1296 ],
kellyhung0c9edb32024-07-15 11:06:26 +00001297 }) + select(soong_config_variable("ANDROID", "RELEASE_BOARD_API_LEVEL_FROZEN"), {
1298 true: ["se_freeze_test"],
1299 default: [],
Nikita Ioffe48966b62024-10-22 14:01:17 +00001300 }) + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
1301 true: ["plat_tee_service_contexts"],
1302 default: [],
kellyhung0c9edb32024-07-15 11:06:26 +00001303 }),
1304}
kellyhungee97d9c2024-10-03 00:54:38 +00001305
1306phony {
1307 name: "selinux_policy",
1308 required: [
1309 // Runs checkfc against merged service_contexts files
1310 "merged_hwservice_contexts_test",
1311 "merged_service_contexts_test",
1312 "selinux_policy_nonsystem",
1313 "selinux_policy_system",
1314 ],
1315}
1316
1317// selinux_policy is a main goal and triggers lots of tests.
1318// Most tests are FAKE modules, so aren'triggered on normal builds. (e.g. 'm')
1319// By setting as droidcore's dependency, tests will run on normal builds.
1320phony_rule {
1321 name: "droidcore",
1322 phony_deps: ["selinux_policy"],
1323}
kellyhung8659c152024-10-07 21:37:14 +00001324
1325//-----------------------------------------------------------------------------
1326// TODO - remove this. Keep around until we get the filesystem creation stuff
1327// taken care of.
1328//
1329// The file_contexts.bin is built in the following way:
1330// 1. Collect all file_contexts files in THIS repository and process them with
1331// m4 into a tmp file called file_contexts.local.tmp.
1332// 2. Collect all device specific file_contexts files and process them with m4
1333// into a tmp file called file_contexts.device.tmp.
1334// 3. Run checkfc -e (allow no device fc entries ie empty) and fc_sort on
1335// file_contexts.device.tmp and output to file_contexts.device.sorted.tmp.
1336// 4. Concatenate file_contexts.local.tmp and file_contexts.device.sorted.tmp
1337// into file_contexts.concat.tmp.
1338// 5. Run checkfc and sefcontext_compile on file_contexts.concat.tmp to produce
1339// file_contexts.bin.
1340//
1341// Note: That a newline file is placed between each file_context file found to
1342// ensure a proper build when an fc file is missing an ending newline.
1343//---
1344// 1. Collect all file_contexts files in THIS repository and process them with
1345// m4 into a tmp file called file_contexts.local.tmp.
Cole Faust30349e32024-10-22 16:31:06 -07001346java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001347 name: "file_contexts.local.tmp",
1348 srcs: [
1349 ":plat_file_contexts",
1350 ":system_ext_file_contexts",
1351 ":product_file_contexts",
1352 ],
1353 tools: [
1354 "m4",
1355 ],
1356 out: ["file_contexts.local.tmp"],
1357 cmd: "$(location m4) --fatal-warnings " +
1358 "-s $(in) > $(out)",
1359}
1360
1361// 2. Collect all device specific file_contexts files and process them with m4
1362// into a tmp file called file_contexts.device.tmp.
1363PRIVATE_ADDITIONAL_M4DEFS = select(soong_config_variable("ANDROID", "ADDITIONAL_M4DEFS"), {
1364 any @ m4defs: m4defs,
1365 default: "",
1366})
Cole Faust30349e32024-10-22 16:31:06 -07001367java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001368 name: "file_contexts.device.tmp",
1369 srcs: [
1370 ":vendor_file_contexts",
1371 ":odm_file_contexts",
1372 ],
1373 tools: [
1374 "m4",
1375 ],
1376 out: ["file_contexts.device.tmp"],
1377 cmd: "$(location m4) --fatal-warnings " +
1378 "-s " + PRIVATE_ADDITIONAL_M4DEFS +
1379 " $(in) > $(out)",
1380}
1381
1382// 3. Run checkfc -e (allow no device fc entries ie empty) and fc_sort on
1383// file_contexts.device.tmp and output to file_contexts.device.sorted.tmp.
Cole Faust30349e32024-10-22 16:31:06 -07001384java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001385 name: "file_contexts.device.sorted.tmp",
1386 srcs: [
1387 ":file_contexts.device.tmp",
1388 ":precompiled_sepolicy",
1389 ],
1390 tools: [
1391 "checkfc",
1392 "fc_sort",
1393 ],
1394 out: ["file_contexts.device.sorted.tmp"],
1395 cmd: "$(location checkfc) " +
1396 "-e $(location :precompiled_sepolicy) " +
1397 "$(location :file_contexts.device.tmp) && " +
1398 "$(location fc_sort) " +
1399 "-i $(location :file_contexts.device.tmp) " +
1400 "-o $(out)",
1401}
1402
1403// 4. Concatenate file_contexts.local.tmp and file_contexts.device.sorted.tmp
1404// into file_contexts.concat.tmp.
Cole Faust30349e32024-10-22 16:31:06 -07001405java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001406 name: "file_contexts.concat.tmp",
1407 srcs: [
1408 ":file_contexts.local.tmp",
1409 ":file_contexts.device.sorted.tmp",
1410 ],
1411 tools: [
1412 "m4",
1413 ],
1414 out: ["file_contexts.concat.tmp"],
1415 cmd: "$(location m4) --fatal-warnings " +
1416 "-s $(location :file_contexts.local.tmp) " +
1417 "$(location :file_contexts.device.sorted.tmp) > $(out)",
1418}
1419
1420// 5. Run checkfc and sefcontext_compile on file_contexts.concat.tmp to produce
1421// file_contexts.bin.
Cole Faust30349e32024-10-22 16:31:06 -07001422java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001423 name: "file_contexts_bin_gen",
1424 srcs: [
1425 ":file_contexts.concat.tmp",
1426 ":precompiled_sepolicy",
1427 ],
1428 tools: [
1429 "checkfc",
1430 "sefcontext_compile",
1431 ],
1432 out: ["file_contexts.bin"],
1433 cmd: "$(location checkfc) " +
1434 "$(location :precompiled_sepolicy) " +
1435 "$(location :file_contexts.concat.tmp) && " +
1436 "$(location sefcontext_compile) " +
1437 "-o $(out) $(location :file_contexts.concat.tmp)",
1438}
1439
1440prebuilt_etc {
1441 name: "file_contexts.bin",
1442 src: ":file_contexts_bin_gen",
1443}