@@ -38,14 +38,13 @@ endif
3838# in this policy to ensure that policy targeting attributes from public
3939# policy from an older platform version continues to work.
4040
41- # TODO - build process for device:
41+ # build process for device:
4242# 1) convert policies to CIL:
4343# - private + public platform policy to CIL
4444# - mapping file to CIL (should already be in CIL form)
4545# - non-platform public policy to CIL
4646# - non-platform public + private policy to CIL
4747# 2) attributize policy
48- # - TODO: do this for platform policy?
4948# - run script which takes non-platform public and non-platform combined
5049# private + public policy and produces attributized and versioned
5150# non-platform policy
5554
5655PLAT_PUBLIC_POLICY := $(LOCAL_PATH ) /public
5756PLAT_PRIVATE_POLICY := $(LOCAL_PATH ) /private
57+ REQD_MASK_POLICY := $(LOCAL_PATH ) /reqd_mask
58+
59+ # TODO: move to README when doing the README update and finalizing versioning.
60+ # BOARD_SEPOLICY_VERS should contain the platform version identifier
61+ # corresponding to the platform on which the non-platform policy is to be
62+ # based. If unspecified, this will build against the current public platform
63+ # policy in tree.
64+ # BOARD_SEPOLICY_VERS_DIR should contain the public platform policy which
65+ # is associated with the given BOARD_SEPOLICY_VERS. The policy therein will be
66+ # versioned according to the BOARD_SEPOLICY_VERS identifier and included as
67+ # part of the non-platform policy to ensure removal of access in future
68+ # platform policy does not break non-platform policy.
69+ ifndef BOARD_SEPOLICY_VERS
70+ $(warning BOARD_SEPOLICY_VERS not specified, assuming current platform version)
71+ BOARD_SEPOLICY_VERS := current
72+ BOARD_SEPOLICY_VERS_DIR := $(PLAT_PUBLIC_POLICY )
73+ else
74+ ifndef BOARD_SEPOLICY_VERS_DIR
75+ $(error BOARD_SEPOLICY_VERS_DIR not specified for versioned sepolicy.)
76+ endif
77+ endif
5878
5979# ##########################################################
6080# Compute policy files to be used in policy build.
@@ -83,13 +103,15 @@ sepolicy_build_files := security_classes \
83103 global_macros \
84104 neverallow_macros \
85105 mls_macros \
106+ mls_decl \
86107 mls \
87108 policy_capabilities \
88109 te_macros \
89110 attributes \
90111 ioctl_defines \
91112 ioctl_macros \
92113 *.te \
114+ roles_decl \
93115 roles \
94116 users \
95117 initial_sid_contexts \
@@ -128,11 +150,64 @@ endif
128150
129151include $(BUILD_SYSTEM ) /base_rules.mk
130152
131- platform_policy.conf := $(intermediates ) /plat_policy.conf
132- $(platform_policy.conf ) : PRIVATE_MLS_SENS := $(MLS_SENS )
133- $(platform_policy.conf ) : PRIVATE_MLS_CATS := $(MLS_CATS )
134- $(platform_policy.conf ) : PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS )
135- $(platform_policy.conf ) : $(call build_policy, $(sepolicy_build_files ) , \
153+ # reqd_policy_mask - a policy.conf file which contains only the bare minimum
154+ # policy necessary to use checkpolicy. This bare-minimum policy needs to be
155+ # present in all policy.conf files, but should not necessarily be exported as
156+ # part of the public policy. The rules generated by reqd_policy_mask will allow
157+ # the compilation of public policy and subsequent removal of CIL policy that
158+ # should not be exported.
159+
160+ reqd_policy_mask.conf := $(intermediates ) /reqd_policy_mask.conf
161+ $(reqd_policy_mask.conf ) : PRIVATE_MLS_SENS := $(MLS_SENS )
162+ $(reqd_policy_mask.conf ) : PRIVATE_MLS_CATS := $(MLS_CATS )
163+ $(reqd_policy_mask.conf ) : PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS )
164+ $(reqd_policy_mask.conf ) : $(call build_policy, $(sepolicy_build_files ) , $(REQD_MASK_POLICY ) )
165+ @mkdir -p $(dir $@ )
166+ $(hide ) m4 $(PRIVATE_ADDITIONAL_M4DEFS ) \
167+ -D mls_num_sens=$(PRIVATE_MLS_SENS ) -D mls_num_cats=$(PRIVATE_MLS_CATS ) \
168+ -D target_build_variant=$(TARGET_BUILD_VARIANT ) \
169+ -s $^ > $@
170+
171+ reqd_policy_mask.cil := $(intermediates ) /reqd_policy_mask.cil
172+ $(reqd_policy_mask.cil ) : $(reqd_policy_mask.conf ) $(HOST_OUT_EXECUTABLES ) /checkpolicy
173+ @mkdir -p $(dir $@ )
174+ $(hide ) $(HOST_OUT_EXECUTABLES ) /checkpolicy -C -M -c $(POLICYVERS ) -o $@ $<
175+
176+ # plat_pub_policy - policy that will be exported to be a part of non-platform
177+ # policy corresponding to this platform version. This is a limited subset of
178+ # policy that would not compile in checkpolicy on its own. To get around this
179+ # limitation, add only the required files from private policy, which will
180+ # generate CIL policy that will then be filtered out by the reqd_policy_mask.
181+ plat_pub_policy.conf := $(intermediates ) /plat_pub_policy.conf
182+ $(plat_pub_policy.conf ) : PRIVATE_MLS_SENS := $(MLS_SENS )
183+ $(plat_pub_policy.conf ) : PRIVATE_MLS_CATS := $(MLS_CATS )
184+ $(plat_pub_policy.conf ) : PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS )
185+ $(plat_pub_policy.conf ) : $(call build_policy, $(sepolicy_build_files ) , \
186+ $(BOARD_SEPOLICY_VERS_DIR ) $(REQD_MASK_POLICY ) )
187+ @mkdir -p $(dir $@ )
188+ $(hide ) m4 $(PRIVATE_ADDITIONAL_M4DEFS ) \
189+ -D mls_num_sens=$(PRIVATE_MLS_SENS ) -D mls_num_cats=$(PRIVATE_MLS_CATS ) \
190+ -D target_build_variant=$(TARGET_BUILD_VARIANT ) \
191+ -s $^ > $@
192+
193+ plat_pub_policy.cil := $(intermediates ) /plat_pub_policy.cil
194+ $(plat_pub_policy.cil ) : $(plat_pub_policy.conf ) $(HOST_OUT_EXECUTABLES ) /checkpolicy
195+ @mkdir -p $(dir $@ )
196+ $(hide ) $(HOST_OUT_EXECUTABLES ) /checkpolicy -C -M -c $(POLICYVERS ) -o $@ $<
197+
198+ pruned_plat_pub_policy.cil := $(intermediates ) /pruned_plat_pub_policy.cil
199+ $(pruned_plat_pub_policy.cil ) : $(reqd_policy_mask.cil ) $(plat_pub_policy.cil )
200+ @mkdir -p $(dir $@ )
201+ $(hide ) grep -Fxv -f $^ > $@
202+
203+ # plat_policy.conf - A combination of the private and public platform policy
204+ # which will ship with the device. The platform will always reflect the most
205+ # recent platform version and is not currently being attributized.
206+ plat_policy.conf := $(intermediates ) /plat_policy.conf
207+ $(plat_policy.conf ) : PRIVATE_MLS_SENS := $(MLS_SENS )
208+ $(plat_policy.conf ) : PRIVATE_MLS_CATS := $(MLS_CATS )
209+ $(plat_policy.conf ) : PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS )
210+ $(plat_policy.conf ) : $(call build_policy, $(sepolicy_build_files ) , \
136211$(PLAT_PUBLIC_POLICY ) $(PLAT_PRIVATE_POLICY ) )
137212 @mkdir -p $(dir $@ )
138213 $(hide ) m4 $(PRIVATE_ADDITIONAL_M4DEFS ) \
@@ -144,15 +219,23 @@ $(PLAT_PUBLIC_POLICY) $(PLAT_PRIVATE_POLICY))
144219 -s $^ > $@
145220 $(hide ) sed ' /dontaudit/d' $@ > $@ .dontaudit
146221
147- # TODO: add steps for non-platform public and combined files with checkpolicy
148- # support. b/31932523
149-
150- sepolicy_policy.conf := $(intermediates ) /policy.conf
151- $(sepolicy_policy.conf ) : PRIVATE_MLS_SENS := $(MLS_SENS )
152- $(sepolicy_policy.conf ) : PRIVATE_MLS_CATS := $(MLS_CATS )
153- $(sepolicy_policy.conf ) : PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS )
154- $(sepolicy_policy.conf ) : $(call build_policy, $(sepolicy_build_files ) , \
155- $(PLAT_PUBLIC_POLICY ) $(PLAT_PRIVATE_POLICY ) $(BOARD_SEPOLICY_DIRS ) )
222+ plat_policy.cil := $(intermediates ) /plat_policy.cil
223+ $(plat_policy.cil ) : $(plat_policy.conf ) $(HOST_OUT_EXECUTABLES ) /checkpolicy
224+ @mkdir -p $(dir $@ )
225+ $(hide ) $(HOST_OUT_EXECUTABLES ) /checkpolicy -M -C -c $(POLICYVERS ) -o $@ .tmp $<
226+ $(hide ) grep -v neverallow $@ .tmp > $@
227+
228+ # nonplat_policy.conf - A combination of the non-platform private and the
229+ # exported platform policy associated with the version the non-platform policy
230+ # targets. This needs attributization and to be combined with the
231+ # platform-provided policy. Like plat_pub_policy.conf, this needs to make use
232+ # of the reqd_policy_mask files from private policy in order to use checkpolicy.
233+ nonplat_policy.conf := $(intermediates ) /nonplat_policy.conf
234+ $(nonplat_policy.conf ) : PRIVATE_MLS_SENS := $(MLS_SENS )
235+ $(nonplat_policy.conf ) : PRIVATE_MLS_CATS := $(MLS_CATS )
236+ $(nonplat_policy.conf ) : PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS )
237+ $(nonplat_policy.conf ) : $(call build_policy, $(sepolicy_build_files ) , \
238+ $(BOARD_SEPOLICY_VERS_DIR ) $(REQD_MASK_POLICY ) $(BOARD_SEPOLICY_DIRS ) )
156239 @mkdir -p $(dir $@ )
157240 $(hide ) m4 $(PRIVATE_ADDITIONAL_M4DEFS ) \
158241 -D mls_num_sens=$(PRIVATE_MLS_SENS ) -D mls_num_cats=$(PRIVATE_MLS_CATS ) \
@@ -164,10 +247,47 @@ $(PLAT_PUBLIC_POLICY) $(PLAT_PRIVATE_POLICY) $(BOARD_SEPOLICY_DIRS))
164247 -s $^ > $@
165248 $(hide ) sed ' /dontaudit/d' $@ > $@ .dontaudit
166249
167- $(LOCAL_BUILT_MODULE ) : $(sepolicy_policy.conf ) $(HOST_OUT_EXECUTABLES ) /checkpolicy $(HOST_OUT_EXECUTABLES ) /sepolicy-analyze
250+ nonplat_policy.cil := $(intermediates ) /nonplat_policy.cil
251+ $(nonplat_policy.cil ) : $(nonplat_policy.conf ) $(HOST_OUT_EXECUTABLES ) /checkpolicy
168252 @mkdir -p $(dir $@ )
169- $(hide ) $(HOST_OUT_EXECUTABLES ) /checkpolicy -M -c $(POLICYVERS ) -o $@ .tmp $< > /dev/null
170- $(hide ) $(HOST_OUT_EXECUTABLES ) /checkpolicy -M -c $(POLICYVERS ) -o $(dir $< ) /$(notdir $@ ) .dontaudit $< .dontaudit > /dev/null
253+ $(hide ) $(HOST_OUT_EXECUTABLES ) /checkpolicy -C -M -c $(POLICYVERS ) -o $@ $<
254+
255+ pruned_nonplat_policy.cil := $(intermediates ) /pruned_nonplat_policy.cil
256+ $(pruned_nonplat_policy.cil ) : $(reqd_policy_mask.cil ) $(nonplat_policy.cil )
257+ @mkdir -p $(dir $@ )
258+ $(hide ) grep -Fxv -f $^ | grep -v neverallow > $@
259+
260+ vers_nonplat_policy.cil := $(intermediates ) /vers_nonplat_policy.cil
261+ $(vers_nonplat_policy.cil ) : PRIVATE_VERS := $(BOARD_SEPOLICY_VERS )
262+ $(vers_nonplat_policy.cil ) : PRIVATE_TGT_POL := $(pruned_nonplat_policy.cil )
263+ $(vers_nonplat_policy.cil ) : $(pruned_plat_pub_policy.cil ) $(pruned_nonplat_policy.cil ) \
264+ $(HOST_OUT_EXECUTABLES)/version_policy
265+ @mkdir -p $(dir $@)
266+ $(HOST_OUT_EXECUTABLES)/version_policy -b $< -t $(PRIVATE_TGT_POL) -n $(PRIVATE_VERS) -o $@
267+
268+ # auto-generate the mapping file for current platform policy, since it needs to
269+ # track platform policy development
270+ current_mapping.cil := $(intermediates ) /mapping/current.cil
271+ $(current_mapping.cil ) : PRIVATE_VERS := $(BOARD_SEPOLICY_VERS )
272+ $(current_mapping.cil ) : $(pruned_plat_pub_policy.cil ) $(HOST_OUT_EXECUTABLES ) /version_policy
273+ @mkdir -p $(dir $@ )
274+ $(hide ) $(HOST_OUT_EXECUTABLES ) /version_policy -b $< -m -n $(PRIVATE_VERS ) -o $@
275+
276+ ifeq ($(BOARD_SEPOLICY_VERS ) , current)
277+ mapping.cil := $(current_mapping.cil )
278+ else
279+ mapping.cil := $(addsuffix /$(BOARD_SEPOLICY_VERS ) .cil, $(PLAT_PRIVATE_POLICY ) /mapping)
280+ endif
281+
282+ all_cil_files := \
283+ $(plat_policy.cil ) \
284+ $(vers_nonplat_policy.cil ) \
285+ $(mapping.cil )
286+
287+ $(LOCAL_BUILT_MODULE ) : PRIVATE_CIL_FILES := $(all_cil_files )
288+ $(LOCAL_BUILT_MODULE ) : $(HOST_OUT_EXECUTABLES ) /secilc $(HOST_OUT_EXECUTABLES ) /sepolicy-analyze $(all_cil_files )
289+ @mkdir -p $(dir $@ )
290+ $(hide ) $< -M true -c $(POLICYVERS ) $(PRIVATE_CIL_FILES ) -o $@ .tmp
171291 $(hide ) $(HOST_OUT_EXECUTABLES ) /sepolicy-analyze $@ .tmp permissive > $@ .permissivedomains
172292 $(hide ) if [ " $( TARGET_BUILD_VARIANT) " = " user" -a -s $@ .permissivedomains ]; then \
173293 echo " ==========" 1>&2 ; \
@@ -179,6 +299,20 @@ $(LOCAL_BUILT_MODULE): $(sepolicy_policy.conf) $(HOST_OUT_EXECUTABLES)/checkpoli
179299 $(hide ) mv $@ .tmp $@
180300
181301built_sepolicy := $(LOCAL_BUILT_MODULE )
302+ reqd_policy_mask.conf :=
303+ reqd_policy_mask.cil :=
304+ plat_pub_policy.conf :=
305+ plat_pub_policy.cil :=
306+ pruned_plat_pub_policy.cil :=
307+ plat_policy.conf :=
308+ plat_policy.cil :=
309+ nonplat_policy.conf :=
310+ nonplat_policy.cil :=
311+ pruned_nonplat_policy.cil :=
312+ vers_nonplat_policy.cil :=
313+ current_mapping.cil :=
314+ mapping.cil :=
315+ all_cil_files :=
182316sepolicy_policy.conf :=
183317
184318# #################################
@@ -311,7 +445,7 @@ file_contexts.device.sorted.tmp := $(intermediates)/file_contexts.device.sorted.
311445$(file_contexts.device.sorted.tmp ) : PRIVATE_SEPOLICY := $(built_sepolicy )
312446$(file_contexts.device.sorted.tmp ) : $(file_contexts.device.tmp ) $(built_sepolicy ) $(HOST_OUT_EXECUTABLES ) /fc_sort $(HOST_OUT_EXECUTABLES ) /checkfc
313447 @mkdir -p $(dir $@ )
314- $(hide ) $(HOST_OUT_EXECUTABLES ) /checkfc -e $(PRIVATE_SEPOLICY ) $<
448+ # TODO: fix with attributized types $(hide) $(HOST_OUT_EXECUTABLES)/checkfc -e $(PRIVATE_SEPOLICY) $<
315449 $(hide ) $(HOST_OUT_EXECUTABLES ) /fc_sort $< $@
316450
317451file_contexts.concat.tmp := $(intermediates ) /file_contexts.concat.tmp
@@ -322,7 +456,7 @@ $(file_contexts.concat.tmp): $(file_contexts.local.tmp) $(file_contexts.device.s
322456$(LOCAL_BUILT_MODULE ) : PRIVATE_SEPOLICY := $(built_sepolicy )
323457$(LOCAL_BUILT_MODULE ) : $(file_contexts.concat.tmp ) $(built_sepolicy ) $(HOST_OUT_EXECUTABLES ) /sefcontext_compile $(HOST_OUT_EXECUTABLES ) /checkfc
324458 @mkdir -p $(dir $@ )
325- $(hide ) $(HOST_OUT_EXECUTABLES ) /checkfc $(PRIVATE_SEPOLICY ) $<
459+ # TODO: fix with attributized types $(hide) $(HOST_OUT_EXECUTABLES)/checkfc $(PRIVATE_SEPOLICY) $<
326460 $(hide ) $(HOST_OUT_EXECUTABLES ) /sefcontext_compile -o $@ $<
327461
328462built_fc := $(LOCAL_BUILT_MODULE )
@@ -352,7 +486,7 @@ $(general_file_contexts.tmp): $(addprefix $(PLAT_PRIVATE_POLICY)/, file_contexts
352486$(LOCAL_BUILT_MODULE ) : PRIVATE_SEPOLICY := $(built_general_sepolicy )
353487$(LOCAL_BUILT_MODULE ) : $(general_file_contexts.tmp ) $(built_general_sepolicy ) $(HOST_OUT_EXECUTABLES ) /sefcontext_compile $(HOST_OUT_EXECUTABLES ) /checkfc
354488 @mkdir -p $(dir $@ )
355- $(hide ) $(HOST_OUT_EXECUTABLES ) /checkfc $(PRIVATE_SEPOLICY ) $<
489+ # TODO: fix with attributized types $(hide) $(HOST_OUT_EXECUTABLES)/checkfc $(PRIVATE_SEPOLICY) $<
356490 $(hide ) $(HOST_OUT_EXECUTABLES ) /sefcontext_compile -o $@ $<
357491
358492general_file_contexts.tmp :=
@@ -433,7 +567,7 @@ $(LOCAL_BUILT_MODULE): PRIVATE_SEPOLICY := $(built_sepolicy)
433567$(LOCAL_BUILT_MODULE ) : $(property_contexts.tmp ) $(built_sepolicy ) $(HOST_OUT_EXECUTABLES ) /checkfc
434568 @mkdir -p $(dir $@ )
435569 $(hide ) sed -e ' s/#.*$$//' -e ' /^$$/d' $< > $@
436- $(hide ) $(HOST_OUT_EXECUTABLES ) /checkfc -p $(PRIVATE_SEPOLICY ) $@
570+ # TODO: fix with attributized types $(hide) $(HOST_OUT_EXECUTABLES)/checkfc -p $(PRIVATE_SEPOLICY) $@
437571
438572built_pc := $(LOCAL_BUILT_MODULE )
439573all_pc_files :=
@@ -458,7 +592,7 @@ $(LOCAL_BUILT_MODULE): PRIVATE_SEPOLICY := $(built_general_sepolicy)
458592$(LOCAL_BUILT_MODULE ) : $(general_property_contexts.tmp ) $(built_general_sepolicy ) $(HOST_OUT_EXECUTABLES ) /checkfc $(ACP )
459593 @mkdir -p $(dir $@ )
460594 $(hide ) sed -e ' s/#.*$$//' -e ' /^$$/d' $< > $@
461- $(hide ) $(HOST_OUT_EXECUTABLES ) /checkfc -p $(PRIVATE_SEPOLICY ) $@
595+ # TODO: fix with attributized types $(hide) $(HOST_OUT_EXECUTABLES)/checkfc -p $(PRIVATE_SEPOLICY) $@
462596
463597general_property_contexts.tmp :=
464598
@@ -486,7 +620,7 @@ $(LOCAL_BUILT_MODULE): PRIVATE_SEPOLICY := $(built_sepolicy)
486620$(LOCAL_BUILT_MODULE ) : $(service_contexts.tmp ) $(built_sepolicy ) $(HOST_OUT_EXECUTABLES ) /checkfc $(ACP )
487621 @mkdir -p $(dir $@ )
488622 sed -e ' s/#.*$$//' -e ' /^$$/d' $< > $@
489- $(hide ) $(HOST_OUT_EXECUTABLES ) /checkfc -s $(PRIVATE_SEPOLICY ) $@
623+ # TODO: fix with attributized types $(hide) $(HOST_OUT_EXECUTABLES)/checkfc -s $(PRIVATE_SEPOLICY) $@
490624
491625built_svc := $(LOCAL_BUILT_MODULE )
492626all_svc_files :=
@@ -511,7 +645,7 @@ $(LOCAL_BUILT_MODULE): PRIVATE_SEPOLICY := $(built_general_sepolicy)
511645$(LOCAL_BUILT_MODULE ) : $(general_service_contexts.tmp ) $(built_general_sepolicy ) $(HOST_OUT_EXECUTABLES ) /checkfc $(ACP )
512646 @mkdir -p $(dir $@ )
513647 sed -e ' s/#.*$$//' -e ' /^$$/d' $< > $@
514- $(hide ) $(HOST_OUT_EXECUTABLES ) /checkfc -s $(PRIVATE_SEPOLICY ) $@
648+ # TODO: fix with attributized types $(hide) $(HOST_OUT_EXECUTABLES)/checkfc -s $(PRIVATE_SEPOLICY) $@
515649
516650general_service_contexts.tmp :=
517651
0 commit comments