blob: b81820a9256991a4a03ca4477bd8efee9462d71b [file] [log] [blame]
Tri Voa5cfd3e2018-03-22 11:35:02 -07001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Bob Badour601ebb42021-02-03 23:07:40 -080015package {
16 default_applicable_licenses: ["system_sepolicy_license"],
17}
18
19// Added automatically by a large-scale-change that took the approach of
20// 'apply every license found to every target'. While this makes sure we respect
21// every license restriction, it may not be entirely correct.
22//
23// e.g. GPL in an MIT project might only apply to the contrib/ directory.
24//
25// Please consider splitting the single license below into multiple licenses,
26// taking care not to lose any license_kind information, and overriding the
27// default license using the 'licenses: [...]' property on targets as needed.
28//
29// For unused files, consider creating a 'filegroup' with "//visibility:private"
30// to attach the license to, and including a comment whether the files may be
31// used in the current project.
32// http://go/android-license-faq
33license {
34 name: "system_sepolicy_license",
35 visibility: [":__subpackages__"],
36 license_kinds: [
37 "SPDX-license-identifier-Apache-2.0",
38 "legacy_unencumbered",
39 ],
40 license_text: [
41 "NOTICE",
42 ],
43}
44
Inseob Kimff2018f2024-04-17 09:48:43 +090045cc_defaults {
46 name: "selinux_policy_version",
47 cflags: ["-DSEPOLICY_VERSION=30"],
48}
Jeff Vander Stoepecd288f2019-02-15 12:18:15 -080049
yangbill3e345372020-04-15 13:55:47 +080050// For vts_treble_sys_prop_test
51filegroup {
52 name: "private_property_contexts",
53 srcs: ["private/property_contexts"],
54 visibility: [
55 "//test/vts-testcase/security/system_property",
56 ],
57}
Inseob Kime35b49b2021-02-18 19:15:41 +090058
Inseob Kima49e7242021-03-22 10:26:13 +090059se_build_files {
60 name: "se_build_files",
Inseob Kime35b49b2021-02-18 19:15:41 +090061 srcs: [
Inseob Kima49e7242021-03-22 10:26:13 +090062 "security_classes",
63 "initial_sids",
64 "access_vectors",
65 "global_macros",
66 "neverallow_macros",
67 "mls_macros",
68 "mls_decl",
69 "mls",
70 "policy_capabilities",
71 "te_macros",
72 "attributes",
73 "ioctl_defines",
74 "ioctl_macros",
75 "*.te",
76 "roles_decl",
77 "roles",
78 "users",
79 "initial_sid_contexts",
80 "fs_use",
81 "genfs_contexts",
82 "port_contexts",
Inseob Kime35b49b2021-02-18 19:15:41 +090083 ],
84}
85
Inseob Kim7cb20812021-12-16 16:52:14 +090086se_build_files {
87 name: "sepolicy_technical_debt",
88 srcs: ["technical_debt.cil"],
89}
90
Cole Faustac1f8152024-06-17 12:39:02 -070091phony {
Inseob Kim151562f2024-04-12 10:53:34 +090092 // Currently used only for aosp_cf_system_x86_64
93 // TODO(b/329208946): migrate selinux_policy_system to Soong
94 name: "selinux_policy_system_soong",
95 required: [
96 "plat_bug_map",
97 "plat_file_contexts",
98 "plat_hwservice_contexts",
99 "plat_keystore2_key_contexts",
100 "plat_mac_permissions.xml",
101 "plat_mapping_file",
102 "plat_property_contexts",
103 "plat_seapp_contexts",
104 "plat_sepolicy.cil",
Inseob Kim9b323082024-11-06 17:10:09 +0900105 "plat_sepolicy_genfs_202504.cil",
Inseob Kim151562f2024-04-12 10:53:34 +0900106 "plat_service_contexts",
107 "secilc",
Cole Faustac1f8152024-06-17 12:39:02 -0700108 "plat_29.0.cil",
109 "29.0.compat.cil",
110 "plat_30.0.cil",
111 "30.0.compat.cil",
112 "plat_31.0.cil",
113 "31.0.compat.cil",
114 "plat_32.0.cil",
115 "32.0.compat.cil",
116 "plat_33.0.cil",
117 "33.0.compat.cil",
118 "plat_34.0.cil",
119 "34.0.compat.cil",
120 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
121 "202404": [],
122 default: [
123 "plat_202404.cil",
124 "202404.compat.cil",
125 ],
126 }) + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
Cole Faustc22dece2024-06-20 12:58:34 -0700127 true: ["plat_sepolicy_and_mapping.sha256"],
Cole Faustac1f8152024-06-17 12:39:02 -0700128 default: [],
129 }),
Inseob Kim151562f2024-04-12 10:53:34 +0900130}
131
Inseob Kimff2018f2024-04-17 09:48:43 +0900132reqd_mask_policy = [":se_build_files{.reqd_mask}"]
133plat_public_policy = [":se_build_files{.plat_public}"]
134plat_private_policy = [":se_build_files{.plat_private}"]
135system_ext_public_policy = [":se_build_files{.system_ext_public}"]
Inseob Kim0a707fa2021-12-09 23:35:11 +0900136system_ext_private_policy = [":se_build_files{.system_ext_private}"]
Inseob Kimff2018f2024-04-17 09:48:43 +0900137product_public_policy = [":se_build_files{.product_public}"]
138product_private_policy = [":se_build_files{.product_private}"]
Inseob Kim0a707fa2021-12-09 23:35:11 +0900139
Inseob Kima49e7242021-03-22 10:26:13 +0900140// reqd_policy_mask - a policy.conf file which contains only the bare minimum
141// policy necessary to use checkpolicy.
142//
143// This bare-minimum policy needs to be present in all policy.conf files, but
144// should not necessarily be exported as part of the public policy.
145//
146// The rules generated by reqd_policy_mask will allow the compilation of public
147// policy and subsequent removal of CIL policy that should not be exported.
148se_policy_conf {
149 name: "reqd_policy_mask.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900150 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900151 srcs: reqd_mask_policy,
Inseob Kime35b49b2021-02-18 19:15:41 +0900152 installable: false,
153}
154
Inseob Kima49e7242021-03-22 10:26:13 +0900155se_policy_cil {
156 name: "reqd_policy_mask.cil",
157 src: ":reqd_policy_mask.conf",
158 secilc_check: false,
159 installable: false,
Inseob Kime35b49b2021-02-18 19:15:41 +0900160}
161
Inseob Kima49e7242021-03-22 10:26:13 +0900162// pub_policy - policy that will be exported to be a part of non-platform
163// policy corresponding to this platform version.
164//
165// This is a limited subset of policy that would not compile in checkpolicy on
166// its own.
167//
168// To get around this limitation, add only the required files from private
169// policy, which will generate CIL policy that will then be filtered out by the
170// reqd_policy_mask.
171//
172// There are three pub_policy.cil files below:
173// - pub_policy.cil: exported 'product', 'system_ext' and 'system' policy.
174// - system_ext_pub_policy.cil: exported 'system_ext' and 'system' policy.
175// - plat_pub_policy.cil: exported 'system' policy.
176//
177// Those above files will in turn be used to generate the following versioned cil files:
178// - product_mapping_file: the versioned, exported 'product' policy in product partition.
179// - system_ext_mapping_file: the versioned, exported 'system_ext' policy in system_ext partition.
180// - plat_mapping_file: the versioned, exported 'system' policy in system partition.
181// - plat_pub_versioned.cil: the versioned, exported 'product', 'system_ext' and 'system' policy
182// in vendor partition.
183//
184se_policy_conf {
185 name: "pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900186 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900187 srcs: plat_public_policy +
188 system_ext_public_policy +
189 product_public_policy +
190 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900191 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900192 installable: false,
193}
194
195se_policy_cil {
196 name: "pub_policy.cil",
197 src: ":pub_policy.conf",
198 filter_out: [":reqd_policy_mask.cil"],
199 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900200 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900201 installable: false,
202}
203
204se_policy_conf {
205 name: "system_ext_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900206 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900207 srcs: plat_public_policy +
208 system_ext_public_policy +
209 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900210 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900211 installable: false,
212}
213
214se_policy_cil {
215 name: "system_ext_pub_policy.cil",
216 src: ":system_ext_pub_policy.conf",
217 filter_out: [":reqd_policy_mask.cil"],
218 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900219 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900220 installable: false,
221}
222
223se_policy_conf {
224 name: "plat_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900225 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900226 srcs: plat_public_policy +
227 reqd_mask_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900228 installable: false,
229}
230
231se_policy_cil {
232 name: "plat_pub_policy.cil",
233 src: ":plat_pub_policy.conf",
234 filter_out: [":reqd_policy_mask.cil"],
235 secilc_check: false,
236 installable: false,
237}
238
239// plat_policy.conf - A combination of the private and public platform policy
240// which will ship with the device.
241//
242// The platform will always reflect the most recent platform version and is not
243// currently being attributized.
244se_policy_conf {
245 name: "plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900246 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900247 srcs: plat_public_policy +
248 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900249 installable: false,
250}
251
252se_policy_cil {
253 name: "plat_sepolicy.cil",
254 src: ":plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900255 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kim4b9929e2024-03-28 17:52:32 +0900256 dist: {
257 targets: ["sepolicy_finalize"],
258 },
Inseob Kima49e7242021-03-22 10:26:13 +0900259}
260
Inseob Kim6cc75f42021-04-29 13:53:20 +0000261// userdebug_plat_policy.conf - the userdebug version plat_sepolicy.cil
262se_policy_conf {
263 name: "userdebug_plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900264 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900265 srcs: plat_public_policy +
266 plat_private_policy,
Inseob Kim6cc75f42021-04-29 13:53:20 +0000267 build_variant: "userdebug",
268 installable: false,
269}
270
271se_policy_cil {
272 name: "userdebug_plat_sepolicy.cil",
273 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900274 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kim6cc75f42021-04-29 13:53:20 +0000275 debug_ramdisk: true,
Yi-Yo Chiang68478b12021-10-16 03:23:05 +0800276 dist: {
277 targets: ["droidcore"],
278 },
Inseob Kim6cc75f42021-04-29 13:53:20 +0000279}
280
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000281// A copy of the userdebug_plat_policy in GSI.
282soong_config_module_type {
283 name: "gsi_se_policy_cil",
284 module_type: "se_policy_cil",
285 config_namespace: "ANDROID",
286 bool_variables: [
287 "PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT",
288 ],
289 properties: [
290 "enabled",
291 "installable",
292 ],
293}
294
295gsi_se_policy_cil {
296 name: "system_ext_userdebug_plat_sepolicy.cil",
297 stem: "userdebug_plat_sepolicy.cil",
298 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900299 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000300 system_ext_specific: true,
301 enabled: false,
302 installable: false,
303 soong_config_variables: {
304 PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT: {
305 enabled: true,
306 installable: true,
307 },
308 },
309}
310
Inseob Kima49e7242021-03-22 10:26:13 +0900311// system_ext_policy.conf - A combination of the private and public system_ext
312// policy which will ship with the device. System_ext policy is not attributized
313se_policy_conf {
314 name: "system_ext_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900315 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900316 srcs: plat_public_policy +
317 plat_private_policy +
318 system_ext_public_policy +
319 system_ext_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900320 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900321 installable: false,
322}
323
324se_policy_cil {
325 name: "system_ext_sepolicy.cil",
326 src: ":system_ext_sepolicy.conf",
327 system_ext_specific: true,
328 filter_out: [":plat_sepolicy.cil"],
329 remove_line_marker: true,
330}
331
332// product_policy.conf - A combination of the private and public product policy
333// which will ship with the device. Product policy is not attributized
334se_policy_conf {
335 name: "product_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900336 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900337 srcs: plat_public_policy +
338 plat_private_policy +
339 system_ext_public_policy +
340 system_ext_private_policy +
341 product_public_policy +
342 product_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900343 product_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900344 installable: false,
345}
346
347se_policy_cil {
348 name: "product_sepolicy.cil",
349 src: ":product_sepolicy.conf",
350 product_specific: true,
Inseob Kimff2018f2024-04-17 09:48:43 +0900351 filter_out: [
352 ":plat_sepolicy.cil",
353 ":system_ext_sepolicy.cil",
354 ],
Inseob Kima49e7242021-03-22 10:26:13 +0900355 remove_line_marker: true,
356}
357
Inseob Kim039175b2021-03-25 15:37:34 +0900358// policy mapping files
359// auto-generate the mapping file for current platform policy, since it needs to
360// track platform policy development
361se_versioned_policy {
362 name: "plat_mapping_file",
363 base: ":plat_pub_policy.cil",
364 mapping: true,
365 version: "current",
366 relative_install_path: "mapping", // install to /system/etc/selinux/mapping
Inseob Kim4b9929e2024-03-28 17:52:32 +0900367 dist: {
368 targets: ["sepolicy_finalize"],
369 },
Inseob Kim039175b2021-03-25 15:37:34 +0900370}
371
372se_versioned_policy {
373 name: "system_ext_mapping_file",
374 base: ":system_ext_pub_policy.cil",
375 mapping: true,
376 version: "current",
377 filter_out: [":plat_mapping_file"],
378 relative_install_path: "mapping", // install to /system_ext/etc/selinux/mapping
379 system_ext_specific: true,
380}
381
382se_versioned_policy {
383 name: "product_mapping_file",
384 base: ":pub_policy.cil",
385 mapping: true,
386 version: "current",
Inseob Kimff2018f2024-04-17 09:48:43 +0900387 filter_out: [
388 ":plat_mapping_file",
389 ":system_ext_mapping_file",
390 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900391 relative_install_path: "mapping", // install to /product/etc/selinux/mapping
392 product_specific: true,
393}
394
Inseob Kim6c6aa012023-08-31 16:47:38 +0900395//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900396// vendor/odm sepolicy
Inseob Kim6c6aa012023-08-31 16:47:38 +0900397//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900398
Inseob Kim039175b2021-03-25 15:37:34 +0900399// plat_pub_versioned.cil - the exported platform policy associated with the version
400// that non-platform policy targets.
401se_versioned_policy {
402 name: "plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900403 base: ":pub_policy.cil",
404 target_policy: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900405 version: "vendor",
Inseob Kim039175b2021-03-25 15:37:34 +0900406 vendor: true,
407}
408
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900409// vendor_policy.cil - the vendor sepolicy. This needs attributization and to be combined
410// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
411// policy and the platform public policy files in order to use checkpolicy.
412se_policy_conf {
413 name: "vendor_sepolicy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900414 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900415 srcs: plat_public_policy +
416 system_ext_public_policy +
417 product_public_policy +
418 reqd_mask_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900419 ":se_build_files{.plat_vendor}",
420 ":se_build_files{.vendor}",
421 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900422 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900423 installable: false,
424}
425
426se_policy_cil {
427 name: "vendor_sepolicy.cil.raw",
428 src: ":vendor_sepolicy.conf",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900429 filter_out: [":reqd_policy_mask.cil"],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900430 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900431 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900432 installable: false,
433}
434
435se_versioned_policy {
436 name: "vendor_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900437 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900438 target_policy: ":vendor_sepolicy.cil.raw",
439 version: "vendor",
440 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900441 ":plat_sepolicy.cil",
442 ":system_ext_sepolicy.cil",
443 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900444 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900445 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900446 ],
447 filter_out: [":plat_pub_versioned.cil"],
448 vendor: true,
449}
450
451// odm_policy.cil - the odl sepolicy. This needs attributization and to be combined
452// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
453// policy and the platform public policy files in order to use checkpolicy.
454se_policy_conf {
455 name: "odm_sepolicy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900456 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900457 srcs: plat_public_policy +
458 system_ext_public_policy +
459 product_public_policy +
460 reqd_mask_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900461 ":se_build_files{.plat_vendor}",
462 ":se_build_files{.vendor}",
463 ":se_build_files{.odm}",
464 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900465 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900466 installable: false,
467}
468
469se_policy_cil {
470 name: "odm_sepolicy.cil.raw",
471 src: ":odm_sepolicy.conf",
472 filter_out: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900473 ":reqd_policy_mask.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900474 ":vendor_sepolicy.cil",
475 ],
476 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900477 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900478 installable: false,
479}
480
481se_versioned_policy {
482 name: "odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900483 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900484 target_policy: ":odm_sepolicy.cil.raw",
485 version: "vendor",
486 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900487 ":plat_sepolicy.cil",
488 ":system_ext_sepolicy.cil",
489 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900490 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900491 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900492 ":vendor_sepolicy.cil",
493 ],
Inseob Kimff2018f2024-04-17 09:48:43 +0900494 filter_out: [
495 ":plat_pub_versioned.cil",
496 ":vendor_sepolicy.cil",
497 ],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900498 device_specific: true,
499}
500
Inseob Kim039175b2021-03-25 15:37:34 +0900501//////////////////////////////////
502// Precompiled sepolicy is loaded if and only if:
503// - plat_sepolicy_and_mapping.sha256 equals
504// precompiled_sepolicy.plat_sepolicy_and_mapping.sha256
505// AND
506// - system_ext_sepolicy_and_mapping.sha256 equals
507// precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256
508// AND
509// - product_sepolicy_and_mapping.sha256 equals
510// precompiled_sepolicy.product_sepolicy_and_mapping.sha256
511// See system/core/init/selinux.cpp for details.
512//////////////////////////////////
Cole Faust30349e32024-10-22 16:31:06 -0700513java_genrule {
Inseob Kim039175b2021-03-25 15:37:34 +0900514 name: "plat_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900515 srcs: [
516 ":plat_sepolicy.cil",
517 ":plat_mapping_file",
518 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900519 out: ["plat_sepolicy_and_mapping.sha256"],
520 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
521}
522
523prebuilt_etc {
524 name: "plat_sepolicy_and_mapping.sha256",
525 filename: "plat_sepolicy_and_mapping.sha256",
526 src: ":plat_sepolicy_and_mapping.sha256_gen",
527 relative_install_path: "selinux",
528}
529
Cole Faust30349e32024-10-22 16:31:06 -0700530java_genrule {
Inseob Kim039175b2021-03-25 15:37:34 +0900531 name: "system_ext_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900532 srcs: [
533 ":system_ext_sepolicy.cil",
534 ":system_ext_mapping_file",
535 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900536 out: ["system_ext_sepolicy_and_mapping.sha256"],
537 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
538}
539
540prebuilt_etc {
541 name: "system_ext_sepolicy_and_mapping.sha256",
542 filename: "system_ext_sepolicy_and_mapping.sha256",
543 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
544 relative_install_path: "selinux",
545 system_ext_specific: true,
546}
547
Cole Faust30349e32024-10-22 16:31:06 -0700548java_genrule {
Inseob Kim039175b2021-03-25 15:37:34 +0900549 name: "product_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900550 srcs: [
551 ":product_sepolicy.cil",
552 ":product_mapping_file",
553 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900554 out: ["product_sepolicy_and_mapping.sha256"],
555 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
556}
557
558prebuilt_etc {
559 name: "product_sepolicy_and_mapping.sha256",
560 filename: "product_sepolicy_and_mapping.sha256",
561 src: ":product_sepolicy_and_mapping.sha256_gen",
562 relative_install_path: "selinux",
563 product_specific: true,
564}
565
Inseob Kim1c056b12021-04-30 00:11:43 +0900566sepolicy_vers {
567 name: "plat_sepolicy_vers.txt",
568 version: "vendor",
569 vendor: true,
570}
571
Inseob Kim9b323082024-11-06 17:10:09 +0900572genrule {
573 name: "genfs_labels_version.txt.gen",
574 out: ["genfs_labels_version.txt"],
575 cmd: select(soong_config_variable("ANDROID", "BOARD_GENFS_LABELS_VERSION"), {
576 any @ value: "echo " + value + " > $(out)",
577 default: "echo > $(out)",
578 }),
579}
580
581prebuilt_etc {
582 name: "genfs_labels_version.txt",
583 src: ":genfs_labels_version.txt.gen",
584 relative_install_path: "selinux",
585 vendor: true,
586}
587
Inseob Kim731182a2021-05-06 11:44:37 +0000588soong_config_module_type {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900589 name: "precompiled_sepolicy_prebuilts_defaults",
Inseob Kim731182a2021-05-06 11:44:37 +0000590 module_type: "prebuilt_defaults",
591 config_namespace: "ANDROID",
592 bool_variables: ["BOARD_USES_ODMIMAGE"],
Inseob Kimff2018f2024-04-17 09:48:43 +0900593 properties: [
594 "vendor",
595 "device_specific",
596 ],
Inseob Kim731182a2021-05-06 11:44:37 +0000597}
598
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900599precompiled_sepolicy_prebuilts_defaults {
600 name: "precompiled_sepolicy_prebuilts",
Inseob Kim731182a2021-05-06 11:44:37 +0000601 soong_config_variables: {
602 BOARD_USES_ODMIMAGE: {
603 device_specific: true,
604 conditions_default: {
605 vendor: true,
606 },
607 },
608 },
609}
610
611//////////////////////////////////
612// SHA-256 digest of the plat_sepolicy.cil and plat_mapping_file against
613// which precompiled_policy was built.
614//////////////////////////////////
615prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900616 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000617 name: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
618 filename: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
619 src: ":plat_sepolicy_and_mapping.sha256_gen",
620 relative_install_path: "selinux",
621}
622
623//////////////////////////////////
624// SHA-256 digest of the system_ext_sepolicy.cil and system_ext_mapping_file against
625// which precompiled_policy was built.
626//////////////////////////////////
627prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900628 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000629 name: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
630 filename: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
631 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
632 relative_install_path: "selinux",
633}
634
635//////////////////////////////////
636// SHA-256 digest of the product_sepolicy.cil and product_mapping_file against
637// which precompiled_policy was built.
638//////////////////////////////////
639prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900640 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000641 name: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
642 filename: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
643 src: ":product_sepolicy_and_mapping.sha256_gen",
644 relative_install_path: "selinux",
645}
646
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900647soong_config_module_type {
648 name: "precompiled_se_policy_binary",
649 module_type: "se_policy_binary",
650 config_namespace: "ANDROID",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900651 bool_variables: ["BOARD_USES_ODMIMAGE"],
Inseob Kimff2018f2024-04-17 09:48:43 +0900652 properties: [
653 "vendor",
654 "device_specific",
655 ],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900656}
657
Garfield Tand8c51f22023-10-02 14:17:04 -0700658filegroup {
659 name: "precompiled_sepolicy_srcs",
Cole Faust30349e32024-10-22 16:31:06 -0700660 device_common_srcs: [
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900661 ":plat_sepolicy.cil",
Sandro143988d2022-08-05 11:38:56 +0000662 ":plat_pub_versioned.cil",
663 ":system_ext_sepolicy.cil",
664 ":product_sepolicy.cil",
665 ":vendor_sepolicy.cil",
666 ":odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900667 ":plat_mapping_file",
668 ":system_ext_mapping_file",
669 ":product_mapping_file",
Sandro143988d2022-08-05 11:38:56 +0000670 ],
Inseob Kim9b323082024-11-06 17:10:09 +0900671 device_first_srcs: select(soong_config_variable("ANDROID", "BOARD_GENFS_LABELS_VERSION"), {
672 "202504": [":plat_sepolicy_genfs_202504.cil"],
673 default: [],
674 }),
Garfield Tand8c51f22023-10-02 14:17:04 -0700675 // Make precompiled_sepolicy_srcs as public so that OEMs have access to them.
676 // Useful when some partitions need to be bind mounted across VM boundaries.
677 visibility: ["//visibility:public"],
678}
679
680precompiled_se_policy_binary {
681 name: "precompiled_sepolicy",
682 srcs: [
683 ":precompiled_sepolicy_srcs",
684 ],
Sandro143988d2022-08-05 11:38:56 +0000685 soong_config_variables: {
686 BOARD_USES_ODMIMAGE: {
687 device_specific: true,
688 conditions_default: {
689 vendor: true,
690 },
691 },
Sandro143988d2022-08-05 11:38:56 +0000692 },
693 required: [
694 "sepolicy_neverallows",
Sandro143988d2022-08-05 11:38:56 +0000695 ],
696 dist: {
697 targets: ["base-sepolicy-files-for-mapping"],
698 },
699}
700
Inseob Kim5bbcd682021-12-28 14:57:03 +0900701// policy for recovery
702se_policy_conf {
703 name: "recovery_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900704 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900705 srcs: plat_public_policy +
706 plat_private_policy +
707 system_ext_public_policy +
708 system_ext_private_policy +
709 product_public_policy +
710 product_private_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900711 ":se_build_files{.plat_vendor}",
712 ":se_build_files{.vendor}",
713 ":se_build_files{.odm}",
714 ],
Inseob Kim5bbcd682021-12-28 14:57:03 +0900715 target_recovery: true,
716 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900717 recovery: true,
Inseob Kim5bbcd682021-12-28 14:57:03 +0900718}
719
720se_policy_cil {
721 name: "recovery_sepolicy.cil",
722 src: ":recovery_sepolicy.conf",
723 secilc_check: false, // will be done in se_policy_binary module
724 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900725 recovery: true,
Inseob Kim5bbcd682021-12-28 14:57:03 +0900726}
727
728se_policy_binary {
729 name: "sepolicy.recovery",
730 srcs: [":recovery_sepolicy.cil"],
731 stem: "sepolicy",
732 recovery: true,
733}
734
Inseob Kima49e7242021-03-22 10:26:13 +0900735//////////////////////////////////
736// SELinux policy embedded into CTS.
737// CTS checks neverallow rules of this policy against the policy of the device under test.
738//////////////////////////////////
739se_policy_conf {
740 name: "general_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900741 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900742 srcs: plat_public_policy +
743 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900744 build_variant: "user",
745 cts: true,
746 exclude_build_test: true,
Inseob Kim4b9929e2024-03-28 17:52:32 +0900747 dist: {
748 targets: ["sepolicy_finalize"],
749 },
Inseob Kima49e7242021-03-22 10:26:13 +0900750}
Inseob Kimd5816612021-09-15 03:01:05 +0000751
752//////////////////////////////////
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000753// Base system policy for treble sepolicy tests.
754// If system sepolicy is extended (e.g. by SoC vendors), their plat_pub_versioned.cil may differ
755// with system/sepolicy/prebuilts/api/{version}/plat_pub_versioned.cil. In that case,
756// BOARD_PLAT_PUB_VERSIONED_POLICY can be used to specify extended plat_pub_versioned.cil.
757// See treble_sepolicy_tests_for_release.mk for more details.
758//////////////////////////////////
759se_policy_conf {
760 name: "base_plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900761 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900762 srcs: plat_public_policy +
763 plat_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000764 build_variant: "user",
765 installable: false,
766}
767
768se_policy_cil {
769 name: "base_plat_sepolicy.cil",
770 src: ":base_plat_sepolicy.conf",
771 additional_cil_files: ["private/technical_debt.cil"],
772 installable: false,
773 secilc_check: false, // done by se_policy_binary
774}
775
776se_policy_binary {
777 name: "base_plat_sepolicy",
778 srcs: [":base_plat_sepolicy.cil"],
779 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900780 dist: {
781 targets: ["base-sepolicy-files-for-mapping"],
782 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000783}
784
785se_policy_conf {
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000786 name: "base_product_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900787 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900788 srcs: plat_public_policy +
789 plat_private_policy +
790 system_ext_public_policy +
791 system_ext_private_policy +
792 product_public_policy +
793 product_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000794 build_variant: "user",
795 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900796 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000797}
798
799se_policy_cil {
800 name: "base_product_sepolicy.cil",
801 src: ":base_product_sepolicy.conf",
802 additional_cil_files: ["private/technical_debt.cil"],
803 product_specific: true,
804 installable: false,
805 secilc_check: false, // done by se_policy_binary
806}
807
808se_policy_binary {
809 name: "base_product_sepolicy",
810 srcs: [":base_product_sepolicy.cil"],
811 product_specific: true,
812 installable: false,
813}
814
815se_policy_conf {
816 name: "base_plat_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900817 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900818 srcs: plat_public_policy +
819 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000820 build_variant: "user",
821 installable: false,
822}
823
824se_policy_cil {
825 name: "base_plat_pub_policy.cil",
826 src: ":base_plat_pub_policy.conf",
827 filter_out: [":reqd_policy_mask.cil"],
828 secilc_check: false,
829 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900830 dist: {
831 targets: ["base-sepolicy-files-for-mapping"],
832 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000833}
834
835se_policy_conf {
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000836 name: "base_product_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900837 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900838 srcs: plat_public_policy +
839 system_ext_public_policy +
840 product_public_policy +
841 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000842 build_variant: "user",
843 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900844 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000845}
846
847se_policy_cil {
848 name: "base_product_pub_policy.cil",
849 src: ":base_product_pub_policy.conf",
850 filter_out: [":reqd_policy_mask.cil"],
851 secilc_check: false,
852 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900853 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000854}
855
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800856// bug_map - Bug tracking information for selinux denials loaded by auditd.
Inseob Kim41964032022-04-22 07:50:22 +0900857se_build_files {
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800858 name: "bug_map_files",
859 srcs: ["bug_map"],
860}
861
862se_bug_map {
863 name: "plat_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900864 srcs: [":bug_map_files{.plat_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800865 stem: "bug_map",
866}
867
868se_bug_map {
869 name: "system_ext_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900870 srcs: [":bug_map_files{.system_ext_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800871 stem: "bug_map",
872 system_ext_specific: true,
873}
874
875se_bug_map {
876 name: "vendor_bug_map",
Inseob Kimff2018f2024-04-17 09:48:43 +0900877 srcs: [
878 ":bug_map_files{.vendor}",
879 ":bug_map_files{.plat_vendor}",
880 ],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800881 // Legacy file name of the vendor partition bug_map.
882 stem: "selinux_denial_metadata",
883 vendor: true,
884}
885
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900886se_neverallow_test {
887 name: "sepolicy_neverallows",
Inseob Kim085f22f2023-11-09 11:13:01 +0900888 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900889 srcs: plat_public_policy +
890 plat_private_policy +
891 system_ext_public_policy +
892 system_ext_private_policy +
893 product_public_policy +
Inseob Kim6c6aa012023-08-31 16:47:38 +0900894 product_private_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900895 ":se_build_files{.plat_vendor}",
896 ":se_build_files{.vendor}",
897 ":se_build_files{.odm}",
898 ],
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900899}
900
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000901//////////////////////////////////
Inseob Kimd5816612021-09-15 03:01:05 +0000902// se_freeze_test compares the plat sepolicy with the prebuilt sepolicy
903// Additional directories can be specified via Makefile variables:
904// SEPOLICY_FREEZE_TEST_EXTRA_DIRS and SEPOLICY_FREEZE_TEST_EXTRA_PREBUILT_DIRS.
905//////////////////////////////////
906se_freeze_test {
Inseob Kim36d9d392023-09-04 17:40:03 +0900907 name: "se_freeze_test",
Inseob Kimd5816612021-09-15 03:01:05 +0000908}
Inseob Kim61257ca2022-02-25 11:26:16 +0900909
910//////////////////////////////////
911// sepolicy_test checks various types of violations, which can't be easily done
912// by CIL itself. Refer tests/sepolicy_tests.py for more detail.
913//////////////////////////////////
Cole Faust30349e32024-10-22 16:31:06 -0700914java_genrule {
Inseob Kim61257ca2022-02-25 11:26:16 +0900915 name: "sepolicy_test",
916 srcs: [
917 ":plat_file_contexts",
918 ":vendor_file_contexts",
919 ":system_ext_file_contexts",
920 ":product_file_contexts",
921 ":odm_file_contexts",
922 ":precompiled_sepolicy",
923 ],
924 tools: ["sepolicy_tests"],
925 out: ["sepolicy_test"],
926 cmd: "$(location sepolicy_tests) " +
927 "-f $(location :plat_file_contexts) " +
928 "-f $(location :vendor_file_contexts) " +
929 "-f $(location :system_ext_file_contexts) " +
930 "-f $(location :product_file_contexts) " +
931 "-f $(location :odm_file_contexts) " +
932 "-p $(location :precompiled_sepolicy) && " +
933 "touch $(out)",
934}
Inseob Kim3a9d91c2023-09-27 17:39:07 +0900935
936//////////////////////////////////
937// TestDevTypeViolations can't run on old devices (V or before)
938//////////////////////////////////
939
940soong_config_module_type {
941 name: "dev_type_test_genrule",
Cole Faust30349e32024-10-22 16:31:06 -0700942 module_type: "java_genrule",
Inseob Kim3a9d91c2023-09-27 17:39:07 +0900943 config_namespace: "ANDROID",
944 bool_variables: ["CHECK_DEV_TYPE_VIOLATIONS"],
945 properties: ["cmd"],
946}
947
948dev_type_test_genrule {
949 name: "sepolicy_dev_type_test",
950 srcs: [
951 ":plat_file_contexts",
952 ":vendor_file_contexts",
953 ":system_ext_file_contexts",
954 ":product_file_contexts",
955 ":odm_file_contexts",
956 ":precompiled_sepolicy",
957 ],
958 tools: ["sepolicy_tests"],
959 out: ["sepolicy_dev_type_test"],
960 soong_config_variables: {
961 CHECK_DEV_TYPE_VIOLATIONS: {
962 cmd: "$(location sepolicy_tests) " +
963 "-f $(location :plat_file_contexts) " +
964 "-f $(location :vendor_file_contexts) " +
965 "-f $(location :system_ext_file_contexts) " +
966 "-f $(location :product_file_contexts) " +
967 "-f $(location :odm_file_contexts) " +
968 "-p $(location :precompiled_sepolicy) " +
969 "-t TestDevTypeViolations && " +
970 "touch $(out)",
971 conditions_default: {
972 cmd: "touch $(out)",
973 },
974 },
975 },
976}
kellyhung08f7c992024-09-18 03:34:53 +0000977
978phony {
979 name: "selinux_policy_system_ext",
980 required: [
981 //"ifdef HAS_SYSTEM_EXT_PUBLIC_SEPOLICY" check included in system_ext_pub_policy.cil
982 "system_ext_mapping_file",
983 //"ifdef HAS_SYSTEM_EXT_SEPOLICY" check included in .cil
984 "system_ext_sepolicy.cil",
985 ] + [
986 //"ifdef HAS_SYSTEM_EXT_SEPOLICY" check included in .cil
987 "system_ext_29.0.cil",
988 "system_ext_30.0.cil",
989 "system_ext_31.0.cil",
990 "system_ext_32.0.cil",
991 "system_ext_33.0.cil",
992 "system_ext_34.0.cil",
993 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
994 "202404": [],
995 default: [
996 "system_ext_202404.cil",
997 ],
998 }) +
999 select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1000 true: ["system_ext_sepolicy_and_mapping.sha256"],
1001 default: [],
1002 }) + [
1003 "system_ext_file_contexts",
1004 "system_ext_file_contexts_test",
1005 "system_ext_keystore2_key_contexts",
1006 "system_ext_hwservice_contexts",
1007 "system_ext_hwservice_contexts_test",
1008 "system_ext_property_contexts",
1009 "system_ext_property_contexts_test",
1010 "system_ext_seapp_contexts",
1011 "system_ext_service_contexts",
1012 "system_ext_service_contexts_test",
1013 "system_ext_mac_permissions.xml",
1014 "system_ext_bug_map",
1015 // $(addprefix system_ext_,$(addsuffix .compat.cil,$(PLATFORM_SEPOLICY_COMPAT_VERSIONS))) \
1016 "system_ext_29.0.compat.cil",
1017 "system_ext_30.0.compat.cil",
1018 "system_ext_31.0.compat.cil",
1019 "system_ext_32.0.compat.cil",
1020 "system_ext_33.0.compat.cil",
1021 "system_ext_34.0.compat.cil",
1022 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1023 "202404": [],
1024 default: [
1025 "system_ext_202404.compat.cil",
1026 ],
1027 }),
Spandan Das80252082024-10-17 21:58:34 +00001028 system_ext_specific: true,
kellyhung08f7c992024-09-18 03:34:53 +00001029}
kellyhung14081902024-09-18 04:59:54 +00001030
1031phony {
1032 name: "selinux_policy_product",
1033 required: [
1034 "product_mapping_file",
1035 "product_sepolicy.cil",
1036 // "ifdef HAS_PRODUCT_PUBLIC_SEPOLICY" check included in .cil
1037 "product_29.0.cil",
1038 "product_30.0.cil",
1039 "product_31.0.cil",
1040 "product_32.0.cil",
1041 "product_33.0.cil",
1042 "product_34.0.cil",
1043 "product_file_contexts",
1044 // "ifdef HAS_PRODUCT_SEPOLICY_DIR" in Android.mk can be ignored.
1045 "product_file_contexts_test",
1046 "product_keystore2_key_contexts",
1047 "product_hwservice_contexts",
1048 "product_hwservice_contexts_test",
1049 "product_property_contexts",
1050 "product_property_contexts_test",
1051 "product_seapp_contexts",
1052 "product_service_contexts",
1053 "product_service_contexts_test",
1054 "product_mac_permissions.xml",
1055 ] + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1056 true: ["product_sepolicy_and_mapping.sha256"],
1057 default: [],
1058 }) + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1059 "202404": [],
1060 default: [
1061 "product_202404.cil",
1062 ],
1063 }),
Spandan Das155cc2f2024-10-18 22:27:25 +00001064 product_specific: true,
kellyhung14081902024-09-18 04:59:54 +00001065}
kellyhunga07b3712024-09-25 03:31:09 +00001066
1067phony {
1068 name: "selinux_policy_nonsystem",
1069 required: [
Spandan Das62656052024-11-01 18:37:13 +00001070 "selinux_policy_system_ext",
1071 "selinux_policy_product",
1072 "selinux_policy_vendor",
1073 "selinux_policy_odm",
1074 // Builds an additional userdebug sepolicy into the debug ramdisk.
1075 "userdebug_plat_sepolicy.cil",
1076 ],
1077}
1078
1079phony {
1080 name: "selinux_policy_vendor",
1081 required: [
Inseob Kim9b323082024-11-06 17:10:09 +09001082 "genfs_labels_version.txt",
kellyhunga07b3712024-09-25 03:31:09 +00001083 "plat_pub_versioned.cil",
1084 "vendor_sepolicy.cil",
1085 "plat_sepolicy_vers.txt",
1086 "vendor_file_contexts",
1087 "vendor_file_contexts_test",
1088 "vendor_keystore2_key_contexts",
1089 "vendor_mac_permissions.xml",
1090 "vendor_property_contexts",
1091 "vendor_property_contexts_test",
1092 "vendor_seapp_contexts",
1093 "vendor_service_contexts",
1094 "vendor_service_contexts_test",
1095 "vendor_hwservice_contexts",
1096 "vendor_hwservice_contexts_test",
1097 "vendor_bug_map",
1098 "vndservice_contexts",
1099 "vndservice_contexts_test",
Spandan Das62656052024-11-01 18:37:13 +00001100 ],
1101 vendor: true,
1102}
1103
1104phony {
1105 name: "selinux_policy_odm",
1106 required: [
kellyhunga07b3712024-09-25 03:31:09 +00001107 "odm_sepolicy.cil",
1108 "odm_file_contexts",
1109 "odm_file_contexts_test",
1110 "odm_seapp_contexts",
1111 "odm_property_contexts",
1112 "odm_property_contexts_test",
1113 "odm_service_contexts",
1114 "odm_service_contexts_test",
1115 "odm_hwservice_contexts",
1116 "odm_hwservice_contexts_test",
1117 "odm_mac_permissions.xml",
kellyhunga07b3712024-09-25 03:31:09 +00001118 ] + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1119 true: [
1120 "precompiled_sepolicy",
1121 "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
1122 "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
1123 "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
1124 ],
1125 default: [],
1126 }),
Spandan Das62656052024-11-01 18:37:13 +00001127 device_specific: true,
kellyhunga07b3712024-09-25 03:31:09 +00001128}
kellyhung0c9edb32024-07-15 11:06:26 +00001129
1130phony {
1131 name: "selinux_policy_system",
1132 required: [
1133 "29.0.compat.cil",
1134 "30.0.compat.cil",
1135 "31.0.compat.cil",
1136 "32.0.compat.cil",
1137 "33.0.compat.cil",
1138 "34.0.compat.cil",
1139 "build_sepolicy",
1140 "fuzzer_bindings_test",
1141 "plat_29.0.cil",
1142 "plat_30.0.cil",
1143 "plat_31.0.cil",
1144 "plat_32.0.cil",
1145 "plat_33.0.cil",
1146 "plat_34.0.cil",
1147 "plat_bug_map",
1148 "plat_file_contexts",
1149 "plat_file_contexts_data_test",
1150 "plat_file_contexts_test",
1151 "plat_hwservice_contexts",
1152 "plat_hwservice_contexts_test",
1153 "plat_keystore2_key_contexts",
1154 "plat_mac_permissions.xml",
1155 "plat_mapping_file",
1156 "plat_property_contexts",
1157 "plat_property_contexts_test",
1158 "plat_seapp_contexts",
1159 "plat_sepolicy.cil",
Inseob Kim9b323082024-11-06 17:10:09 +09001160 "plat_sepolicy_genfs_202504.cil",
kellyhung0c9edb32024-07-15 11:06:26 +00001161 "plat_service_contexts",
1162 "plat_service_contexts_test",
1163 "searchpolicy",
1164 "secilc",
1165 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1166 "202404": [],
1167 default: [
1168 "202404.compat.cil",
1169 "plat_202404.cil",
1170 ],
1171 }) + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1172 true: ["plat_sepolicy_and_mapping.sha256"],
1173 default: [],
1174 }) + select((
1175 soong_config_variable("ANDROID", "ASAN_ENABLED"),
1176 product_variable("selinux_ignore_neverallows"),
1177 ), {
1178 (true, true): [
1179 ],
1180 (default, default): [
1181 "sepolicy_compat_test",
1182 "sepolicy_test",
1183 "sepolicy_dev_type_test",
1184 "treble_sepolicy_tests_29.0",
1185 "treble_sepolicy_tests_30.0",
1186 "treble_sepolicy_tests_31.0",
1187 "treble_sepolicy_tests_32.0",
1188 "treble_sepolicy_tests_33.0",
1189 "treble_sepolicy_tests_34.0",
1190 ],
1191 }) + select((
1192 soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"),
1193 soong_config_variable("ANDROID", "ASAN_ENABLED"),
1194 product_variable("selinux_ignore_neverallows"),
1195 ), {
1196 ("202404", true, true): [],
1197 (default, true, true): [],
1198 (default, default, default): [
1199 "treble_sepolicy_tests_202404",
1200 ],
1201 }) + select(soong_config_variable("ANDROID", "RELEASE_BOARD_API_LEVEL_FROZEN"), {
1202 true: ["se_freeze_test"],
1203 default: [],
1204 }),
1205}
kellyhungee97d9c2024-10-03 00:54:38 +00001206
1207phony {
1208 name: "selinux_policy",
1209 required: [
1210 // Runs checkfc against merged service_contexts files
1211 "merged_hwservice_contexts_test",
1212 "merged_service_contexts_test",
1213 "selinux_policy_nonsystem",
1214 "selinux_policy_system",
1215 ],
1216}
1217
1218// selinux_policy is a main goal and triggers lots of tests.
1219// Most tests are FAKE modules, so aren'triggered on normal builds. (e.g. 'm')
1220// By setting as droidcore's dependency, tests will run on normal builds.
1221phony_rule {
1222 name: "droidcore",
1223 phony_deps: ["selinux_policy"],
1224}
kellyhung8659c152024-10-07 21:37:14 +00001225
1226//-----------------------------------------------------------------------------
1227// TODO - remove this. Keep around until we get the filesystem creation stuff
1228// taken care of.
1229//
1230// The file_contexts.bin is built in the following way:
1231// 1. Collect all file_contexts files in THIS repository and process them with
1232// m4 into a tmp file called file_contexts.local.tmp.
1233// 2. Collect all device specific file_contexts files and process them with m4
1234// into a tmp file called file_contexts.device.tmp.
1235// 3. Run checkfc -e (allow no device fc entries ie empty) and fc_sort on
1236// file_contexts.device.tmp and output to file_contexts.device.sorted.tmp.
1237// 4. Concatenate file_contexts.local.tmp and file_contexts.device.sorted.tmp
1238// into file_contexts.concat.tmp.
1239// 5. Run checkfc and sefcontext_compile on file_contexts.concat.tmp to produce
1240// file_contexts.bin.
1241//
1242// Note: That a newline file is placed between each file_context file found to
1243// ensure a proper build when an fc file is missing an ending newline.
1244//---
1245// 1. Collect all file_contexts files in THIS repository and process them with
1246// m4 into a tmp file called file_contexts.local.tmp.
Cole Faust30349e32024-10-22 16:31:06 -07001247java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001248 name: "file_contexts.local.tmp",
1249 srcs: [
1250 ":plat_file_contexts",
1251 ":system_ext_file_contexts",
1252 ":product_file_contexts",
1253 ],
1254 tools: [
1255 "m4",
1256 ],
1257 out: ["file_contexts.local.tmp"],
1258 cmd: "$(location m4) --fatal-warnings " +
1259 "-s $(in) > $(out)",
1260}
1261
1262// 2. Collect all device specific file_contexts files and process them with m4
1263// into a tmp file called file_contexts.device.tmp.
1264PRIVATE_ADDITIONAL_M4DEFS = select(soong_config_variable("ANDROID", "ADDITIONAL_M4DEFS"), {
1265 any @ m4defs: m4defs,
1266 default: "",
1267})
Cole Faust30349e32024-10-22 16:31:06 -07001268java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001269 name: "file_contexts.device.tmp",
1270 srcs: [
1271 ":vendor_file_contexts",
1272 ":odm_file_contexts",
1273 ],
1274 tools: [
1275 "m4",
1276 ],
1277 out: ["file_contexts.device.tmp"],
1278 cmd: "$(location m4) --fatal-warnings " +
1279 "-s " + PRIVATE_ADDITIONAL_M4DEFS +
1280 " $(in) > $(out)",
1281}
1282
1283// 3. Run checkfc -e (allow no device fc entries ie empty) and fc_sort on
1284// file_contexts.device.tmp and output to file_contexts.device.sorted.tmp.
Cole Faust30349e32024-10-22 16:31:06 -07001285java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001286 name: "file_contexts.device.sorted.tmp",
1287 srcs: [
1288 ":file_contexts.device.tmp",
1289 ":precompiled_sepolicy",
1290 ],
1291 tools: [
1292 "checkfc",
1293 "fc_sort",
1294 ],
1295 out: ["file_contexts.device.sorted.tmp"],
1296 cmd: "$(location checkfc) " +
1297 "-e $(location :precompiled_sepolicy) " +
1298 "$(location :file_contexts.device.tmp) && " +
1299 "$(location fc_sort) " +
1300 "-i $(location :file_contexts.device.tmp) " +
1301 "-o $(out)",
1302}
1303
1304// 4. Concatenate file_contexts.local.tmp and file_contexts.device.sorted.tmp
1305// into file_contexts.concat.tmp.
Cole Faust30349e32024-10-22 16:31:06 -07001306java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001307 name: "file_contexts.concat.tmp",
1308 srcs: [
1309 ":file_contexts.local.tmp",
1310 ":file_contexts.device.sorted.tmp",
1311 ],
1312 tools: [
1313 "m4",
1314 ],
1315 out: ["file_contexts.concat.tmp"],
1316 cmd: "$(location m4) --fatal-warnings " +
1317 "-s $(location :file_contexts.local.tmp) " +
1318 "$(location :file_contexts.device.sorted.tmp) > $(out)",
1319}
1320
1321// 5. Run checkfc and sefcontext_compile on file_contexts.concat.tmp to produce
1322// file_contexts.bin.
Cole Faust30349e32024-10-22 16:31:06 -07001323java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001324 name: "file_contexts_bin_gen",
1325 srcs: [
1326 ":file_contexts.concat.tmp",
1327 ":precompiled_sepolicy",
1328 ],
1329 tools: [
1330 "checkfc",
1331 "sefcontext_compile",
1332 ],
1333 out: ["file_contexts.bin"],
1334 cmd: "$(location checkfc) " +
1335 "$(location :precompiled_sepolicy) " +
1336 "$(location :file_contexts.concat.tmp) && " +
1337 "$(location sefcontext_compile) " +
1338 "-o $(out) $(location :file_contexts.concat.tmp)",
1339}
1340
1341prebuilt_etc {
1342 name: "file_contexts.bin",
1343 src: ":file_contexts_bin_gen",
1344}