blob: 24b6fbc3ec93f30172e97ce95ffa4e760a2e2036 [file] [log] [blame]
Tri Voa5cfd3e2018-03-22 11:35:02 -07001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Bob Badour601ebb42021-02-03 23:07:40 -080015package {
16 default_applicable_licenses: ["system_sepolicy_license"],
17}
18
19// Added automatically by a large-scale-change that took the approach of
20// 'apply every license found to every target'. While this makes sure we respect
21// every license restriction, it may not be entirely correct.
22//
23// e.g. GPL in an MIT project might only apply to the contrib/ directory.
24//
25// Please consider splitting the single license below into multiple licenses,
26// taking care not to lose any license_kind information, and overriding the
27// default license using the 'licenses: [...]' property on targets as needed.
28//
29// For unused files, consider creating a 'filegroup' with "//visibility:private"
30// to attach the license to, and including a comment whether the files may be
31// used in the current project.
32// http://go/android-license-faq
33license {
34 name: "system_sepolicy_license",
35 visibility: [":__subpackages__"],
36 license_kinds: [
37 "SPDX-license-identifier-Apache-2.0",
38 "legacy_unencumbered",
39 ],
40 license_text: [
41 "NOTICE",
42 ],
43}
44
Inseob Kimff2018f2024-04-17 09:48:43 +090045cc_defaults {
46 name: "selinux_policy_version",
47 cflags: ["-DSEPOLICY_VERSION=30"],
48}
Jeff Vander Stoepecd288f2019-02-15 12:18:15 -080049
yangbill3e345372020-04-15 13:55:47 +080050// For vts_treble_sys_prop_test
51filegroup {
52 name: "private_property_contexts",
53 srcs: ["private/property_contexts"],
54 visibility: [
55 "//test/vts-testcase/security/system_property",
56 ],
57}
Inseob Kime35b49b2021-02-18 19:15:41 +090058
Inseob Kima49e7242021-03-22 10:26:13 +090059se_build_files {
60 name: "se_build_files",
Inseob Kime35b49b2021-02-18 19:15:41 +090061 srcs: [
Inseob Kima49e7242021-03-22 10:26:13 +090062 "security_classes",
63 "initial_sids",
64 "access_vectors",
65 "global_macros",
66 "neverallow_macros",
67 "mls_macros",
68 "mls_decl",
69 "mls",
70 "policy_capabilities",
71 "te_macros",
72 "attributes",
73 "ioctl_defines",
74 "ioctl_macros",
75 "*.te",
76 "roles_decl",
77 "roles",
78 "users",
79 "initial_sid_contexts",
80 "fs_use",
81 "genfs_contexts",
82 "port_contexts",
Inseob Kime35b49b2021-02-18 19:15:41 +090083 ],
84}
85
Inseob Kim7cb20812021-12-16 16:52:14 +090086se_build_files {
87 name: "sepolicy_technical_debt",
88 srcs: ["technical_debt.cil"],
89}
90
Cole Faustac1f8152024-06-17 12:39:02 -070091phony {
Inseob Kim151562f2024-04-12 10:53:34 +090092 // Currently used only for aosp_cf_system_x86_64
93 // TODO(b/329208946): migrate selinux_policy_system to Soong
94 name: "selinux_policy_system_soong",
95 required: [
96 "plat_bug_map",
97 "plat_file_contexts",
98 "plat_hwservice_contexts",
99 "plat_keystore2_key_contexts",
100 "plat_mac_permissions.xml",
101 "plat_mapping_file",
102 "plat_property_contexts",
103 "plat_seapp_contexts",
104 "plat_sepolicy.cil",
Inseob Kim9b323082024-11-06 17:10:09 +0900105 "plat_sepolicy_genfs_202504.cil",
Inseob Kim151562f2024-04-12 10:53:34 +0900106 "plat_service_contexts",
107 "secilc",
Cole Faustac1f8152024-06-17 12:39:02 -0700108 "plat_29.0.cil",
109 "29.0.compat.cil",
110 "plat_30.0.cil",
111 "30.0.compat.cil",
112 "plat_31.0.cil",
113 "31.0.compat.cil",
114 "plat_32.0.cil",
115 "32.0.compat.cil",
116 "plat_33.0.cil",
117 "33.0.compat.cil",
118 "plat_34.0.cil",
119 "34.0.compat.cil",
120 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
121 "202404": [],
122 default: [
123 "plat_202404.cil",
124 "202404.compat.cil",
125 ],
126 }) + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
Cole Faustc22dece2024-06-20 12:58:34 -0700127 true: ["plat_sepolicy_and_mapping.sha256"],
Cole Faustac1f8152024-06-17 12:39:02 -0700128 default: [],
Nikita Ioffe48966b62024-10-22 14:01:17 +0000129 }) + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
130 true: ["plat_tee_service_contexts"],
131 default: [],
Cole Faustac1f8152024-06-17 12:39:02 -0700132 }),
Inseob Kim151562f2024-04-12 10:53:34 +0900133}
134
Inseob Kimff2018f2024-04-17 09:48:43 +0900135reqd_mask_policy = [":se_build_files{.reqd_mask}"]
136plat_public_policy = [":se_build_files{.plat_public}"]
137plat_private_policy = [":se_build_files{.plat_private}"]
138system_ext_public_policy = [":se_build_files{.system_ext_public}"]
Inseob Kim0a707fa2021-12-09 23:35:11 +0900139system_ext_private_policy = [":se_build_files{.system_ext_private}"]
Inseob Kimff2018f2024-04-17 09:48:43 +0900140product_public_policy = [":se_build_files{.product_public}"]
141product_private_policy = [":se_build_files{.product_private}"]
Inseob Kim0a707fa2021-12-09 23:35:11 +0900142
Inseob Kima49e7242021-03-22 10:26:13 +0900143// reqd_policy_mask - a policy.conf file which contains only the bare minimum
144// policy necessary to use checkpolicy.
145//
146// This bare-minimum policy needs to be present in all policy.conf files, but
147// should not necessarily be exported as part of the public policy.
148//
149// The rules generated by reqd_policy_mask will allow the compilation of public
150// policy and subsequent removal of CIL policy that should not be exported.
151se_policy_conf {
152 name: "reqd_policy_mask.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900153 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900154 srcs: reqd_mask_policy,
Inseob Kime35b49b2021-02-18 19:15:41 +0900155 installable: false,
156}
157
Inseob Kima49e7242021-03-22 10:26:13 +0900158se_policy_cil {
159 name: "reqd_policy_mask.cil",
160 src: ":reqd_policy_mask.conf",
161 secilc_check: false,
162 installable: false,
Inseob Kime35b49b2021-02-18 19:15:41 +0900163}
164
Inseob Kima49e7242021-03-22 10:26:13 +0900165// pub_policy - policy that will be exported to be a part of non-platform
166// policy corresponding to this platform version.
167//
168// This is a limited subset of policy that would not compile in checkpolicy on
169// its own.
170//
171// To get around this limitation, add only the required files from private
172// policy, which will generate CIL policy that will then be filtered out by the
173// reqd_policy_mask.
174//
175// There are three pub_policy.cil files below:
176// - pub_policy.cil: exported 'product', 'system_ext' and 'system' policy.
177// - system_ext_pub_policy.cil: exported 'system_ext' and 'system' policy.
178// - plat_pub_policy.cil: exported 'system' policy.
179//
180// Those above files will in turn be used to generate the following versioned cil files:
181// - product_mapping_file: the versioned, exported 'product' policy in product partition.
182// - system_ext_mapping_file: the versioned, exported 'system_ext' policy in system_ext partition.
183// - plat_mapping_file: the versioned, exported 'system' policy in system partition.
184// - plat_pub_versioned.cil: the versioned, exported 'product', 'system_ext' and 'system' policy
185// in vendor partition.
186//
187se_policy_conf {
188 name: "pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900189 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900190 srcs: plat_public_policy +
191 system_ext_public_policy +
192 product_public_policy +
193 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900194 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900195 installable: false,
196}
197
198se_policy_cil {
199 name: "pub_policy.cil",
200 src: ":pub_policy.conf",
201 filter_out: [":reqd_policy_mask.cil"],
202 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900203 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900204 installable: false,
205}
206
207se_policy_conf {
208 name: "system_ext_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900209 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900210 srcs: plat_public_policy +
211 system_ext_public_policy +
212 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900213 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900214 installable: false,
215}
216
217se_policy_cil {
218 name: "system_ext_pub_policy.cil",
219 src: ":system_ext_pub_policy.conf",
220 filter_out: [":reqd_policy_mask.cil"],
221 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900222 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900223 installable: false,
224}
225
226se_policy_conf {
227 name: "plat_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900228 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900229 srcs: plat_public_policy +
230 reqd_mask_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900231 installable: false,
232}
233
234se_policy_cil {
235 name: "plat_pub_policy.cil",
236 src: ":plat_pub_policy.conf",
237 filter_out: [":reqd_policy_mask.cil"],
238 secilc_check: false,
239 installable: false,
240}
241
242// plat_policy.conf - A combination of the private and public platform policy
243// which will ship with the device.
244//
245// The platform will always reflect the most recent platform version and is not
246// currently being attributized.
247se_policy_conf {
248 name: "plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900249 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900250 srcs: plat_public_policy +
251 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900252 installable: false,
253}
254
255se_policy_cil {
256 name: "plat_sepolicy.cil",
257 src: ":plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900258 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kim4b9929e2024-03-28 17:52:32 +0900259 dist: {
260 targets: ["sepolicy_finalize"],
261 },
Inseob Kima49e7242021-03-22 10:26:13 +0900262}
263
Inseob Kim6cc75f42021-04-29 13:53:20 +0000264// userdebug_plat_policy.conf - the userdebug version plat_sepolicy.cil
265se_policy_conf {
266 name: "userdebug_plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900267 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900268 srcs: plat_public_policy +
269 plat_private_policy,
Inseob Kim6cc75f42021-04-29 13:53:20 +0000270 build_variant: "userdebug",
271 installable: false,
272}
273
274se_policy_cil {
275 name: "userdebug_plat_sepolicy.cil",
276 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900277 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kim6cc75f42021-04-29 13:53:20 +0000278 debug_ramdisk: true,
Yi-Yo Chiang68478b12021-10-16 03:23:05 +0800279 dist: {
280 targets: ["droidcore"],
281 },
Inseob Kim6cc75f42021-04-29 13:53:20 +0000282}
283
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000284// A copy of the userdebug_plat_policy in GSI.
285soong_config_module_type {
286 name: "gsi_se_policy_cil",
287 module_type: "se_policy_cil",
288 config_namespace: "ANDROID",
289 bool_variables: [
290 "PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT",
291 ],
292 properties: [
293 "enabled",
294 "installable",
295 ],
296}
297
298gsi_se_policy_cil {
299 name: "system_ext_userdebug_plat_sepolicy.cil",
300 stem: "userdebug_plat_sepolicy.cil",
301 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900302 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000303 system_ext_specific: true,
304 enabled: false,
305 installable: false,
306 soong_config_variables: {
307 PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT: {
308 enabled: true,
309 installable: true,
310 },
311 },
312}
313
Inseob Kima49e7242021-03-22 10:26:13 +0900314// system_ext_policy.conf - A combination of the private and public system_ext
315// policy which will ship with the device. System_ext policy is not attributized
316se_policy_conf {
317 name: "system_ext_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900318 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900319 srcs: plat_public_policy +
320 plat_private_policy +
321 system_ext_public_policy +
322 system_ext_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900323 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900324 installable: false,
325}
326
327se_policy_cil {
328 name: "system_ext_sepolicy.cil",
329 src: ":system_ext_sepolicy.conf",
330 system_ext_specific: true,
331 filter_out: [":plat_sepolicy.cil"],
332 remove_line_marker: true,
333}
334
335// product_policy.conf - A combination of the private and public product policy
336// which will ship with the device. Product policy is not attributized
337se_policy_conf {
338 name: "product_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900339 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900340 srcs: plat_public_policy +
341 plat_private_policy +
342 system_ext_public_policy +
343 system_ext_private_policy +
344 product_public_policy +
345 product_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900346 product_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900347 installable: false,
348}
349
350se_policy_cil {
351 name: "product_sepolicy.cil",
352 src: ":product_sepolicy.conf",
353 product_specific: true,
Inseob Kimff2018f2024-04-17 09:48:43 +0900354 filter_out: [
355 ":plat_sepolicy.cil",
356 ":system_ext_sepolicy.cil",
357 ],
Inseob Kima49e7242021-03-22 10:26:13 +0900358 remove_line_marker: true,
359}
360
Inseob Kim039175b2021-03-25 15:37:34 +0900361// policy mapping files
362// auto-generate the mapping file for current platform policy, since it needs to
363// track platform policy development
364se_versioned_policy {
365 name: "plat_mapping_file",
366 base: ":plat_pub_policy.cil",
367 mapping: true,
368 version: "current",
369 relative_install_path: "mapping", // install to /system/etc/selinux/mapping
Inseob Kim4b9929e2024-03-28 17:52:32 +0900370 dist: {
371 targets: ["sepolicy_finalize"],
372 },
Inseob Kim039175b2021-03-25 15:37:34 +0900373}
374
375se_versioned_policy {
376 name: "system_ext_mapping_file",
377 base: ":system_ext_pub_policy.cil",
378 mapping: true,
379 version: "current",
380 filter_out: [":plat_mapping_file"],
381 relative_install_path: "mapping", // install to /system_ext/etc/selinux/mapping
382 system_ext_specific: true,
383}
384
385se_versioned_policy {
386 name: "product_mapping_file",
387 base: ":pub_policy.cil",
388 mapping: true,
389 version: "current",
Inseob Kimff2018f2024-04-17 09:48:43 +0900390 filter_out: [
391 ":plat_mapping_file",
392 ":system_ext_mapping_file",
393 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900394 relative_install_path: "mapping", // install to /product/etc/selinux/mapping
395 product_specific: true,
396}
397
Inseob Kim6c6aa012023-08-31 16:47:38 +0900398//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900399// vendor/odm sepolicy
Inseob Kim6c6aa012023-08-31 16:47:38 +0900400//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900401
Inseob Kim039175b2021-03-25 15:37:34 +0900402// plat_pub_versioned.cil - the exported platform policy associated with the version
403// that non-platform policy targets.
404se_versioned_policy {
405 name: "plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900406 base: ":pub_policy.cil",
407 target_policy: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900408 version: "vendor",
Inseob Kim039175b2021-03-25 15:37:34 +0900409 vendor: true,
410}
411
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900412// vendor_policy.cil - the vendor sepolicy. This needs attributization and to be combined
413// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
414// policy and the platform public policy files in order to use checkpolicy.
415se_policy_conf {
416 name: "vendor_sepolicy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900417 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900418 srcs: plat_public_policy +
419 system_ext_public_policy +
420 product_public_policy +
421 reqd_mask_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900422 ":se_build_files{.plat_vendor}",
423 ":se_build_files{.vendor}",
424 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900425 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900426 installable: false,
427}
428
429se_policy_cil {
430 name: "vendor_sepolicy.cil.raw",
431 src: ":vendor_sepolicy.conf",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900432 filter_out: [":reqd_policy_mask.cil"],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900433 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900434 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900435 installable: false,
436}
437
438se_versioned_policy {
439 name: "vendor_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900440 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900441 target_policy: ":vendor_sepolicy.cil.raw",
442 version: "vendor",
443 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900444 ":plat_sepolicy.cil",
445 ":system_ext_sepolicy.cil",
446 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900447 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900448 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900449 ],
450 filter_out: [":plat_pub_versioned.cil"],
451 vendor: true,
452}
453
454// odm_policy.cil - the odl sepolicy. This needs attributization and to be combined
455// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
456// policy and the platform public policy files in order to use checkpolicy.
457se_policy_conf {
458 name: "odm_sepolicy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900459 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900460 srcs: plat_public_policy +
461 system_ext_public_policy +
462 product_public_policy +
463 reqd_mask_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900464 ":se_build_files{.plat_vendor}",
465 ":se_build_files{.vendor}",
466 ":se_build_files{.odm}",
467 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900468 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900469 installable: false,
470}
471
472se_policy_cil {
473 name: "odm_sepolicy.cil.raw",
474 src: ":odm_sepolicy.conf",
475 filter_out: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900476 ":reqd_policy_mask.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900477 ":vendor_sepolicy.cil",
478 ],
479 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900480 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900481 installable: false,
482}
483
484se_versioned_policy {
485 name: "odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900486 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900487 target_policy: ":odm_sepolicy.cil.raw",
488 version: "vendor",
489 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900490 ":plat_sepolicy.cil",
491 ":system_ext_sepolicy.cil",
492 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900493 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900494 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900495 ":vendor_sepolicy.cil",
496 ],
Inseob Kimff2018f2024-04-17 09:48:43 +0900497 filter_out: [
498 ":plat_pub_versioned.cil",
499 ":vendor_sepolicy.cil",
500 ],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900501 device_specific: true,
502}
503
Inseob Kim039175b2021-03-25 15:37:34 +0900504//////////////////////////////////
505// Precompiled sepolicy is loaded if and only if:
506// - plat_sepolicy_and_mapping.sha256 equals
507// precompiled_sepolicy.plat_sepolicy_and_mapping.sha256
508// AND
509// - system_ext_sepolicy_and_mapping.sha256 equals
510// precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256
511// AND
512// - product_sepolicy_and_mapping.sha256 equals
513// precompiled_sepolicy.product_sepolicy_and_mapping.sha256
514// See system/core/init/selinux.cpp for details.
515//////////////////////////////////
Cole Faust30349e32024-10-22 16:31:06 -0700516java_genrule {
Inseob Kim039175b2021-03-25 15:37:34 +0900517 name: "plat_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900518 srcs: [
519 ":plat_sepolicy.cil",
520 ":plat_mapping_file",
521 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900522 out: ["plat_sepolicy_and_mapping.sha256"],
523 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
524}
525
526prebuilt_etc {
527 name: "plat_sepolicy_and_mapping.sha256",
528 filename: "plat_sepolicy_and_mapping.sha256",
529 src: ":plat_sepolicy_and_mapping.sha256_gen",
530 relative_install_path: "selinux",
531}
532
Cole Faust30349e32024-10-22 16:31:06 -0700533java_genrule {
Inseob Kim039175b2021-03-25 15:37:34 +0900534 name: "system_ext_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900535 srcs: [
536 ":system_ext_sepolicy.cil",
537 ":system_ext_mapping_file",
538 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900539 out: ["system_ext_sepolicy_and_mapping.sha256"],
540 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
541}
542
543prebuilt_etc {
544 name: "system_ext_sepolicy_and_mapping.sha256",
545 filename: "system_ext_sepolicy_and_mapping.sha256",
546 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
547 relative_install_path: "selinux",
548 system_ext_specific: true,
549}
550
Cole Faust30349e32024-10-22 16:31:06 -0700551java_genrule {
Inseob Kim039175b2021-03-25 15:37:34 +0900552 name: "product_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900553 srcs: [
554 ":product_sepolicy.cil",
555 ":product_mapping_file",
556 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900557 out: ["product_sepolicy_and_mapping.sha256"],
558 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
559}
560
561prebuilt_etc {
562 name: "product_sepolicy_and_mapping.sha256",
563 filename: "product_sepolicy_and_mapping.sha256",
564 src: ":product_sepolicy_and_mapping.sha256_gen",
565 relative_install_path: "selinux",
566 product_specific: true,
567}
568
Inseob Kim1c056b12021-04-30 00:11:43 +0900569sepolicy_vers {
570 name: "plat_sepolicy_vers.txt",
571 version: "vendor",
572 vendor: true,
573}
574
Inseob Kim9b323082024-11-06 17:10:09 +0900575genrule {
576 name: "genfs_labels_version.txt.gen",
577 out: ["genfs_labels_version.txt"],
578 cmd: select(soong_config_variable("ANDROID", "BOARD_GENFS_LABELS_VERSION"), {
579 any @ value: "echo " + value + " > $(out)",
580 default: "echo > $(out)",
581 }),
582}
583
584prebuilt_etc {
585 name: "genfs_labels_version.txt",
586 src: ":genfs_labels_version.txt.gen",
587 relative_install_path: "selinux",
588 vendor: true,
589}
590
Inseob Kim731182a2021-05-06 11:44:37 +0000591soong_config_module_type {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900592 name: "precompiled_sepolicy_prebuilts_defaults",
Inseob Kim731182a2021-05-06 11:44:37 +0000593 module_type: "prebuilt_defaults",
594 config_namespace: "ANDROID",
595 bool_variables: ["BOARD_USES_ODMIMAGE"],
Inseob Kimff2018f2024-04-17 09:48:43 +0900596 properties: [
597 "vendor",
598 "device_specific",
599 ],
Inseob Kim731182a2021-05-06 11:44:37 +0000600}
601
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900602precompiled_sepolicy_prebuilts_defaults {
603 name: "precompiled_sepolicy_prebuilts",
Inseob Kim731182a2021-05-06 11:44:37 +0000604 soong_config_variables: {
605 BOARD_USES_ODMIMAGE: {
606 device_specific: true,
607 conditions_default: {
608 vendor: true,
609 },
610 },
611 },
612}
613
614//////////////////////////////////
615// SHA-256 digest of the plat_sepolicy.cil and plat_mapping_file against
616// which precompiled_policy was built.
617//////////////////////////////////
618prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900619 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000620 name: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
621 filename: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
622 src: ":plat_sepolicy_and_mapping.sha256_gen",
623 relative_install_path: "selinux",
624}
625
626//////////////////////////////////
627// SHA-256 digest of the system_ext_sepolicy.cil and system_ext_mapping_file against
628// which precompiled_policy was built.
629//////////////////////////////////
630prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900631 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000632 name: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
633 filename: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
634 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
635 relative_install_path: "selinux",
636}
637
638//////////////////////////////////
639// SHA-256 digest of the product_sepolicy.cil and product_mapping_file against
640// which precompiled_policy was built.
641//////////////////////////////////
642prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900643 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000644 name: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
645 filename: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
646 src: ":product_sepolicy_and_mapping.sha256_gen",
647 relative_install_path: "selinux",
648}
649
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900650soong_config_module_type {
651 name: "precompiled_se_policy_binary",
652 module_type: "se_policy_binary",
653 config_namespace: "ANDROID",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900654 bool_variables: ["BOARD_USES_ODMIMAGE"],
Inseob Kimff2018f2024-04-17 09:48:43 +0900655 properties: [
656 "vendor",
657 "device_specific",
658 ],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900659}
660
Garfield Tand8c51f22023-10-02 14:17:04 -0700661filegroup {
662 name: "precompiled_sepolicy_srcs",
Cole Faust30349e32024-10-22 16:31:06 -0700663 device_common_srcs: [
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900664 ":plat_sepolicy.cil",
Sandro143988d2022-08-05 11:38:56 +0000665 ":plat_pub_versioned.cil",
666 ":system_ext_sepolicy.cil",
667 ":product_sepolicy.cil",
668 ":vendor_sepolicy.cil",
669 ":odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900670 ":plat_mapping_file",
671 ":system_ext_mapping_file",
672 ":product_mapping_file",
Sandro143988d2022-08-05 11:38:56 +0000673 ],
Inseob Kim9b323082024-11-06 17:10:09 +0900674 device_first_srcs: select(soong_config_variable("ANDROID", "BOARD_GENFS_LABELS_VERSION"), {
675 "202504": [":plat_sepolicy_genfs_202504.cil"],
676 default: [],
677 }),
Garfield Tand8c51f22023-10-02 14:17:04 -0700678 // Make precompiled_sepolicy_srcs as public so that OEMs have access to them.
679 // Useful when some partitions need to be bind mounted across VM boundaries.
680 visibility: ["//visibility:public"],
681}
682
683precompiled_se_policy_binary {
684 name: "precompiled_sepolicy",
685 srcs: [
686 ":precompiled_sepolicy_srcs",
687 ],
Sandro143988d2022-08-05 11:38:56 +0000688 soong_config_variables: {
689 BOARD_USES_ODMIMAGE: {
690 device_specific: true,
691 conditions_default: {
692 vendor: true,
693 },
694 },
Sandro143988d2022-08-05 11:38:56 +0000695 },
696 required: [
697 "sepolicy_neverallows",
Sandro143988d2022-08-05 11:38:56 +0000698 ],
699 dist: {
700 targets: ["base-sepolicy-files-for-mapping"],
701 },
702}
703
Inseob Kim5bbcd682021-12-28 14:57:03 +0900704// policy for recovery
705se_policy_conf {
706 name: "recovery_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900707 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900708 srcs: plat_public_policy +
709 plat_private_policy +
710 system_ext_public_policy +
711 system_ext_private_policy +
712 product_public_policy +
713 product_private_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900714 ":se_build_files{.plat_vendor}",
715 ":se_build_files{.vendor}",
716 ":se_build_files{.odm}",
717 ],
Inseob Kim5bbcd682021-12-28 14:57:03 +0900718 target_recovery: true,
719 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900720 recovery: true,
Inseob Kim5bbcd682021-12-28 14:57:03 +0900721}
722
723se_policy_cil {
724 name: "recovery_sepolicy.cil",
725 src: ":recovery_sepolicy.conf",
726 secilc_check: false, // will be done in se_policy_binary module
727 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900728 recovery: true,
Inseob Kim5bbcd682021-12-28 14:57:03 +0900729}
730
731se_policy_binary {
732 name: "sepolicy.recovery",
733 srcs: [":recovery_sepolicy.cil"],
734 stem: "sepolicy",
735 recovery: true,
736}
737
Inseob Kima49e7242021-03-22 10:26:13 +0900738//////////////////////////////////
739// SELinux policy embedded into CTS.
740// CTS checks neverallow rules of this policy against the policy of the device under test.
741//////////////////////////////////
742se_policy_conf {
743 name: "general_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900744 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900745 srcs: plat_public_policy +
746 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900747 build_variant: "user",
748 cts: true,
749 exclude_build_test: true,
Inseob Kim4b9929e2024-03-28 17:52:32 +0900750 dist: {
751 targets: ["sepolicy_finalize"],
752 },
Inseob Kima49e7242021-03-22 10:26:13 +0900753}
Inseob Kimd5816612021-09-15 03:01:05 +0000754
755//////////////////////////////////
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000756// Base system policy for treble sepolicy tests.
757// If system sepolicy is extended (e.g. by SoC vendors), their plat_pub_versioned.cil may differ
758// with system/sepolicy/prebuilts/api/{version}/plat_pub_versioned.cil. In that case,
759// BOARD_PLAT_PUB_VERSIONED_POLICY can be used to specify extended plat_pub_versioned.cil.
760// See treble_sepolicy_tests_for_release.mk for more details.
761//////////////////////////////////
762se_policy_conf {
763 name: "base_plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900764 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900765 srcs: plat_public_policy +
766 plat_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000767 build_variant: "user",
768 installable: false,
769}
770
771se_policy_cil {
772 name: "base_plat_sepolicy.cil",
773 src: ":base_plat_sepolicy.conf",
774 additional_cil_files: ["private/technical_debt.cil"],
775 installable: false,
776 secilc_check: false, // done by se_policy_binary
777}
778
779se_policy_binary {
780 name: "base_plat_sepolicy",
781 srcs: [":base_plat_sepolicy.cil"],
782 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900783 dist: {
784 targets: ["base-sepolicy-files-for-mapping"],
785 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000786}
787
788se_policy_conf {
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000789 name: "base_product_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900790 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900791 srcs: plat_public_policy +
792 plat_private_policy +
793 system_ext_public_policy +
794 system_ext_private_policy +
795 product_public_policy +
796 product_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000797 build_variant: "user",
798 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900799 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000800}
801
802se_policy_cil {
803 name: "base_product_sepolicy.cil",
804 src: ":base_product_sepolicy.conf",
805 additional_cil_files: ["private/technical_debt.cil"],
806 product_specific: true,
807 installable: false,
808 secilc_check: false, // done by se_policy_binary
809}
810
811se_policy_binary {
812 name: "base_product_sepolicy",
813 srcs: [":base_product_sepolicy.cil"],
814 product_specific: true,
815 installable: false,
816}
817
818se_policy_conf {
819 name: "base_plat_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900820 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900821 srcs: plat_public_policy +
822 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000823 build_variant: "user",
824 installable: false,
825}
826
827se_policy_cil {
828 name: "base_plat_pub_policy.cil",
829 src: ":base_plat_pub_policy.conf",
830 filter_out: [":reqd_policy_mask.cil"],
831 secilc_check: false,
832 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900833 dist: {
834 targets: ["base-sepolicy-files-for-mapping"],
835 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000836}
837
838se_policy_conf {
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000839 name: "base_product_pub_policy.conf",
Inseob Kimd75dac62024-09-03 10:15:30 +0900840 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900841 srcs: plat_public_policy +
842 system_ext_public_policy +
843 product_public_policy +
844 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000845 build_variant: "user",
846 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900847 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000848}
849
850se_policy_cil {
851 name: "base_product_pub_policy.cil",
852 src: ":base_product_pub_policy.conf",
853 filter_out: [":reqd_policy_mask.cil"],
854 secilc_check: false,
855 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900856 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000857}
858
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800859// bug_map - Bug tracking information for selinux denials loaded by auditd.
Inseob Kim41964032022-04-22 07:50:22 +0900860se_build_files {
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800861 name: "bug_map_files",
862 srcs: ["bug_map"],
863}
864
865se_bug_map {
866 name: "plat_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900867 srcs: [":bug_map_files{.plat_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800868 stem: "bug_map",
869}
870
871se_bug_map {
872 name: "system_ext_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900873 srcs: [":bug_map_files{.system_ext_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800874 stem: "bug_map",
875 system_ext_specific: true,
876}
877
878se_bug_map {
879 name: "vendor_bug_map",
Inseob Kimff2018f2024-04-17 09:48:43 +0900880 srcs: [
881 ":bug_map_files{.vendor}",
882 ":bug_map_files{.plat_vendor}",
883 ],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800884 // Legacy file name of the vendor partition bug_map.
885 stem: "selinux_denial_metadata",
886 vendor: true,
887}
888
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900889se_neverallow_test {
890 name: "sepolicy_neverallows",
Inseob Kim085f22f2023-11-09 11:13:01 +0900891 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900892 srcs: plat_public_policy +
893 plat_private_policy +
894 system_ext_public_policy +
895 system_ext_private_policy +
896 product_public_policy +
Inseob Kim6c6aa012023-08-31 16:47:38 +0900897 product_private_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900898 ":se_build_files{.plat_vendor}",
899 ":se_build_files{.vendor}",
900 ":se_build_files{.odm}",
901 ],
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900902}
903
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000904//////////////////////////////////
Inseob Kimd5816612021-09-15 03:01:05 +0000905// se_freeze_test compares the plat sepolicy with the prebuilt sepolicy
906// Additional directories can be specified via Makefile variables:
907// SEPOLICY_FREEZE_TEST_EXTRA_DIRS and SEPOLICY_FREEZE_TEST_EXTRA_PREBUILT_DIRS.
908//////////////////////////////////
Inseob Kimb19ca8d2024-12-27 17:00:25 +0900909
910FREEZE_TEST_BOARD_API_LEVEL = "202404"
911
912se_policy_conf {
913 name: "base_plat_pub_policy_for_freeze_test.conf",
914 defaults: ["se_policy_conf_flags_defaults"],
915 srcs: plat_public_policy +
916 reqd_mask_policy,
917 build_variant: "user",
918 installable: false,
919 board_api_level: FREEZE_TEST_BOARD_API_LEVEL,
920}
921
922se_policy_cil {
923 name: "base_plat_pub_policy_for_freeze_test.cil",
924 src: ":base_plat_pub_policy_for_freeze_test.conf",
925 filter_out: [":reqd_policy_mask.cil"],
926 secilc_check: false,
927 installable: false,
928}
929
Inseob Kimd5816612021-09-15 03:01:05 +0000930se_freeze_test {
Inseob Kim36d9d392023-09-04 17:40:03 +0900931 name: "se_freeze_test",
Inseob Kimb19ca8d2024-12-27 17:00:25 +0900932 board_api_level: FREEZE_TEST_BOARD_API_LEVEL,
933 current_cil: ":base_plat_pub_policy_for_freeze_test.cil",
934 prebuilt_cil: ":" + FREEZE_TEST_BOARD_API_LEVEL + "_plat_pub_policy.cil",
Inseob Kimd5816612021-09-15 03:01:05 +0000935}
Inseob Kim61257ca2022-02-25 11:26:16 +0900936
937//////////////////////////////////
938// sepolicy_test checks various types of violations, which can't be easily done
939// by CIL itself. Refer tests/sepolicy_tests.py for more detail.
940//////////////////////////////////
Cole Faust30349e32024-10-22 16:31:06 -0700941java_genrule {
Inseob Kim61257ca2022-02-25 11:26:16 +0900942 name: "sepolicy_test",
943 srcs: [
944 ":plat_file_contexts",
945 ":vendor_file_contexts",
946 ":system_ext_file_contexts",
947 ":product_file_contexts",
948 ":odm_file_contexts",
949 ":precompiled_sepolicy",
950 ],
951 tools: ["sepolicy_tests"],
952 out: ["sepolicy_test"],
953 cmd: "$(location sepolicy_tests) " +
954 "-f $(location :plat_file_contexts) " +
955 "-f $(location :vendor_file_contexts) " +
956 "-f $(location :system_ext_file_contexts) " +
957 "-f $(location :product_file_contexts) " +
958 "-f $(location :odm_file_contexts) " +
959 "-p $(location :precompiled_sepolicy) && " +
960 "touch $(out)",
961}
Inseob Kim3a9d91c2023-09-27 17:39:07 +0900962
963//////////////////////////////////
964// TestDevTypeViolations can't run on old devices (V or before)
965//////////////////////////////////
966
967soong_config_module_type {
968 name: "dev_type_test_genrule",
Cole Faust30349e32024-10-22 16:31:06 -0700969 module_type: "java_genrule",
Inseob Kim3a9d91c2023-09-27 17:39:07 +0900970 config_namespace: "ANDROID",
971 bool_variables: ["CHECK_DEV_TYPE_VIOLATIONS"],
972 properties: ["cmd"],
973}
974
975dev_type_test_genrule {
976 name: "sepolicy_dev_type_test",
977 srcs: [
978 ":plat_file_contexts",
979 ":vendor_file_contexts",
980 ":system_ext_file_contexts",
981 ":product_file_contexts",
982 ":odm_file_contexts",
983 ":precompiled_sepolicy",
984 ],
985 tools: ["sepolicy_tests"],
986 out: ["sepolicy_dev_type_test"],
987 soong_config_variables: {
988 CHECK_DEV_TYPE_VIOLATIONS: {
989 cmd: "$(location sepolicy_tests) " +
990 "-f $(location :plat_file_contexts) " +
991 "-f $(location :vendor_file_contexts) " +
992 "-f $(location :system_ext_file_contexts) " +
993 "-f $(location :product_file_contexts) " +
994 "-f $(location :odm_file_contexts) " +
995 "-p $(location :precompiled_sepolicy) " +
996 "-t TestDevTypeViolations && " +
997 "touch $(out)",
998 conditions_default: {
999 cmd: "touch $(out)",
1000 },
1001 },
1002 },
1003}
kellyhung08f7c992024-09-18 03:34:53 +00001004
1005phony {
1006 name: "selinux_policy_system_ext",
1007 required: [
1008 //"ifdef HAS_SYSTEM_EXT_PUBLIC_SEPOLICY" check included in system_ext_pub_policy.cil
1009 "system_ext_mapping_file",
1010 //"ifdef HAS_SYSTEM_EXT_SEPOLICY" check included in .cil
1011 "system_ext_sepolicy.cil",
1012 ] + [
1013 //"ifdef HAS_SYSTEM_EXT_SEPOLICY" check included in .cil
1014 "system_ext_29.0.cil",
1015 "system_ext_30.0.cil",
1016 "system_ext_31.0.cil",
1017 "system_ext_32.0.cil",
1018 "system_ext_33.0.cil",
1019 "system_ext_34.0.cil",
1020 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1021 "202404": [],
1022 default: [
1023 "system_ext_202404.cil",
1024 ],
1025 }) +
1026 select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1027 true: ["system_ext_sepolicy_and_mapping.sha256"],
1028 default: [],
1029 }) + [
1030 "system_ext_file_contexts",
1031 "system_ext_file_contexts_test",
1032 "system_ext_keystore2_key_contexts",
1033 "system_ext_hwservice_contexts",
1034 "system_ext_hwservice_contexts_test",
1035 "system_ext_property_contexts",
1036 "system_ext_property_contexts_test",
1037 "system_ext_seapp_contexts",
1038 "system_ext_service_contexts",
1039 "system_ext_service_contexts_test",
1040 "system_ext_mac_permissions.xml",
1041 "system_ext_bug_map",
1042 // $(addprefix system_ext_,$(addsuffix .compat.cil,$(PLATFORM_SEPOLICY_COMPAT_VERSIONS))) \
1043 "system_ext_29.0.compat.cil",
1044 "system_ext_30.0.compat.cil",
1045 "system_ext_31.0.compat.cil",
1046 "system_ext_32.0.compat.cil",
1047 "system_ext_33.0.compat.cil",
1048 "system_ext_34.0.compat.cil",
1049 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1050 "202404": [],
1051 default: [
1052 "system_ext_202404.compat.cil",
1053 ],
Nikita Ioffe48966b62024-10-22 14:01:17 +00001054 }) + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
1055 true: ["system_ext_tee_service_contexts"],
1056 default: [],
kellyhung08f7c992024-09-18 03:34:53 +00001057 }),
Spandan Das80252082024-10-17 21:58:34 +00001058 system_ext_specific: true,
kellyhung08f7c992024-09-18 03:34:53 +00001059}
kellyhung14081902024-09-18 04:59:54 +00001060
1061phony {
1062 name: "selinux_policy_product",
1063 required: [
1064 "product_mapping_file",
1065 "product_sepolicy.cil",
1066 // "ifdef HAS_PRODUCT_PUBLIC_SEPOLICY" check included in .cil
1067 "product_29.0.cil",
1068 "product_30.0.cil",
1069 "product_31.0.cil",
1070 "product_32.0.cil",
1071 "product_33.0.cil",
1072 "product_34.0.cil",
1073 "product_file_contexts",
1074 // "ifdef HAS_PRODUCT_SEPOLICY_DIR" in Android.mk can be ignored.
1075 "product_file_contexts_test",
1076 "product_keystore2_key_contexts",
1077 "product_hwservice_contexts",
1078 "product_hwservice_contexts_test",
1079 "product_property_contexts",
1080 "product_property_contexts_test",
1081 "product_seapp_contexts",
1082 "product_service_contexts",
1083 "product_service_contexts_test",
1084 "product_mac_permissions.xml",
1085 ] + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1086 true: ["product_sepolicy_and_mapping.sha256"],
1087 default: [],
1088 }) + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1089 "202404": [],
1090 default: [
1091 "product_202404.cil",
1092 ],
Nikita Ioffe48966b62024-10-22 14:01:17 +00001093 }) + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
1094 true: ["product_tee_service_contexts"],
1095 default: [],
kellyhung14081902024-09-18 04:59:54 +00001096 }),
Spandan Das155cc2f2024-10-18 22:27:25 +00001097 product_specific: true,
kellyhung14081902024-09-18 04:59:54 +00001098}
kellyhunga07b3712024-09-25 03:31:09 +00001099
1100phony {
1101 name: "selinux_policy_nonsystem",
1102 required: [
Spandan Das62656052024-11-01 18:37:13 +00001103 "selinux_policy_system_ext",
1104 "selinux_policy_product",
1105 "selinux_policy_vendor",
1106 "selinux_policy_odm",
1107 // Builds an additional userdebug sepolicy into the debug ramdisk.
1108 "userdebug_plat_sepolicy.cil",
1109 ],
1110}
1111
1112phony {
1113 name: "selinux_policy_vendor",
1114 required: [
Inseob Kim9b323082024-11-06 17:10:09 +09001115 "genfs_labels_version.txt",
kellyhunga07b3712024-09-25 03:31:09 +00001116 "plat_pub_versioned.cil",
1117 "vendor_sepolicy.cil",
1118 "plat_sepolicy_vers.txt",
1119 "vendor_file_contexts",
1120 "vendor_file_contexts_test",
1121 "vendor_keystore2_key_contexts",
1122 "vendor_mac_permissions.xml",
1123 "vendor_property_contexts",
1124 "vendor_property_contexts_test",
1125 "vendor_seapp_contexts",
1126 "vendor_service_contexts",
1127 "vendor_service_contexts_test",
1128 "vendor_hwservice_contexts",
1129 "vendor_hwservice_contexts_test",
1130 "vendor_bug_map",
1131 "vndservice_contexts",
1132 "vndservice_contexts_test",
Nikita Ioffe48966b62024-10-22 14:01:17 +00001133 ] + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
1134 true: ["vendor_tee_service_contexts"],
1135 default: [],
1136 }),
Spandan Das62656052024-11-01 18:37:13 +00001137 vendor: true,
1138}
1139
1140phony {
1141 name: "selinux_policy_odm",
1142 required: [
kellyhunga07b3712024-09-25 03:31:09 +00001143 "odm_sepolicy.cil",
1144 "odm_file_contexts",
1145 "odm_file_contexts_test",
1146 "odm_seapp_contexts",
1147 "odm_property_contexts",
1148 "odm_property_contexts_test",
1149 "odm_service_contexts",
1150 "odm_service_contexts_test",
1151 "odm_hwservice_contexts",
1152 "odm_hwservice_contexts_test",
1153 "odm_mac_permissions.xml",
kellyhunga07b3712024-09-25 03:31:09 +00001154 ] + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1155 true: [
1156 "precompiled_sepolicy",
1157 "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
1158 "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
1159 "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
1160 ],
1161 default: [],
1162 }),
Spandan Das62656052024-11-01 18:37:13 +00001163 device_specific: true,
kellyhunga07b3712024-09-25 03:31:09 +00001164}
kellyhung0c9edb32024-07-15 11:06:26 +00001165
1166phony {
1167 name: "selinux_policy_system",
1168 required: [
1169 "29.0.compat.cil",
1170 "30.0.compat.cil",
1171 "31.0.compat.cil",
1172 "32.0.compat.cil",
1173 "33.0.compat.cil",
1174 "34.0.compat.cil",
1175 "build_sepolicy",
1176 "fuzzer_bindings_test",
1177 "plat_29.0.cil",
1178 "plat_30.0.cil",
1179 "plat_31.0.cil",
1180 "plat_32.0.cil",
1181 "plat_33.0.cil",
1182 "plat_34.0.cil",
1183 "plat_bug_map",
1184 "plat_file_contexts",
1185 "plat_file_contexts_data_test",
1186 "plat_file_contexts_test",
1187 "plat_hwservice_contexts",
1188 "plat_hwservice_contexts_test",
1189 "plat_keystore2_key_contexts",
1190 "plat_mac_permissions.xml",
1191 "plat_mapping_file",
1192 "plat_property_contexts",
1193 "plat_property_contexts_test",
1194 "plat_seapp_contexts",
1195 "plat_sepolicy.cil",
Inseob Kim9b323082024-11-06 17:10:09 +09001196 "plat_sepolicy_genfs_202504.cil",
kellyhung0c9edb32024-07-15 11:06:26 +00001197 "plat_service_contexts",
1198 "plat_service_contexts_test",
1199 "searchpolicy",
1200 "secilc",
1201 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
1202 "202404": [],
1203 default: [
1204 "202404.compat.cil",
1205 "plat_202404.cil",
1206 ],
1207 }) + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
1208 true: ["plat_sepolicy_and_mapping.sha256"],
1209 default: [],
1210 }) + select((
1211 soong_config_variable("ANDROID", "ASAN_ENABLED"),
1212 product_variable("selinux_ignore_neverallows"),
1213 ), {
1214 (true, true): [
1215 ],
1216 (default, default): [
1217 "sepolicy_compat_test",
1218 "sepolicy_test",
1219 "sepolicy_dev_type_test",
1220 "treble_sepolicy_tests_29.0",
1221 "treble_sepolicy_tests_30.0",
1222 "treble_sepolicy_tests_31.0",
1223 "treble_sepolicy_tests_32.0",
1224 "treble_sepolicy_tests_33.0",
1225 "treble_sepolicy_tests_34.0",
1226 ],
1227 }) + select((
1228 soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"),
1229 soong_config_variable("ANDROID", "ASAN_ENABLED"),
1230 product_variable("selinux_ignore_neverallows"),
1231 ), {
1232 ("202404", true, true): [],
1233 (default, true, true): [],
1234 (default, default, default): [
1235 "treble_sepolicy_tests_202404",
1236 ],
1237 }) + select(soong_config_variable("ANDROID", "RELEASE_BOARD_API_LEVEL_FROZEN"), {
1238 true: ["se_freeze_test"],
1239 default: [],
Nikita Ioffe48966b62024-10-22 14:01:17 +00001240 }) + select(release_flag("RELEASE_AVF_ENABLE_VM_TO_TEE_SERVICES_ALLOWLIST"), {
1241 true: ["plat_tee_service_contexts"],
1242 default: [],
kellyhung0c9edb32024-07-15 11:06:26 +00001243 }),
1244}
kellyhungee97d9c2024-10-03 00:54:38 +00001245
1246phony {
1247 name: "selinux_policy",
1248 required: [
1249 // Runs checkfc against merged service_contexts files
1250 "merged_hwservice_contexts_test",
1251 "merged_service_contexts_test",
1252 "selinux_policy_nonsystem",
1253 "selinux_policy_system",
1254 ],
1255}
1256
1257// selinux_policy is a main goal and triggers lots of tests.
1258// Most tests are FAKE modules, so aren'triggered on normal builds. (e.g. 'm')
1259// By setting as droidcore's dependency, tests will run on normal builds.
1260phony_rule {
1261 name: "droidcore",
1262 phony_deps: ["selinux_policy"],
1263}
kellyhung8659c152024-10-07 21:37:14 +00001264
1265//-----------------------------------------------------------------------------
1266// TODO - remove this. Keep around until we get the filesystem creation stuff
1267// taken care of.
1268//
1269// The file_contexts.bin is built in the following way:
1270// 1. Collect all file_contexts files in THIS repository and process them with
1271// m4 into a tmp file called file_contexts.local.tmp.
1272// 2. Collect all device specific file_contexts files and process them with m4
1273// into a tmp file called file_contexts.device.tmp.
1274// 3. Run checkfc -e (allow no device fc entries ie empty) and fc_sort on
1275// file_contexts.device.tmp and output to file_contexts.device.sorted.tmp.
1276// 4. Concatenate file_contexts.local.tmp and file_contexts.device.sorted.tmp
1277// into file_contexts.concat.tmp.
1278// 5. Run checkfc and sefcontext_compile on file_contexts.concat.tmp to produce
1279// file_contexts.bin.
1280//
1281// Note: That a newline file is placed between each file_context file found to
1282// ensure a proper build when an fc file is missing an ending newline.
1283//---
1284// 1. Collect all file_contexts files in THIS repository and process them with
1285// m4 into a tmp file called file_contexts.local.tmp.
Cole Faust30349e32024-10-22 16:31:06 -07001286java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001287 name: "file_contexts.local.tmp",
1288 srcs: [
1289 ":plat_file_contexts",
1290 ":system_ext_file_contexts",
1291 ":product_file_contexts",
1292 ],
1293 tools: [
1294 "m4",
1295 ],
1296 out: ["file_contexts.local.tmp"],
1297 cmd: "$(location m4) --fatal-warnings " +
1298 "-s $(in) > $(out)",
1299}
1300
1301// 2. Collect all device specific file_contexts files and process them with m4
1302// into a tmp file called file_contexts.device.tmp.
1303PRIVATE_ADDITIONAL_M4DEFS = select(soong_config_variable("ANDROID", "ADDITIONAL_M4DEFS"), {
1304 any @ m4defs: m4defs,
1305 default: "",
1306})
Cole Faust30349e32024-10-22 16:31:06 -07001307java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001308 name: "file_contexts.device.tmp",
1309 srcs: [
1310 ":vendor_file_contexts",
1311 ":odm_file_contexts",
1312 ],
1313 tools: [
1314 "m4",
1315 ],
1316 out: ["file_contexts.device.tmp"],
1317 cmd: "$(location m4) --fatal-warnings " +
1318 "-s " + PRIVATE_ADDITIONAL_M4DEFS +
1319 " $(in) > $(out)",
1320}
1321
1322// 3. Run checkfc -e (allow no device fc entries ie empty) and fc_sort on
1323// file_contexts.device.tmp and output to file_contexts.device.sorted.tmp.
Cole Faust30349e32024-10-22 16:31:06 -07001324java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001325 name: "file_contexts.device.sorted.tmp",
1326 srcs: [
1327 ":file_contexts.device.tmp",
1328 ":precompiled_sepolicy",
1329 ],
1330 tools: [
1331 "checkfc",
1332 "fc_sort",
1333 ],
1334 out: ["file_contexts.device.sorted.tmp"],
1335 cmd: "$(location checkfc) " +
1336 "-e $(location :precompiled_sepolicy) " +
1337 "$(location :file_contexts.device.tmp) && " +
1338 "$(location fc_sort) " +
1339 "-i $(location :file_contexts.device.tmp) " +
1340 "-o $(out)",
1341}
1342
1343// 4. Concatenate file_contexts.local.tmp and file_contexts.device.sorted.tmp
1344// into file_contexts.concat.tmp.
Cole Faust30349e32024-10-22 16:31:06 -07001345java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001346 name: "file_contexts.concat.tmp",
1347 srcs: [
1348 ":file_contexts.local.tmp",
1349 ":file_contexts.device.sorted.tmp",
1350 ],
1351 tools: [
1352 "m4",
1353 ],
1354 out: ["file_contexts.concat.tmp"],
1355 cmd: "$(location m4) --fatal-warnings " +
1356 "-s $(location :file_contexts.local.tmp) " +
1357 "$(location :file_contexts.device.sorted.tmp) > $(out)",
1358}
1359
1360// 5. Run checkfc and sefcontext_compile on file_contexts.concat.tmp to produce
1361// file_contexts.bin.
Cole Faust30349e32024-10-22 16:31:06 -07001362java_genrule {
kellyhung8659c152024-10-07 21:37:14 +00001363 name: "file_contexts_bin_gen",
1364 srcs: [
1365 ":file_contexts.concat.tmp",
1366 ":precompiled_sepolicy",
1367 ],
1368 tools: [
1369 "checkfc",
1370 "sefcontext_compile",
1371 ],
1372 out: ["file_contexts.bin"],
1373 cmd: "$(location checkfc) " +
1374 "$(location :precompiled_sepolicy) " +
1375 "$(location :file_contexts.concat.tmp) && " +
1376 "$(location sefcontext_compile) " +
1377 "-o $(out) $(location :file_contexts.concat.tmp)",
1378}
1379
1380prebuilt_etc {
1381 name: "file_contexts.bin",
1382 src: ":file_contexts_bin_gen",
1383}