Skip to content

Commit c8801fe

Browse files
author
Richard Haines
committed
Ensure newlines are added between context config files
When multiple file_contexts, service_contexts and property_contexts are processed by the m4(1) macro processor, they will fail if one or more of the intermediate files final line is not terminated by a newline. This patch adds an intervening file only containing a newline. Change-Id: Ie66b32fe477d08c69e6d6eb1725f658adc384ce4 Signed-off-by: Richard Haines <[email protected]>
1 parent f01453a commit c8801fe

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

Android.mk

+32-6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ endif
3030
# $(1): the set of policy name paths to build
3131
build_policy = $(foreach type, $(1), $(foreach file, $(addsuffix /$(type), $(LOCAL_PATH) $(BOARD_SEPOLICY_DIRS)), $(sort $(wildcard $(file)))))
3232

33+
# Add a file containing only a newline in-between each policy configuration
34+
# 'contexts' file. This will allow OEM policy configuration files without a
35+
# final newline (0x0A) to be built correctly by the m4(1) macro processor.
36+
# $(1): the set of contexts file names.
37+
# $(2): the file containing only 0x0A.
38+
add_nl = $(foreach entry, $(1), $(subst $(entry), $(entry) $(2), $(entry)))
39+
3340
sepolicy_build_files := security_classes \
3441
initial_sids \
3542
access_vectors \
@@ -52,6 +59,21 @@ sepolicy_build_files := security_classes \
5259
##################################
5360
include $(CLEAR_VARS)
5461

62+
LOCAL_MODULE := sectxfile_nl
63+
LOCAL_MODULE_CLASS := ETC
64+
LOCAL_MODULE_TAGS := optional
65+
66+
# Create a file containing newline only to add between context config files
67+
include $(BUILD_SYSTEM)/base_rules.mk
68+
$(LOCAL_BUILT_MODULE): $(all_fcfiles_with_nl) $(all_pcfiles_with_nl) $(all_svcfiles_with_nl)
69+
@mkdir -p $(dir $@)
70+
$(hide) echo > $@
71+
72+
built_nl := $(LOCAL_BUILT_MODULE)
73+
74+
#################################
75+
include $(CLEAR_VARS)
76+
5577
LOCAL_MODULE := sepolicy
5678
LOCAL_MODULE_CLASS := ETC
5779
LOCAL_MODULE_TAGS := optional
@@ -161,11 +183,12 @@ ifneq ($(filter address,$(SANITIZE_TARGET)),)
161183
all_fc_files := $(all_fc_files) file_contexts_asan
162184
endif
163185
all_fc_files := $(call build_policy, $(all_fc_files))
186+
all_fcfiles_with_nl := $(call add_nl, $(all_fc_files), $(built_nl))
164187

165188
file_contexts.tmp := $(intermediates)/file_contexts.tmp
166-
$(file_contexts.tmp): PRIVATE_FC_FILES := $(all_fc_files)
189+
$(file_contexts.tmp): PRIVATE_FC_FILES := $(all_fcfiles_with_nl)
167190
$(file_contexts.tmp): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
168-
$(file_contexts.tmp): $(all_fc_files)
191+
$(file_contexts.tmp): $(all_fc_files) $(all_fcfiles_with_nl) $(built_nl)
169192
@mkdir -p $(dir $@)
170193
$(hide) m4 -s $(PRIVATE_ADDITIONAL_M4DEFS) $(PRIVATE_FC_FILES) > $@
171194

@@ -263,11 +286,12 @@ LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
263286
include $(BUILD_SYSTEM)/base_rules.mk
264287

265288
all_pc_files := $(call build_policy, property_contexts)
289+
all_pcfiles_with_nl := $(call add_nl, $(all_pc_files), $(built_nl))
266290

267291
property_contexts.tmp := $(intermediates)/property_contexts.tmp
268-
$(property_contexts.tmp): PRIVATE_PC_FILES := $(all_pc_files)
292+
$(property_contexts.tmp): PRIVATE_PC_FILES := $(all_pcfiles_with_nl)
269293
$(property_contexts.tmp): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
270-
$(property_contexts.tmp): $(all_pc_files)
294+
$(property_contexts.tmp): $(all_pc_files) $(all_pcfiles_with_nl) $(built_nl)
271295
@mkdir -p $(dir $@)
272296
$(hide) m4 -s $(PRIVATE_ADDITIONAL_M4DEFS) $(PRIVATE_PC_FILES) > $@
273297

@@ -315,11 +339,12 @@ LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
315339
include $(BUILD_SYSTEM)/base_rules.mk
316340

317341
all_svc_files := $(call build_policy, service_contexts)
342+
all_svcfiles_with_nl := $(call add_nl, $(all_svc_files), $(built_nl))
318343

319344
service_contexts.tmp := $(intermediates)/service_contexts.tmp
320-
$(service_contexts.tmp): PRIVATE_SVC_FILES := $(all_svc_files)
345+
$(service_contexts.tmp): PRIVATE_SVC_FILES := $(all_svcfiles_with_nl)
321346
$(service_contexts.tmp): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
322-
$(service_contexts.tmp): $(all_svc_files)
347+
$(service_contexts.tmp): $(all_svc_files) $(all_svcfiles_with_nl) $(built_nl)
323348
@mkdir -p $(dir $@)
324349
$(hide) m4 -s $(PRIVATE_ADDITIONAL_M4DEFS) $(PRIVATE_SVC_FILES) > $@
325350

@@ -407,5 +432,6 @@ built_pc :=
407432
built_svc :=
408433
built_general_sepolicy :=
409434
built_general_sepolicy.conf :=
435+
built_nl :=
410436

411437
include $(call all-makefiles-under,$(LOCAL_PATH))

README

+13-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ into the policy build as described below.
77
Policy Generation:
88

99
Additional, per device, policy files can be added into the
10-
policy build.
11-
12-
They can be configured through the use of the BOARD_SEPOLICY_DIRS
13-
variable. This variable should be set in the BoardConfig.mk file in
14-
the device or vendor directories.
10+
policy build. These files should have each line including the
11+
final line terminated by a newline character (0x0A). This
12+
will allow files to be concatenated and processed whenever
13+
the m4(1) macro processor is called by the build process.
14+
Adding the newline will also make the intermediate text files
15+
easier to read when debugging build failures. The sets of file,
16+
service and property contexts files will automatically have a
17+
newline inserted between each file as these are common failure
18+
points.
19+
20+
These device policy files can be configured through the use of
21+
the BOARD_SEPOLICY_DIRS variable. This variable should be set
22+
in the BoardConfig.mk file in the device or vendor directories.
1523

1624
BOARD_SEPOLICY_DIRS contains a list of directories to search
1725
for additional policy files. Order matters in this list.

0 commit comments

Comments
 (0)