blob: dfaca5af413789dbb6c5df6097aae2013f53d7d8 [file] [log] [blame]
Stephen Smalley2dd4e512012-01-04 12:33:27 -05001LOCAL_PATH:= $(call my-dir)
William Robertsf0e0a942012-08-27 15:41:15 -07002
Dan Cashman36ee91d2017-07-07 14:59:51 -07003include $(LOCAL_PATH)/definitions.mk
Jeff Vander Stoepecd288f2019-02-15 12:18:15 -08004include $(LOCAL_PATH)/policy_version.mk
Dan Cashman36ee91d2017-07-07 14:59:51 -07005
Stephen Smalley2dd4e512012-01-04 12:33:27 -05006include $(CLEAR_VARS)
Stephen Smalley2dd4e512012-01-04 12:33:27 -05007
8MLS_SENS=1
9MLS_CATS=1024
10
Stephen Smalley8e0ca882015-04-01 10:14:56 -040011ifdef BOARD_SEPOLICY_UNION
12$(warning BOARD_SEPOLICY_UNION is no longer required - all files found in BOARD_SEPOLICY_DIRS are implicitly unioned; please remove from your BoardConfig.mk or other .mk file.)
13endif
Robert Craig6b0ff472014-01-29 13:10:58 -050014
William Robertsd2185582015-07-16 11:28:02 -070015ifdef BOARD_SEPOLICY_M4DEFS
16LOCAL_ADDITIONAL_M4DEFS := $(addprefix -D, $(BOARD_SEPOLICY_M4DEFS))
Dan Cashman36ee91d2017-07-07 14:59:51 -070017else
18LOCAL_ADDITIONAL_M4DEFS :=
William Robertsd2185582015-07-16 11:28:02 -070019endif
20
dcashmancc39f632016-07-22 13:13:11 -070021# sepolicy is now divided into multiple portions:
22# public - policy exported on which non-platform policy developers may write
23# additional policy. types and attributes are versioned and included in
24# delivered non-platform policy, which is to be combined with platform policy.
25# private - platform-only policy required for platform functionality but which
26# is not exported to vendor policy developers and as such may not be assumed
27# to exist.
Alex Klyubin55961722017-01-30 18:44:59 -080028# vendor - vendor-only policy required for vendor functionality. This policy can
29# reference the public policy but cannot reference the private policy. This
30# policy is for components which are produced from the core/non-vendor tree and
31# placed into a vendor partition.
dcashman07791552016-12-07 11:27:47 -080032# mapping - This contains policy statements which map the attributes
dcashmancc39f632016-07-22 13:13:11 -070033# exposed in the public policy of previous versions to the concrete types used
34# in this policy to ensure that policy targeting attributes from public
35# policy from an older platform version continues to work.
36
dcashman2e00e632016-10-12 14:58:09 -070037# build process for device:
dcashmancc39f632016-07-22 13:13:11 -070038# 1) convert policies to CIL:
39# - private + public platform policy to CIL
40# - mapping file to CIL (should already be in CIL form)
41# - non-platform public policy to CIL
42# - non-platform public + private policy to CIL
43# 2) attributize policy
dcashmancc39f632016-07-22 13:13:11 -070044# - run script which takes non-platform public and non-platform combined
45# private + public policy and produces attributized and versioned
46# non-platform policy
47# 3) combine policy files
48# - combine mapping, platform and non-platform policy.
49# - compile output binary policy file
50
51PLAT_PUBLIC_POLICY := $(LOCAL_PATH)/public
52PLAT_PRIVATE_POLICY := $(LOCAL_PATH)/private
Alex Klyubin55961722017-01-30 18:44:59 -080053PLAT_VENDOR_POLICY := $(LOCAL_PATH)/vendor
dcashman2e00e632016-10-12 14:58:09 -070054REQD_MASK_POLICY := $(LOCAL_PATH)/reqd_mask
Felix8c53a332020-07-14 21:28:51 +020055
56SYSTEM_EXT_PUBLIC_POLICY := $(SYSTEM_EXT_PUBLIC_SEPOLICY_DIRS)
57ifneq (,$(BOARD_PLAT_PUBLIC_SEPOLICY_DIR))
Bowgo Tsai72b2acb2020-10-28 05:01:17 +000058 # TODO: Disallow BOARD_PLAT_*
Felix8c53a332020-07-14 21:28:51 +020059 SYSTEM_EXT_PUBLIC_POLICY += $(BOARD_PLAT_PUBLIC_SEPOLICY_DIR)
60endif
61SYSTEM_EXT_PRIVATE_POLICY := $(SYSTEM_EXT_PRIVATE_SEPOLICY_DIRS)
62ifneq (,$(BOARD_PLAT_PRIVATE_SEPOLICY_DIR))
Bowgo Tsai72b2acb2020-10-28 05:01:17 +000063 # TODO: Disallow BOARD_PLAT_*
Felix8c53a332020-07-14 21:28:51 +020064 SYSTEM_EXT_PRIVATE_POLICY += $(BOARD_PLAT_PRIVATE_SEPOLICY_DIR)
65endif
66
Tri Vo9918f282019-02-01 11:41:08 -080067PRODUCT_PUBLIC_POLICY := $(PRODUCT_PUBLIC_SEPOLICY_DIRS)
68PRODUCT_PRIVATE_POLICY := $(PRODUCT_PRIVATE_SEPOLICY_DIRS)
Tri Vo75887dd2018-12-14 14:30:56 -080069
Bowgo Tsai948934b2019-08-29 17:12:11 +080070ifneq (,$(SYSTEM_EXT_PUBLIC_POLICY)$(SYSTEM_EXT_PRIVATE_POLICY))
Bowgo Tsaiac381252019-10-04 14:34:18 +080071HAS_SYSTEM_EXT_SEPOLICY_DIR := true
Bowgo Tsai948934b2019-08-29 17:12:11 +080072endif
73
Tri Vo75887dd2018-12-14 14:30:56 -080074# TODO(b/119305624): Currently if the device doesn't have a product partition,
75# we install product sepolicy into /system/product. We do that because bits of
76# product sepolicy that's still in /system might depend on bits that have moved
77# to /product. Once we finish migrating product sepolicy out of system, change
78# it so that if no product partition is present, product sepolicy artifacts are
79# not built and installed at all.
80ifneq (,$(PRODUCT_PUBLIC_POLICY)$(PRODUCT_PRIVATE_POLICY))
Bowgo Tsai7c4150c2019-10-04 15:36:05 +080081HAS_PRODUCT_SEPOLICY_DIR := true
Tri Vo75887dd2018-12-14 14:30:56 -080082endif
dcashman2e00e632016-10-12 14:58:09 -070083
Inseob Kim8ada8a72020-11-09 20:58:58 +090084ifneq ($(PLATFORM_SEPOLICY_VERSION),$(BOARD_SEPOLICY_VERS))
85mixed_sepolicy_build := true
86else
87mixed_sepolicy_build :=
88endif
89
Joel Galenson5988b562018-01-03 16:53:24 -080090NEVERALLOW_ARG :=
91ifeq ($(SELINUX_IGNORE_NEVERALLOWS),true)
92ifeq ($(TARGET_BUILD_VARIANT),user)
93$(error SELINUX_IGNORE_NEVERALLOWS := true cannot be used in user builds)
94endif
95$(warning Be careful when using the SELINUX_IGNORE_NEVERALLOWS flag. \
96 It does not work in user builds and using it will \
97 not stop you from failing CTS.)
98NEVERALLOW_ARG := -N
99endif
100
Bowgo Tsai45457e32017-11-27 11:41:33 +0800101# BOARD_SEPOLICY_DIRS was used for vendor/odm sepolicy customization before.
102# It has been replaced by BOARD_VENDOR_SEPOLICY_DIRS (mandatory) and
103# BOARD_ODM_SEPOLICY_DIRS (optional). BOARD_SEPOLICY_DIRS is still allowed for
104# backward compatibility, which will be merged into BOARD_VENDOR_SEPOLICY_DIRS.
Bowgo Tsaiafbcf212018-02-05 17:34:52 +0800105ifdef BOARD_SEPOLICY_DIRS
106BOARD_VENDOR_SEPOLICY_DIRS += $(BOARD_SEPOLICY_DIRS)
107endif
Dan Cashman4d24a772017-04-12 14:28:34 -0700108
Inseob Kim8ada8a72020-11-09 20:58:58 +0900109# Set default values for these prebuilt directories
110ifeq (,$(BOARD_REQD_MASK_POLICY))
111BOARD_REQD_MASK_POLICY := $(REQD_MASK_POLICY)
112endif
113
114ifeq (,$(BOARD_PLAT_VENDOR_POLICY))
115BOARD_PLAT_VENDOR_POLICY := $(PLAT_VENDOR_POLICY)
116endif
117
118$(foreach p,SYSTEM_EXT PRODUCT,$(foreach q,PUBLIC PRIVATE,$(eval \
119 $(if $(BOARD_$(p)_$(q)_PREBUILT_DIRS),,\
120 BOARD_$(p)_$(q)_PREBUILT_DIRS := $($(p)_$(q)_POLICY) \
121 ) \
122)))
123
Bowgo Tsai45457e32017-11-27 11:41:33 +0800124ifdef BOARD_ODM_SEPOLICY_DIRS
125ifneq ($(PRODUCT_SEPOLICY_SPLIT),true)
126$(error PRODUCT_SEPOLICY_SPLIT needs to be true when using BOARD_ODM_SEPOLICY_DIRS)
127endif
128endif
129
dcashmancc39f632016-07-22 13:13:11 -0700130###########################################################
131# Compute policy files to be used in policy build.
132# $(1): files to include
133# $(2): directories in which to find files
134###########################################################
135
136define build_policy
Cole Faust087d5272021-09-30 15:48:34 -0700137$(strip $(foreach type, $(1), $(foreach file, $(addsuffix /$(type), $(2)), $(sort $(wildcard $(file))))))
dcashmancc39f632016-07-22 13:13:11 -0700138endef
William Roberts29d14682016-01-04 12:20:57 -0800139
Bowgo Tsaiafbcf212018-02-05 17:34:52 +0800140# Builds paths for all policy files found in BOARD_VENDOR_SEPOLICY_DIRS.
William Roberts49693f12016-01-04 12:20:57 -0800141# $(1): the set of policy name paths to build
Inseob Kim7174ffe2021-12-08 22:45:58 +0900142build_vendor_policy = $(call build_policy, $(1), $(BOARD_PLAT_VENDOR_POLICY) $(BOARD_VENDOR_SEPOLICY_DIRS))
William Roberts49693f12016-01-04 12:20:57 -0800143
Bowgo Tsaibae15172017-11-29 16:14:53 +0800144# Builds paths for all policy files found in BOARD_ODM_SEPOLICY_DIRS.
145build_odm_policy = $(call build_policy, $(1), $(BOARD_ODM_SEPOLICY_DIRS))
146
dcashman704741a2014-07-25 19:11:52 -0700147sepolicy_build_files := security_classes \
148 initial_sids \
149 access_vectors \
150 global_macros \
Nick Kralevicha17a2662014-11-05 15:30:41 -0800151 neverallow_macros \
dcashman704741a2014-07-25 19:11:52 -0700152 mls_macros \
dcashman2e00e632016-10-12 14:58:09 -0700153 mls_decl \
dcashman704741a2014-07-25 19:11:52 -0700154 mls \
155 policy_capabilities \
156 te_macros \
157 attributes \
Jeff Vander Stoepcbaa2b72015-12-22 10:39:34 -0800158 ioctl_defines \
Jeff Vander Stoepde9b5302015-06-05 15:28:55 -0700159 ioctl_macros \
dcashman704741a2014-07-25 19:11:52 -0700160 *.te \
dcashman2e00e632016-10-12 14:58:09 -0700161 roles_decl \
dcashman704741a2014-07-25 19:11:52 -0700162 roles \
163 users \
164 initial_sid_contexts \
165 fs_use \
166 genfs_contexts \
167 port_contexts
168
Chris Gross12c0b242020-09-21 15:32:16 -0700169sepolicy_compat_files := $(foreach ver, $(PLATFORM_SEPOLICY_COMPAT_VERSIONS), \
170 $(addprefix compat/$(ver)/, $(addsuffix .cil, $(ver))))
171
Tri Vo71f12392019-10-07 16:31:40 -0700172# Security classes and permissions defined outside of system/sepolicy.
173security_class_extension_files := $(call build_policy, security_classes access_vectors, \
174 $(SYSTEM_EXT_PUBLIC_POLICY) $(SYSTEM_EXT_PRIVATE_POLICY) \
175 $(PRODUCT_PUBLIC_POLICY) $(PRODUCT_PRIVATE_POLICY) \
176 $(BOARD_VENDOR_SEPOLICY_DIRS) $(BOARD_ODM_SEPOLICY_DIRS))
177
178ifneq (,$(strip $(security_class_extension_files)))
179 $(error Only platform SELinux policy may define classes and permissions: $(strip $(security_class_extension_files)))
180endif
181
Bowgo Tsaiac381252019-10-04 14:34:18 +0800182ifdef HAS_SYSTEM_EXT_SEPOLICY_DIR
183 # Checks if there are public system_ext policy files.
184 policy_files := $(call build_policy, $(sepolicy_build_files), $(SYSTEM_EXT_PUBLIC_POLICY))
185 ifneq (,$(strip $(policy_files)))
186 HAS_SYSTEM_EXT_PUBLIC_SEPOLICY := true
187 endif
188 # Checks if there are public/private system_ext policy files.
189 policy_files := $(call build_policy, $(sepolicy_build_files), $(SYSTEM_EXT_PUBLIC_POLICY) $(SYSTEM_EXT_PRIVATE_POLICY))
190 ifneq (,$(strip $(policy_files)))
191 HAS_SYSTEM_EXT_SEPOLICY := true
192 endif
193endif # ifdef HAS_SYSTEM_EXT_SEPOLICY_DIR
194
Bowgo Tsai7c4150c2019-10-04 15:36:05 +0800195ifdef HAS_PRODUCT_SEPOLICY_DIR
196 # Checks if there are public product policy files.
197 policy_files := $(call build_policy, $(sepolicy_build_files), $(PRODUCT_PUBLIC_POLICY))
198 ifneq (,$(strip $(policy_files)))
199 HAS_PRODUCT_PUBLIC_SEPOLICY := true
200 endif
201 # Checks if there are public/private product policy files.
202 policy_files := $(call build_policy, $(sepolicy_build_files), $(PRODUCT_PUBLIC_POLICY) $(PRODUCT_PRIVATE_POLICY))
203 ifneq (,$(strip $(policy_files)))
204 HAS_PRODUCT_SEPOLICY := true
205 endif
206endif # ifdef HAS_PRODUCT_SEPOLICY_DIR
207
Alex Klyubin7cda44f2017-03-21 14:28:53 -0700208# CIL files which contain workarounds for current limitation of human-readable
209# module policy language. These files are appended to the CIL files produced
210# from module language files.
211sepolicy_build_cil_workaround_files := technical_debt.cil
212
Dan Cashman1c040272016-12-15 15:28:44 -0800213my_target_arch := $(TARGET_ARCH)
214ifneq (,$(filter mips mips64,$(TARGET_ARCH)))
215 my_target_arch := mips
216endif
217
Jeff Vander Stoepd2053bd2017-03-15 13:37:35 -0700218intermediates := $(TARGET_OUT_INTERMEDIATES)/ETC/sepolicy_intermediates
219
Jeff Vander Stoep74434842017-03-13 12:22:15 -0700220with_asan := false
221ifneq (,$(filter address,$(SANITIZE_TARGET)))
222 with_asan := true
223endif
224
Pirama Arumuga Nainarce9c0c52019-06-13 15:05:15 -0700225with_native_coverage := false
226ifeq ($(NATIVE_COVERAGE),true)
227 with_native_coverage := true
228endif
Oliver Nguyenfad5f812019-12-09 16:37:59 -0800229ifeq ($(CLANG_COVERAGE),true)
230 with_native_coverage := true
231endif
Pirama Arumuga Nainarce9c0c52019-06-13 15:05:15 -0700232
Inseob Kimed59c222019-09-26 15:14:55 +0900233treble_sysprop_neverallow := true
234ifeq ($(BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW),true)
235 treble_sysprop_neverallow := false
236endif
237
238ifeq ($(PRODUCT_SHIPPING_API_LEVEL),)
239 #$(warning no product shipping level defined)
240else ifneq ($(call math_lt,29,$(PRODUCT_SHIPPING_API_LEVEL)),)
241 ifneq ($(BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW),)
242 $(error BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW cannot be set on a device shipping with R or later, and this is tested by CTS.)
243 endif
244endif
245
Inseob Kimafc09932020-09-28 13:32:43 +0900246enforce_sysprop_owner := true
247ifeq ($(BUILD_BROKEN_ENFORCE_SYSPROP_OWNER),true)
248 enforce_sysprop_owner := false
249endif
250
Hridya Valsarajua885dd82021-04-26 16:32:17 -0700251enforce_debugfs_restriction := false
252ifeq ($(PRODUCT_SET_DEBUGFS_RESTRICTIONS),true)
253 enforce_debugfs_restriction := true
254endif
255
Inseob Kimafc09932020-09-28 13:32:43 +0900256ifeq ($(PRODUCT_SHIPPING_API_LEVEL),)
257 #$(warning no product shipping level defined)
258else ifneq ($(call math_lt,30,$(PRODUCT_SHIPPING_API_LEVEL)),)
259 ifneq ($(BUILD_BROKEN_ENFORCE_SYSPROP_OWNER),)
260 $(error BUILD_BROKEN_ENFORCE_SYSPROP_OWNER cannot be set on a device shipping with S or later, and this is tested by CTS.)
261 endif
262endif
263
Jeff Vander Stoep3ca843a2017-10-04 09:42:29 -0700264# Library extension for host-side tests
Jeff Vander Stoepe06e4c12017-10-04 18:15:44 -0700265ifeq ($(HOST_OS),darwin)
Jeff Vander Stoep3ca843a2017-10-04 09:42:29 -0700266SHAREDLIB_EXT=dylib
267else
268SHAREDLIB_EXT=so
269endif
270
Jiyong Parke7fab182019-01-24 16:41:47 +0900271# Convert a file_context file for a non-flattened APEX into a file for
272# flattened APEX. /system/apex/<apex_name> path is prepended to the original paths
273# $(1): path to the input file_contexts file for non-flattened APEX
Jooyung Hana9324742019-11-20 17:54:34 +0900274# $(2): path to the flattened APEX
275# $(3): path to the generated file_contexts file for flattened APEX
Jiyong Parke7fab182019-01-24 16:41:47 +0900276# $(4): variable where $(3) is added to
277define build_flattened_apex_file_contexts
278$(4) += $(3)
Jooyung Hana9324742019-11-20 17:54:34 +0900279$(3): PRIVATE_APEX_PATH := $(subst .,\\.,$(2))
Jiyong Parke7fab182019-01-24 16:41:47 +0900280$(3): $(1)
281 $(hide) awk '/object_r/{printf("$$(PRIVATE_APEX_PATH)%s\n",$$$$0)}' $$< > $$@
282endef
283
Anton Hansson8cfe1e62018-07-02 14:31:29 +0100284#################################
285
Dan Cashman4f9a6482017-04-10 12:27:18 -0700286include $(CLEAR_VARS)
Anton Hansson8cfe1e62018-07-02 14:31:29 +0100287
Dan Cashman4f9a6482017-04-10 12:27:18 -0700288LOCAL_MODULE := selinux_policy
Bob Badour601ebb42021-02-03 23:07:40 -0800289LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered
290LOCAL_LICENSE_CONDITIONS := notice unencumbered
291LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE
Dan Cashman4f9a6482017-04-10 12:27:18 -0700292LOCAL_MODULE_TAGS := optional
Tri Vo1f4a28b2018-05-08 18:52:11 -0700293LOCAL_REQUIRED_MODULES += \
Anton Hansson8cfe1e62018-07-02 14:31:29 +0100294 selinux_policy_nonsystem \
295 selinux_policy_system \
Tri Vo1f4a28b2018-05-08 18:52:11 -0700296
Anton Hansson8cfe1e62018-07-02 14:31:29 +0100297include $(BUILD_PHONY_PACKAGE)
Tri Vo1f4a28b2018-05-08 18:52:11 -0700298
Jooyung Han749cf932019-05-30 01:05:43 +0900299# selinux_policy is a main goal and triggers lots of tests.
300# Most tests are FAKE modules, so aren'triggered on normal builds. (e.g. 'm')
301# By setting as droidcore's dependency, tests will run on normal builds.
302droidcore: selinux_policy
Tri Vo1f4a28b2018-05-08 18:52:11 -0700303
Anton Hansson8cfe1e62018-07-02 14:31:29 +0100304include $(CLEAR_VARS)
305LOCAL_MODULE := selinux_policy_system
Bob Badour601ebb42021-02-03 23:07:40 -0800306LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered
307LOCAL_LICENSE_CONDITIONS := notice unencumbered
308LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE
Tri Vo1f4a28b2018-05-08 18:52:11 -0700309# These build targets are not used on non-Treble devices. However, we build these to avoid
310# divergence between Treble and non-Treble devices.
Dan Cashman4f9a6482017-04-10 12:27:18 -0700311LOCAL_REQUIRED_MODULES += \
Tri Vo937e6642019-01-15 15:16:55 -0800312 plat_mapping_file \
Tri Vo61178552019-10-10 16:29:40 -0700313 $(addprefix plat_,$(addsuffix .cil,$(PLATFORM_SEPOLICY_COMPAT_VERSIONS))) \
Jeff Vander Stoep564e2922019-05-02 13:48:44 -0700314 $(addsuffix .compat.cil,$(PLATFORM_SEPOLICY_COMPAT_VERSIONS)) \
Dan Cashman4f9a6482017-04-10 12:27:18 -0700315 plat_sepolicy.cil \
Dan Cashman4f9a6482017-04-10 12:27:18 -0700316 secilc \
Dan Cashman91d398d2017-09-26 12:58:29 -0700317
Inseob Kim8ada8a72020-11-09 20:58:58 +0900318ifneq ($(PRODUCT_PRECOMPILED_SEPOLICY),false)
319LOCAL_REQUIRED_MODULES += plat_sepolicy_and_mapping.sha256
320endif
321
Jeff Vander Stoep7a68c5a2017-06-08 13:24:15 -0700322LOCAL_REQUIRED_MODULES += \
Bowgo Tsai741a70a2018-02-05 17:41:02 +0800323 build_sepolicy \
Jeff Vander Stoep13fb5ed2017-08-22 13:29:53 -0700324 plat_file_contexts \
Inseob Kimb554e592019-04-15 20:10:46 +0900325 plat_file_contexts_test \
Janis Danisevskisc40681f2020-07-25 13:02:29 -0700326 plat_keystore2_key_contexts \
Jeff Vander Stoep13fb5ed2017-08-22 13:29:53 -0700327 plat_mac_permissions.xml \
328 plat_property_contexts \
Inseob Kimb554e592019-04-15 20:10:46 +0900329 plat_property_contexts_test \
Jeff Vander Stoep13fb5ed2017-08-22 13:29:53 -0700330 plat_seapp_contexts \
331 plat_service_contexts \
Inseob Kimb554e592019-04-15 20:10:46 +0900332 plat_service_contexts_test \
Jeff Vander Stoep13fb5ed2017-08-22 13:29:53 -0700333 plat_hwservice_contexts \
Inseob Kimb554e592019-04-15 20:10:46 +0900334 plat_hwservice_contexts_test \
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800335 plat_bug_map \
Dan Cashman91d398d2017-09-26 12:58:29 -0700336 searchpolicy \
Anton Hansson8cfe1e62018-07-02 14:31:29 +0100337
338# This conditional inclusion closely mimics the conditional logic
339# inside init/init.cpp for loading SELinux policy from files.
340ifneq ($(PRODUCT_SEPOLICY_SPLIT),true)
341# The following files are only allowed for non-Treble devices.
342LOCAL_REQUIRED_MODULES += \
343 sepolicy \
344 vendor_service_contexts \
345
346endif # ($(PRODUCT_SEPOLICY_SPLIT),true)
Jeff Vander Stoep7a68c5a2017-06-08 13:24:15 -0700347
Dan Cashman91d398d2017-09-26 12:58:29 -0700348ifneq ($(with_asan),true)
Jeff Vander Stoep3d4965b2018-02-13 20:29:55 -0800349ifneq ($(SELINUX_IGNORE_NEVERALLOWS),true)
Dan Cashman91d398d2017-09-26 12:58:29 -0700350LOCAL_REQUIRED_MODULES += \
351 sepolicy_tests \
Jeff Vander Stoep564e2922019-05-02 13:48:44 -0700352 $(addsuffix _compat_test,$(PLATFORM_SEPOLICY_COMPAT_VERSIONS)) \
Dan Cashman91d398d2017-09-26 12:58:29 -0700353
Steven Moreland1cb64c42019-09-20 11:16:29 -0700354ifeq ($(PRODUCT_SEPOLICY_SPLIT),true)
355LOCAL_REQUIRED_MODULES += \
356 $(addprefix treble_sepolicy_tests_,$(PLATFORM_SEPOLICY_COMPAT_VERSIONS)) \
357
358endif # PRODUCT_SEPOLICY_SPLIT
359endif # SELINUX_IGNORE_NEVERALLOWS
360endif # with_asan
Dan Cashman91d398d2017-09-26 12:58:29 -0700361
Anton Hansson8cfe1e62018-07-02 14:31:29 +0100362ifneq ($(PLATFORM_SEPOLICY_VERSION),$(TOT_SEPOLICY_VERSION))
363LOCAL_REQUIRED_MODULES += \
Inseob Kimd5816612021-09-15 03:01:05 +0000364 sepolicy_freeze_test
Anton Hansson8cfe1e62018-07-02 14:31:29 +0100365endif # ($(PLATFORM_SEPOLICY_VERSION),$(TOT_SEPOLICY_VERSION))
366
367include $(BUILD_PHONY_PACKAGE)
368
369#################################
370
371include $(CLEAR_VARS)
372
Justin Yun0f722692020-10-07 18:28:47 +0900373LOCAL_MODULE := selinux_policy_system_ext
Bob Badour601ebb42021-02-03 23:07:40 -0800374LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered
375LOCAL_LICENSE_CONDITIONS := notice unencumbered
376LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE
Justin Yun0f722692020-10-07 18:28:47 +0900377# Include precompiled policy, unless told otherwise.
378ifneq ($(PRODUCT_PRECOMPILED_SEPOLICY),false)
Inseob Kima76c0c82021-04-29 19:45:50 +0900379ifdef HAS_SYSTEM_EXT_SEPOLICY
Justin Yun0f722692020-10-07 18:28:47 +0900380LOCAL_REQUIRED_MODULES += system_ext_sepolicy_and_mapping.sha256
381endif
Inseob Kima76c0c82021-04-29 19:45:50 +0900382endif
Justin Yun0f722692020-10-07 18:28:47 +0900383
384ifdef HAS_SYSTEM_EXT_SEPOLICY
385LOCAL_REQUIRED_MODULES += system_ext_sepolicy.cil
386endif
387
388ifdef HAS_SYSTEM_EXT_PUBLIC_SEPOLICY
389LOCAL_REQUIRED_MODULES += \
390 system_ext_mapping_file
391
392system_ext_compat_files := $(call build_policy, $(sepolicy_compat_files), $(SYSTEM_EXT_PRIVATE_POLICY))
393
394LOCAL_REQUIRED_MODULES += $(addprefix system_ext_, $(notdir $(system_ext_compat_files)))
395
396endif
397
398ifdef HAS_SYSTEM_EXT_SEPOLICY_DIR
399LOCAL_REQUIRED_MODULES += \
400 system_ext_file_contexts \
401 system_ext_file_contexts_test \
402 system_ext_hwservice_contexts \
403 system_ext_hwservice_contexts_test \
404 system_ext_property_contexts \
405 system_ext_property_contexts_test \
406 system_ext_seapp_contexts \
407 system_ext_service_contexts \
408 system_ext_service_contexts_test \
409 system_ext_mac_permissions.xml \
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800410 system_ext_bug_map \
Yi-Yo Chiang8be93c02021-04-13 02:49:29 +0800411 $(addprefix system_ext_,$(addsuffix .compat.cil,$(PLATFORM_SEPOLICY_COMPAT_VERSIONS))) \
Justin Yun0f722692020-10-07 18:28:47 +0900412
413endif
414
415include $(BUILD_PHONY_PACKAGE)
416
417#################################
418
419include $(CLEAR_VARS)
420
421LOCAL_MODULE := selinux_policy_product
Bob Badour601ebb42021-02-03 23:07:40 -0800422LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered
423LOCAL_LICENSE_CONDITIONS := notice unencumbered
424LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE
Justin Yun0f722692020-10-07 18:28:47 +0900425# Include precompiled policy, unless told otherwise.
426ifneq ($(PRODUCT_PRECOMPILED_SEPOLICY),false)
Inseob Kima76c0c82021-04-29 19:45:50 +0900427ifdef HAS_PRODUCT_SEPOLICY
Justin Yun0f722692020-10-07 18:28:47 +0900428LOCAL_REQUIRED_MODULES += product_sepolicy_and_mapping.sha256
429endif
Inseob Kima76c0c82021-04-29 19:45:50 +0900430endif
Justin Yun0f722692020-10-07 18:28:47 +0900431
432ifdef HAS_PRODUCT_SEPOLICY
433LOCAL_REQUIRED_MODULES += product_sepolicy.cil
434endif
435
436ifdef HAS_PRODUCT_PUBLIC_SEPOLICY
437LOCAL_REQUIRED_MODULES += \
438 product_mapping_file
439
440product_compat_files := $(call build_policy, $(sepolicy_compat_files), $(PRODUCT_PRIVATE_POLICY))
441
442LOCAL_REQUIRED_MODULES += $(addprefix product_, $(notdir $(product_compat_files)))
443
444endif
445
446ifdef HAS_PRODUCT_SEPOLICY_DIR
447LOCAL_REQUIRED_MODULES += \
448 product_file_contexts \
449 product_file_contexts_test \
450 product_hwservice_contexts \
451 product_hwservice_contexts_test \
452 product_property_contexts \
453 product_property_contexts_test \
454 product_seapp_contexts \
455 product_service_contexts \
456 product_service_contexts_test \
457 product_mac_permissions.xml \
458
459endif
460
461include $(BUILD_PHONY_PACKAGE)
462
463#################################
464
465include $(CLEAR_VARS)
466
Anton Hansson8cfe1e62018-07-02 14:31:29 +0100467LOCAL_MODULE := selinux_policy_nonsystem
Bob Badour601ebb42021-02-03 23:07:40 -0800468LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered
469LOCAL_LICENSE_CONDITIONS := notice unencumbered
470LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE
Anton Hansson8cfe1e62018-07-02 14:31:29 +0100471# Include precompiled policy, unless told otherwise.
472ifneq ($(PRODUCT_PRECOMPILED_SEPOLICY),false)
473LOCAL_REQUIRED_MODULES += \
474 precompiled_sepolicy \
Inseob Kima76c0c82021-04-29 19:45:50 +0900475 precompiled_sepolicy.plat_sepolicy_and_mapping.sha256
476
477ifdef HAS_SYSTEM_EXT_SEPOLICY
478LOCAL_REQUIRED_MODULES += precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256
479endif
480
481ifdef HAS_PRODUCT_SEPOLICY
482LOCAL_REQUIRED_MODULES += precompiled_sepolicy.product_sepolicy_and_mapping.sha256
483endif
Anton Hansson8cfe1e62018-07-02 14:31:29 +0100484
485endif # ($(PRODUCT_PRECOMPILED_SEPOLICY),false)
486
487
488# These build targets are not used on non-Treble devices. However, we build these to avoid
489# divergence between Treble and non-Treble devices.
490LOCAL_REQUIRED_MODULES += \
491 plat_pub_versioned.cil \
492 vendor_sepolicy.cil \
493 plat_sepolicy_vers.txt \
494
495LOCAL_REQUIRED_MODULES += \
496 vendor_file_contexts \
Inseob Kimb554e592019-04-15 20:10:46 +0900497 vendor_file_contexts_test \
Anton Hansson8cfe1e62018-07-02 14:31:29 +0100498 vendor_mac_permissions.xml \
499 vendor_property_contexts \
Inseob Kimb554e592019-04-15 20:10:46 +0900500 vendor_property_contexts_test \
Anton Hansson8cfe1e62018-07-02 14:31:29 +0100501 vendor_seapp_contexts \
linpeter87c72612020-06-12 16:25:41 +0800502 vendor_service_contexts \
Anton Hansson8cfe1e62018-07-02 14:31:29 +0100503 vendor_hwservice_contexts \
Inseob Kimb554e592019-04-15 20:10:46 +0900504 vendor_hwservice_contexts_test \
Yi-Yo Chiang2c189652021-11-08 19:30:04 +0800505 vendor_bug_map \
Anton Hansson8cfe1e62018-07-02 14:31:29 +0100506 vndservice_contexts \
507
Bowgo Tsai45457e32017-11-27 11:41:33 +0800508ifdef BOARD_ODM_SEPOLICY_DIRS
Bowgo Tsaibae15172017-11-29 16:14:53 +0800509LOCAL_REQUIRED_MODULES += \
510 odm_sepolicy.cil \
Bowgo Tsaiecf656b2017-11-29 16:15:28 +0800511 odm_file_contexts \
Inseob Kimb554e592019-04-15 20:10:46 +0900512 odm_file_contexts_test \
Bowgo Tsai1f717b12017-11-29 16:15:55 +0800513 odm_seapp_contexts \
Bowgo Tsaiad6231f2017-11-29 16:16:26 +0800514 odm_property_contexts \
Inseob Kimb554e592019-04-15 20:10:46 +0900515 odm_property_contexts_test \
Bowgo Tsaiaf7d85f2017-11-29 16:06:15 +0800516 odm_hwservice_contexts \
Inseob Kimb554e592019-04-15 20:10:46 +0900517 odm_hwservice_contexts_test \
Bowgo Tsaiaf7d85f2017-11-29 16:06:15 +0800518 odm_mac_permissions.xml
Bowgo Tsai45457e32017-11-27 11:41:33 +0800519endif
Tri Vo75887dd2018-12-14 14:30:56 -0800520
Justin Yun0f722692020-10-07 18:28:47 +0900521LOCAL_REQUIRED_MODULES += selinux_policy_system_ext
522LOCAL_REQUIRED_MODULES += selinux_policy_product
Tri Vo4eb68152019-01-23 09:47:05 -0800523
Bowgo Tsaie7636672019-04-19 22:03:33 +0800524# Builds an addtional userdebug sepolicy into the debug ramdisk.
525LOCAL_REQUIRED_MODULES += \
526 userdebug_plat_sepolicy.cil \
527
Dan Cashman4f9a6482017-04-10 12:27:18 -0700528include $(BUILD_PHONY_PACKAGE)
529
Joel Galenson5988b562018-01-03 16:53:24 -0800530#################################
Inseob Kim8ada8a72020-11-09 20:58:58 +0900531
532ifeq ($(mixed_sepolicy_build),true)
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900533ver := $(BOARD_SEPOLICY_VERS)
534reqd_policy_$(ver) := $(BOARD_REQD_MASK_POLICY)
535plat_public_policy_$(ver) := $(LOCAL_PATH)/prebuilts/api/$(ver)/public
536plat_private_policy_$(ver) := $(LOCAL_PATH)/prebuilts/api/$(ver)/private
537system_ext_public_policy_$(ver) := $(BOARD_SYSTEM_EXT_PUBLIC_PREBUILT_DIRS)
538system_ext_private_policy_$(ver) := $(BOARD_SYSTEM_EXT_PRIVATE_PREBUILT_DIRS)
539product_public_policy_$(ver) := $(BOARD_PRODUCT_PUBLIC_PREBUILT_DIRS)
540product_private_policy_$(ver) := $(BOARD_PRODUCT_PRIVATE_PREBUILT_DIRS)
541ver :=
Inseob Kim8ada8a72020-11-09 20:58:58 +0900542else
543reqd_policy_$(PLATFORM_SEPOLICY_VERSION) := $(REQD_MASK_POLICY)
544plat_public_policy_$(PLATFORM_SEPOLICY_VERSION) := $(LOCAL_PATH)/public
545plat_private_policy_$(PLATFORM_SEPOLICY_VERSION) := $(LOCAL_PATH)/private
546system_ext_public_policy_$(PLATFORM_SEPOLICY_VERSION) := $(SYSTEM_EXT_PUBLIC_POLICY)
547system_ext_private_policy_$(PLATFORM_SEPOLICY_VERSION) := $(SYSTEM_EXT_PRIVATE_POLICY)
548product_public_policy_$(PLATFORM_SEPOLICY_VERSION) := $(PRODUCT_PUBLIC_POLICY)
549product_private_policy_$(PLATFORM_SEPOLICY_VERSION) := $(PRODUCT_PRIVATE_POLICY)
550endif
551
Inseob Kim0de7fcc2021-12-22 23:06:53 +0900552built_sepolicy_neverallows := $(call intermediates-dir-for,ETC,sepolicy_neverallows)/sepolicy_neverallows
553built_sepolicy_neverallows += $(call intermediates-dir-for,ETC,sepolicy_neverallows_vendor)/sepolicy_neverallows_vendor
Inseob Kim8ada8a72020-11-09 20:58:58 +0900554
Ying Wang02fb5f32012-01-17 17:51:09 -0800555##################################
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900556# Policy files are now built with Android.bp. Grab them from intermediate.
557# See Android.bp for details of policy files.
Inseob Kima49e7242021-03-22 10:26:13 +0900558#
559reqd_policy_mask.cil := $(call intermediates-dir-for,ETC,reqd_policy_mask.cil)/reqd_policy_mask.cil
Inseob Kimd869d022021-03-19 07:04:51 +0000560
Inseob Kima49e7242021-03-22 10:26:13 +0900561pub_policy.cil := $(call intermediates-dir-for,ETC,pub_policy.cil)/pub_policy.cil
Inseob Kima49e7242021-03-22 10:26:13 +0900562system_ext_pub_policy.cil := $(call intermediates-dir-for,ETC,system_ext_pub_policy.cil)/system_ext_pub_policy.cil
Inseob Kima49e7242021-03-22 10:26:13 +0900563plat_pub_policy.cil := $(call intermediates-dir-for,ETC,plat_pub_policy.cil)/plat_pub_policy.cil
Inseob Kimd869d022021-03-19 07:04:51 +0000564
Inseob Kima49e7242021-03-22 10:26:13 +0900565built_plat_cil := $(call intermediates-dir-for,ETC,plat_sepolicy.cil)/plat_sepolicy.cil
Inseob Kim039175b2021-03-25 15:37:34 +0900566built_plat_mapping_cil := $(call intermediates-dir-for,ETC,plat_mapping_file)/plat_mapping_file
Inseob Kima49e7242021-03-22 10:26:13 +0900567
568ifdef HAS_SYSTEM_EXT_SEPOLICY
569built_system_ext_cil := $(call intermediates-dir-for,ETC,system_ext_sepolicy.cil)/system_ext_sepolicy.cil
Inseob Kim039175b2021-03-25 15:37:34 +0900570built_system_ext_mapping_cil := $(call intermediates-dir-for,ETC,system_ext_mapping_file)/system_ext_mapping_file
Inseob Kima49e7242021-03-22 10:26:13 +0900571endif # ifdef HAS_SYSTEM_EXT_SEPOLICY
572
573ifdef HAS_PRODUCT_SEPOLICY
574built_product_cil := $(call intermediates-dir-for,ETC,product_sepolicy.cil)/product_sepolicy.cil
Inseob Kim039175b2021-03-25 15:37:34 +0900575built_product_mapping_cil := $(call intermediates-dir-for,ETC,product_mapping_file)/product_mapping_file
Inseob Kima49e7242021-03-22 10:26:13 +0900576endif # ifdef HAS_PRODUCT_SEPOLICY
577
Inseob Kim039175b2021-03-25 15:37:34 +0900578built_pub_vers_cil := $(call intermediates-dir-for,ETC,plat_pub_versioned.cil)/plat_pub_versioned.cil
Inseob Kim039175b2021-03-25 15:37:34 +0900579
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900580built_vendor_cil := $(call intermediates-dir-for,ETC,vendor_sepolicy.cil)/vendor_sepolicy.cil
Alex Klyubin193dccd2017-03-07 14:05:57 -0800581
Nick Kralevich1b2ea492018-09-25 11:03:48 -0700582ifdef BOARD_ODM_SEPOLICY_DIRS
Inseob Kim3ac62fe2021-12-16 19:00:03 +0900583built_odm_cil := $(call intermediates-dir-for,ETC,odm_sepolicy.cil)/odm_sepolicy.cil
Nick Kralevich1b2ea492018-09-25 11:03:48 -0700584endif
Bowgo Tsai45457e32017-11-27 11:41:33 +0800585
Inseob Kim3d5f9252021-12-21 20:42:35 +0900586built_sepolicy := $(call intermediates-dir-for,ETC,precompiled_sepolicy)/precompiled_sepolicy
Stephen Smalley01a58af2012-10-02 12:46:37 -0400587
Alex Klyubin84aa7422017-03-10 09:36:07 -0800588#################################
Inseob Kim81cd51a2021-12-24 12:56:09 +0900589# sepolicy is also built with Android.bp.
590# This module is to keep compatibility with monolithic sepolicy devices.
591include $(CLEAR_VARS)
592
593LOCAL_MODULE := sepolicy
594LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered
595LOCAL_LICENSE_CONDITIONS := notice unencumbered
596LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE
597LOCAL_MODULE_CLASS := ETC
598LOCAL_MODULE_TAGS := optional
599LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
600
601include $(BUILD_SYSTEM)/base_rules.mk
602
603$(LOCAL_BUILT_MODULE): $(built_sepolicy)
604 $(copy-file-to-target)
605
dcashman704741a2014-07-25 19:11:52 -0700606##################################
dcashmand225b692016-12-12 09:29:04 -0800607# TODO - remove this. Keep around until we get the filesystem creation stuff taken care of.
608#
William Robertsb8769932015-06-29 16:31:23 -0700609include $(CLEAR_VARS)
610
Richard Hainesc2d01912015-08-06 17:43:52 +0100611LOCAL_MODULE := file_contexts.bin
Bob Badour601ebb42021-02-03 23:07:40 -0800612LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered
613LOCAL_LICENSE_CONDITIONS := notice unencumbered
614LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE
Ying Wang02fb5f32012-01-17 17:51:09 -0800615LOCAL_MODULE_CLASS := ETC
616LOCAL_MODULE_TAGS := optional
617LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
618
Stephen Smalley5b340be2012-03-06 11:12:41 -0500619include $(BUILD_SYSTEM)/base_rules.mk
Ying Wang02fb5f32012-01-17 17:51:09 -0800620
William Roberts49693f12016-01-04 12:20:57 -0800621# The file_contexts.bin is built in the following way:
622# 1. Collect all file_contexts files in THIS repository and process them with
623# m4 into a tmp file called file_contexts.local.tmp.
Jooyung Han0606ce72020-09-23 19:16:10 +0900624# 2. Collect all file_contexts files from LOCAL_FILE_CONTEXTS of installed
625# modules with m4 with a tmp file called file_contexts.modules.tmp.
626# 3. Collect all device specific file_contexts files and process them with m4
William Roberts49693f12016-01-04 12:20:57 -0800627# into a tmp file called file_contexts.device.tmp.
Jooyung Han0606ce72020-09-23 19:16:10 +0900628# 4. Run checkfc -e (allow no device fc entries ie empty) and fc_sort on
William Roberts49693f12016-01-04 12:20:57 -0800629# file_contexts.device.tmp and output to file_contexts.device.sorted.tmp.
Jooyung Han0606ce72020-09-23 19:16:10 +0900630# 5. Concatenate file_contexts.local.tmp, file_contexts.modules.tmp and
Inseob Kim8ada8a72020-11-09 20:58:58 +0900631# file_contexts.device.sorted.tmp into file_contexts.concat.tmp.
Jooyung Han0606ce72020-09-23 19:16:10 +0900632# 6. Run checkfc and sefcontext_compile on file_contexts.concat.tmp to produce
William Roberts49693f12016-01-04 12:20:57 -0800633# file_contexts.bin.
634#
635# Note: That a newline file is placed between each file_context file found to
636# ensure a proper build when an fc file is missing an ending newline.
William Roberts29d14682016-01-04 12:20:57 -0800637
Dan Cashman1b0a71f2017-05-08 14:26:52 -0700638local_fc_files := $(call build_policy, file_contexts, $(PLAT_PRIVATE_POLICY))
639
Bowgo Tsaiac381252019-10-04 14:34:18 +0800640ifdef HAS_SYSTEM_EXT_SEPOLICY_DIR
Bowgo Tsai86a048d2019-09-09 22:04:06 +0800641local_fc_files += $(call build_policy, file_contexts, $(SYSTEM_EXT_PRIVATE_POLICY))
642endif
643
Bowgo Tsai7c4150c2019-10-04 15:36:05 +0800644ifdef HAS_PRODUCT_SEPOLICY_DIR
Tri Vo75887dd2018-12-14 14:30:56 -0800645local_fc_files += $(call build_policy, file_contexts, $(PRODUCT_PRIVATE_POLICY))
646endif
647
William Roberts49693f12016-01-04 12:20:57 -0800648ifneq ($(filter address,$(SANITIZE_TARGET)),)
Mark Salyzyn9b398f32018-06-13 08:02:29 -0700649 local_fc_files += $(wildcard $(addsuffix /file_contexts_asan, $(PLAT_PRIVATE_POLICY)))
650endif
651ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
652 local_fc_files += $(wildcard $(addsuffix /file_contexts_overlayfs, $(PLAT_PRIVATE_POLICY)))
William Roberts49693f12016-01-04 12:20:57 -0800653endif
Jooyung Hana9324742019-11-20 17:54:34 +0900654
William Roberts49693f12016-01-04 12:20:57 -0800655file_contexts.local.tmp := $(intermediates)/file_contexts.local.tmp
Jooyung Han0606ce72020-09-23 19:16:10 +0900656$(call merge-fc-files,$(local_fc_files),$(file_contexts.local.tmp))
657
658# The rule for file_contexts.modules.tmp is defined in build/make/core/Makefile.
659# it gathers LOCAL_FILE_CONTEXTS from product_MODULES
660file_contexts.modules.tmp := $(intermediates)/file_contexts.modules.tmp
William Roberts49693f12016-01-04 12:20:57 -0800661
Bowgo Tsaiafbcf212018-02-05 17:34:52 +0800662device_fc_files := $(call build_vendor_policy, file_contexts)
Bowgo Tsaibae15172017-11-29 16:14:53 +0800663
664ifdef BOARD_ODM_SEPOLICY_DIRS
665device_fc_files += $(call build_odm_policy, file_contexts)
666endif
667
William Roberts49693f12016-01-04 12:20:57 -0800668file_contexts.device.tmp := $(intermediates)/file_contexts.device.tmp
669$(file_contexts.device.tmp): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
Dan Willemsen3c3e59b2019-06-19 10:52:50 -0700670$(file_contexts.device.tmp): PRIVATE_DEVICE_FC_FILES := $(device_fc_files)
671$(file_contexts.device.tmp): $(device_fc_files) $(M4)
William Roberts49693f12016-01-04 12:20:57 -0800672 @mkdir -p $(dir $@)
Dan Willemsen3c3e59b2019-06-19 10:52:50 -0700673 $(hide) $(M4) --fatal-warnings -s $(PRIVATE_ADDITIONAL_M4DEFS) $(PRIVATE_DEVICE_FC_FILES) > $@
William Roberts49693f12016-01-04 12:20:57 -0800674
675file_contexts.device.sorted.tmp := $(intermediates)/file_contexts.device.sorted.tmp
676$(file_contexts.device.sorted.tmp): PRIVATE_SEPOLICY := $(built_sepolicy)
Bowgo Tsaiafbcf212018-02-05 17:34:52 +0800677$(file_contexts.device.sorted.tmp): $(file_contexts.device.tmp) $(built_sepolicy) \
678 $(HOST_OUT_EXECUTABLES)/fc_sort $(HOST_OUT_EXECUTABLES)/checkfc
William Roberts49693f12016-01-04 12:20:57 -0800679 @mkdir -p $(dir $@)
dcashman07791552016-12-07 11:27:47 -0800680 $(hide) $(HOST_OUT_EXECUTABLES)/checkfc -e $(PRIVATE_SEPOLICY) $<
Jeff Vander Stoep1ca7a4c2019-04-10 16:53:17 -0700681 $(hide) $(HOST_OUT_EXECUTABLES)/fc_sort -i $< -o $@
William Roberts49693f12016-01-04 12:20:57 -0800682
683file_contexts.concat.tmp := $(intermediates)/file_contexts.concat.tmp
Jooyung Han0606ce72020-09-23 19:16:10 +0900684$(call merge-fc-files,\
685 $(file_contexts.local.tmp) $(file_contexts.modules.tmp) $(file_contexts.device.sorted.tmp),\
686 $(file_contexts.concat.tmp))
Stephen Smalley5b340be2012-03-06 11:12:41 -0500687
William Roberts3746a0a2015-09-25 10:18:44 -0700688$(LOCAL_BUILT_MODULE): PRIVATE_SEPOLICY := $(built_sepolicy)
William Roberts49693f12016-01-04 12:20:57 -0800689$(LOCAL_BUILT_MODULE): $(file_contexts.concat.tmp) $(built_sepolicy) $(HOST_OUT_EXECUTABLES)/sefcontext_compile $(HOST_OUT_EXECUTABLES)/checkfc
Richard Hainesc2d01912015-08-06 17:43:52 +0100690 @mkdir -p $(dir $@)
dcashman07791552016-12-07 11:27:47 -0800691 $(hide) $(HOST_OUT_EXECUTABLES)/checkfc $(PRIVATE_SEPOLICY) $<
Richard Hainesc2d01912015-08-06 17:43:52 +0100692 $(hide) $(HOST_OUT_EXECUTABLES)/sefcontext_compile -o $@ $<
693
Robert Craig8b7545b2014-03-20 09:35:08 -0400694built_fc := $(LOCAL_BUILT_MODULE)
William Roberts49693f12016-01-04 12:20:57 -0800695local_fc_files :=
696local_fcfiles_with_nl :=
697device_fc_files :=
698device_fcfiles_with_nl :=
699file_contexts.concat.tmp :=
700file_contexts.device.sorted.tmp :=
701file_contexts.device.tmp :=
702file_contexts.local.tmp :=
Jooyung Han0606ce72020-09-23 19:16:10 +0900703file_contexts.modules.tmp :=
William Roberts171a0622012-08-16 10:55:05 -0700704
Ying Wang02fb5f32012-01-17 17:51:09 -0800705##################################
Tri Vo8b3016b2019-01-07 16:43:31 -0800706include $(LOCAL_PATH)/seapp_contexts.mk
Stephen Smalley2e0cd5a2015-03-12 17:45:03 -0400707
708##################################
Inseob Kimb554e592019-04-15 20:10:46 +0900709include $(LOCAL_PATH)/contexts_tests.mk
Martijn Coenen3ea47b92017-04-07 16:14:43 -0700710
711##################################
712include $(CLEAR_VARS)
713
Martijn Coenen6676c232017-03-31 17:29:53 -0700714LOCAL_MODULE := vndservice_contexts
Bob Badour601ebb42021-02-03 23:07:40 -0800715LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered
716LOCAL_LICENSE_CONDITIONS := notice unencumbered
717LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE
Martijn Coenen6676c232017-03-31 17:29:53 -0700718LOCAL_MODULE_CLASS := ETC
719LOCAL_MODULE_TAGS := optional
Martijn Coenen6676c232017-03-31 17:29:53 -0700720LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc/selinux
Martijn Coenen6676c232017-03-31 17:29:53 -0700721
722include $(BUILD_SYSTEM)/base_rules.mk
723
Inseob Kim7174ffe2021-12-08 22:45:58 +0900724vnd_svcfiles := $(call build_policy, vndservice_contexts, $(BOARD_PLAT_VENDOR_POLICY) $(BOARD_VENDOR_SEPOLICY_DIRS) $(BOARD_REQD_MASK_POLICY))
Martijn Coenen6676c232017-03-31 17:29:53 -0700725
726vndservice_contexts.tmp := $(intermediates)/vndservice_contexts.tmp
727$(vndservice_contexts.tmp): PRIVATE_SVC_FILES := $(vnd_svcfiles)
728$(vndservice_contexts.tmp): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
Dan Willemsen3c3e59b2019-06-19 10:52:50 -0700729$(vndservice_contexts.tmp): $(vnd_svcfiles) $(M4)
Martijn Coenen6676c232017-03-31 17:29:53 -0700730 @mkdir -p $(dir $@)
Dan Willemsen3c3e59b2019-06-19 10:52:50 -0700731 $(hide) $(M4) --fatal-warnings -s $(PRIVATE_ADDITIONAL_M4DEFS) $(PRIVATE_SVC_FILES) > $@
Martijn Coenen6676c232017-03-31 17:29:53 -0700732
733$(LOCAL_BUILT_MODULE): PRIVATE_SEPOLICY := $(built_sepolicy)
734$(LOCAL_BUILT_MODULE): $(vndservice_contexts.tmp) $(built_sepolicy) $(HOST_OUT_EXECUTABLES)/checkfc $(ACP)
735 @mkdir -p $(dir $@)
736 sed -e 's/#.*$$//' -e '/^$$/d' $< > $@
Martijn Coenenee976622017-04-07 10:08:55 -0700737 $(hide) $(HOST_OUT_EXECUTABLES)/checkfc -e -v $(PRIVATE_SEPOLICY) $@
Martijn Coenen6676c232017-03-31 17:29:53 -0700738
739vnd_svcfiles :=
740vndservice_contexts.tmp :=
dcashman90b3b942016-12-14 13:47:55 -0800741
742##################################
Tri Vo8b3016b2019-01-07 16:43:31 -0800743include $(LOCAL_PATH)/mac_permissions.mk
Bowgo Tsaiaf7d85f2017-11-29 16:06:15 +0800744
Dan Cashman91d398d2017-09-26 12:58:29 -0700745#################################
746include $(CLEAR_VARS)
747LOCAL_MODULE := sepolicy_tests
Bob Badour601ebb42021-02-03 23:07:40 -0800748LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 legacy_unencumbered
749LOCAL_LICENSE_CONDITIONS := notice unencumbered
750LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE
Jooyung Han749cf932019-05-30 01:05:43 +0900751LOCAL_MODULE_CLASS := FAKE
752LOCAL_MODULE_TAGS := optional
Dan Cashman91d398d2017-09-26 12:58:29 -0700753
754include $(BUILD_SYSTEM)/base_rules.mk
755
Inseob Kimb554e592019-04-15 20:10:46 +0900756all_fc_files := $(TARGET_OUT)/etc/selinux/plat_file_contexts
757all_fc_files += $(TARGET_OUT_VENDOR)/etc/selinux/vendor_file_contexts
Bowgo Tsaiac381252019-10-04 14:34:18 +0800758ifdef HAS_SYSTEM_EXT_SEPOLICY_DIR
Bowgo Tsai86a048d2019-09-09 22:04:06 +0800759all_fc_files += $(TARGET_OUT_SYSTEM_EXT)/etc/selinux/system_ext_file_contexts
760endif
Bowgo Tsai7c4150c2019-10-04 15:36:05 +0800761ifdef HAS_PRODUCT_SEPOLICY_DIR
Inseob Kimb554e592019-04-15 20:10:46 +0900762all_fc_files += $(TARGET_OUT_PRODUCT)/etc/selinux/product_file_contexts
Tri Vo3361ec42018-12-18 19:51:19 -0800763endif
Bowgo Tsaibae15172017-11-29 16:14:53 +0800764ifdef BOARD_ODM_SEPOLICY_DIRS
Inseob Kimb554e592019-04-15 20:10:46 +0900765all_fc_files += $(TARGET_OUT_ODM)/etc/selinux/odm_file_contexts
Bowgo Tsaibae15172017-11-29 16:14:53 +0800766endif
Bowgo Tsaiafbcf212018-02-05 17:34:52 +0800767all_fc_args := $(foreach file, $(all_fc_files), -f $(file))
768
Jooyung Han749cf932019-05-30 01:05:43 +0900769$(LOCAL_BUILT_MODULE): ALL_FC_ARGS := $(all_fc_args)
770$(LOCAL_BUILT_MODULE): PRIVATE_SEPOLICY := $(built_sepolicy)
771$(LOCAL_BUILT_MODULE): $(HOST_OUT_EXECUTABLES)/sepolicy_tests $(all_fc_files) $(built_sepolicy)
Dan Cashman91d398d2017-09-26 12:58:29 -0700772 @mkdir -p $(dir $@)
Jeff Vander Stoep3ca843a2017-10-04 09:42:29 -0700773 $(hide) $(HOST_OUT_EXECUTABLES)/sepolicy_tests -l $(HOST_OUT)/lib64/libsepolwrap.$(SHAREDLIB_EXT) \
Bowgo Tsaiafbcf212018-02-05 17:34:52 +0800774 $(ALL_FC_ARGS) -p $(PRIVATE_SEPOLICY)
Dan Cashman91d398d2017-09-26 12:58:29 -0700775 $(hide) touch $@
776
rpcraigb19665c2012-07-30 09:33:03 -0400777##################################
Tri Vo14069262018-01-31 16:22:35 -0800778# Tests for Treble compatibility of current platform policy and vendor policy of
779# given release version.
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000780ifeq ($(PRODUCT_SEPOLICY_SPLIT),true)
781
782built_plat_sepolicy := $(call intermediates-dir-for,ETC,base_plat_sepolicy)/base_plat_sepolicy
783built_system_ext_sepolicy := $(call intermediates-dir-for,ETC,base_system_ext_sepolicy)/base_system_ext_sepolicy
784built_product_sepolicy := $(call intermediates-dir-for,ETC,base_product_sepolicy)/base_product_sepolicy
785
786base_plat_pub_policy.cil := $(call intermediates-dir-for,ETC,base_plat_pub_policy.cil)/base_plat_pub_policy.cil
787base_system_ext_pub_polcy.cil := $(call intermediates-dir-for,ETC,base_system_ext_pub_polcy.cil)/base_system_ext_pub_polcy.cil
788base_product_pub_policy.cil := $(call intermediates-dir-for,ETC,base_product_pub_policy.cil)/base_product_pub_policy.cil
789
Inseob Kimed2dc8c2021-12-10 18:34:41 +0900790$(foreach v,$(PLATFORM_SEPOLICY_COMPAT_VERSIONS), \
791 $(eval version_under_treble_tests := $(v)) \
792 $(eval include $(LOCAL_PATH)/treble_sepolicy_tests_for_release.mk) \
793)
Steven Moreland1cb64c42019-09-20 11:16:29 -0700794endif # PRODUCT_SEPOLICY_SPLIT
Jae Shin1fa96342018-07-11 18:30:44 +0900795
Inseob Kimed2dc8c2021-12-10 18:34:41 +0900796$(foreach v,$(PLATFORM_SEPOLICY_COMPAT_VERSIONS), \
797 $(eval version_under_treble_tests := $(v)) \
798 $(eval include $(LOCAL_PATH)/compat.mk) \
799)
Jeff Vander Stoep564e2922019-05-02 13:48:44 -0700800
Inseob Kim4d90b7e2021-09-27 13:43:01 +0000801built_plat_sepolicy :=
802built_system_ext_sepolicy :=
803built_product_sepolicy :=
804base_plat_pub_policy.cil :=
805base_system_ext_pub_polcy.cil :=
806base_product_pub_policy.cil :=
Inseob Kimb554e592019-04-15 20:10:46 +0900807all_fc_files :=
808all_fc_args :=
Dan Cashman91d398d2017-09-26 12:58:29 -0700809
Jeff Vander Stoep1fc06822017-05-31 15:36:07 -0700810#################################
Tri Vo81198bb2018-03-15 11:38:08 -0700811
rpcraig47cd3962012-10-17 21:09:52 -0400812
Bowgo Tsaiafbcf212018-02-05 17:34:52 +0800813build_vendor_policy :=
Bowgo Tsaibae15172017-11-29 16:14:53 +0800814build_odm_policy :=
Dan Cashman1c040272016-12-15 15:28:44 -0800815build_policy :=
Alex Klyubin8f7173b2017-02-25 14:47:53 -0800816built_plat_cil :=
Bowgo Tsai948934b2019-08-29 17:12:11 +0800817built_system_ext_cil :=
818built_product_cil :=
Tri Voe68ba592019-01-15 13:31:03 -0800819built_pub_vers_cil :=
Tri Vo937e6642019-01-15 15:16:55 -0800820built_plat_mapping_cil :=
Bowgo Tsai948934b2019-08-29 17:12:11 +0800821built_system_ext_mapping_cil :=
Tri Vo937e6642019-01-15 15:16:55 -0800822built_product_mapping_cil :=
Bowgo Tsaiafbcf212018-02-05 17:34:52 +0800823built_vendor_cil :=
Bowgo Tsai45457e32017-11-27 11:41:33 +0800824built_odm_cil :=
Dan Cashman1c040272016-12-15 15:28:44 -0800825built_sepolicy :=
Joel Galenson5988b562018-01-03 16:53:24 -0800826built_sepolicy_neverallows :=
Sandeep Patila058b562016-12-27 15:10:48 -0800827built_plat_svc :=
Bowgo Tsaiafbcf212018-02-05 17:34:52 +0800828built_vendor_svc :=
Inseob Kimed59c222019-09-26 15:14:55 +0900829treble_sysprop_neverallow :=
Inseob Kimafc09932020-09-28 13:32:43 +0900830enforce_sysprop_owner :=
Hridya Valsarajua885dd82021-04-26 16:32:17 -0700831enforce_debugfs_restriction :=
Jeff Vander Stoepb8787692017-04-21 15:57:07 -0700832mapping_policy :=
Dan Cashman1c040272016-12-15 15:28:44 -0800833my_target_arch :=
Tri Voe68ba592019-01-15 13:31:03 -0800834pub_policy.cil :=
Bowgo Tsai948934b2019-08-29 17:12:11 +0800835system_ext_pub_policy.cil :=
836plat_pub_policy.cil :=
dcashman1faa6442016-11-28 07:20:28 -0800837reqd_policy_mask.cil :=
Dan Cashman1c040272016-12-15 15:28:44 -0800838sepolicy_build_files :=
Alex Klyubin7cda44f2017-03-21 14:28:53 -0700839sepolicy_build_cil_workaround_files :=
Jeff Vander Stoep74434842017-03-13 12:22:15 -0700840with_asan :=
Alice Chucdfb06f2012-11-01 11:33:04 -0700841
842include $(call all-makefiles-under,$(LOCAL_PATH))