blob: 6474b2ab14809a6d241b18e43d53567666b7be78 [file] [log] [blame]
Stephen Smalley2dd4e512012-01-04 12:33:27 -05001LOCAL_PATH:= $(call my-dir)
William Robertsf0e0a942012-08-27 15:41:15 -07002
Stephen Smalley2dd4e512012-01-04 12:33:27 -05003include $(CLEAR_VARS)
Stephen Smalley2dd4e512012-01-04 12:33:27 -05004
Stephen Smalley8e0ca882015-04-01 10:14:56 -04005ifdef BOARD_SEPOLICY_UNION
6$(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.)
7endif
Robert Craig6b0ff472014-01-29 13:10:58 -05008
dcashmancc39f632016-07-22 13:13:11 -07009# sepolicy is now divided into multiple portions:
10# public - policy exported on which non-platform policy developers may write
11# additional policy. types and attributes are versioned and included in
12# delivered non-platform policy, which is to be combined with platform policy.
13# private - platform-only policy required for platform functionality but which
14# is not exported to vendor policy developers and as such may not be assumed
15# to exist.
Alex Klyubin55961722017-01-30 18:44:59 -080016# vendor - vendor-only policy required for vendor functionality. This policy can
17# reference the public policy but cannot reference the private policy. This
18# policy is for components which are produced from the core/non-vendor tree and
19# placed into a vendor partition.
dcashman07791552016-12-07 11:27:47 -080020# mapping - This contains policy statements which map the attributes
dcashmancc39f632016-07-22 13:13:11 -070021# exposed in the public policy of previous versions to the concrete types used
22# in this policy to ensure that policy targeting attributes from public
23# policy from an older platform version continues to work.
24
dcashman2e00e632016-10-12 14:58:09 -070025# build process for device:
dcashmancc39f632016-07-22 13:13:11 -070026# 1) convert policies to CIL:
27# - private + public platform policy to CIL
28# - mapping file to CIL (should already be in CIL form)
29# - non-platform public policy to CIL
30# - non-platform public + private policy to CIL
31# 2) attributize policy
dcashmancc39f632016-07-22 13:13:11 -070032# - run script which takes non-platform public and non-platform combined
33# private + public policy and produces attributized and versioned
34# non-platform policy
35# 3) combine policy files
36# - combine mapping, platform and non-platform policy.
37# - compile output binary policy file
38
39PLAT_PUBLIC_POLICY := $(LOCAL_PATH)/public
40PLAT_PRIVATE_POLICY := $(LOCAL_PATH)/private
Alex Klyubin55961722017-01-30 18:44:59 -080041PLAT_VENDOR_POLICY := $(LOCAL_PATH)/vendor
dcashman2e00e632016-10-12 14:58:09 -070042REQD_MASK_POLICY := $(LOCAL_PATH)/reqd_mask
Felix8c53a332020-07-14 21:28:51 +020043
44SYSTEM_EXT_PUBLIC_POLICY := $(SYSTEM_EXT_PUBLIC_SEPOLICY_DIRS)
Felix8c53a332020-07-14 21:28:51 +020045SYSTEM_EXT_PRIVATE_POLICY := $(SYSTEM_EXT_PRIVATE_SEPOLICY_DIRS)
Felix8c53a332020-07-14 21:28:51 +020046
Tri Vo9918f282019-02-01 11:41:08 -080047PRODUCT_PUBLIC_POLICY := $(PRODUCT_PUBLIC_SEPOLICY_DIRS)
48PRODUCT_PRIVATE_POLICY := $(PRODUCT_PRIVATE_SEPOLICY_DIRS)
Tri Vo75887dd2018-12-14 14:30:56 -080049
Bowgo Tsai948934b2019-08-29 17:12:11 +080050ifneq (,$(SYSTEM_EXT_PUBLIC_POLICY)$(SYSTEM_EXT_PRIVATE_POLICY))
Bowgo Tsaiac381252019-10-04 14:34:18 +080051HAS_SYSTEM_EXT_SEPOLICY_DIR := true
Bowgo Tsai948934b2019-08-29 17:12:11 +080052endif
53
Tri Vo75887dd2018-12-14 14:30:56 -080054# TODO(b/119305624): Currently if the device doesn't have a product partition,
55# we install product sepolicy into /system/product. We do that because bits of
56# product sepolicy that's still in /system might depend on bits that have moved
57# to /product. Once we finish migrating product sepolicy out of system, change
58# it so that if no product partition is present, product sepolicy artifacts are
59# not built and installed at all.
60ifneq (,$(PRODUCT_PUBLIC_POLICY)$(PRODUCT_PRIVATE_POLICY))
Bowgo Tsai7c4150c2019-10-04 15:36:05 +080061HAS_PRODUCT_SEPOLICY_DIR := true
Tri Vo75887dd2018-12-14 14:30:56 -080062endif
dcashman2e00e632016-10-12 14:58:09 -070063
Joel Galenson5988b562018-01-03 16:53:24 -080064ifeq ($(SELINUX_IGNORE_NEVERALLOWS),true)
65ifeq ($(TARGET_BUILD_VARIANT),user)
66$(error SELINUX_IGNORE_NEVERALLOWS := true cannot be used in user builds)
67endif
68$(warning Be careful when using the SELINUX_IGNORE_NEVERALLOWS flag. \
69 It does not work in user builds and using it will \
70 not stop you from failing CTS.)
Joel Galenson5988b562018-01-03 16:53:24 -080071endif
72
Bowgo Tsai45457e32017-11-27 11:41:33 +080073# BOARD_SEPOLICY_DIRS was used for vendor/odm sepolicy customization before.
74# It has been replaced by BOARD_VENDOR_SEPOLICY_DIRS (mandatory) and
75# BOARD_ODM_SEPOLICY_DIRS (optional). BOARD_SEPOLICY_DIRS is still allowed for
76# backward compatibility, which will be merged into BOARD_VENDOR_SEPOLICY_DIRS.
Bowgo Tsaiafbcf212018-02-05 17:34:52 +080077ifdef BOARD_SEPOLICY_DIRS
78BOARD_VENDOR_SEPOLICY_DIRS += $(BOARD_SEPOLICY_DIRS)
79endif
Dan Cashman4d24a772017-04-12 14:28:34 -070080
dcashmancc39f632016-07-22 13:13:11 -070081###########################################################
82# Compute policy files to be used in policy build.
83# $(1): files to include
84# $(2): directories in which to find files
85###########################################################
86
87define build_policy
Cole Faust087d5272021-09-30 15:48:34 -070088$(strip $(foreach type, $(1), $(foreach file, $(addsuffix /$(type), $(2)), $(sort $(wildcard $(file))))))
dcashmancc39f632016-07-22 13:13:11 -070089endef
William Roberts29d14682016-01-04 12:20:57 -080090
dcashman704741a2014-07-25 19:11:52 -070091sepolicy_build_files := security_classes \
92 initial_sids \
93 access_vectors \
94 global_macros \
Nick Kralevicha17a2662014-11-05 15:30:41 -080095 neverallow_macros \
dcashman704741a2014-07-25 19:11:52 -070096 mls_macros \
dcashman2e00e632016-10-12 14:58:09 -070097 mls_decl \
dcashman704741a2014-07-25 19:11:52 -070098 mls \
99 policy_capabilities \
100 te_macros \
101 attributes \
Jeff Vander Stoepcbaa2b72015-12-22 10:39:34 -0800102 ioctl_defines \
Jeff Vander Stoepde9b5302015-06-05 15:28:55 -0700103 ioctl_macros \
dcashman704741a2014-07-25 19:11:52 -0700104 *.te \
dcashman2e00e632016-10-12 14:58:09 -0700105 roles_decl \
dcashman704741a2014-07-25 19:11:52 -0700106 roles \
107 users \
108 initial_sid_contexts \
109 fs_use \
110 genfs_contexts \
111 port_contexts
112
Chris Gross12c0b242020-09-21 15:32:16 -0700113sepolicy_compat_files := $(foreach ver, $(PLATFORM_SEPOLICY_COMPAT_VERSIONS), \
114 $(addprefix compat/$(ver)/, $(addsuffix .cil, $(ver))))
115
Tri Vo71f12392019-10-07 16:31:40 -0700116# Security classes and permissions defined outside of system/sepolicy.
117security_class_extension_files := $(call build_policy, security_classes access_vectors, \
118 $(SYSTEM_EXT_PUBLIC_POLICY) $(SYSTEM_EXT_PRIVATE_POLICY) \
119 $(PRODUCT_PUBLIC_POLICY) $(PRODUCT_PRIVATE_POLICY) \
120 $(BOARD_VENDOR_SEPOLICY_DIRS) $(BOARD_ODM_SEPOLICY_DIRS))
121
122ifneq (,$(strip $(security_class_extension_files)))
123 $(error Only platform SELinux policy may define classes and permissions: $(strip $(security_class_extension_files)))
124endif
125
Bowgo Tsaiac381252019-10-04 14:34:18 +0800126ifdef HAS_SYSTEM_EXT_SEPOLICY_DIR
127 # Checks if there are public system_ext policy files.
128 policy_files := $(call build_policy, $(sepolicy_build_files), $(SYSTEM_EXT_PUBLIC_POLICY))
129 ifneq (,$(strip $(policy_files)))
130 HAS_SYSTEM_EXT_PUBLIC_SEPOLICY := true
131 endif
132 # Checks if there are public/private system_ext policy files.
133 policy_files := $(call build_policy, $(sepolicy_build_files), $(SYSTEM_EXT_PUBLIC_POLICY) $(SYSTEM_EXT_PRIVATE_POLICY))
134 ifneq (,$(strip $(policy_files)))
135 HAS_SYSTEM_EXT_SEPOLICY := true
136 endif
137endif # ifdef HAS_SYSTEM_EXT_SEPOLICY_DIR
138
Bowgo Tsai7c4150c2019-10-04 15:36:05 +0800139ifdef HAS_PRODUCT_SEPOLICY_DIR
140 # Checks if there are public product policy files.
141 policy_files := $(call build_policy, $(sepolicy_build_files), $(PRODUCT_PUBLIC_POLICY))
142 ifneq (,$(strip $(policy_files)))
143 HAS_PRODUCT_PUBLIC_SEPOLICY := true
144 endif
145 # Checks if there are public/private product policy files.
146 policy_files := $(call build_policy, $(sepolicy_build_files), $(PRODUCT_PUBLIC_POLICY) $(PRODUCT_PRIVATE_POLICY))
147 ifneq (,$(strip $(policy_files)))
148 HAS_PRODUCT_SEPOLICY := true
149 endif
150endif # ifdef HAS_PRODUCT_SEPOLICY_DIR
151
Jeff Vander Stoep74434842017-03-13 12:22:15 -0700152with_asan := false
153ifneq (,$(filter address,$(SANITIZE_TARGET)))
154 with_asan := true
155endif
156
Inseob Kimd7b381c2023-08-23 02:07:40 +0000157ifeq ($(PRODUCT_SHIPPING_API_LEVEL),)
158 #$(warning no product shipping level defined)
159else ifneq ($(call math_lt,29,$(PRODUCT_SHIPPING_API_LEVEL)),)
160 ifneq ($(BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW),)
161 $(error BUILD_BROKEN_TREBLE_SYSPROP_NEVERALLOW cannot be set on a device shipping with R or later, and this is tested by CTS.)
162 endif
163endif
164
Inseob Kimd7b381c2023-08-23 02:07:40 +0000165ifeq ($(PRODUCT_SHIPPING_API_LEVEL),)
Inseob Kimafc09932020-09-28 13:32:43 +0900166 #$(warning no product shipping level defined)
Inseob Kimd7b381c2023-08-23 02:07:40 +0000167else ifneq ($(call math_lt,30,$(PRODUCT_SHIPPING_API_LEVEL)),)
168 ifneq ($(BUILD_BROKEN_ENFORCE_SYSPROP_OWNER),)
Inseob Kimafc09932020-09-28 13:32:43 +0900169 $(error BUILD_BROKEN_ENFORCE_SYSPROP_OWNER cannot be set on a device shipping with S or later, and this is tested by CTS.)
170 endif
171endif
172
Jeff Vander Stoep1fc06822017-05-31 15:36:07 -0700173#################################
Tri Vo81198bb2018-03-15 11:38:08 -0700174
rpcraig47cd3962012-10-17 21:09:52 -0400175
Dan Cashman1c040272016-12-15 15:28:44 -0800176build_policy :=
Dan Cashman1c040272016-12-15 15:28:44 -0800177sepolicy_build_files :=
Jeff Vander Stoep74434842017-03-13 12:22:15 -0700178with_asan :=