blob: 6c8fa2a57a693a974911a1a5628e5e32de85ba99 [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
Jeff Vander Stoepecd288f2019-02-15 12:18:15 -080045cc_defaults { name: "selinux_policy_version", cflags: ["-DSEPOLICY_VERSION=30"], }
46
yangbill3e345372020-04-15 13:55:47 +080047// For vts_treble_sys_prop_test
48filegroup {
49 name: "private_property_contexts",
50 srcs: ["private/property_contexts"],
51 visibility: [
52 "//test/vts-testcase/security/system_property",
53 ],
54}
Inseob Kime35b49b2021-02-18 19:15:41 +090055
Inseob Kima49e7242021-03-22 10:26:13 +090056se_build_files {
57 name: "se_build_files",
Inseob Kime35b49b2021-02-18 19:15:41 +090058 srcs: [
Inseob Kima49e7242021-03-22 10:26:13 +090059 "security_classes",
60 "initial_sids",
61 "access_vectors",
62 "global_macros",
63 "neverallow_macros",
64 "mls_macros",
65 "mls_decl",
66 "mls",
67 "policy_capabilities",
68 "te_macros",
69 "attributes",
70 "ioctl_defines",
71 "ioctl_macros",
72 "*.te",
73 "roles_decl",
74 "roles",
75 "users",
76 "initial_sid_contexts",
77 "fs_use",
78 "genfs_contexts",
79 "port_contexts",
Inseob Kime35b49b2021-02-18 19:15:41 +090080 ],
81}
82
Inseob Kim7cb20812021-12-16 16:52:14 +090083se_build_files {
84 name: "sepolicy_technical_debt",
85 srcs: ["technical_debt.cil"],
86}
87
Inseob Kim0a707fa2021-12-09 23:35:11 +090088reqd_mask_policy = [":se_build_files{.reqd_mask}"]
89plat_public_policy = [":se_build_files{.plat_public}"]
90plat_private_policy = [":se_build_files{.plat_private}"]
91system_ext_public_policy = [":se_build_files{.system_ext_public}"]
92system_ext_private_policy = [":se_build_files{.system_ext_private}"]
93product_public_policy = [":se_build_files{.product_public}"]
94product_private_policy = [":se_build_files{.product_private}"]
95
Inseob Kima49e7242021-03-22 10:26:13 +090096// reqd_policy_mask - a policy.conf file which contains only the bare minimum
97// policy necessary to use checkpolicy.
98//
99// This bare-minimum policy needs to be present in all policy.conf files, but
100// should not necessarily be exported as part of the public policy.
101//
102// The rules generated by reqd_policy_mask will allow the compilation of public
103// policy and subsequent removal of CIL policy that should not be exported.
104se_policy_conf {
105 name: "reqd_policy_mask.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900106 srcs: reqd_mask_policy,
Inseob Kime35b49b2021-02-18 19:15:41 +0900107 installable: false,
108}
109
Inseob Kima49e7242021-03-22 10:26:13 +0900110se_policy_cil {
111 name: "reqd_policy_mask.cil",
112 src: ":reqd_policy_mask.conf",
113 secilc_check: false,
114 installable: false,
Inseob Kime35b49b2021-02-18 19:15:41 +0900115}
116
Inseob Kima49e7242021-03-22 10:26:13 +0900117// pub_policy - policy that will be exported to be a part of non-platform
118// policy corresponding to this platform version.
119//
120// This is a limited subset of policy that would not compile in checkpolicy on
121// its own.
122//
123// To get around this limitation, add only the required files from private
124// policy, which will generate CIL policy that will then be filtered out by the
125// reqd_policy_mask.
126//
127// There are three pub_policy.cil files below:
128// - pub_policy.cil: exported 'product', 'system_ext' and 'system' policy.
129// - system_ext_pub_policy.cil: exported 'system_ext' and 'system' policy.
130// - plat_pub_policy.cil: exported 'system' policy.
131//
132// Those above files will in turn be used to generate the following versioned cil files:
133// - product_mapping_file: the versioned, exported 'product' policy in product partition.
134// - system_ext_mapping_file: the versioned, exported 'system_ext' policy in system_ext partition.
135// - plat_mapping_file: the versioned, exported 'system' policy in system partition.
136// - plat_pub_versioned.cil: the versioned, exported 'product', 'system_ext' and 'system' policy
137// in vendor partition.
138//
139se_policy_conf {
140 name: "pub_policy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900141 srcs: plat_public_policy +
142 system_ext_public_policy +
143 product_public_policy +
144 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900145 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900146 installable: false,
147}
148
149se_policy_cil {
150 name: "pub_policy.cil",
151 src: ":pub_policy.conf",
152 filter_out: [":reqd_policy_mask.cil"],
153 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900154 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900155 installable: false,
156}
157
158se_policy_conf {
159 name: "system_ext_pub_policy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900160 srcs: plat_public_policy +
161 system_ext_public_policy +
162 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900163 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900164 installable: false,
165}
166
167se_policy_cil {
168 name: "system_ext_pub_policy.cil",
169 src: ":system_ext_pub_policy.conf",
170 filter_out: [":reqd_policy_mask.cil"],
171 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900172 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900173 installable: false,
174}
175
176se_policy_conf {
177 name: "plat_pub_policy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900178 srcs: plat_public_policy +
179 reqd_mask_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900180 installable: false,
181}
182
183se_policy_cil {
184 name: "plat_pub_policy.cil",
185 src: ":plat_pub_policy.conf",
186 filter_out: [":reqd_policy_mask.cil"],
187 secilc_check: false,
188 installable: false,
189}
190
191// plat_policy.conf - A combination of the private and public platform policy
192// which will ship with the device.
193//
194// The platform will always reflect the most recent platform version and is not
195// currently being attributized.
196se_policy_conf {
197 name: "plat_sepolicy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900198 srcs: plat_public_policy +
199 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900200 installable: false,
201}
202
203se_policy_cil {
204 name: "plat_sepolicy.cil",
205 src: ":plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900206 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kima49e7242021-03-22 10:26:13 +0900207}
208
Lokesh Gidra1269a172022-08-01 17:20:38 +0000209
Inseob Kim6cc75f42021-04-29 13:53:20 +0000210// userdebug_plat_policy.conf - the userdebug version plat_sepolicy.cil
211se_policy_conf {
212 name: "userdebug_plat_sepolicy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900213 srcs: plat_public_policy +
214 plat_private_policy,
Inseob Kim6cc75f42021-04-29 13:53:20 +0000215 build_variant: "userdebug",
216 installable: false,
217}
218
219se_policy_cil {
220 name: "userdebug_plat_sepolicy.cil",
221 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900222 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kim6cc75f42021-04-29 13:53:20 +0000223 debug_ramdisk: true,
Yi-Yo Chiang68478b12021-10-16 03:23:05 +0800224 dist: {
225 targets: ["droidcore"],
226 },
Inseob Kim6cc75f42021-04-29 13:53:20 +0000227}
228
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000229// A copy of the userdebug_plat_policy in GSI.
230soong_config_module_type {
231 name: "gsi_se_policy_cil",
232 module_type: "se_policy_cil",
233 config_namespace: "ANDROID",
234 bool_variables: [
235 "PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT",
236 ],
237 properties: [
238 "enabled",
239 "installable",
240 ],
241}
242
243gsi_se_policy_cil {
244 name: "system_ext_userdebug_plat_sepolicy.cil",
245 stem: "userdebug_plat_sepolicy.cil",
246 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900247 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000248 system_ext_specific: true,
249 enabled: false,
250 installable: false,
251 soong_config_variables: {
252 PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT: {
253 enabled: true,
254 installable: true,
255 },
256 },
257}
258
Inseob Kima49e7242021-03-22 10:26:13 +0900259// system_ext_policy.conf - A combination of the private and public system_ext
260// policy which will ship with the device. System_ext policy is not attributized
261se_policy_conf {
262 name: "system_ext_sepolicy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900263 srcs: plat_public_policy +
264 plat_private_policy +
265 system_ext_public_policy +
266 system_ext_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900267 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900268 installable: false,
269}
270
271se_policy_cil {
272 name: "system_ext_sepolicy.cil",
273 src: ":system_ext_sepolicy.conf",
274 system_ext_specific: true,
275 filter_out: [":plat_sepolicy.cil"],
276 remove_line_marker: true,
277}
278
279// product_policy.conf - A combination of the private and public product policy
280// which will ship with the device. Product policy is not attributized
281se_policy_conf {
282 name: "product_sepolicy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900283 srcs: plat_public_policy +
284 plat_private_policy +
285 system_ext_public_policy +
286 system_ext_private_policy +
287 product_public_policy +
288 product_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900289 product_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900290 installable: false,
291}
292
293se_policy_cil {
294 name: "product_sepolicy.cil",
295 src: ":product_sepolicy.conf",
296 product_specific: true,
297 filter_out: [":plat_sepolicy.cil", ":system_ext_sepolicy.cil"],
298 remove_line_marker: true,
299}
300
Inseob Kim039175b2021-03-25 15:37:34 +0900301// policy mapping files
302// auto-generate the mapping file for current platform policy, since it needs to
303// track platform policy development
304se_versioned_policy {
305 name: "plat_mapping_file",
306 base: ":plat_pub_policy.cil",
307 mapping: true,
308 version: "current",
309 relative_install_path: "mapping", // install to /system/etc/selinux/mapping
310}
311
312se_versioned_policy {
313 name: "system_ext_mapping_file",
314 base: ":system_ext_pub_policy.cil",
315 mapping: true,
316 version: "current",
317 filter_out: [":plat_mapping_file"],
318 relative_install_path: "mapping", // install to /system_ext/etc/selinux/mapping
319 system_ext_specific: true,
320}
321
322se_versioned_policy {
323 name: "product_mapping_file",
324 base: ":pub_policy.cil",
325 mapping: true,
326 version: "current",
327 filter_out: [":plat_mapping_file", ":system_ext_mapping_file"],
328 relative_install_path: "mapping", // install to /product/etc/selinux/mapping
329 product_specific: true,
330}
331
Inseob Kim6c6aa012023-08-31 16:47:38 +0900332//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900333// vendor/odm sepolicy
Inseob Kim6c6aa012023-08-31 16:47:38 +0900334//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900335
Inseob Kim039175b2021-03-25 15:37:34 +0900336// plat_pub_versioned.cil - the exported platform policy associated with the version
337// that non-platform policy targets.
338se_versioned_policy {
339 name: "plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900340 base: ":pub_policy.cil",
341 target_policy: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900342 version: "vendor",
Inseob Kim039175b2021-03-25 15:37:34 +0900343 vendor: true,
344}
345
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900346// vendor_policy.cil - the vendor sepolicy. This needs attributization and to be combined
347// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
348// policy and the platform public policy files in order to use checkpolicy.
349se_policy_conf {
350 name: "vendor_sepolicy.conf",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900351 srcs: plat_public_policy +
352 system_ext_public_policy +
353 product_public_policy +
354 reqd_mask_policy + [
355 ":se_build_files{.plat_vendor}",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900356 ":se_build_files{.vendor}",
357 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900358 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900359 installable: false,
360}
361
362se_policy_cil {
363 name: "vendor_sepolicy.cil.raw",
364 src: ":vendor_sepolicy.conf",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900365 filter_out: [":reqd_policy_mask.cil"],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900366 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900367 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900368 installable: false,
369}
370
371se_versioned_policy {
372 name: "vendor_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900373 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900374 target_policy: ":vendor_sepolicy.cil.raw",
375 version: "vendor",
376 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900377 ":plat_sepolicy.cil",
378 ":system_ext_sepolicy.cil",
379 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900380 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900381 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900382 ],
383 filter_out: [":plat_pub_versioned.cil"],
384 vendor: true,
385}
386
387// odm_policy.cil - the odl sepolicy. This needs attributization and to be combined
388// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
389// policy and the platform public policy files in order to use checkpolicy.
390se_policy_conf {
391 name: "odm_sepolicy.conf",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900392 srcs: plat_public_policy +
393 system_ext_public_policy +
394 product_public_policy +
395 reqd_mask_policy + [
396 ":se_build_files{.plat_vendor}",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900397 ":se_build_files{.vendor}",
398 ":se_build_files{.odm}",
399 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900400 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900401 installable: false,
402}
403
404se_policy_cil {
405 name: "odm_sepolicy.cil.raw",
406 src: ":odm_sepolicy.conf",
407 filter_out: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900408 ":reqd_policy_mask.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900409 ":vendor_sepolicy.cil",
410 ],
411 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900412 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900413 installable: false,
414}
415
416se_versioned_policy {
417 name: "odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900418 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900419 target_policy: ":odm_sepolicy.cil.raw",
420 version: "vendor",
421 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900422 ":plat_sepolicy.cil",
423 ":system_ext_sepolicy.cil",
424 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900425 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900426 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900427 ":vendor_sepolicy.cil",
428 ],
429 filter_out: [":plat_pub_versioned.cil", ":vendor_sepolicy.cil"],
430 device_specific: true,
431}
432
Inseob Kim039175b2021-03-25 15:37:34 +0900433//////////////////////////////////
434// Precompiled sepolicy is loaded if and only if:
435// - plat_sepolicy_and_mapping.sha256 equals
436// precompiled_sepolicy.plat_sepolicy_and_mapping.sha256
437// AND
438// - system_ext_sepolicy_and_mapping.sha256 equals
439// precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256
440// AND
441// - product_sepolicy_and_mapping.sha256 equals
442// precompiled_sepolicy.product_sepolicy_and_mapping.sha256
443// See system/core/init/selinux.cpp for details.
444//////////////////////////////////
445genrule {
446 name: "plat_sepolicy_and_mapping.sha256_gen",
447 srcs: [":plat_sepolicy.cil", ":plat_mapping_file"],
448 out: ["plat_sepolicy_and_mapping.sha256"],
449 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
450}
451
452prebuilt_etc {
453 name: "plat_sepolicy_and_mapping.sha256",
454 filename: "plat_sepolicy_and_mapping.sha256",
455 src: ":plat_sepolicy_and_mapping.sha256_gen",
456 relative_install_path: "selinux",
457}
458
459genrule {
460 name: "system_ext_sepolicy_and_mapping.sha256_gen",
461 srcs: [":system_ext_sepolicy.cil", ":system_ext_mapping_file"],
462 out: ["system_ext_sepolicy_and_mapping.sha256"],
463 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
464}
465
466prebuilt_etc {
467 name: "system_ext_sepolicy_and_mapping.sha256",
468 filename: "system_ext_sepolicy_and_mapping.sha256",
469 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
470 relative_install_path: "selinux",
471 system_ext_specific: true,
472}
473
474genrule {
475 name: "product_sepolicy_and_mapping.sha256_gen",
476 srcs: [":product_sepolicy.cil", ":product_mapping_file"],
477 out: ["product_sepolicy_and_mapping.sha256"],
478 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
479}
480
481prebuilt_etc {
482 name: "product_sepolicy_and_mapping.sha256",
483 filename: "product_sepolicy_and_mapping.sha256",
484 src: ":product_sepolicy_and_mapping.sha256_gen",
485 relative_install_path: "selinux",
486 product_specific: true,
487}
488
Inseob Kim1c056b12021-04-30 00:11:43 +0900489sepolicy_vers {
490 name: "plat_sepolicy_vers.txt",
491 version: "vendor",
492 vendor: true,
493}
494
Inseob Kim731182a2021-05-06 11:44:37 +0000495soong_config_module_type {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900496 name: "precompiled_sepolicy_prebuilts_defaults",
Inseob Kim731182a2021-05-06 11:44:37 +0000497 module_type: "prebuilt_defaults",
498 config_namespace: "ANDROID",
499 bool_variables: ["BOARD_USES_ODMIMAGE"],
500 properties: ["vendor", "device_specific"],
501}
502
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900503precompiled_sepolicy_prebuilts_defaults {
504 name: "precompiled_sepolicy_prebuilts",
Inseob Kim731182a2021-05-06 11:44:37 +0000505 soong_config_variables: {
506 BOARD_USES_ODMIMAGE: {
507 device_specific: true,
508 conditions_default: {
509 vendor: true,
510 },
511 },
512 },
513}
514
515//////////////////////////////////
516// SHA-256 digest of the plat_sepolicy.cil and plat_mapping_file against
517// which precompiled_policy was built.
518//////////////////////////////////
519prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900520 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000521 name: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
522 filename: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
523 src: ":plat_sepolicy_and_mapping.sha256_gen",
524 relative_install_path: "selinux",
525}
526
527//////////////////////////////////
528// SHA-256 digest of the system_ext_sepolicy.cil and system_ext_mapping_file against
529// which precompiled_policy was built.
530//////////////////////////////////
531prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900532 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000533 name: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
534 filename: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
535 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
536 relative_install_path: "selinux",
537}
538
539//////////////////////////////////
540// SHA-256 digest of the product_sepolicy.cil and product_mapping_file against
541// which precompiled_policy was built.
542//////////////////////////////////
543prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900544 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000545 name: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
546 filename: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
547 src: ":product_sepolicy_and_mapping.sha256_gen",
548 relative_install_path: "selinux",
549}
550
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900551soong_config_module_type {
552 name: "precompiled_se_policy_binary",
553 module_type: "se_policy_binary",
554 config_namespace: "ANDROID",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900555 bool_variables: ["BOARD_USES_ODMIMAGE"],
556 properties: ["vendor", "device_specific"],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900557}
558
Garfield Tand8c51f22023-10-02 14:17:04 -0700559filegroup {
560 name: "precompiled_sepolicy_srcs",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900561 srcs: [
562 ":plat_sepolicy.cil",
Sandro143988d2022-08-05 11:38:56 +0000563 ":plat_pub_versioned.cil",
564 ":system_ext_sepolicy.cil",
565 ":product_sepolicy.cil",
566 ":vendor_sepolicy.cil",
567 ":odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900568 ":plat_mapping_file",
569 ":system_ext_mapping_file",
570 ":product_mapping_file",
Sandro143988d2022-08-05 11:38:56 +0000571 ],
Garfield Tand8c51f22023-10-02 14:17:04 -0700572 // Make precompiled_sepolicy_srcs as public so that OEMs have access to them.
573 // Useful when some partitions need to be bind mounted across VM boundaries.
574 visibility: ["//visibility:public"],
575}
576
577precompiled_se_policy_binary {
578 name: "precompiled_sepolicy",
579 srcs: [
580 ":precompiled_sepolicy_srcs",
581 ],
Sandro143988d2022-08-05 11:38:56 +0000582 soong_config_variables: {
583 BOARD_USES_ODMIMAGE: {
584 device_specific: true,
585 conditions_default: {
586 vendor: true,
587 },
588 },
Sandro143988d2022-08-05 11:38:56 +0000589 },
590 required: [
591 "sepolicy_neverallows",
Sandro143988d2022-08-05 11:38:56 +0000592 ],
593 dist: {
594 targets: ["base-sepolicy-files-for-mapping"],
595 },
596}
597
Inseob Kim5bbcd682021-12-28 14:57:03 +0900598// policy for recovery
599se_policy_conf {
600 name: "recovery_sepolicy.conf",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900601 srcs: plat_public_policy +
602 plat_private_policy +
603 system_ext_public_policy +
604 system_ext_private_policy +
605 product_public_policy +
606 product_private_policy + [
607 ":se_build_files{.plat_vendor}",
Inseob Kim5bbcd682021-12-28 14:57:03 +0900608 ":se_build_files{.vendor}",
609 ":se_build_files{.odm}",
610 ],
611 target_recovery: true,
612 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900613 recovery: true,
Inseob Kim5bbcd682021-12-28 14:57:03 +0900614}
615
616se_policy_cil {
617 name: "recovery_sepolicy.cil",
618 src: ":recovery_sepolicy.conf",
619 secilc_check: false, // will be done in se_policy_binary module
620 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900621 recovery: true,
Inseob Kim5bbcd682021-12-28 14:57:03 +0900622}
623
624se_policy_binary {
625 name: "sepolicy.recovery",
626 srcs: [":recovery_sepolicy.cil"],
627 stem: "sepolicy",
628 recovery: true,
629}
630
Inseob Kima49e7242021-03-22 10:26:13 +0900631//////////////////////////////////
632// SELinux policy embedded into CTS.
633// CTS checks neverallow rules of this policy against the policy of the device under test.
634//////////////////////////////////
635se_policy_conf {
636 name: "general_sepolicy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900637 srcs: plat_public_policy +
638 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900639 build_variant: "user",
640 cts: true,
641 exclude_build_test: true,
642}
Inseob Kimd5816612021-09-15 03:01:05 +0000643
644//////////////////////////////////
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000645// Base system policy for treble sepolicy tests.
646// If system sepolicy is extended (e.g. by SoC vendors), their plat_pub_versioned.cil may differ
647// with system/sepolicy/prebuilts/api/{version}/plat_pub_versioned.cil. In that case,
648// BOARD_PLAT_PUB_VERSIONED_POLICY can be used to specify extended plat_pub_versioned.cil.
649// See treble_sepolicy_tests_for_release.mk for more details.
650//////////////////////////////////
651se_policy_conf {
652 name: "base_plat_sepolicy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900653 srcs: plat_public_policy +
654 plat_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000655 build_variant: "user",
656 installable: false,
657}
658
659se_policy_cil {
660 name: "base_plat_sepolicy.cil",
661 src: ":base_plat_sepolicy.conf",
662 additional_cil_files: ["private/technical_debt.cil"],
663 installable: false,
664 secilc_check: false, // done by se_policy_binary
665}
666
667se_policy_binary {
668 name: "base_plat_sepolicy",
669 srcs: [":base_plat_sepolicy.cil"],
670 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900671 dist: {
672 targets: ["base-sepolicy-files-for-mapping"],
673 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000674}
675
676se_policy_conf {
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000677 name: "base_product_sepolicy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900678 srcs: plat_public_policy +
679 plat_private_policy +
680 system_ext_public_policy +
681 system_ext_private_policy +
682 product_public_policy +
683 product_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000684 build_variant: "user",
685 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900686 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000687}
688
689se_policy_cil {
690 name: "base_product_sepolicy.cil",
691 src: ":base_product_sepolicy.conf",
692 additional_cil_files: ["private/technical_debt.cil"],
693 product_specific: true,
694 installable: false,
695 secilc_check: false, // done by se_policy_binary
696}
697
698se_policy_binary {
699 name: "base_product_sepolicy",
700 srcs: [":base_product_sepolicy.cil"],
701 product_specific: true,
702 installable: false,
703}
704
705se_policy_conf {
706 name: "base_plat_pub_policy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900707 srcs: plat_public_policy +
708 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000709 build_variant: "user",
710 installable: false,
711}
712
713se_policy_cil {
714 name: "base_plat_pub_policy.cil",
715 src: ":base_plat_pub_policy.conf",
716 filter_out: [":reqd_policy_mask.cil"],
717 secilc_check: false,
718 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900719 dist: {
720 targets: ["base-sepolicy-files-for-mapping"],
721 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000722}
723
724se_policy_conf {
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000725 name: "base_product_pub_policy.conf",
Inseob Kim0a707fa2021-12-09 23:35:11 +0900726 srcs: plat_public_policy +
727 system_ext_public_policy +
728 product_public_policy +
729 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000730 build_variant: "user",
731 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900732 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000733}
734
735se_policy_cil {
736 name: "base_product_pub_policy.cil",
737 src: ":base_product_pub_policy.conf",
738 filter_out: [":reqd_policy_mask.cil"],
739 secilc_check: false,
740 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900741 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000742}
743
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800744// bug_map - Bug tracking information for selinux denials loaded by auditd.
Inseob Kim41964032022-04-22 07:50:22 +0900745se_build_files {
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800746 name: "bug_map_files",
747 srcs: ["bug_map"],
748}
749
750se_bug_map {
751 name: "plat_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900752 srcs: [":bug_map_files{.plat_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800753 stem: "bug_map",
754}
755
756se_bug_map {
757 name: "system_ext_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900758 srcs: [":bug_map_files{.system_ext_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800759 stem: "bug_map",
760 system_ext_specific: true,
761}
762
763se_bug_map {
764 name: "vendor_bug_map",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900765 srcs: [":bug_map_files{.vendor}", ":bug_map_files{.plat_vendor}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800766 // Legacy file name of the vendor partition bug_map.
767 stem: "selinux_denial_metadata",
768 vendor: true,
769}
770
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900771se_neverallow_test {
772 name: "sepolicy_neverallows",
773 srcs: plat_public_policy +
774 plat_private_policy +
775 system_ext_public_policy +
776 system_ext_private_policy +
777 product_public_policy +
Inseob Kim6c6aa012023-08-31 16:47:38 +0900778 product_private_policy + [
779 ":se_build_files{.plat_vendor}",
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900780 ":se_build_files{.vendor}",
781 ":se_build_files{.odm}",
782 ],
783}
784
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000785//////////////////////////////////
Inseob Kimd5816612021-09-15 03:01:05 +0000786// se_freeze_test compares the plat sepolicy with the prebuilt sepolicy
787// Additional directories can be specified via Makefile variables:
788// SEPOLICY_FREEZE_TEST_EXTRA_DIRS and SEPOLICY_FREEZE_TEST_EXTRA_PREBUILT_DIRS.
789//////////////////////////////////
790se_freeze_test {
Inseob Kim36d9d392023-09-04 17:40:03 +0900791 name: "se_freeze_test",
Inseob Kimd5816612021-09-15 03:01:05 +0000792}
Inseob Kim61257ca2022-02-25 11:26:16 +0900793
794//////////////////////////////////
795// sepolicy_test checks various types of violations, which can't be easily done
796// by CIL itself. Refer tests/sepolicy_tests.py for more detail.
797//////////////////////////////////
798genrule {
799 name: "sepolicy_test",
800 srcs: [
801 ":plat_file_contexts",
802 ":vendor_file_contexts",
803 ":system_ext_file_contexts",
804 ":product_file_contexts",
805 ":odm_file_contexts",
806 ":precompiled_sepolicy",
807 ],
808 tools: ["sepolicy_tests"],
809 out: ["sepolicy_test"],
810 cmd: "$(location sepolicy_tests) " +
811 "-f $(location :plat_file_contexts) " +
812 "-f $(location :vendor_file_contexts) " +
813 "-f $(location :system_ext_file_contexts) " +
814 "-f $(location :product_file_contexts) " +
815 "-f $(location :odm_file_contexts) " +
816 "-p $(location :precompiled_sepolicy) && " +
817 "touch $(out)",
818}