blob: 1a2d1efd78cfa40de27c5f14c3fc8277eff1da15 [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",
105 "plat_service_contexts",
106 "secilc",
Cole Faustac1f8152024-06-17 12:39:02 -0700107 "plat_29.0.cil",
108 "29.0.compat.cil",
109 "plat_30.0.cil",
110 "30.0.compat.cil",
111 "plat_31.0.cil",
112 "31.0.compat.cil",
113 "plat_32.0.cil",
114 "32.0.compat.cil",
115 "plat_33.0.cil",
116 "33.0.compat.cil",
117 "plat_34.0.cil",
118 "34.0.compat.cil",
119 ] + select(soong_config_variable("ANDROID", "PLATFORM_SEPOLICY_VERSION"), {
120 "202404": [],
121 default: [
122 "plat_202404.cil",
123 "202404.compat.cil",
124 ],
125 }) + select(soong_config_variable("ANDROID", "PRODUCT_PRECOMPILED_SEPOLICY"), {
126 "true": ["plat_sepolicy_and_mapping.sha256"],
127 default: [],
128 }),
Inseob Kim151562f2024-04-12 10:53:34 +0900129}
130
Inseob Kimff2018f2024-04-17 09:48:43 +0900131reqd_mask_policy = [":se_build_files{.reqd_mask}"]
132plat_public_policy = [":se_build_files{.plat_public}"]
133plat_private_policy = [":se_build_files{.plat_private}"]
134system_ext_public_policy = [":se_build_files{.system_ext_public}"]
Inseob Kim0a707fa2021-12-09 23:35:11 +0900135system_ext_private_policy = [":se_build_files{.system_ext_private}"]
Inseob Kimff2018f2024-04-17 09:48:43 +0900136product_public_policy = [":se_build_files{.product_public}"]
137product_private_policy = [":se_build_files{.product_private}"]
Inseob Kim0a707fa2021-12-09 23:35:11 +0900138
Inseob Kima49e7242021-03-22 10:26:13 +0900139// reqd_policy_mask - a policy.conf file which contains only the bare minimum
140// policy necessary to use checkpolicy.
141//
142// This bare-minimum policy needs to be present in all policy.conf files, but
143// should not necessarily be exported as part of the public policy.
144//
145// The rules generated by reqd_policy_mask will allow the compilation of public
146// policy and subsequent removal of CIL policy that should not be exported.
147se_policy_conf {
148 name: "reqd_policy_mask.conf",
Inseob Kim8697fc82024-04-16 14:45:32 +0900149 defaults: ["se_policy_conf_public_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900150 srcs: reqd_mask_policy,
Inseob Kime35b49b2021-02-18 19:15:41 +0900151 installable: false,
152}
153
Inseob Kima49e7242021-03-22 10:26:13 +0900154se_policy_cil {
155 name: "reqd_policy_mask.cil",
156 src: ":reqd_policy_mask.conf",
157 secilc_check: false,
158 installable: false,
Inseob Kime35b49b2021-02-18 19:15:41 +0900159}
160
Inseob Kima49e7242021-03-22 10:26:13 +0900161// pub_policy - policy that will be exported to be a part of non-platform
162// policy corresponding to this platform version.
163//
164// This is a limited subset of policy that would not compile in checkpolicy on
165// its own.
166//
167// To get around this limitation, add only the required files from private
168// policy, which will generate CIL policy that will then be filtered out by the
169// reqd_policy_mask.
170//
171// There are three pub_policy.cil files below:
172// - pub_policy.cil: exported 'product', 'system_ext' and 'system' policy.
173// - system_ext_pub_policy.cil: exported 'system_ext' and 'system' policy.
174// - plat_pub_policy.cil: exported 'system' policy.
175//
176// Those above files will in turn be used to generate the following versioned cil files:
177// - product_mapping_file: the versioned, exported 'product' policy in product partition.
178// - system_ext_mapping_file: the versioned, exported 'system_ext' policy in system_ext partition.
179// - plat_mapping_file: the versioned, exported 'system' policy in system partition.
180// - plat_pub_versioned.cil: the versioned, exported 'product', 'system_ext' and 'system' policy
181// in vendor partition.
182//
183se_policy_conf {
184 name: "pub_policy.conf",
Inseob Kim8697fc82024-04-16 14:45:32 +0900185 defaults: ["se_policy_conf_public_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900186 srcs: plat_public_policy +
187 system_ext_public_policy +
188 product_public_policy +
189 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900190 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900191 installable: false,
192}
193
194se_policy_cil {
195 name: "pub_policy.cil",
196 src: ":pub_policy.conf",
197 filter_out: [":reqd_policy_mask.cil"],
198 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900199 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900200 installable: false,
201}
202
203se_policy_conf {
204 name: "system_ext_pub_policy.conf",
Inseob Kim8697fc82024-04-16 14:45:32 +0900205 defaults: ["se_policy_conf_public_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900206 srcs: plat_public_policy +
207 system_ext_public_policy +
208 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900209 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900210 installable: false,
211}
212
213se_policy_cil {
214 name: "system_ext_pub_policy.cil",
215 src: ":system_ext_pub_policy.conf",
216 filter_out: [":reqd_policy_mask.cil"],
217 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900218 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900219 installable: false,
220}
221
222se_policy_conf {
223 name: "plat_pub_policy.conf",
Inseob Kim8697fc82024-04-16 14:45:32 +0900224 defaults: ["se_policy_conf_public_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900225 srcs: plat_public_policy +
226 reqd_mask_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900227 installable: false,
228}
229
230se_policy_cil {
231 name: "plat_pub_policy.cil",
232 src: ":plat_pub_policy.conf",
233 filter_out: [":reqd_policy_mask.cil"],
234 secilc_check: false,
235 installable: false,
236}
237
238// plat_policy.conf - A combination of the private and public platform policy
239// which will ship with the device.
240//
241// The platform will always reflect the most recent platform version and is not
242// currently being attributized.
243se_policy_conf {
244 name: "plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900245 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900246 srcs: plat_public_policy +
247 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900248 installable: false,
249}
250
251se_policy_cil {
252 name: "plat_sepolicy.cil",
253 src: ":plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900254 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kim4b9929e2024-03-28 17:52:32 +0900255 dist: {
256 targets: ["sepolicy_finalize"],
257 },
Inseob Kima49e7242021-03-22 10:26:13 +0900258}
259
Inseob Kim6cc75f42021-04-29 13:53:20 +0000260// userdebug_plat_policy.conf - the userdebug version plat_sepolicy.cil
261se_policy_conf {
262 name: "userdebug_plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900263 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900264 srcs: plat_public_policy +
265 plat_private_policy,
Inseob Kim6cc75f42021-04-29 13:53:20 +0000266 build_variant: "userdebug",
267 installable: false,
268}
269
270se_policy_cil {
271 name: "userdebug_plat_sepolicy.cil",
272 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900273 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kim6cc75f42021-04-29 13:53:20 +0000274 debug_ramdisk: true,
Yi-Yo Chiang68478b12021-10-16 03:23:05 +0800275 dist: {
276 targets: ["droidcore"],
277 },
Inseob Kim6cc75f42021-04-29 13:53:20 +0000278}
279
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000280// A copy of the userdebug_plat_policy in GSI.
281soong_config_module_type {
282 name: "gsi_se_policy_cil",
283 module_type: "se_policy_cil",
284 config_namespace: "ANDROID",
285 bool_variables: [
286 "PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT",
287 ],
288 properties: [
289 "enabled",
290 "installable",
291 ],
292}
293
294gsi_se_policy_cil {
295 name: "system_ext_userdebug_plat_sepolicy.cil",
296 stem: "userdebug_plat_sepolicy.cil",
297 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900298 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000299 system_ext_specific: true,
300 enabled: false,
301 installable: false,
302 soong_config_variables: {
303 PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT: {
304 enabled: true,
305 installable: true,
306 },
307 },
308}
309
Inseob Kima49e7242021-03-22 10:26:13 +0900310// system_ext_policy.conf - A combination of the private and public system_ext
311// policy which will ship with the device. System_ext policy is not attributized
312se_policy_conf {
313 name: "system_ext_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900314 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900315 srcs: plat_public_policy +
316 plat_private_policy +
317 system_ext_public_policy +
318 system_ext_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900319 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900320 installable: false,
321}
322
323se_policy_cil {
324 name: "system_ext_sepolicy.cil",
325 src: ":system_ext_sepolicy.conf",
326 system_ext_specific: true,
327 filter_out: [":plat_sepolicy.cil"],
328 remove_line_marker: true,
329}
330
331// product_policy.conf - A combination of the private and public product policy
332// which will ship with the device. Product policy is not attributized
333se_policy_conf {
334 name: "product_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900335 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900336 srcs: plat_public_policy +
337 plat_private_policy +
338 system_ext_public_policy +
339 system_ext_private_policy +
340 product_public_policy +
341 product_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900342 product_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900343 installable: false,
344}
345
346se_policy_cil {
347 name: "product_sepolicy.cil",
348 src: ":product_sepolicy.conf",
349 product_specific: true,
Inseob Kimff2018f2024-04-17 09:48:43 +0900350 filter_out: [
351 ":plat_sepolicy.cil",
352 ":system_ext_sepolicy.cil",
353 ],
Inseob Kima49e7242021-03-22 10:26:13 +0900354 remove_line_marker: true,
355}
356
Inseob Kim039175b2021-03-25 15:37:34 +0900357// policy mapping files
358// auto-generate the mapping file for current platform policy, since it needs to
359// track platform policy development
360se_versioned_policy {
361 name: "plat_mapping_file",
362 base: ":plat_pub_policy.cil",
363 mapping: true,
364 version: "current",
365 relative_install_path: "mapping", // install to /system/etc/selinux/mapping
Inseob Kim4b9929e2024-03-28 17:52:32 +0900366 dist: {
367 targets: ["sepolicy_finalize"],
368 },
Inseob Kim039175b2021-03-25 15:37:34 +0900369}
370
371se_versioned_policy {
372 name: "system_ext_mapping_file",
373 base: ":system_ext_pub_policy.cil",
374 mapping: true,
375 version: "current",
376 filter_out: [":plat_mapping_file"],
377 relative_install_path: "mapping", // install to /system_ext/etc/selinux/mapping
378 system_ext_specific: true,
379}
380
381se_versioned_policy {
382 name: "product_mapping_file",
383 base: ":pub_policy.cil",
384 mapping: true,
385 version: "current",
Inseob Kimff2018f2024-04-17 09:48:43 +0900386 filter_out: [
387 ":plat_mapping_file",
388 ":system_ext_mapping_file",
389 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900390 relative_install_path: "mapping", // install to /product/etc/selinux/mapping
391 product_specific: true,
392}
393
Inseob Kim6c6aa012023-08-31 16:47:38 +0900394//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900395// vendor/odm sepolicy
Inseob Kim6c6aa012023-08-31 16:47:38 +0900396//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900397
Inseob Kim039175b2021-03-25 15:37:34 +0900398// plat_pub_versioned.cil - the exported platform policy associated with the version
399// that non-platform policy targets.
400se_versioned_policy {
401 name: "plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900402 base: ":pub_policy.cil",
403 target_policy: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900404 version: "vendor",
Inseob Kim039175b2021-03-25 15:37:34 +0900405 vendor: true,
406}
407
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900408// vendor_policy.cil - the vendor sepolicy. This needs attributization and to be combined
409// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
410// policy and the platform public policy files in order to use checkpolicy.
411se_policy_conf {
412 name: "vendor_sepolicy.conf",
Inseob Kim8697fc82024-04-16 14:45:32 +0900413 defaults: ["se_policy_conf_public_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900414 srcs: plat_public_policy +
415 system_ext_public_policy +
416 product_public_policy +
417 reqd_mask_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900418 ":se_build_files{.plat_vendor}",
419 ":se_build_files{.vendor}",
420 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900421 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900422 installable: false,
423}
424
425se_policy_cil {
426 name: "vendor_sepolicy.cil.raw",
427 src: ":vendor_sepolicy.conf",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900428 filter_out: [":reqd_policy_mask.cil"],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900429 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900430 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900431 installable: false,
432}
433
434se_versioned_policy {
435 name: "vendor_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900436 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900437 target_policy: ":vendor_sepolicy.cil.raw",
438 version: "vendor",
439 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900440 ":plat_sepolicy.cil",
441 ":system_ext_sepolicy.cil",
442 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900443 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900444 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900445 ],
446 filter_out: [":plat_pub_versioned.cil"],
447 vendor: true,
448}
449
450// odm_policy.cil - the odl sepolicy. This needs attributization and to be combined
451// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
452// policy and the platform public policy files in order to use checkpolicy.
453se_policy_conf {
454 name: "odm_sepolicy.conf",
Inseob Kim8697fc82024-04-16 14:45:32 +0900455 defaults: ["se_policy_conf_public_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900456 srcs: plat_public_policy +
457 system_ext_public_policy +
458 product_public_policy +
459 reqd_mask_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900460 ":se_build_files{.plat_vendor}",
461 ":se_build_files{.vendor}",
462 ":se_build_files{.odm}",
463 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900464 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900465 installable: false,
466}
467
468se_policy_cil {
469 name: "odm_sepolicy.cil.raw",
470 src: ":odm_sepolicy.conf",
471 filter_out: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900472 ":reqd_policy_mask.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900473 ":vendor_sepolicy.cil",
474 ],
475 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900476 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900477 installable: false,
478}
479
480se_versioned_policy {
481 name: "odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900482 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900483 target_policy: ":odm_sepolicy.cil.raw",
484 version: "vendor",
485 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900486 ":plat_sepolicy.cil",
487 ":system_ext_sepolicy.cil",
488 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900489 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900490 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900491 ":vendor_sepolicy.cil",
492 ],
Inseob Kimff2018f2024-04-17 09:48:43 +0900493 filter_out: [
494 ":plat_pub_versioned.cil",
495 ":vendor_sepolicy.cil",
496 ],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900497 device_specific: true,
498}
499
Inseob Kim039175b2021-03-25 15:37:34 +0900500//////////////////////////////////
501// Precompiled sepolicy is loaded if and only if:
502// - plat_sepolicy_and_mapping.sha256 equals
503// precompiled_sepolicy.plat_sepolicy_and_mapping.sha256
504// AND
505// - system_ext_sepolicy_and_mapping.sha256 equals
506// precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256
507// AND
508// - product_sepolicy_and_mapping.sha256 equals
509// precompiled_sepolicy.product_sepolicy_and_mapping.sha256
510// See system/core/init/selinux.cpp for details.
511//////////////////////////////////
512genrule {
513 name: "plat_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900514 srcs: [
515 ":plat_sepolicy.cil",
516 ":plat_mapping_file",
517 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900518 out: ["plat_sepolicy_and_mapping.sha256"],
519 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
520}
521
522prebuilt_etc {
523 name: "plat_sepolicy_and_mapping.sha256",
524 filename: "plat_sepolicy_and_mapping.sha256",
525 src: ":plat_sepolicy_and_mapping.sha256_gen",
526 relative_install_path: "selinux",
527}
528
529genrule {
530 name: "system_ext_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900531 srcs: [
532 ":system_ext_sepolicy.cil",
533 ":system_ext_mapping_file",
534 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900535 out: ["system_ext_sepolicy_and_mapping.sha256"],
536 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
537}
538
539prebuilt_etc {
540 name: "system_ext_sepolicy_and_mapping.sha256",
541 filename: "system_ext_sepolicy_and_mapping.sha256",
542 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
543 relative_install_path: "selinux",
544 system_ext_specific: true,
545}
546
547genrule {
548 name: "product_sepolicy_and_mapping.sha256_gen",
Inseob Kimff2018f2024-04-17 09:48:43 +0900549 srcs: [
550 ":product_sepolicy.cil",
551 ":product_mapping_file",
552 ],
Inseob Kim039175b2021-03-25 15:37:34 +0900553 out: ["product_sepolicy_and_mapping.sha256"],
554 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
555}
556
557prebuilt_etc {
558 name: "product_sepolicy_and_mapping.sha256",
559 filename: "product_sepolicy_and_mapping.sha256",
560 src: ":product_sepolicy_and_mapping.sha256_gen",
561 relative_install_path: "selinux",
562 product_specific: true,
563}
564
Inseob Kim1c056b12021-04-30 00:11:43 +0900565sepolicy_vers {
566 name: "plat_sepolicy_vers.txt",
567 version: "vendor",
568 vendor: true,
569}
570
Inseob Kim731182a2021-05-06 11:44:37 +0000571soong_config_module_type {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900572 name: "precompiled_sepolicy_prebuilts_defaults",
Inseob Kim731182a2021-05-06 11:44:37 +0000573 module_type: "prebuilt_defaults",
574 config_namespace: "ANDROID",
575 bool_variables: ["BOARD_USES_ODMIMAGE"],
Inseob Kimff2018f2024-04-17 09:48:43 +0900576 properties: [
577 "vendor",
578 "device_specific",
579 ],
Inseob Kim731182a2021-05-06 11:44:37 +0000580}
581
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900582precompiled_sepolicy_prebuilts_defaults {
583 name: "precompiled_sepolicy_prebuilts",
Inseob Kim731182a2021-05-06 11:44:37 +0000584 soong_config_variables: {
585 BOARD_USES_ODMIMAGE: {
586 device_specific: true,
587 conditions_default: {
588 vendor: true,
589 },
590 },
591 },
592}
593
594//////////////////////////////////
595// SHA-256 digest of the plat_sepolicy.cil and plat_mapping_file against
596// which precompiled_policy was built.
597//////////////////////////////////
598prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900599 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000600 name: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
601 filename: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
602 src: ":plat_sepolicy_and_mapping.sha256_gen",
603 relative_install_path: "selinux",
604}
605
606//////////////////////////////////
607// SHA-256 digest of the system_ext_sepolicy.cil and system_ext_mapping_file against
608// which precompiled_policy was built.
609//////////////////////////////////
610prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900611 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000612 name: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
613 filename: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
614 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
615 relative_install_path: "selinux",
616}
617
618//////////////////////////////////
619// SHA-256 digest of the product_sepolicy.cil and product_mapping_file against
620// which precompiled_policy was built.
621//////////////////////////////////
622prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900623 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000624 name: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
625 filename: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
626 src: ":product_sepolicy_and_mapping.sha256_gen",
627 relative_install_path: "selinux",
628}
629
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900630soong_config_module_type {
631 name: "precompiled_se_policy_binary",
632 module_type: "se_policy_binary",
633 config_namespace: "ANDROID",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900634 bool_variables: ["BOARD_USES_ODMIMAGE"],
Inseob Kimff2018f2024-04-17 09:48:43 +0900635 properties: [
636 "vendor",
637 "device_specific",
638 ],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900639}
640
Garfield Tand8c51f22023-10-02 14:17:04 -0700641filegroup {
642 name: "precompiled_sepolicy_srcs",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900643 srcs: [
644 ":plat_sepolicy.cil",
Sandro143988d2022-08-05 11:38:56 +0000645 ":plat_pub_versioned.cil",
646 ":system_ext_sepolicy.cil",
647 ":product_sepolicy.cil",
648 ":vendor_sepolicy.cil",
649 ":odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900650 ":plat_mapping_file",
651 ":system_ext_mapping_file",
652 ":product_mapping_file",
Sandro143988d2022-08-05 11:38:56 +0000653 ],
Garfield Tand8c51f22023-10-02 14:17:04 -0700654 // Make precompiled_sepolicy_srcs as public so that OEMs have access to them.
655 // Useful when some partitions need to be bind mounted across VM boundaries.
656 visibility: ["//visibility:public"],
657}
658
659precompiled_se_policy_binary {
660 name: "precompiled_sepolicy",
661 srcs: [
662 ":precompiled_sepolicy_srcs",
663 ],
Sandro143988d2022-08-05 11:38:56 +0000664 soong_config_variables: {
665 BOARD_USES_ODMIMAGE: {
666 device_specific: true,
667 conditions_default: {
668 vendor: true,
669 },
670 },
Sandro143988d2022-08-05 11:38:56 +0000671 },
672 required: [
673 "sepolicy_neverallows",
Sandro143988d2022-08-05 11:38:56 +0000674 ],
675 dist: {
676 targets: ["base-sepolicy-files-for-mapping"],
677 },
678}
679
Inseob Kim5bbcd682021-12-28 14:57:03 +0900680// policy for recovery
681se_policy_conf {
682 name: "recovery_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900683 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900684 srcs: plat_public_policy +
685 plat_private_policy +
686 system_ext_public_policy +
687 system_ext_private_policy +
688 product_public_policy +
689 product_private_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900690 ":se_build_files{.plat_vendor}",
691 ":se_build_files{.vendor}",
692 ":se_build_files{.odm}",
693 ],
Inseob Kim5bbcd682021-12-28 14:57:03 +0900694 target_recovery: true,
695 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900696 recovery: true,
Inseob Kim5bbcd682021-12-28 14:57:03 +0900697}
698
699se_policy_cil {
700 name: "recovery_sepolicy.cil",
701 src: ":recovery_sepolicy.conf",
702 secilc_check: false, // will be done in se_policy_binary module
703 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900704 recovery: true,
Inseob Kim5bbcd682021-12-28 14:57:03 +0900705}
706
707se_policy_binary {
708 name: "sepolicy.recovery",
709 srcs: [":recovery_sepolicy.cil"],
710 stem: "sepolicy",
711 recovery: true,
712}
713
Inseob Kima49e7242021-03-22 10:26:13 +0900714//////////////////////////////////
715// SELinux policy embedded into CTS.
716// CTS checks neverallow rules of this policy against the policy of the device under test.
717//////////////////////////////////
718se_policy_conf {
719 name: "general_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900720 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900721 srcs: plat_public_policy +
722 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900723 build_variant: "user",
724 cts: true,
725 exclude_build_test: true,
Inseob Kim4b9929e2024-03-28 17:52:32 +0900726 dist: {
727 targets: ["sepolicy_finalize"],
728 },
Inseob Kima49e7242021-03-22 10:26:13 +0900729}
Inseob Kimd5816612021-09-15 03:01:05 +0000730
731//////////////////////////////////
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000732// Base system policy for treble sepolicy tests.
733// If system sepolicy is extended (e.g. by SoC vendors), their plat_pub_versioned.cil may differ
734// with system/sepolicy/prebuilts/api/{version}/plat_pub_versioned.cil. In that case,
735// BOARD_PLAT_PUB_VERSIONED_POLICY can be used to specify extended plat_pub_versioned.cil.
736// See treble_sepolicy_tests_for_release.mk for more details.
737//////////////////////////////////
738se_policy_conf {
739 name: "base_plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900740 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900741 srcs: plat_public_policy +
742 plat_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000743 build_variant: "user",
744 installable: false,
745}
746
747se_policy_cil {
748 name: "base_plat_sepolicy.cil",
749 src: ":base_plat_sepolicy.conf",
750 additional_cil_files: ["private/technical_debt.cil"],
751 installable: false,
752 secilc_check: false, // done by se_policy_binary
753}
754
755se_policy_binary {
756 name: "base_plat_sepolicy",
757 srcs: [":base_plat_sepolicy.cil"],
758 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900759 dist: {
760 targets: ["base-sepolicy-files-for-mapping"],
761 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000762}
763
764se_policy_conf {
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000765 name: "base_product_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900766 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900767 srcs: plat_public_policy +
768 plat_private_policy +
769 system_ext_public_policy +
770 system_ext_private_policy +
771 product_public_policy +
772 product_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000773 build_variant: "user",
774 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900775 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000776}
777
778se_policy_cil {
779 name: "base_product_sepolicy.cil",
780 src: ":base_product_sepolicy.conf",
781 additional_cil_files: ["private/technical_debt.cil"],
782 product_specific: true,
783 installable: false,
784 secilc_check: false, // done by se_policy_binary
785}
786
787se_policy_binary {
788 name: "base_product_sepolicy",
789 srcs: [":base_product_sepolicy.cil"],
790 product_specific: true,
791 installable: false,
792}
793
794se_policy_conf {
795 name: "base_plat_pub_policy.conf",
Inseob Kim8697fc82024-04-16 14:45:32 +0900796 defaults: ["se_policy_conf_public_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900797 srcs: plat_public_policy +
798 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000799 build_variant: "user",
800 installable: false,
801}
802
803se_policy_cil {
804 name: "base_plat_pub_policy.cil",
805 src: ":base_plat_pub_policy.conf",
806 filter_out: [":reqd_policy_mask.cil"],
807 secilc_check: false,
808 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900809 dist: {
810 targets: ["base-sepolicy-files-for-mapping"],
811 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000812}
813
814se_policy_conf {
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000815 name: "base_product_pub_policy.conf",
Inseob Kim8697fc82024-04-16 14:45:32 +0900816 defaults: ["se_policy_conf_public_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900817 srcs: plat_public_policy +
818 system_ext_public_policy +
819 product_public_policy +
820 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000821 build_variant: "user",
822 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900823 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000824}
825
826se_policy_cil {
827 name: "base_product_pub_policy.cil",
828 src: ":base_product_pub_policy.conf",
829 filter_out: [":reqd_policy_mask.cil"],
830 secilc_check: false,
831 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900832 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000833}
834
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800835// bug_map - Bug tracking information for selinux denials loaded by auditd.
Inseob Kim41964032022-04-22 07:50:22 +0900836se_build_files {
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800837 name: "bug_map_files",
838 srcs: ["bug_map"],
839}
840
841se_bug_map {
842 name: "plat_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900843 srcs: [":bug_map_files{.plat_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800844 stem: "bug_map",
845}
846
847se_bug_map {
848 name: "system_ext_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900849 srcs: [":bug_map_files{.system_ext_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800850 stem: "bug_map",
851 system_ext_specific: true,
852}
853
854se_bug_map {
855 name: "vendor_bug_map",
Inseob Kimff2018f2024-04-17 09:48:43 +0900856 srcs: [
857 ":bug_map_files{.vendor}",
858 ":bug_map_files{.plat_vendor}",
859 ],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800860 // Legacy file name of the vendor partition bug_map.
861 stem: "selinux_denial_metadata",
862 vendor: true,
863}
864
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900865se_neverallow_test {
866 name: "sepolicy_neverallows",
Inseob Kim085f22f2023-11-09 11:13:01 +0900867 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900868 srcs: plat_public_policy +
869 plat_private_policy +
870 system_ext_public_policy +
871 system_ext_private_policy +
872 product_public_policy +
Inseob Kim6c6aa012023-08-31 16:47:38 +0900873 product_private_policy + [
Inseob Kimff2018f2024-04-17 09:48:43 +0900874 ":se_build_files{.plat_vendor}",
875 ":se_build_files{.vendor}",
876 ":se_build_files{.odm}",
877 ],
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900878}
879
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000880//////////////////////////////////
Inseob Kimd5816612021-09-15 03:01:05 +0000881// se_freeze_test compares the plat sepolicy with the prebuilt sepolicy
882// Additional directories can be specified via Makefile variables:
883// SEPOLICY_FREEZE_TEST_EXTRA_DIRS and SEPOLICY_FREEZE_TEST_EXTRA_PREBUILT_DIRS.
884//////////////////////////////////
885se_freeze_test {
Inseob Kim36d9d392023-09-04 17:40:03 +0900886 name: "se_freeze_test",
Inseob Kimd5816612021-09-15 03:01:05 +0000887}
Inseob Kim61257ca2022-02-25 11:26:16 +0900888
889//////////////////////////////////
890// sepolicy_test checks various types of violations, which can't be easily done
891// by CIL itself. Refer tests/sepolicy_tests.py for more detail.
892//////////////////////////////////
893genrule {
894 name: "sepolicy_test",
895 srcs: [
896 ":plat_file_contexts",
897 ":vendor_file_contexts",
898 ":system_ext_file_contexts",
899 ":product_file_contexts",
900 ":odm_file_contexts",
901 ":precompiled_sepolicy",
902 ],
903 tools: ["sepolicy_tests"],
904 out: ["sepolicy_test"],
905 cmd: "$(location sepolicy_tests) " +
906 "-f $(location :plat_file_contexts) " +
907 "-f $(location :vendor_file_contexts) " +
908 "-f $(location :system_ext_file_contexts) " +
909 "-f $(location :product_file_contexts) " +
910 "-f $(location :odm_file_contexts) " +
911 "-p $(location :precompiled_sepolicy) && " +
912 "touch $(out)",
913}
Inseob Kim3a9d91c2023-09-27 17:39:07 +0900914
915//////////////////////////////////
916// TestDevTypeViolations can't run on old devices (V or before)
917//////////////////////////////////
918
919soong_config_module_type {
920 name: "dev_type_test_genrule",
921 module_type: "genrule",
922 config_namespace: "ANDROID",
923 bool_variables: ["CHECK_DEV_TYPE_VIOLATIONS"],
924 properties: ["cmd"],
925}
926
927dev_type_test_genrule {
928 name: "sepolicy_dev_type_test",
929 srcs: [
930 ":plat_file_contexts",
931 ":vendor_file_contexts",
932 ":system_ext_file_contexts",
933 ":product_file_contexts",
934 ":odm_file_contexts",
935 ":precompiled_sepolicy",
936 ],
937 tools: ["sepolicy_tests"],
938 out: ["sepolicy_dev_type_test"],
939 soong_config_variables: {
940 CHECK_DEV_TYPE_VIOLATIONS: {
941 cmd: "$(location sepolicy_tests) " +
942 "-f $(location :plat_file_contexts) " +
943 "-f $(location :vendor_file_contexts) " +
944 "-f $(location :system_ext_file_contexts) " +
945 "-f $(location :product_file_contexts) " +
946 "-f $(location :odm_file_contexts) " +
947 "-p $(location :precompiled_sepolicy) " +
948 "-t TestDevTypeViolations && " +
949 "touch $(out)",
950 conditions_default: {
951 cmd: "touch $(out)",
952 },
953 },
954 },
955}