blob: d208920c4289fe440b1677710cc261358b18fd12 [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
Inseob Kim151562f2024-04-12 10:53:34 +090091soong_config_module_type {
92 name: "se_phony",
93 module_type: "phony",
94 config_namespace: "ANDROID",
95 bool_variables: ["PRODUCT_PRECOMPILED_SEPOLICY"],
96 list_variables: ["PLATFORM_SEPOLICY_COMPAT_VERSIONS"],
97 properties: ["required"],
98}
99
100se_phony {
101 // Currently used only for aosp_cf_system_x86_64
102 // TODO(b/329208946): migrate selinux_policy_system to Soong
103 name: "selinux_policy_system_soong",
104 required: [
105 "plat_bug_map",
106 "plat_file_contexts",
107 "plat_hwservice_contexts",
108 "plat_keystore2_key_contexts",
109 "plat_mac_permissions.xml",
110 "plat_mapping_file",
111 "plat_property_contexts",
112 "plat_seapp_contexts",
113 "plat_sepolicy.cil",
114 "plat_service_contexts",
115 "secilc",
116 ],
117 soong_config_variables: {
118 PLATFORM_SEPOLICY_COMPAT_VERSIONS: {
119 required: [
120 "plat_%s.cil",
121 "%s.compat.cil",
122 ],
123 },
124 PRODUCT_PRECOMPILED_SEPOLICY: {
125 required: ["plat_sepolicy_and_mapping.sha256"],
126 },
127 },
128}
129
Inseob Kimff2018f2024-04-17 09:48:43 +0900130reqd_mask_policy = [":se_build_files{.reqd_mask}"]
131plat_public_policy = [":se_build_files{.plat_public}"]
132plat_private_policy = [":se_build_files{.plat_private}"]
133system_ext_public_policy = [":se_build_files{.system_ext_public}"]
Inseob Kim0a707fa2021-12-09 23:35:11 +0900134system_ext_private_policy = [":se_build_files{.system_ext_private}"]
Inseob Kimff2018f2024-04-17 09:48:43 +0900135product_public_policy = [":se_build_files{.product_public}"]
136product_private_policy = [":se_build_files{.product_private}"]
Inseob Kim0a707fa2021-12-09 23:35:11 +0900137
Inseob Kima49e7242021-03-22 10:26:13 +0900138// reqd_policy_mask - a policy.conf file which contains only the bare minimum
139// policy necessary to use checkpolicy.
140//
141// This bare-minimum policy needs to be present in all policy.conf files, but
142// should not necessarily be exported as part of the public policy.
143//
144// The rules generated by reqd_policy_mask will allow the compilation of public
145// policy and subsequent removal of CIL policy that should not be exported.
146se_policy_conf {
147 name: "reqd_policy_mask.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900148 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900149 srcs: reqd_mask_policy,
Inseob Kime35b49b2021-02-18 19:15:41 +0900150 installable: false,
151}
152
Inseob Kima49e7242021-03-22 10:26:13 +0900153se_policy_cil {
154 name: "reqd_policy_mask.cil",
155 src: ":reqd_policy_mask.conf",
156 secilc_check: false,
157 installable: false,
Inseob Kime35b49b2021-02-18 19:15:41 +0900158}
159
Inseob Kima49e7242021-03-22 10:26:13 +0900160// pub_policy - policy that will be exported to be a part of non-platform
161// policy corresponding to this platform version.
162//
163// This is a limited subset of policy that would not compile in checkpolicy on
164// its own.
165//
166// To get around this limitation, add only the required files from private
167// policy, which will generate CIL policy that will then be filtered out by the
168// reqd_policy_mask.
169//
170// There are three pub_policy.cil files below:
171// - pub_policy.cil: exported 'product', 'system_ext' and 'system' policy.
172// - system_ext_pub_policy.cil: exported 'system_ext' and 'system' policy.
173// - plat_pub_policy.cil: exported 'system' policy.
174//
175// Those above files will in turn be used to generate the following versioned cil files:
176// - product_mapping_file: the versioned, exported 'product' policy in product partition.
177// - system_ext_mapping_file: the versioned, exported 'system_ext' policy in system_ext partition.
178// - plat_mapping_file: the versioned, exported 'system' policy in system partition.
179// - plat_pub_versioned.cil: the versioned, exported 'product', 'system_ext' and 'system' policy
180// in vendor partition.
181//
182se_policy_conf {
183 name: "pub_policy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900184 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900185 srcs: plat_public_policy +
186 system_ext_public_policy +
187 product_public_policy +
188 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900189 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900190 installable: false,
191}
192
193se_policy_cil {
194 name: "pub_policy.cil",
195 src: ":pub_policy.conf",
196 filter_out: [":reqd_policy_mask.cil"],
197 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900198 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900199 installable: false,
200}
201
202se_policy_conf {
203 name: "system_ext_pub_policy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900204 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900205 srcs: plat_public_policy +
206 system_ext_public_policy +
207 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900208 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900209 installable: false,
210}
211
212se_policy_cil {
213 name: "system_ext_pub_policy.cil",
214 src: ":system_ext_pub_policy.conf",
215 filter_out: [":reqd_policy_mask.cil"],
216 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900217 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900218 installable: false,
219}
220
221se_policy_conf {
222 name: "plat_pub_policy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900223 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900224 srcs: plat_public_policy +
225 reqd_mask_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900226 installable: false,
227}
228
229se_policy_cil {
230 name: "plat_pub_policy.cil",
231 src: ":plat_pub_policy.conf",
232 filter_out: [":reqd_policy_mask.cil"],
233 secilc_check: false,
234 installable: false,
235}
236
237// plat_policy.conf - A combination of the private and public platform policy
238// which will ship with the device.
239//
240// The platform will always reflect the most recent platform version and is not
241// currently being attributized.
242se_policy_conf {
243 name: "plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900244 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900245 srcs: plat_public_policy +
246 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900247 installable: false,
248}
249
250se_policy_cil {
251 name: "plat_sepolicy.cil",
252 src: ":plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900253 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kim4b9929e2024-03-28 17:52:32 +0900254 dist: {
255 targets: ["sepolicy_finalize"],
256 },
Inseob Kima49e7242021-03-22 10:26:13 +0900257}
258
Inseob Kim6cc75f42021-04-29 13:53:20 +0000259// userdebug_plat_policy.conf - the userdebug version plat_sepolicy.cil
260se_policy_conf {
261 name: "userdebug_plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900262 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900263 srcs: plat_public_policy +
264 plat_private_policy,
Inseob Kim6cc75f42021-04-29 13:53:20 +0000265 build_variant: "userdebug",
266 installable: false,
267}
268
269se_policy_cil {
270 name: "userdebug_plat_sepolicy.cil",
271 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900272 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kim6cc75f42021-04-29 13:53:20 +0000273 debug_ramdisk: true,
Yi-Yo Chiang68478b12021-10-16 03:23:05 +0800274 dist: {
275 targets: ["droidcore"],
276 },
Inseob Kim6cc75f42021-04-29 13:53:20 +0000277}
278
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000279// A copy of the userdebug_plat_policy in GSI.
280soong_config_module_type {
281 name: "gsi_se_policy_cil",
282 module_type: "se_policy_cil",
283 config_namespace: "ANDROID",
284 bool_variables: [
285 "PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT",
286 ],
287 properties: [
288 "enabled",
289 "installable",
290 ],
291}
292
293gsi_se_policy_cil {
294 name: "system_ext_userdebug_plat_sepolicy.cil",
295 stem: "userdebug_plat_sepolicy.cil",
296 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900297 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000298 system_ext_specific: true,
299 enabled: false,
300 installable: false,
301 soong_config_variables: {
302 PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT: {
303 enabled: true,
304 installable: true,
305 },
306 },
307}
308
Inseob Kima49e7242021-03-22 10:26:13 +0900309// system_ext_policy.conf - A combination of the private and public system_ext
310// policy which will ship with the device. System_ext policy is not attributized
311se_policy_conf {
312 name: "system_ext_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900313 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900314 srcs: plat_public_policy +
315 plat_private_policy +
316 system_ext_public_policy +
317 system_ext_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900318 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900319 installable: false,
320}
321
322se_policy_cil {
323 name: "system_ext_sepolicy.cil",
324 src: ":system_ext_sepolicy.conf",
325 system_ext_specific: true,
326 filter_out: [":plat_sepolicy.cil"],
327 remove_line_marker: true,
328}
329
330// product_policy.conf - A combination of the private and public product policy
331// which will ship with the device. Product policy is not attributized
332se_policy_conf {
333 name: "product_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900334 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900335 srcs: plat_public_policy +
336 plat_private_policy +
337 system_ext_public_policy +
338 system_ext_private_policy +
339 product_public_policy +
340 product_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900341 product_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900342 installable: false,
343}
344
345se_policy_cil {
346 name: "product_sepolicy.cil",
347 src: ":product_sepolicy.conf",
348 product_specific: true,
Inseob Kimff2018f2024-04-17 09:48:43 +0900349 filter_out: [
350 ":plat_sepolicy.cil",
351 ":system_ext_sepolicy.cil",
352 ],
Inseob Kima49e7242021-03-22 10:26:13 +0900353 remove_line_marker: true,
354}
355
Inseob Kim039175b2021-03-25 15:37:34 +0900356// policy mapping files
357// auto-generate the mapping file for current platform policy, since it needs to
358// track platform policy development
359se_versioned_policy {
360 name: "plat_mapping_file",
361 base: ":plat_pub_policy.cil",
362 mapping: true,
363 version: "current",
364 relative_install_path: "mapping", // install to /system/etc/selinux/mapping
Inseob Kim4b9929e2024-03-28 17:52:32 +0900365 dist: {
366 targets: ["sepolicy_finalize"],
367 },
Inseob Kim039175b2021-03-25 15:37:34 +0900368}
369
370se_versioned_policy {
371 name: "system_ext_mapping_file",
372 base: ":system_ext_pub_policy.cil",
373 mapping: true,
374 version: "current",
375 filter_out: [":plat_mapping_file"],
376 relative_install_path: "mapping", // install to /system_ext/etc/selinux/mapping
377 system_ext_specific: true,
378}
379
380se_versioned_policy {
381 name: "product_mapping_file",
382 base: ":pub_policy.cil",
383 mapping: true,
384 version: "current",
Inseob Kimff2018f2024-04-17 09:48:43 +0900385 filter_out: [
386 ":plat_mapping_file",
387 ":system_ext_mapping_file",
388 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900389 relative_install_path: "mapping", // install to /product/etc/selinux/mapping
390 product_specific: true,
391}
392
Inseob Kime41e95e2024-02-13 02:19:24 +0000393// HACK to support vendor blobs using 1000000.0
394// TODO(b/314010177): remove after new ToT (202404) fully propagates
395se_versioned_policy {
396 name: "plat_mapping_file_1000000.0",
397 base: ":plat_pub_policy.cil",
398 mapping: true,
399 version: "1000000.0",
400 relative_install_path: "mapping", // install to /system/etc/selinux/mapping
401}
402
403se_versioned_policy {
404 name: "system_ext_mapping_file_1000000.0",
405 base: ":system_ext_pub_policy.cil",
406 mapping: true,
407 version: "1000000.0",
408 filter_out: [":plat_mapping_file"],
409 relative_install_path: "mapping", // install to /system_ext/etc/selinux/mapping
410 system_ext_specific: true,
411}
412
413se_versioned_policy {
414 name: "product_mapping_file_1000000.0",
415 base: ":pub_policy.cil",
416 mapping: true,
417 version: "1000000.0",
Inseob Kimff2018f2024-04-17 09:48:43 +0900418 filter_out: [
419 ":plat_mapping_file",
420 ":system_ext_mapping_file",
421 ],
Inseob Kime41e95e2024-02-13 02:19:24 +0000422 relative_install_path: "mapping", // install to /product/etc/selinux/mapping
423 product_specific: true,
424}
425
Inseob Kim6c6aa012023-08-31 16:47:38 +0900426//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900427// vendor/odm sepolicy
Inseob Kim6c6aa012023-08-31 16:47:38 +0900428//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900429
Inseob Kim039175b2021-03-25 15:37:34 +0900430// plat_pub_versioned.cil - the exported platform policy associated with the version
431// that non-platform policy targets.
432se_versioned_policy {
433 name: "plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900434 base: ":pub_policy.cil",
435 target_policy: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900436 version: "vendor",
Inseob Kim039175b2021-03-25 15:37:34 +0900437 vendor: true,
438}
439
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900440// vendor_policy.cil - the vendor sepolicy. This needs attributization and to be combined
441// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
442// policy and the platform public policy files in order to use checkpolicy.
443se_policy_conf {
444 name: "vendor_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900445 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900446 srcs: plat_public_policy +
447 system_ext_public_policy +
448 product_public_policy +
449 reqd_mask_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900450 ":se_build_files{.plat_vendor}",
451 ":se_build_files{.vendor}",
452 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900453 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900454 installable: false,
455}
456
457se_policy_cil {
458 name: "vendor_sepolicy.cil.raw",
459 src: ":vendor_sepolicy.conf",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900460 filter_out: [":reqd_policy_mask.cil"],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900461 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900462 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900463 installable: false,
464}
465
466se_versioned_policy {
467 name: "vendor_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900468 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900469 target_policy: ":vendor_sepolicy.cil.raw",
470 version: "vendor",
471 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900472 ":plat_sepolicy.cil",
473 ":system_ext_sepolicy.cil",
474 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900475 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900476 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900477 ],
478 filter_out: [":plat_pub_versioned.cil"],
479 vendor: true,
480}
481
482// odm_policy.cil - the odl sepolicy. This needs attributization and to be combined
483// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
484// policy and the platform public policy files in order to use checkpolicy.
485se_policy_conf {
486 name: "odm_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900487 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900488 srcs: plat_public_policy +
489 system_ext_public_policy +
490 product_public_policy +
491 reqd_mask_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900492 ":se_build_files{.plat_vendor}",
493 ":se_build_files{.vendor}",
494 ":se_build_files{.odm}",
495 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900496 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900497 installable: false,
498}
499
500se_policy_cil {
501 name: "odm_sepolicy.cil.raw",
502 src: ":odm_sepolicy.conf",
503 filter_out: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900504 ":reqd_policy_mask.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900505 ":vendor_sepolicy.cil",
506 ],
507 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900508 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900509 installable: false,
510}
511
512se_versioned_policy {
513 name: "odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900514 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900515 target_policy: ":odm_sepolicy.cil.raw",
516 version: "vendor",
517 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900518 ":plat_sepolicy.cil",
519 ":system_ext_sepolicy.cil",
520 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900521 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900522 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900523 ":vendor_sepolicy.cil",
524 ],
Inseob Kimff2018f2024-04-17 09:48:43 +0900525 filter_out: [
526 ":plat_pub_versioned.cil",
527 ":vendor_sepolicy.cil",
528 ],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900529 device_specific: true,
530}
531
Inseob Kim039175b2021-03-25 15:37:34 +0900532//////////////////////////////////
533// Precompiled sepolicy is loaded if and only if:
534// - plat_sepolicy_and_mapping.sha256 equals
535// precompiled_sepolicy.plat_sepolicy_and_mapping.sha256
536// AND
537// - system_ext_sepolicy_and_mapping.sha256 equals
538// precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256
539// AND
540// - product_sepolicy_and_mapping.sha256 equals
541// precompiled_sepolicy.product_sepolicy_and_mapping.sha256
542// See system/core/init/selinux.cpp for details.
543//////////////////////////////////
544genrule {
545 name: "plat_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900546 srcs: [
547 ":plat_sepolicy.cil",
548 ":plat_mapping_file",
549 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900550 out: ["plat_sepolicy_and_mapping.sha256"],
551 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
552}
553
554prebuilt_etc {
555 name: "plat_sepolicy_and_mapping.sha256",
556 filename: "plat_sepolicy_and_mapping.sha256",
557 src: ":plat_sepolicy_and_mapping.sha256_gen",
558 relative_install_path: "selinux",
559}
560
561genrule {
562 name: "system_ext_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900563 srcs: [
564 ":system_ext_sepolicy.cil",
565 ":system_ext_mapping_file",
566 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900567 out: ["system_ext_sepolicy_and_mapping.sha256"],
568 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
569}
570
571prebuilt_etc {
572 name: "system_ext_sepolicy_and_mapping.sha256",
573 filename: "system_ext_sepolicy_and_mapping.sha256",
574 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
575 relative_install_path: "selinux",
576 system_ext_specific: true,
577}
578
579genrule {
580 name: "product_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900581 srcs: [
582 ":product_sepolicy.cil",
583 ":product_mapping_file",
584 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900585 out: ["product_sepolicy_and_mapping.sha256"],
586 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
587}
588
589prebuilt_etc {
590 name: "product_sepolicy_and_mapping.sha256",
591 filename: "product_sepolicy_and_mapping.sha256",
592 src: ":product_sepolicy_and_mapping.sha256_gen",
593 relative_install_path: "selinux",
594 product_specific: true,
595}
596
Inseob Kim1c056b12021-04-30 00:11:43 +0900597sepolicy_vers {
598 name: "plat_sepolicy_vers.txt",
599 version: "vendor",
600 vendor: true,
601}
602
Inseob Kim731182a2021-05-06 11:44:37 +0000603soong_config_module_type {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900604 name: "precompiled_sepolicy_prebuilts_defaults",
Inseob Kim731182a2021-05-06 11:44:37 +0000605 module_type: "prebuilt_defaults",
606 config_namespace: "ANDROID",
607 bool_variables: ["BOARD_USES_ODMIMAGE"],
Inseob Kimff2018f2024-04-17 09:48:43 +0900608 properties: [
609 "vendor",
610 "device_specific",
611 ],
Inseob Kim731182a2021-05-06 11:44:37 +0000612}
613
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900614precompiled_sepolicy_prebuilts_defaults {
615 name: "precompiled_sepolicy_prebuilts",
Inseob Kim731182a2021-05-06 11:44:37 +0000616 soong_config_variables: {
617 BOARD_USES_ODMIMAGE: {
618 device_specific: true,
619 conditions_default: {
620 vendor: true,
621 },
622 },
623 },
624}
625
626//////////////////////////////////
627// SHA-256 digest of the plat_sepolicy.cil and plat_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.plat_sepolicy_and_mapping.sha256",
633 filename: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
634 src: ":plat_sepolicy_and_mapping.sha256_gen",
635 relative_install_path: "selinux",
636}
637
638//////////////////////////////////
639// SHA-256 digest of the system_ext_sepolicy.cil and system_ext_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.system_ext_sepolicy_and_mapping.sha256",
645 filename: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
646 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
647 relative_install_path: "selinux",
648}
649
650//////////////////////////////////
651// SHA-256 digest of the product_sepolicy.cil and product_mapping_file against
652// which precompiled_policy was built.
653//////////////////////////////////
654prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900655 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000656 name: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
657 filename: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
658 src: ":product_sepolicy_and_mapping.sha256_gen",
659 relative_install_path: "selinux",
660}
661
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900662soong_config_module_type {
663 name: "precompiled_se_policy_binary",
664 module_type: "se_policy_binary",
665 config_namespace: "ANDROID",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900666 bool_variables: ["BOARD_USES_ODMIMAGE"],
Inseob Kimff2018f2024-04-17 09:48:43 +0900667 properties: [
668 "vendor",
669 "device_specific",
670 ],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900671}
672
Garfield Tand8c51f22023-10-02 14:17:04 -0700673filegroup {
674 name: "precompiled_sepolicy_srcs",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900675 srcs: [
676 ":plat_sepolicy.cil",
Sandro143988d2022-08-05 11:38:56 +0000677 ":plat_pub_versioned.cil",
678 ":system_ext_sepolicy.cil",
679 ":product_sepolicy.cil",
680 ":vendor_sepolicy.cil",
681 ":odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900682 ":plat_mapping_file",
683 ":system_ext_mapping_file",
684 ":product_mapping_file",
Sandro143988d2022-08-05 11:38:56 +0000685 ],
Garfield Tand8c51f22023-10-02 14:17:04 -0700686 // Make precompiled_sepolicy_srcs as public so that OEMs have access to them.
687 // Useful when some partitions need to be bind mounted across VM boundaries.
688 visibility: ["//visibility:public"],
689}
690
691precompiled_se_policy_binary {
692 name: "precompiled_sepolicy",
693 srcs: [
694 ":precompiled_sepolicy_srcs",
695 ],
Sandro143988d2022-08-05 11:38:56 +0000696 soong_config_variables: {
697 BOARD_USES_ODMIMAGE: {
698 device_specific: true,
699 conditions_default: {
700 vendor: true,
701 },
702 },
Sandro143988d2022-08-05 11:38:56 +0000703 },
704 required: [
705 "sepolicy_neverallows",
Sandro143988d2022-08-05 11:38:56 +0000706 ],
707 dist: {
708 targets: ["base-sepolicy-files-for-mapping"],
709 },
710}
711
Inseob Kim5bbcd682021-12-28 14:57:03 +0900712// policy for recovery
713se_policy_conf {
714 name: "recovery_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900715 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900716 srcs: plat_public_policy +
717 plat_private_policy +
718 system_ext_public_policy +
719 system_ext_private_policy +
720 product_public_policy +
721 product_private_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900722 ":se_build_files{.plat_vendor}",
723 ":se_build_files{.vendor}",
724 ":se_build_files{.odm}",
725 ],
Inseob Kim5bbcd682021-12-28 14:57:03 +0900726 target_recovery: true,
727 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900728 recovery: true,
Inseob Kim5bbcd682021-12-28 14:57:03 +0900729}
730
731se_policy_cil {
732 name: "recovery_sepolicy.cil",
733 src: ":recovery_sepolicy.conf",
734 secilc_check: false, // will be done in se_policy_binary module
735 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900736 recovery: true,
Inseob Kim5bbcd682021-12-28 14:57:03 +0900737}
738
739se_policy_binary {
740 name: "sepolicy.recovery",
741 srcs: [":recovery_sepolicy.cil"],
742 stem: "sepolicy",
743 recovery: true,
744}
745
Inseob Kima49e7242021-03-22 10:26:13 +0900746//////////////////////////////////
747// SELinux policy embedded into CTS.
748// CTS checks neverallow rules of this policy against the policy of the device under test.
749//////////////////////////////////
750se_policy_conf {
751 name: "general_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900752 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900753 srcs: plat_public_policy +
754 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900755 build_variant: "user",
756 cts: true,
757 exclude_build_test: true,
Inseob Kim4b9929e2024-03-28 17:52:32 +0900758 dist: {
759 targets: ["sepolicy_finalize"],
760 },
Inseob Kima49e7242021-03-22 10:26:13 +0900761}
Inseob Kimd5816612021-09-15 03:01:05 +0000762
763//////////////////////////////////
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000764// Base system policy for treble sepolicy tests.
765// If system sepolicy is extended (e.g. by SoC vendors), their plat_pub_versioned.cil may differ
766// with system/sepolicy/prebuilts/api/{version}/plat_pub_versioned.cil. In that case,
767// BOARD_PLAT_PUB_VERSIONED_POLICY can be used to specify extended plat_pub_versioned.cil.
768// See treble_sepolicy_tests_for_release.mk for more details.
769//////////////////////////////////
770se_policy_conf {
771 name: "base_plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900772 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900773 srcs: plat_public_policy +
774 plat_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000775 build_variant: "user",
776 installable: false,
777}
778
779se_policy_cil {
780 name: "base_plat_sepolicy.cil",
781 src: ":base_plat_sepolicy.conf",
782 additional_cil_files: ["private/technical_debt.cil"],
783 installable: false,
784 secilc_check: false, // done by se_policy_binary
785}
786
787se_policy_binary {
788 name: "base_plat_sepolicy",
789 srcs: [":base_plat_sepolicy.cil"],
790 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900791 dist: {
792 targets: ["base-sepolicy-files-for-mapping"],
793 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000794}
795
796se_policy_conf {
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000797 name: "base_product_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900798 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900799 srcs: plat_public_policy +
800 plat_private_policy +
801 system_ext_public_policy +
802 system_ext_private_policy +
803 product_public_policy +
804 product_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000805 build_variant: "user",
806 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900807 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000808}
809
810se_policy_cil {
811 name: "base_product_sepolicy.cil",
812 src: ":base_product_sepolicy.conf",
813 additional_cil_files: ["private/technical_debt.cil"],
814 product_specific: true,
815 installable: false,
816 secilc_check: false, // done by se_policy_binary
817}
818
819se_policy_binary {
820 name: "base_product_sepolicy",
821 srcs: [":base_product_sepolicy.cil"],
822 product_specific: true,
823 installable: false,
824}
825
826se_policy_conf {
827 name: "base_plat_pub_policy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900828 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900829 srcs: plat_public_policy +
830 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000831 build_variant: "user",
832 installable: false,
833}
834
835se_policy_cil {
836 name: "base_plat_pub_policy.cil",
837 src: ":base_plat_pub_policy.conf",
838 filter_out: [":reqd_policy_mask.cil"],
839 secilc_check: false,
840 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900841 dist: {
842 targets: ["base-sepolicy-files-for-mapping"],
843 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000844}
845
846se_policy_conf {
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000847 name: "base_product_pub_policy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900848 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900849 srcs: plat_public_policy +
850 system_ext_public_policy +
851 product_public_policy +
852 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000853 build_variant: "user",
854 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900855 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000856}
857
858se_policy_cil {
859 name: "base_product_pub_policy.cil",
860 src: ":base_product_pub_policy.conf",
861 filter_out: [":reqd_policy_mask.cil"],
862 secilc_check: false,
863 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900864 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000865}
866
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800867// bug_map - Bug tracking information for selinux denials loaded by auditd.
Inseob Kim41964032022-04-22 07:50:22 +0900868se_build_files {
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800869 name: "bug_map_files",
870 srcs: ["bug_map"],
871}
872
873se_bug_map {
874 name: "plat_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900875 srcs: [":bug_map_files{.plat_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800876 stem: "bug_map",
877}
878
879se_bug_map {
880 name: "system_ext_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900881 srcs: [":bug_map_files{.system_ext_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800882 stem: "bug_map",
883 system_ext_specific: true,
884}
885
886se_bug_map {
887 name: "vendor_bug_map",
Inseob Kimff2018f2024-04-17 09:48:43 +0900888 srcs: [
889 ":bug_map_files{.vendor}",
890 ":bug_map_files{.plat_vendor}",
891 ],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800892 // Legacy file name of the vendor partition bug_map.
893 stem: "selinux_denial_metadata",
894 vendor: true,
895}
896
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900897se_neverallow_test {
898 name: "sepolicy_neverallows",
Inseob Kim085f22f2023-11-09 11:13:01 +0900899 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900900 srcs: plat_public_policy +
901 plat_private_policy +
902 system_ext_public_policy +
903 system_ext_private_policy +
904 product_public_policy +
Inseob Kim6c6aa012023-08-31 16:47:38 +0900905 product_private_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900906 ":se_build_files{.plat_vendor}",
907 ":se_build_files{.vendor}",
908 ":se_build_files{.odm}",
909 ],
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900910}
911
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000912//////////////////////////////////
Inseob Kimd5816612021-09-15 03:01:05 +0000913// se_freeze_test compares the plat sepolicy with the prebuilt sepolicy
914// Additional directories can be specified via Makefile variables:
915// SEPOLICY_FREEZE_TEST_EXTRA_DIRS and SEPOLICY_FREEZE_TEST_EXTRA_PREBUILT_DIRS.
916//////////////////////////////////
917se_freeze_test {
Inseob Kim36d9d392023-09-04 17:40:03 +0900918 name: "se_freeze_test",
Inseob Kimd5816612021-09-15 03:01:05 +0000919}
Inseob Kim61257ca2022-02-25 11:26:16 +0900920
921//////////////////////////////////
922// sepolicy_test checks various types of violations, which can't be easily done
923// by CIL itself. Refer tests/sepolicy_tests.py for more detail.
924//////////////////////////////////
925genrule {
926 name: "sepolicy_test",
927 srcs: [
928 ":plat_file_contexts",
929 ":vendor_file_contexts",
930 ":system_ext_file_contexts",
931 ":product_file_contexts",
932 ":odm_file_contexts",
933 ":precompiled_sepolicy",
934 ],
935 tools: ["sepolicy_tests"],
936 out: ["sepolicy_test"],
937 cmd: "$(location sepolicy_tests) " +
938 "-f $(location :plat_file_contexts) " +
939 "-f $(location :vendor_file_contexts) " +
940 "-f $(location :system_ext_file_contexts) " +
941 "-f $(location :product_file_contexts) " +
942 "-f $(location :odm_file_contexts) " +
943 "-p $(location :precompiled_sepolicy) && " +
944 "touch $(out)",
945}
Inseob Kim3a9d91c2023-09-27 17:39:07 +0900946
947//////////////////////////////////
948// TestDevTypeViolations can't run on old devices (V or before)
949//////////////////////////////////
950
951soong_config_module_type {
952 name: "dev_type_test_genrule",
953 module_type: "genrule",
954 config_namespace: "ANDROID",
955 bool_variables: ["CHECK_DEV_TYPE_VIOLATIONS"],
956 properties: ["cmd"],
957}
958
959dev_type_test_genrule {
960 name: "sepolicy_dev_type_test",
961 srcs: [
962 ":plat_file_contexts",
963 ":vendor_file_contexts",
964 ":system_ext_file_contexts",
965 ":product_file_contexts",
966 ":odm_file_contexts",
967 ":precompiled_sepolicy",
968 ],
969 tools: ["sepolicy_tests"],
970 out: ["sepolicy_dev_type_test"],
971 soong_config_variables: {
972 CHECK_DEV_TYPE_VIOLATIONS: {
973 cmd: "$(location sepolicy_tests) " +
974 "-f $(location :plat_file_contexts) " +
975 "-f $(location :vendor_file_contexts) " +
976 "-f $(location :system_ext_file_contexts) " +
977 "-f $(location :product_file_contexts) " +
978 "-f $(location :odm_file_contexts) " +
979 "-p $(location :precompiled_sepolicy) " +
980 "-t TestDevTypeViolations && " +
981 "touch $(out)",
982 conditions_default: {
983 cmd: "touch $(out)",
984 },
985 },
986 },
987}