blob: e3017f964dde741546dac50d4230c63b0dca65ea [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 ],
Inseob Kime468a372025-01-22 17:19:44 +0900126 }) + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
127 // TODO(b/391513934): clean up once we can simplify complex select statements.
128 "202404": [],
129 "202504": [],
130 default: [
131 "plat_202504.cil",
132 "202504.compat.cil",
133 ],
Cole Faustac1f8152024-06-17 12:39:02 -0700134 }) + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
Cole Faustc22dece2024-06-20 12:58:34 -0700135 true: ["plat_sepolicy_and_mapping.sha256"],
Cole Faustac1f8152024-06-17 12:39:02 -0700136 default: [],
Nikita Ioffe48966b62024-10-22 14:01:17 +0000137 }) + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
138 true: ["plat_tee_service_contexts"],
139 default: [],
Cole Faustac1f8152024-06-17 12:39:02 -0700140 }),
Inseob Kim151562f2024-04-12 10:53:34 +0900141}
142
Inseob Kimff2018f2024-04-17 09:48:43 +0900143reqd_mask_policy = [":se_build_files{.reqd_mask}"]
144plat_public_policy = [":se_build_files{.plat_public}"]
145plat_private_policy = [":se_build_files{.plat_private}"]
146system_ext_public_policy = [":se_build_files{.system_ext_public}"]
Inseob Kim0a707fa2021-12-09 23:35:11 +0900147system_ext_private_policy = [":se_build_files{.system_ext_private}"]
Inseob Kimff2018f2024-04-17 09:48:43 +0900148product_public_policy = [":se_build_files{.product_public}"]
149product_private_policy = [":se_build_files{.product_private}"]
Inseob Kim0a707fa2021-12-09 23:35:11 +0900150
Inseob Kima49e7242021-03-22 10:26:13 +0900151// reqd_policy_mask - a policy.conf file which contains only the bare minimum
152// policy necessary to use checkpolicy.
153//
154// This bare-minimum policy needs to be present in all policy.conf files, but
155// should not necessarily be exported as part of the public policy.
156//
157// The rules generated by reqd_policy_mask will allow the compilation of public
158// policy and subsequent removal of CIL policy that should not be exported.
159se_policy_conf {
160 name: "reqd_policy_mask.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900161 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900162 srcs: reqd_mask_policy,
Inseob Kime35b49b2021-02-18 19:15:41 +0900163 installable: false,
164}
165
Inseob Kima49e7242021-03-22 10:26:13 +0900166se_policy_cil {
167 name: "reqd_policy_mask.cil",
168 src: ":reqd_policy_mask.conf",
169 secilc_check: false,
170 installable: false,
Inseob Kime35b49b2021-02-18 19:15:41 +0900171}
172
Inseob Kima49e7242021-03-22 10:26:13 +0900173// pub_policy - policy that will be exported to be a part of non-platform
174// policy corresponding to this platform version.
175//
176// This is a limited subset of policy that would not compile in checkpolicy on
177// its own.
178//
179// To get around this limitation, add only the required files from private
180// policy, which will generate CIL policy that will then be filtered out by the
181// reqd_policy_mask.
182//
183// There are three pub_policy.cil files below:
184// - pub_policy.cil: exported 'product', 'system_ext' and 'system' policy.
185// - system_ext_pub_policy.cil: exported 'system_ext' and 'system' policy.
186// - plat_pub_policy.cil: exported 'system' policy.
187//
188// Those above files will in turn be used to generate the following versioned cil files:
189// - product_mapping_file: the versioned, exported 'product' policy in product partition.
190// - system_ext_mapping_file: the versioned, exported 'system_ext' policy in system_ext partition.
191// - plat_mapping_file: the versioned, exported 'system' policy in system partition.
192// - plat_pub_versioned.cil: the versioned, exported 'product', 'system_ext' and 'system' policy
193// in vendor partition.
194//
195se_policy_conf {
196 name: "pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900197 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900198 srcs: plat_public_policy +
199 system_ext_public_policy +
200 product_public_policy +
201 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900202 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900203 installable: false,
204}
205
206se_policy_cil {
207 name: "pub_policy.cil",
208 src: ":pub_policy.conf",
209 filter_out: [":reqd_policy_mask.cil"],
210 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900211 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900212 installable: false,
213}
214
215se_policy_conf {
216 name: "system_ext_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900217 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900218 srcs: plat_public_policy +
219 system_ext_public_policy +
220 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900221 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900222 installable: false,
223}
224
225se_policy_cil {
226 name: "system_ext_pub_policy.cil",
227 src: ":system_ext_pub_policy.conf",
228 filter_out: [":reqd_policy_mask.cil"],
229 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900230 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900231 installable: false,
232}
233
234se_policy_conf {
235 name: "plat_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900236 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900237 srcs: plat_public_policy +
238 reqd_mask_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900239 installable: false,
240}
241
242se_policy_cil {
243 name: "plat_pub_policy.cil",
244 src: ":plat_pub_policy.conf",
245 filter_out: [":reqd_policy_mask.cil"],
246 secilc_check: false,
247 installable: false,
248}
249
250// plat_policy.conf - A combination of the private and public platform policy
251// which will ship with the device.
252//
253// The platform will always reflect the most recent platform version and is not
254// currently being attributized.
255se_policy_conf {
256 name: "plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900257 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900258 srcs: plat_public_policy +
259 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900260 installable: false,
261}
262
263se_policy_cil {
264 name: "plat_sepolicy.cil",
265 src: ":plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900266 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kima49e7242021-03-22 10:26:13 +0900267}
268
Inseob Kim6cc75f42021-04-29 13:53:20 +0000269// userdebug_plat_policy.conf - the userdebug version plat_sepolicy.cil
270se_policy_conf {
271 name: "userdebug_plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900272 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900273 srcs: plat_public_policy +
274 plat_private_policy,
Inseob Kim6cc75f42021-04-29 13:53:20 +0000275 build_variant: "userdebug",
276 installable: false,
277}
278
279se_policy_cil {
280 name: "userdebug_plat_sepolicy.cil",
281 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900282 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kim6cc75f42021-04-29 13:53:20 +0000283 debug_ramdisk: true,
Yi-Yo Chiang68478b12021-10-16 03:23:05 +0800284 dist: {
285 targets: ["droidcore"],
286 },
Inseob Kim6cc75f42021-04-29 13:53:20 +0000287}
288
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000289// A copy of the userdebug_plat_policy in GSI.
290soong_config_module_type {
291 name: "gsi_se_policy_cil",
292 module_type: "se_policy_cil",
293 config_namespace: "ANDROID",
294 bool_variables: [
295 "PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT",
296 ],
297 properties: [
298 "enabled",
299 "installable",
300 ],
301}
302
303gsi_se_policy_cil {
304 name: "system_ext_userdebug_plat_sepolicy.cil",
305 stem: "userdebug_plat_sepolicy.cil",
306 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900307 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000308 system_ext_specific: true,
309 enabled: false,
310 installable: false,
311 soong_config_variables: {
312 PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT: {
313 enabled: true,
314 installable: true,
315 },
316 },
317}
318
Inseob Kima49e7242021-03-22 10:26:13 +0900319// system_ext_policy.conf - A combination of the private and public system_ext
320// policy which will ship with the device. System_ext policy is not attributized
321se_policy_conf {
322 name: "system_ext_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900323 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900324 srcs: plat_public_policy +
325 plat_private_policy +
326 system_ext_public_policy +
327 system_ext_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900328 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900329 installable: false,
330}
331
332se_policy_cil {
333 name: "system_ext_sepolicy.cil",
334 src: ":system_ext_sepolicy.conf",
335 system_ext_specific: true,
336 filter_out: [":plat_sepolicy.cil"],
337 remove_line_marker: true,
338}
339
340// product_policy.conf - A combination of the private and public product policy
341// which will ship with the device. Product policy is not attributized
342se_policy_conf {
343 name: "product_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900344 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900345 srcs: plat_public_policy +
346 plat_private_policy +
347 system_ext_public_policy +
348 system_ext_private_policy +
349 product_public_policy +
350 product_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900351 product_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900352 installable: false,
353}
354
355se_policy_cil {
356 name: "product_sepolicy.cil",
357 src: ":product_sepolicy.conf",
358 product_specific: true,
Inseob Kimff2018f2024-04-17 09:48:43 +0900359 filter_out: [
360 ":plat_sepolicy.cil",
361 ":system_ext_sepolicy.cil",
362 ],
Inseob Kima49e7242021-03-22 10:26:13 +0900363 remove_line_marker: true,
364}
365
Inseob Kim039175b2021-03-25 15:37:34 +0900366// policy mapping files
367// auto-generate the mapping file for current platform policy, since it needs to
368// track platform policy development
369se_versioned_policy {
370 name: "plat_mapping_file",
371 base: ":plat_pub_policy.cil",
372 mapping: true,
373 version: "current",
374 relative_install_path: "mapping", // install to /system/etc/selinux/mapping
375}
376
377se_versioned_policy {
378 name: "system_ext_mapping_file",
379 base: ":system_ext_pub_policy.cil",
380 mapping: true,
381 version: "current",
382 filter_out: [":plat_mapping_file"],
383 relative_install_path: "mapping", // install to /system_ext/etc/selinux/mapping
384 system_ext_specific: true,
385}
386
387se_versioned_policy {
388 name: "product_mapping_file",
389 base: ":pub_policy.cil",
390 mapping: true,
391 version: "current",
Inseob Kimff2018f2024-04-17 09:48:43 +0900392 filter_out: [
393 ":plat_mapping_file",
394 ":system_ext_mapping_file",
395 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900396 relative_install_path: "mapping", // install to /product/etc/selinux/mapping
397 product_specific: true,
398}
399
Inseob Kim6c6aa012023-08-31 16:47:38 +0900400//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900401// vendor/odm sepolicy
Inseob Kim6c6aa012023-08-31 16:47:38 +0900402//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900403
Inseob Kim039175b2021-03-25 15:37:34 +0900404// plat_pub_versioned.cil - the exported platform policy associated with the version
405// that non-platform policy targets.
406se_versioned_policy {
407 name: "plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900408 base: ":pub_policy.cil",
409 target_policy: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900410 version: "vendor",
Inseob Kim039175b2021-03-25 15:37:34 +0900411 vendor: true,
412}
413
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900414// vendor_policy.cil - the vendor sepolicy. This needs attributization and to be combined
415// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
416// policy and the platform public policy files in order to use checkpolicy.
417se_policy_conf {
418 name: "vendor_sepolicy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900419 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900420 srcs: plat_public_policy +
421 system_ext_public_policy +
422 product_public_policy +
423 reqd_mask_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900424 ":se_build_files{.plat_vendor}",
425 ":se_build_files{.vendor}",
426 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900427 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900428 installable: false,
429}
430
431se_policy_cil {
432 name: "vendor_sepolicy.cil.raw",
433 src: ":vendor_sepolicy.conf",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900434 filter_out: [":reqd_policy_mask.cil"],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900435 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900436 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900437 installable: false,
438}
439
440se_versioned_policy {
441 name: "vendor_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900442 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900443 target_policy: ":vendor_sepolicy.cil.raw",
444 version: "vendor",
445 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900446 ":plat_sepolicy.cil",
447 ":system_ext_sepolicy.cil",
448 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900449 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900450 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900451 ],
452 filter_out: [":plat_pub_versioned.cil"],
453 vendor: true,
454}
455
456// odm_policy.cil - the odl sepolicy. This needs attributization and to be combined
457// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
458// policy and the platform public policy files in order to use checkpolicy.
459se_policy_conf {
460 name: "odm_sepolicy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900461 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900462 srcs: plat_public_policy +
463 system_ext_public_policy +
464 product_public_policy +
465 reqd_mask_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900466 ":se_build_files{.plat_vendor}",
467 ":se_build_files{.vendor}",
468 ":se_build_files{.odm}",
469 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900470 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900471 installable: false,
472}
473
474se_policy_cil {
475 name: "odm_sepolicy.cil.raw",
476 src: ":odm_sepolicy.conf",
477 filter_out: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900478 ":reqd_policy_mask.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900479 ":vendor_sepolicy.cil",
480 ],
481 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900482 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900483 installable: false,
484}
485
486se_versioned_policy {
487 name: "odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900488 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900489 target_policy: ":odm_sepolicy.cil.raw",
490 version: "vendor",
491 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900492 ":plat_sepolicy.cil",
493 ":system_ext_sepolicy.cil",
494 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900495 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900496 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900497 ":vendor_sepolicy.cil",
498 ],
Inseob Kimff2018f2024-04-17 09:48:43 +0900499 filter_out: [
500 ":plat_pub_versioned.cil",
501 ":vendor_sepolicy.cil",
502 ],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900503 device_specific: true,
504}
505
Inseob Kim039175b2021-03-25 15:37:34 +0900506//////////////////////////////////
507// Precompiled sepolicy is loaded if and only if:
508// - plat_sepolicy_and_mapping.sha256 equals
509// precompiled_sepolicy.plat_sepolicy_and_mapping.sha256
510// AND
511// - system_ext_sepolicy_and_mapping.sha256 equals
512// precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256
513// AND
514// - product_sepolicy_and_mapping.sha256 equals
515// precompiled_sepolicy.product_sepolicy_and_mapping.sha256
516// See system/core/init/selinux.cpp for details.
517//////////////////////////////////
Cole Faust30349e32024-10-22 16:31:06 -0700518java_genrule {
Inseob Kim039175b2021-03-25 15:37:34 +0900519 name: "plat_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900520 srcs: [
521 ":plat_sepolicy.cil",
522 ":plat_mapping_file",
523 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900524 out: ["plat_sepolicy_and_mapping.sha256"],
525 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
526}
527
528prebuilt_etc {
529 name: "plat_sepolicy_and_mapping.sha256",
530 filename: "plat_sepolicy_and_mapping.sha256",
531 src: ":plat_sepolicy_and_mapping.sha256_gen",
532 relative_install_path: "selinux",
533}
534
Cole Faust30349e32024-10-22 16:31:06 -0700535java_genrule {
Inseob Kim039175b2021-03-25 15:37:34 +0900536 name: "system_ext_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900537 srcs: [
538 ":system_ext_sepolicy.cil",
539 ":system_ext_mapping_file",
540 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900541 out: ["system_ext_sepolicy_and_mapping.sha256"],
542 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
543}
544
545prebuilt_etc {
546 name: "system_ext_sepolicy_and_mapping.sha256",
547 filename: "system_ext_sepolicy_and_mapping.sha256",
548 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
549 relative_install_path: "selinux",
550 system_ext_specific: true,
551}
552
Cole Faust30349e32024-10-22 16:31:06 -0700553java_genrule {
Inseob Kim039175b2021-03-25 15:37:34 +0900554 name: "product_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900555 srcs: [
556 ":product_sepolicy.cil",
557 ":product_mapping_file",
558 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900559 out: ["product_sepolicy_and_mapping.sha256"],
560 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
561}
562
563prebuilt_etc {
564 name: "product_sepolicy_and_mapping.sha256",
565 filename: "product_sepolicy_and_mapping.sha256",
566 src: ":product_sepolicy_and_mapping.sha256_gen",
567 relative_install_path: "selinux",
568 product_specific: true,
569}
570
Inseob Kim1c056b12021-04-30 00:11:43 +0900571sepolicy_vers {
572 name: "plat_sepolicy_vers.txt",
573 version: "vendor",
574 vendor: true,
575}
576
Inseob Kim9b323082024-11-06 17:10:09 +0900577genrule {
578 name: "genfs_labels_version.txt.gen",
579 out: ["genfs_labels_version.txt"],
580 cmd: select(soong_config_variable("ANDROID", "BOARD_GENFS_LABELS_VERSION"), {
581 any @ value: "echo " + value + " > $(out)",
582 default: "echo > $(out)",
583 }),
584}
585
586prebuilt_etc {
587 name: "genfs_labels_version.txt",
588 src: ":genfs_labels_version.txt.gen",
589 relative_install_path: "selinux",
590 vendor: true,
591}
592
Inseob Kim731182a2021-05-06 11:44:37 +0000593soong_config_module_type {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900594 name: "precompiled_sepolicy_prebuilts_defaults",
Inseob Kim731182a2021-05-06 11:44:37 +0000595 module_type: "prebuilt_defaults",
596 config_namespace: "ANDROID",
597 bool_variables: ["BOARD_USES_ODMIMAGE"],
Inseob Kimff2018f2024-04-17 09:48:43 +0900598 properties: [
599 "vendor",
600 "device_specific",
601 ],
Inseob Kim731182a2021-05-06 11:44:37 +0000602}
603
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900604precompiled_sepolicy_prebuilts_defaults {
605 name: "precompiled_sepolicy_prebuilts",
Inseob Kim731182a2021-05-06 11:44:37 +0000606 soong_config_variables: {
607 BOARD_USES_ODMIMAGE: {
608 device_specific: true,
609 conditions_default: {
610 vendor: true,
611 },
612 },
613 },
614}
615
616//////////////////////////////////
617// SHA-256 digest of the plat_sepolicy.cil and plat_mapping_file against
618// which precompiled_policy was built.
619//////////////////////////////////
620prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900621 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000622 name: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
623 filename: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
624 src: ":plat_sepolicy_and_mapping.sha256_gen",
625 relative_install_path: "selinux",
626}
627
628//////////////////////////////////
629// SHA-256 digest of the system_ext_sepolicy.cil and system_ext_mapping_file against
630// which precompiled_policy was built.
631//////////////////////////////////
632prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900633 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000634 name: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
635 filename: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
636 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
637 relative_install_path: "selinux",
638}
639
640//////////////////////////////////
641// SHA-256 digest of the product_sepolicy.cil and product_mapping_file against
642// which precompiled_policy was built.
643//////////////////////////////////
644prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900645 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000646 name: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
647 filename: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
648 src: ":product_sepolicy_and_mapping.sha256_gen",
649 relative_install_path: "selinux",
650}
651
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900652soong_config_module_type {
653 name: "precompiled_se_policy_binary",
654 module_type: "se_policy_binary",
655 config_namespace: "ANDROID",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900656 bool_variables: ["BOARD_USES_ODMIMAGE"],
Inseob Kimff2018f2024-04-17 09:48:43 +0900657 properties: [
658 "vendor",
659 "device_specific",
660 ],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900661}
662
Garfield Tand8c51f22023-10-02 14:17:04 -0700663filegroup {
664 name: "precompiled_sepolicy_srcs",
Cole Faust30349e32024-10-22 16:31:06 -0700665 device_common_srcs: [
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900666 ":plat_sepolicy.cil",
Sandro143988d2022-08-05 11:38:56 +0000667 ":plat_pub_versioned.cil",
668 ":system_ext_sepolicy.cil",
669 ":product_sepolicy.cil",
670 ":vendor_sepolicy.cil",
671 ":odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900672 ":plat_mapping_file",
673 ":system_ext_mapping_file",
674 ":product_mapping_file",
Sandro143988d2022-08-05 11:38:56 +0000675 ],
Inseob Kim9b323082024-11-06 17:10:09 +0900676 device_first_srcs: select(soong_config_variable("ANDROID", "BOARD_GENFS_LABELS_VERSION"), {
Inseob Kime468a372025-01-22 17:19:44 +0900677 // TODO(b/391513934): clean up once we can simplify complex select statements.
Inseob Kim9b323082024-11-06 17:10:09 +0900678 "202504": [":plat_sepolicy_genfs_202504.cil"],
Inseob Kime468a372025-01-22 17:19:44 +0900679 "202604": [":plat_sepolicy_genfs_202504.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",
kellyhung0c9edb32024-07-15 11:06:26 +00001237 "plat_service_contexts",
1238 "plat_service_contexts_test",
1239 "searchpolicy",
1240 "secilc",
1241 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1242 "202404": [],
1243 default: [
1244 "202404.compat.cil",
1245 "plat_202404.cil",
1246 ],
Inseob Kime468a372025-01-22 17:19:44 +09001247 }) + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1248 // TODO(b/391513934): clean up once we can simplify complex select statements.
1249 "202404": [],
1250 "202504": [],
1251 default: [
1252 "202504.compat.cil",
1253 "plat_202504.cil",
1254 ],
kellyhung0c9edb32024-07-15 11:06:26 +00001255 }) + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1256 true: ["plat_sepolicy_and_mapping.sha256"],
1257 default: [],
1258 }) + select((
1259 soong_config_variable("ANDROID", "ASAN_ENABLED"),
1260 product_variable("selinux_ignore_neverallows"),
1261 ), {
1262 (true, true): [
1263 ],
1264 (default, default): [
1265 "sepolicy_compat_test",
1266 "sepolicy_test",
1267 "sepolicy_dev_type_test",
1268 "treble_sepolicy_tests_29.0",
1269 "treble_sepolicy_tests_30.0",
1270 "treble_sepolicy_tests_31.0",
1271 "treble_sepolicy_tests_32.0",
1272 "treble_sepolicy_tests_33.0",
1273 "treble_sepolicy_tests_34.0",
1274 ],
1275 }) + select((
1276 soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"),
1277 soong_config_variable("ANDROID", "ASAN_ENABLED"),
1278 product_variable("selinux_ignore_neverallows"),
1279 ), {
1280 ("202404", true, true): [],
1281 (default, true, true): [],
1282 (default, default, default): [
1283 "treble_sepolicy_tests_202404",
1284 ],
Inseob Kime468a372025-01-22 17:19:44 +09001285 }) + select((
1286 soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"),
1287 soong_config_variable("ANDROID", "ASAN_ENABLED"),
1288 product_variable("selinux_ignore_neverallows"),
1289 ), {
1290 ("202404", default, default): [], // TODO(b/391513934): clean up once we can simplify complex select statements.
1291 ("202504", true, true): [],
1292 (default, true, true): [],
1293 (default, default, default): [
1294 "treble_sepolicy_tests_202504",
1295 ],
kellyhung0c9edb32024-07-15 11:06:26 +00001296 }) + select(soong_config_variable("ANDROID", "RELEASE_BOARD_API_LEVEL_FROZEN"), {
1297 true: ["se_freeze_test"],
1298 default: [],
Nikita Ioffe48966b62024-10-22 14:01:17 +00001299 }) + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
1300 true: ["plat_tee_service_contexts"],
1301 default: [],
kellyhung0c9edb32024-07-15 11:06:26 +00001302 }),
1303}
kellyhungee97d9c2024-10-03 00:54:38 +00001304
1305phony {
1306 name: "selinux_policy",
1307 required: [
1308 // Runs checkfc against merged service_contexts files
1309 "merged_hwservice_contexts_test",
1310 "merged_service_contexts_test",
1311 "selinux_policy_nonsystem",
1312 "selinux_policy_system",
1313 ],
1314}
1315
1316// selinux_policy is a main goal and triggers lots of tests.
1317// Most tests are FAKE modules, so aren'triggered on normal builds. (e.g. 'm')
1318// By setting as droidcore's dependency, tests will run on normal builds.
1319phony_rule {
1320 name: "droidcore",
1321 phony_deps: ["selinux_policy"],
1322}
kellyhung8659c152024-10-07 21:37:14 +00001323
1324//-----------------------------------------------------------------------------
1325// TODO - remove this. Keep around until we get the filesystem creation stuff
1326// taken care of.
1327//
1328// The file_contexts.bin is built in the following way:
1329// 1. Collect all file_contexts files in THIS repository and process them with
1330// m4 into a tmp file called file_contexts.local.tmp.
1331// 2. Collect all device specific file_contexts files and process them with m4
1332// into a tmp file called file_contexts.device.tmp.
1333// 3. Run checkfc -e (allow no device fc entries ie empty) and fc_sort on
1334// file_contexts.device.tmp and output to file_contexts.device.sorted.tmp.
1335// 4. Concatenate file_contexts.local.tmp and file_contexts.device.sorted.tmp
1336// into file_contexts.concat.tmp.
1337// 5. Run checkfc and sefcontext_compile on file_contexts.concat.tmp to produce
1338// file_contexts.bin.
1339//
1340// Note: That a newline file is placed between each file_context file found to
1341// ensure a proper build when an fc file is missing an ending newline.
1342//---
1343// 1. Collect all file_contexts files in THIS repository and process them with
1344// m4 into a tmp file called file_contexts.local.tmp.
Cole Faust30349e32024-10-22 16:31:06 -07001345java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001346 name: "file_contexts.local.tmp",
1347 srcs: [
1348 ":plat_file_contexts",
1349 ":system_ext_file_contexts",
1350 ":product_file_contexts",
1351 ],
1352 tools: [
1353 "m4",
1354 ],
1355 out: ["file_contexts.local.tmp"],
1356 cmd: "$(location m4) --fatal-warnings " +
1357 "-s $(in) > $(out)",
1358}
1359
1360// 2. Collect all device specific file_contexts files and process them with m4
1361// into a tmp file called file_contexts.device.tmp.
1362PRIVATE_ADDITIONAL_M4DEFS = select(soong_config_variable("ANDROID", "ADDITIONAL_M4DEFS"), {
1363 any @ m4defs: m4defs,
1364 default: "",
1365})
Cole Faust30349e32024-10-22 16:31:06 -07001366java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001367 name: "file_contexts.device.tmp",
1368 srcs: [
1369 ":vendor_file_contexts",
1370 ":odm_file_contexts",
1371 ],
1372 tools: [
1373 "m4",
1374 ],
1375 out: ["file_contexts.device.tmp"],
1376 cmd: "$(location m4) --fatal-warnings " +
1377 "-s " + PRIVATE_ADDITIONAL_M4DEFS +
1378 " $(in) > $(out)",
1379}
1380
1381// 3. Run checkfc -e (allow no device fc entries ie empty) and fc_sort on
1382// file_contexts.device.tmp and output to file_contexts.device.sorted.tmp.
Cole Faust30349e32024-10-22 16:31:06 -07001383java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001384 name: "file_contexts.device.sorted.tmp",
1385 srcs: [
1386 ":file_contexts.device.tmp",
1387 ":precompiled_sepolicy",
1388 ],
1389 tools: [
1390 "checkfc",
1391 "fc_sort",
1392 ],
1393 out: ["file_contexts.device.sorted.tmp"],
1394 cmd: "$(location checkfc) " +
1395 "-e $(location :precompiled_sepolicy) " +
1396 "$(location :file_contexts.device.tmp) && " +
1397 "$(location fc_sort) " +
1398 "-i $(location :file_contexts.device.tmp) " +
1399 "-o $(out)",
1400}
1401
1402// 4. Concatenate file_contexts.local.tmp and file_contexts.device.sorted.tmp
1403// into file_contexts.concat.tmp.
Cole Faust30349e32024-10-22 16:31:06 -07001404java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001405 name: "file_contexts.concat.tmp",
1406 srcs: [
1407 ":file_contexts.local.tmp",
1408 ":file_contexts.device.sorted.tmp",
1409 ],
1410 tools: [
1411 "m4",
1412 ],
1413 out: ["file_contexts.concat.tmp"],
1414 cmd: "$(location m4) --fatal-warnings " +
1415 "-s $(location :file_contexts.local.tmp) " +
1416 "$(location :file_contexts.device.sorted.tmp) > $(out)",
1417}
1418
1419// 5. Run checkfc and sefcontext_compile on file_contexts.concat.tmp to produce
1420// file_contexts.bin.
Cole Faust30349e32024-10-22 16:31:06 -07001421java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001422 name: "file_contexts_bin_gen",
1423 srcs: [
1424 ":file_contexts.concat.tmp",
1425 ":precompiled_sepolicy",
1426 ],
1427 tools: [
1428 "checkfc",
1429 "sefcontext_compile",
1430 ],
1431 out: ["file_contexts.bin"],
1432 cmd: "$(location checkfc) " +
1433 "$(location :precompiled_sepolicy) " +
1434 "$(location :file_contexts.concat.tmp) && " +
1435 "$(location sefcontext_compile) " +
1436 "-o $(out) $(location :file_contexts.concat.tmp)",
1437}
1438
1439prebuilt_etc {
1440 name: "file_contexts.bin",
1441 src: ":file_contexts_bin_gen",
1442}