blob: 1d8e5dd468d4d468bcc95937972cc169bedad011 [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 Kim085f22f2023-11-09 11:13:01 +0900106 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900107 srcs: reqd_mask_policy,
Inseob Kime35b49b2021-02-18 19:15:41 +0900108 installable: false,
109}
110
Inseob Kima49e7242021-03-22 10:26:13 +0900111se_policy_cil {
112 name: "reqd_policy_mask.cil",
113 src: ":reqd_policy_mask.conf",
114 secilc_check: false,
115 installable: false,
Inseob Kime35b49b2021-02-18 19:15:41 +0900116}
117
Inseob Kima49e7242021-03-22 10:26:13 +0900118// pub_policy - policy that will be exported to be a part of non-platform
119// policy corresponding to this platform version.
120//
121// This is a limited subset of policy that would not compile in checkpolicy on
122// its own.
123//
124// To get around this limitation, add only the required files from private
125// policy, which will generate CIL policy that will then be filtered out by the
126// reqd_policy_mask.
127//
128// There are three pub_policy.cil files below:
129// - pub_policy.cil: exported 'product', 'system_ext' and 'system' policy.
130// - system_ext_pub_policy.cil: exported 'system_ext' and 'system' policy.
131// - plat_pub_policy.cil: exported 'system' policy.
132//
133// Those above files will in turn be used to generate the following versioned cil files:
134// - product_mapping_file: the versioned, exported 'product' policy in product partition.
135// - system_ext_mapping_file: the versioned, exported 'system_ext' policy in system_ext partition.
136// - plat_mapping_file: the versioned, exported 'system' policy in system partition.
137// - plat_pub_versioned.cil: the versioned, exported 'product', 'system_ext' and 'system' policy
138// in vendor partition.
139//
140se_policy_conf {
141 name: "pub_policy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900142 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900143 srcs: plat_public_policy +
144 system_ext_public_policy +
145 product_public_policy +
146 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900147 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900148 installable: false,
149}
150
151se_policy_cil {
152 name: "pub_policy.cil",
153 src: ":pub_policy.conf",
154 filter_out: [":reqd_policy_mask.cil"],
155 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900156 vendor: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900157 installable: false,
158}
159
160se_policy_conf {
161 name: "system_ext_pub_policy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900162 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900163 srcs: plat_public_policy +
164 system_ext_public_policy +
165 reqd_mask_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900166 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900167 installable: false,
168}
169
170se_policy_cil {
171 name: "system_ext_pub_policy.cil",
172 src: ":system_ext_pub_policy.conf",
173 filter_out: [":reqd_policy_mask.cil"],
174 secilc_check: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900175 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900176 installable: false,
177}
178
179se_policy_conf {
180 name: "plat_pub_policy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900181 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900182 srcs: plat_public_policy +
183 reqd_mask_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900184 installable: false,
185}
186
187se_policy_cil {
188 name: "plat_pub_policy.cil",
189 src: ":plat_pub_policy.conf",
190 filter_out: [":reqd_policy_mask.cil"],
191 secilc_check: false,
192 installable: false,
193}
194
195// plat_policy.conf - A combination of the private and public platform policy
196// which will ship with the device.
197//
198// The platform will always reflect the most recent platform version and is not
199// currently being attributized.
200se_policy_conf {
201 name: "plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900202 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900203 srcs: plat_public_policy +
204 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900205 installable: false,
206}
207
208se_policy_cil {
209 name: "plat_sepolicy.cil",
210 src: ":plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900211 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kima49e7242021-03-22 10:26:13 +0900212}
213
Lokesh Gidra1269a172022-08-01 17:20:38 +0000214
Inseob Kim6cc75f42021-04-29 13:53:20 +0000215// userdebug_plat_policy.conf - the userdebug version plat_sepolicy.cil
216se_policy_conf {
217 name: "userdebug_plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900218 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900219 srcs: plat_public_policy +
220 plat_private_policy,
Inseob Kim6cc75f42021-04-29 13:53:20 +0000221 build_variant: "userdebug",
222 installable: false,
223}
224
225se_policy_cil {
226 name: "userdebug_plat_sepolicy.cil",
227 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900228 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Inseob Kim6cc75f42021-04-29 13:53:20 +0000229 debug_ramdisk: true,
Yi-Yo Chiang68478b12021-10-16 03:23:05 +0800230 dist: {
231 targets: ["droidcore"],
232 },
Inseob Kim6cc75f42021-04-29 13:53:20 +0000233}
234
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000235// A copy of the userdebug_plat_policy in GSI.
236soong_config_module_type {
237 name: "gsi_se_policy_cil",
238 module_type: "se_policy_cil",
239 config_namespace: "ANDROID",
240 bool_variables: [
241 "PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT",
242 ],
243 properties: [
244 "enabled",
245 "installable",
246 ],
247}
248
249gsi_se_policy_cil {
250 name: "system_ext_userdebug_plat_sepolicy.cil",
251 stem: "userdebug_plat_sepolicy.cil",
252 src: ":userdebug_plat_sepolicy.conf",
Inseob Kim7cb20812021-12-16 16:52:14 +0900253 additional_cil_files: [":sepolicy_technical_debt{.plat_private}"],
Yi-Yo Chiang857ffc42021-09-23 14:14:16 +0000254 system_ext_specific: true,
255 enabled: false,
256 installable: false,
257 soong_config_variables: {
258 PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT: {
259 enabled: true,
260 installable: true,
261 },
262 },
263}
264
Inseob Kima49e7242021-03-22 10:26:13 +0900265// system_ext_policy.conf - A combination of the private and public system_ext
266// policy which will ship with the device. System_ext policy is not attributized
267se_policy_conf {
268 name: "system_ext_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900269 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900270 srcs: plat_public_policy +
271 plat_private_policy +
272 system_ext_public_policy +
273 system_ext_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900274 system_ext_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900275 installable: false,
276}
277
278se_policy_cil {
279 name: "system_ext_sepolicy.cil",
280 src: ":system_ext_sepolicy.conf",
281 system_ext_specific: true,
282 filter_out: [":plat_sepolicy.cil"],
283 remove_line_marker: true,
284}
285
286// product_policy.conf - A combination of the private and public product policy
287// which will ship with the device. Product policy is not attributized
288se_policy_conf {
289 name: "product_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900290 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900291 srcs: plat_public_policy +
292 plat_private_policy +
293 system_ext_public_policy +
294 system_ext_private_policy +
295 product_public_policy +
296 product_private_policy,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900297 product_specific: true,
Inseob Kima49e7242021-03-22 10:26:13 +0900298 installable: false,
299}
300
301se_policy_cil {
302 name: "product_sepolicy.cil",
303 src: ":product_sepolicy.conf",
304 product_specific: true,
305 filter_out: [":plat_sepolicy.cil", ":system_ext_sepolicy.cil"],
306 remove_line_marker: true,
307}
308
Inseob Kim039175b2021-03-25 15:37:34 +0900309// policy mapping files
310// auto-generate the mapping file for current platform policy, since it needs to
311// track platform policy development
312se_versioned_policy {
313 name: "plat_mapping_file",
314 base: ":plat_pub_policy.cil",
315 mapping: true,
316 version: "current",
317 relative_install_path: "mapping", // install to /system/etc/selinux/mapping
318}
319
320se_versioned_policy {
321 name: "system_ext_mapping_file",
322 base: ":system_ext_pub_policy.cil",
323 mapping: true,
324 version: "current",
325 filter_out: [":plat_mapping_file"],
326 relative_install_path: "mapping", // install to /system_ext/etc/selinux/mapping
327 system_ext_specific: true,
328}
329
330se_versioned_policy {
331 name: "product_mapping_file",
332 base: ":pub_policy.cil",
333 mapping: true,
334 version: "current",
335 filter_out: [":plat_mapping_file", ":system_ext_mapping_file"],
336 relative_install_path: "mapping", // install to /product/etc/selinux/mapping
337 product_specific: true,
338}
339
Inseob Kime41e95e2024-02-13 02:19:24 +0000340// HACK to support vendor blobs using 1000000.0
341// TODO(b/314010177): remove after new ToT (202404) fully propagates
342se_versioned_policy {
343 name: "plat_mapping_file_1000000.0",
344 base: ":plat_pub_policy.cil",
345 mapping: true,
346 version: "1000000.0",
347 relative_install_path: "mapping", // install to /system/etc/selinux/mapping
348}
349
350se_versioned_policy {
351 name: "system_ext_mapping_file_1000000.0",
352 base: ":system_ext_pub_policy.cil",
353 mapping: true,
354 version: "1000000.0",
355 filter_out: [":plat_mapping_file"],
356 relative_install_path: "mapping", // install to /system_ext/etc/selinux/mapping
357 system_ext_specific: true,
358}
359
360se_versioned_policy {
361 name: "product_mapping_file_1000000.0",
362 base: ":pub_policy.cil",
363 mapping: true,
364 version: "1000000.0",
365 filter_out: [":plat_mapping_file", ":system_ext_mapping_file"],
366 relative_install_path: "mapping", // install to /product/etc/selinux/mapping
367 product_specific: true,
368}
369
Inseob Kim6c6aa012023-08-31 16:47:38 +0900370//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900371// vendor/odm sepolicy
Inseob Kim6c6aa012023-08-31 16:47:38 +0900372//////////////////////////////////
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900373
Inseob Kim039175b2021-03-25 15:37:34 +0900374// plat_pub_versioned.cil - the exported platform policy associated with the version
375// that non-platform policy targets.
376se_versioned_policy {
377 name: "plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900378 base: ":pub_policy.cil",
379 target_policy: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900380 version: "vendor",
Inseob Kim039175b2021-03-25 15:37:34 +0900381 vendor: true,
382}
383
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900384// vendor_policy.cil - the vendor sepolicy. This needs attributization and to be combined
385// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
386// policy and the platform public policy files in order to use checkpolicy.
387se_policy_conf {
388 name: "vendor_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900389 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900390 srcs: plat_public_policy +
391 system_ext_public_policy +
392 product_public_policy +
393 reqd_mask_policy + [
394 ":se_build_files{.plat_vendor}",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900395 ":se_build_files{.vendor}",
396 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900397 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900398 installable: false,
399}
400
401se_policy_cil {
402 name: "vendor_sepolicy.cil.raw",
403 src: ":vendor_sepolicy.conf",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900404 filter_out: [":reqd_policy_mask.cil"],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900405 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900406 vendor: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900407 installable: false,
408}
409
410se_versioned_policy {
411 name: "vendor_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900412 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900413 target_policy: ":vendor_sepolicy.cil.raw",
414 version: "vendor",
415 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900416 ":plat_sepolicy.cil",
417 ":system_ext_sepolicy.cil",
418 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900419 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900420 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900421 ],
422 filter_out: [":plat_pub_versioned.cil"],
423 vendor: true,
424}
425
426// odm_policy.cil - the odl sepolicy. This needs attributization and to be combined
427// with the platform-provided policy. It makes use of the reqd_policy_mask files from private
428// policy and the platform public policy files in order to use checkpolicy.
429se_policy_conf {
430 name: "odm_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900431 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900432 srcs: plat_public_policy +
433 system_ext_public_policy +
434 product_public_policy +
435 reqd_mask_policy + [
436 ":se_build_files{.plat_vendor}",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900437 ":se_build_files{.vendor}",
438 ":se_build_files{.odm}",
439 ],
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900440 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900441 installable: false,
442}
443
444se_policy_cil {
445 name: "odm_sepolicy.cil.raw",
446 src: ":odm_sepolicy.conf",
447 filter_out: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900448 ":reqd_policy_mask.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900449 ":vendor_sepolicy.cil",
450 ],
451 secilc_check: false, // will be done in se_versioned_policy module
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900452 device_specific: true,
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900453 installable: false,
454}
455
456se_versioned_policy {
457 name: "odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900458 base: ":pub_policy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900459 target_policy: ":odm_sepolicy.cil.raw",
460 version: "vendor",
461 dependent_cils: [
Inseob Kim6c6aa012023-08-31 16:47:38 +0900462 ":plat_sepolicy.cil",
463 ":system_ext_sepolicy.cil",
464 ":product_sepolicy.cil",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900465 ":plat_pub_versioned.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900466 ":plat_mapping_file",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900467 ":vendor_sepolicy.cil",
468 ],
469 filter_out: [":plat_pub_versioned.cil", ":vendor_sepolicy.cil"],
470 device_specific: true,
471}
472
Inseob Kim039175b2021-03-25 15:37:34 +0900473//////////////////////////////////
474// Precompiled sepolicy is loaded if and only if:
475// - plat_sepolicy_and_mapping.sha256 equals
476// precompiled_sepolicy.plat_sepolicy_and_mapping.sha256
477// AND
478// - system_ext_sepolicy_and_mapping.sha256 equals
479// precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256
480// AND
481// - product_sepolicy_and_mapping.sha256 equals
482// precompiled_sepolicy.product_sepolicy_and_mapping.sha256
483// See system/core/init/selinux.cpp for details.
484//////////////////////////////////
485genrule {
486 name: "plat_sepolicy_and_mapping.sha256_gen",
487 srcs: [":plat_sepolicy.cil", ":plat_mapping_file"],
488 out: ["plat_sepolicy_and_mapping.sha256"],
489 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
490}
491
492prebuilt_etc {
493 name: "plat_sepolicy_and_mapping.sha256",
494 filename: "plat_sepolicy_and_mapping.sha256",
495 src: ":plat_sepolicy_and_mapping.sha256_gen",
496 relative_install_path: "selinux",
497}
498
499genrule {
500 name: "system_ext_sepolicy_and_mapping.sha256_gen",
501 srcs: [":system_ext_sepolicy.cil", ":system_ext_mapping_file"],
502 out: ["system_ext_sepolicy_and_mapping.sha256"],
503 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
504}
505
506prebuilt_etc {
507 name: "system_ext_sepolicy_and_mapping.sha256",
508 filename: "system_ext_sepolicy_and_mapping.sha256",
509 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
510 relative_install_path: "selinux",
511 system_ext_specific: true,
512}
513
514genrule {
515 name: "product_sepolicy_and_mapping.sha256_gen",
516 srcs: [":product_sepolicy.cil", ":product_mapping_file"],
517 out: ["product_sepolicy_and_mapping.sha256"],
518 cmd: "cat $(in) | sha256sum | cut -d' ' -f1 > $(out)",
519}
520
521prebuilt_etc {
522 name: "product_sepolicy_and_mapping.sha256",
523 filename: "product_sepolicy_and_mapping.sha256",
524 src: ":product_sepolicy_and_mapping.sha256_gen",
525 relative_install_path: "selinux",
526 product_specific: true,
527}
528
Inseob Kim1c056b12021-04-30 00:11:43 +0900529sepolicy_vers {
530 name: "plat_sepolicy_vers.txt",
531 version: "vendor",
532 vendor: true,
533}
534
Inseob Kim731182a2021-05-06 11:44:37 +0000535soong_config_module_type {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900536 name: "precompiled_sepolicy_prebuilts_defaults",
Inseob Kim731182a2021-05-06 11:44:37 +0000537 module_type: "prebuilt_defaults",
538 config_namespace: "ANDROID",
539 bool_variables: ["BOARD_USES_ODMIMAGE"],
540 properties: ["vendor", "device_specific"],
541}
542
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900543precompiled_sepolicy_prebuilts_defaults {
544 name: "precompiled_sepolicy_prebuilts",
Inseob Kim731182a2021-05-06 11:44:37 +0000545 soong_config_variables: {
546 BOARD_USES_ODMIMAGE: {
547 device_specific: true,
548 conditions_default: {
549 vendor: true,
550 },
551 },
552 },
553}
554
555//////////////////////////////////
556// SHA-256 digest of the plat_sepolicy.cil and plat_mapping_file against
557// which precompiled_policy was built.
558//////////////////////////////////
559prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900560 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000561 name: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
562 filename: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
563 src: ":plat_sepolicy_and_mapping.sha256_gen",
564 relative_install_path: "selinux",
565}
566
567//////////////////////////////////
568// SHA-256 digest of the system_ext_sepolicy.cil and system_ext_mapping_file against
569// which precompiled_policy was built.
570//////////////////////////////////
571prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900572 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000573 name: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
574 filename: "precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256",
575 src: ":system_ext_sepolicy_and_mapping.sha256_gen",
576 relative_install_path: "selinux",
577}
578
579//////////////////////////////////
580// SHA-256 digest of the product_sepolicy.cil and product_mapping_file against
581// which precompiled_policy was built.
582//////////////////////////////////
583prebuilt_etc {
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900584 defaults: ["precompiled_sepolicy_prebuilts"],
Inseob Kim731182a2021-05-06 11:44:37 +0000585 name: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
586 filename: "precompiled_sepolicy.product_sepolicy_and_mapping.sha256",
587 src: ":product_sepolicy_and_mapping.sha256_gen",
588 relative_install_path: "selinux",
589}
590
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900591soong_config_module_type {
592 name: "precompiled_se_policy_binary",
593 module_type: "se_policy_binary",
594 config_namespace: "ANDROID",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900595 bool_variables: ["BOARD_USES_ODMIMAGE"],
596 properties: ["vendor", "device_specific"],
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900597}
598
Garfield Tand8c51f22023-10-02 14:17:04 -0700599filegroup {
600 name: "precompiled_sepolicy_srcs",
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900601 srcs: [
602 ":plat_sepolicy.cil",
Sandro143988d2022-08-05 11:38:56 +0000603 ":plat_pub_versioned.cil",
604 ":system_ext_sepolicy.cil",
605 ":product_sepolicy.cil",
606 ":vendor_sepolicy.cil",
607 ":odm_sepolicy.cil",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900608 ":plat_mapping_file",
609 ":system_ext_mapping_file",
610 ":product_mapping_file",
Sandro143988d2022-08-05 11:38:56 +0000611 ],
Garfield Tand8c51f22023-10-02 14:17:04 -0700612 // Make precompiled_sepolicy_srcs as public so that OEMs have access to them.
613 // Useful when some partitions need to be bind mounted across VM boundaries.
614 visibility: ["//visibility:public"],
615}
616
617precompiled_se_policy_binary {
618 name: "precompiled_sepolicy",
619 srcs: [
620 ":precompiled_sepolicy_srcs",
621 ],
Sandro143988d2022-08-05 11:38:56 +0000622 soong_config_variables: {
623 BOARD_USES_ODMIMAGE: {
624 device_specific: true,
625 conditions_default: {
626 vendor: true,
627 },
628 },
Sandro143988d2022-08-05 11:38:56 +0000629 },
630 required: [
631 "sepolicy_neverallows",
Sandro143988d2022-08-05 11:38:56 +0000632 ],
633 dist: {
634 targets: ["base-sepolicy-files-for-mapping"],
635 },
636}
637
Inseob Kim5bbcd682021-12-28 14:57:03 +0900638// policy for recovery
639se_policy_conf {
640 name: "recovery_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900641 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim6c6aa012023-08-31 16:47:38 +0900642 srcs: plat_public_policy +
643 plat_private_policy +
644 system_ext_public_policy +
645 system_ext_private_policy +
646 product_public_policy +
647 product_private_policy + [
648 ":se_build_files{.plat_vendor}",
Inseob Kim5bbcd682021-12-28 14:57:03 +0900649 ":se_build_files{.vendor}",
650 ":se_build_files{.odm}",
651 ],
652 target_recovery: true,
653 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900654 recovery: true,
Inseob Kim5bbcd682021-12-28 14:57:03 +0900655}
656
657se_policy_cil {
658 name: "recovery_sepolicy.cil",
659 src: ":recovery_sepolicy.conf",
660 secilc_check: false, // will be done in se_policy_binary module
661 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900662 recovery: true,
Inseob Kim5bbcd682021-12-28 14:57:03 +0900663}
664
665se_policy_binary {
666 name: "sepolicy.recovery",
667 srcs: [":recovery_sepolicy.cil"],
668 stem: "sepolicy",
669 recovery: true,
670}
671
Inseob Kima49e7242021-03-22 10:26:13 +0900672//////////////////////////////////
673// SELinux policy embedded into CTS.
674// CTS checks neverallow rules of this policy against the policy of the device under test.
675//////////////////////////////////
676se_policy_conf {
677 name: "general_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900678 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900679 srcs: plat_public_policy +
680 plat_private_policy,
Inseob Kima49e7242021-03-22 10:26:13 +0900681 build_variant: "user",
682 cts: true,
683 exclude_build_test: true,
684}
Inseob Kimd5816612021-09-15 03:01:05 +0000685
686//////////////////////////////////
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000687// Base system policy for treble sepolicy tests.
688// If system sepolicy is extended (e.g. by SoC vendors), their plat_pub_versioned.cil may differ
689// with system/sepolicy/prebuilts/api/{version}/plat_pub_versioned.cil. In that case,
690// BOARD_PLAT_PUB_VERSIONED_POLICY can be used to specify extended plat_pub_versioned.cil.
691// See treble_sepolicy_tests_for_release.mk for more details.
692//////////////////////////////////
693se_policy_conf {
694 name: "base_plat_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900695 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900696 srcs: plat_public_policy +
697 plat_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000698 build_variant: "user",
699 installable: false,
700}
701
702se_policy_cil {
703 name: "base_plat_sepolicy.cil",
704 src: ":base_plat_sepolicy.conf",
705 additional_cil_files: ["private/technical_debt.cil"],
706 installable: false,
707 secilc_check: false, // done by se_policy_binary
708}
709
710se_policy_binary {
711 name: "base_plat_sepolicy",
712 srcs: [":base_plat_sepolicy.cil"],
713 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900714 dist: {
715 targets: ["base-sepolicy-files-for-mapping"],
716 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000717}
718
719se_policy_conf {
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000720 name: "base_product_sepolicy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900721 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900722 srcs: plat_public_policy +
723 plat_private_policy +
724 system_ext_public_policy +
725 system_ext_private_policy +
726 product_public_policy +
727 product_private_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000728 build_variant: "user",
729 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900730 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000731}
732
733se_policy_cil {
734 name: "base_product_sepolicy.cil",
735 src: ":base_product_sepolicy.conf",
736 additional_cil_files: ["private/technical_debt.cil"],
737 product_specific: true,
738 installable: false,
739 secilc_check: false, // done by se_policy_binary
740}
741
742se_policy_binary {
743 name: "base_product_sepolicy",
744 srcs: [":base_product_sepolicy.cil"],
745 product_specific: true,
746 installable: false,
747}
748
749se_policy_conf {
750 name: "base_plat_pub_policy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900751 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900752 srcs: plat_public_policy +
753 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000754 build_variant: "user",
755 installable: false,
756}
757
758se_policy_cil {
759 name: "base_plat_pub_policy.cil",
760 src: ":base_plat_pub_policy.conf",
761 filter_out: [":reqd_policy_mask.cil"],
762 secilc_check: false,
763 installable: false,
Inseob Kimeec39192022-01-21 11:47:54 +0900764 dist: {
765 targets: ["base-sepolicy-files-for-mapping"],
766 },
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000767}
768
769se_policy_conf {
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000770 name: "base_product_pub_policy.conf",
Inseob Kim085f22f2023-11-09 11:13:01 +0900771 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0a707fa2021-12-09 23:35:11 +0900772 srcs: plat_public_policy +
773 system_ext_public_policy +
774 product_public_policy +
775 reqd_mask_policy,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000776 build_variant: "user",
777 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900778 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000779}
780
781se_policy_cil {
782 name: "base_product_pub_policy.cil",
783 src: ":base_product_pub_policy.conf",
784 filter_out: [":reqd_policy_mask.cil"],
785 secilc_check: false,
786 installable: false,
Inseob Kim6c6f53b2023-04-26 11:03:35 +0900787 product_specific: true,
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000788}
789
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800790// bug_map - Bug tracking information for selinux denials loaded by auditd.
Inseob Kim41964032022-04-22 07:50:22 +0900791se_build_files {
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800792 name: "bug_map_files",
793 srcs: ["bug_map"],
794}
795
796se_bug_map {
797 name: "plat_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900798 srcs: [":bug_map_files{.plat_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800799 stem: "bug_map",
800}
801
802se_bug_map {
803 name: "system_ext_bug_map",
Inseob Kim41964032022-04-22 07:50:22 +0900804 srcs: [":bug_map_files{.system_ext_private}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800805 stem: "bug_map",
806 system_ext_specific: true,
807}
808
809se_bug_map {
810 name: "vendor_bug_map",
Inseob Kim6c6aa012023-08-31 16:47:38 +0900811 srcs: [":bug_map_files{.vendor}", ":bug_map_files{.plat_vendor}"],
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800812 // Legacy file name of the vendor partition bug_map.
813 stem: "selinux_denial_metadata",
814 vendor: true,
815}
816
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900817se_neverallow_test {
818 name: "sepolicy_neverallows",
Inseob Kim085f22f2023-11-09 11:13:01 +0900819 defaults: ["se_policy_conf_flags_defaults"],
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900820 srcs: plat_public_policy +
821 plat_private_policy +
822 system_ext_public_policy +
823 system_ext_private_policy +
824 product_public_policy +
Inseob Kim6c6aa012023-08-31 16:47:38 +0900825 product_private_policy + [
826 ":se_build_files{.plat_vendor}",
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900827 ":se_build_files{.vendor}",
828 ":se_build_files{.odm}",
829 ],
830}
831
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000832//////////////////////////////////
Inseob Kimd5816612021-09-15 03:01:05 +0000833// se_freeze_test compares the plat sepolicy with the prebuilt sepolicy
834// Additional directories can be specified via Makefile variables:
835// SEPOLICY_FREEZE_TEST_EXTRA_DIRS and SEPOLICY_FREEZE_TEST_EXTRA_PREBUILT_DIRS.
836//////////////////////////////////
837se_freeze_test {
Inseob Kim36d9d392023-09-04 17:40:03 +0900838 name: "se_freeze_test",
Inseob Kimd5816612021-09-15 03:01:05 +0000839}
Inseob Kim61257ca2022-02-25 11:26:16 +0900840
841//////////////////////////////////
842// sepolicy_test checks various types of violations, which can't be easily done
843// by CIL itself. Refer tests/sepolicy_tests.py for more detail.
844//////////////////////////////////
845genrule {
846 name: "sepolicy_test",
847 srcs: [
848 ":plat_file_contexts",
849 ":vendor_file_contexts",
850 ":system_ext_file_contexts",
851 ":product_file_contexts",
852 ":odm_file_contexts",
853 ":precompiled_sepolicy",
854 ],
855 tools: ["sepolicy_tests"],
856 out: ["sepolicy_test"],
857 cmd: "$(location sepolicy_tests) " +
858 "-f $(location :plat_file_contexts) " +
859 "-f $(location :vendor_file_contexts) " +
860 "-f $(location :system_ext_file_contexts) " +
861 "-f $(location :product_file_contexts) " +
862 "-f $(location :odm_file_contexts) " +
863 "-p $(location :precompiled_sepolicy) && " +
864 "touch $(out)",
865}
Inseob Kim3a9d91c2023-09-27 17:39:07 +0900866
867//////////////////////////////////
868// TestDevTypeViolations can't run on old devices (V or before)
869//////////////////////////////////
870
871soong_config_module_type {
872 name: "dev_type_test_genrule",
873 module_type: "genrule",
874 config_namespace: "ANDROID",
875 bool_variables: ["CHECK_DEV_TYPE_VIOLATIONS"],
876 properties: ["cmd"],
877}
878
879dev_type_test_genrule {
880 name: "sepolicy_dev_type_test",
881 srcs: [
882 ":plat_file_contexts",
883 ":vendor_file_contexts",
884 ":system_ext_file_contexts",
885 ":product_file_contexts",
886 ":odm_file_contexts",
887 ":precompiled_sepolicy",
888 ],
889 tools: ["sepolicy_tests"],
890 out: ["sepolicy_dev_type_test"],
891 soong_config_variables: {
892 CHECK_DEV_TYPE_VIOLATIONS: {
893 cmd: "$(location sepolicy_tests) " +
894 "-f $(location :plat_file_contexts) " +
895 "-f $(location :vendor_file_contexts) " +
896 "-f $(location :system_ext_file_contexts) " +
897 "-f $(location :product_file_contexts) " +
898 "-f $(location :odm_file_contexts) " +
899 "-p $(location :precompiled_sepolicy) " +
900 "-t TestDevTypeViolations && " +
901 "touch $(out)",
902 conditions_default: {
903 cmd: "touch $(out)",
904 },
905 },
906 },
907}