Android.mk 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  1. LOCAL_PATH:= $(call my-dir)
  2. include $(LOCAL_PATH)/definitions.mk
  3. include $(LOCAL_PATH)/policy_version.mk
  4. include $(CLEAR_VARS)
  5. MLS_SENS=1
  6. MLS_CATS=1024
  7. ifdef BOARD_SEPOLICY_UNION
  8. $(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.)
  9. endif
  10. ifdef BOARD_SEPOLICY_M4DEFS
  11. LOCAL_ADDITIONAL_M4DEFS := $(addprefix -D, $(BOARD_SEPOLICY_M4DEFS))
  12. else
  13. LOCAL_ADDITIONAL_M4DEFS :=
  14. endif
  15. # sepolicy is now divided into multiple portions:
  16. # public - policy exported on which non-platform policy developers may write
  17. # additional policy. types and attributes are versioned and included in
  18. # delivered non-platform policy, which is to be combined with platform policy.
  19. # private - platform-only policy required for platform functionality but which
  20. # is not exported to vendor policy developers and as such may not be assumed
  21. # to exist.
  22. # vendor - vendor-only policy required for vendor functionality. This policy can
  23. # reference the public policy but cannot reference the private policy. This
  24. # policy is for components which are produced from the core/non-vendor tree and
  25. # placed into a vendor partition.
  26. # mapping - This contains policy statements which map the attributes
  27. # exposed in the public policy of previous versions to the concrete types used
  28. # in this policy to ensure that policy targeting attributes from public
  29. # policy from an older platform version continues to work.
  30. # build process for device:
  31. # 1) convert policies to CIL:
  32. # - private + public platform policy to CIL
  33. # - mapping file to CIL (should already be in CIL form)
  34. # - non-platform public policy to CIL
  35. # - non-platform public + private policy to CIL
  36. # 2) attributize policy
  37. # - run script which takes non-platform public and non-platform combined
  38. # private + public policy and produces attributized and versioned
  39. # non-platform policy
  40. # 3) combine policy files
  41. # - combine mapping, platform and non-platform policy.
  42. # - compile output binary policy file
  43. PLAT_PUBLIC_POLICY := $(LOCAL_PATH)/public
  44. ifneq ( ,$(BOARD_PLAT_PUBLIC_SEPOLICY_DIR))
  45. PLAT_PUBLIC_POLICY += $(BOARD_PLAT_PUBLIC_SEPOLICY_DIR)
  46. endif
  47. PLAT_PRIVATE_POLICY := $(LOCAL_PATH)/private
  48. ifneq ( ,$(BOARD_PLAT_PRIVATE_SEPOLICY_DIR))
  49. PLAT_PRIVATE_POLICY += $(BOARD_PLAT_PRIVATE_SEPOLICY_DIR)
  50. endif
  51. PLAT_VENDOR_POLICY := $(LOCAL_PATH)/vendor
  52. REQD_MASK_POLICY := $(LOCAL_PATH)/reqd_mask
  53. PRODUCT_PUBLIC_POLICY := $(PRODUCT_PUBLIC_SEPOLICY_DIRS)
  54. PRODUCT_PRIVATE_POLICY := $(PRODUCT_PRIVATE_SEPOLICY_DIRS)
  55. # TODO(b/119305624): Currently if the device doesn't have a product partition,
  56. # we install product sepolicy into /system/product. We do that because bits of
  57. # product sepolicy that's still in /system might depend on bits that have moved
  58. # to /product. Once we finish migrating product sepolicy out of system, change
  59. # it so that if no product partition is present, product sepolicy artifacts are
  60. # not built and installed at all.
  61. ifneq (,$(PRODUCT_PUBLIC_POLICY)$(PRODUCT_PRIVATE_POLICY))
  62. HAS_PRODUCT_SEPOLICY := true
  63. endif
  64. # TODO: move to README when doing the README update and finalizing versioning.
  65. # BOARD_SEPOLICY_VERS must take the format "NN.m" and contain the sepolicy
  66. # version identifier corresponding to the sepolicy on which the non-platform
  67. # policy is to be based. If unspecified, this will build against the current
  68. # public platform policy in tree
  69. ifndef BOARD_SEPOLICY_VERS
  70. # The default platform policy version.
  71. BOARD_SEPOLICY_VERS := $(PLATFORM_SEPOLICY_VERSION)
  72. endif
  73. NEVERALLOW_ARG :=
  74. ifeq ($(SELINUX_IGNORE_NEVERALLOWS),true)
  75. ifeq ($(TARGET_BUILD_VARIANT),user)
  76. $(error SELINUX_IGNORE_NEVERALLOWS := true cannot be used in user builds)
  77. endif
  78. $(warning Be careful when using the SELINUX_IGNORE_NEVERALLOWS flag. \
  79. It does not work in user builds and using it will \
  80. not stop you from failing CTS.)
  81. NEVERALLOW_ARG := -N
  82. endif
  83. # BOARD_SEPOLICY_DIRS was used for vendor/odm sepolicy customization before.
  84. # It has been replaced by BOARD_VENDOR_SEPOLICY_DIRS (mandatory) and
  85. # BOARD_ODM_SEPOLICY_DIRS (optional). BOARD_SEPOLICY_DIRS is still allowed for
  86. # backward compatibility, which will be merged into BOARD_VENDOR_SEPOLICY_DIRS.
  87. ifdef BOARD_SEPOLICY_DIRS
  88. BOARD_VENDOR_SEPOLICY_DIRS += $(BOARD_SEPOLICY_DIRS)
  89. endif
  90. ifdef BOARD_ODM_SEPOLICY_DIRS
  91. ifneq ($(PRODUCT_SEPOLICY_SPLIT),true)
  92. $(error PRODUCT_SEPOLICY_SPLIT needs to be true when using BOARD_ODM_SEPOLICY_DIRS)
  93. endif
  94. endif
  95. ###########################################################
  96. # Compute policy files to be used in policy build.
  97. # $(1): files to include
  98. # $(2): directories in which to find files
  99. ###########################################################
  100. define build_policy
  101. $(foreach type, $(1), $(foreach file, $(addsuffix /$(type), $(2)), $(sort $(wildcard $(file)))))
  102. endef
  103. # Builds paths for all policy files found in BOARD_VENDOR_SEPOLICY_DIRS.
  104. # $(1): the set of policy name paths to build
  105. build_vendor_policy = $(call build_policy, $(1), $(PLAT_VENDOR_POLICY) $(BOARD_VENDOR_SEPOLICY_DIRS))
  106. # Builds paths for all policy files found in BOARD_ODM_SEPOLICY_DIRS.
  107. build_odm_policy = $(call build_policy, $(1), $(BOARD_ODM_SEPOLICY_DIRS))
  108. # Add a file containing only a newline in-between each policy configuration
  109. # 'contexts' file. This will allow OEM policy configuration files without a
  110. # final newline (0x0A) to be built correctly by the m4(1) macro processor.
  111. # $(1): the set of contexts file names.
  112. # $(2): the file containing only 0x0A.
  113. add_nl = $(foreach entry, $(1), $(subst $(entry), $(entry) $(2), $(entry)))
  114. sepolicy_build_files := security_classes \
  115. initial_sids \
  116. access_vectors \
  117. global_macros \
  118. neverallow_macros \
  119. mls_macros \
  120. mls_decl \
  121. mls \
  122. policy_capabilities \
  123. te_macros \
  124. attributes \
  125. ioctl_defines \
  126. ioctl_macros \
  127. *.te \
  128. roles_decl \
  129. roles \
  130. users \
  131. initial_sid_contexts \
  132. fs_use \
  133. genfs_contexts \
  134. port_contexts
  135. # CIL files which contain workarounds for current limitation of human-readable
  136. # module policy language. These files are appended to the CIL files produced
  137. # from module language files.
  138. sepolicy_build_cil_workaround_files := technical_debt.cil
  139. my_target_arch := $(TARGET_ARCH)
  140. ifneq (,$(filter mips mips64,$(TARGET_ARCH)))
  141. my_target_arch := mips
  142. endif
  143. intermediates := $(TARGET_OUT_INTERMEDIATES)/ETC/sepolicy_intermediates
  144. with_asan := false
  145. ifneq (,$(filter address,$(SANITIZE_TARGET)))
  146. with_asan := true
  147. endif
  148. with_native_coverage := false
  149. ifeq ($(NATIVE_COVERAGE),true)
  150. with_native_coverage := true
  151. endif
  152. # Library extension for host-side tests
  153. ifeq ($(HOST_OS),darwin)
  154. SHAREDLIB_EXT=dylib
  155. else
  156. SHAREDLIB_EXT=so
  157. endif
  158. # Convert a file_context file for a non-flattened APEX into a file for
  159. # flattened APEX. /system/apex/<apex_name> path is prepended to the original paths
  160. # $(1): path to the input file_contexts file for non-flattened APEX
  161. # $(2): name of the APEX
  162. # $(3): path to the generated file_contexs file for flattened APEX
  163. # $(4): variable where $(3) is added to
  164. define build_flattened_apex_file_contexts
  165. $(4) += $(3)
  166. $(3): PRIVATE_APEX_PATH := /system/apex/$(subst .,\\.,$(2))
  167. $(3): $(1)
  168. $(hide) awk '/object_r/{printf("$$(PRIVATE_APEX_PATH)%s\n",$$$$0)}' $$< > $$@
  169. endef
  170. #################################
  171. include $(CLEAR_VARS)
  172. LOCAL_MODULE := selinux_policy
  173. LOCAL_MODULE_TAGS := optional
  174. LOCAL_REQUIRED_MODULES += \
  175. selinux_policy_nonsystem \
  176. selinux_policy_system \
  177. include $(BUILD_PHONY_PACKAGE)
  178. include $(CLEAR_VARS)
  179. LOCAL_MODULE := selinux_policy_system
  180. # These build targets are not used on non-Treble devices. However, we build these to avoid
  181. # divergence between Treble and non-Treble devices.
  182. LOCAL_REQUIRED_MODULES += \
  183. plat_mapping_file \
  184. $(addsuffix .cil,$(PLATFORM_SEPOLICY_COMPAT_VERSIONS)) \
  185. plat_sepolicy.cil \
  186. plat_sepolicy_and_mapping.sha256 \
  187. secilc \
  188. LOCAL_REQUIRED_MODULES += \
  189. build_sepolicy \
  190. plat_file_contexts \
  191. plat_mac_permissions.xml \
  192. plat_property_contexts \
  193. plat_seapp_contexts \
  194. plat_service_contexts \
  195. plat_hwservice_contexts \
  196. searchpolicy \
  197. # This conditional inclusion closely mimics the conditional logic
  198. # inside init/init.cpp for loading SELinux policy from files.
  199. ifneq ($(PRODUCT_SEPOLICY_SPLIT),true)
  200. # The following files are only allowed for non-Treble devices.
  201. LOCAL_REQUIRED_MODULES += \
  202. sepolicy \
  203. vendor_service_contexts \
  204. endif # ($(PRODUCT_SEPOLICY_SPLIT),true)
  205. ifneq ($(with_asan),true)
  206. ifneq ($(SELINUX_IGNORE_NEVERALLOWS),true)
  207. LOCAL_REQUIRED_MODULES += \
  208. sepolicy_tests \
  209. $(addprefix treble_sepolicy_tests_,$(PLATFORM_SEPOLICY_COMPAT_VERSIONS)) \
  210. endif
  211. endif
  212. ifneq ($(PLATFORM_SEPOLICY_VERSION),$(TOT_SEPOLICY_VERSION))
  213. LOCAL_REQUIRED_MODULES += \
  214. sepolicy_freeze_test \
  215. endif # ($(PLATFORM_SEPOLICY_VERSION),$(TOT_SEPOLICY_VERSION))
  216. include $(BUILD_PHONY_PACKAGE)
  217. #################################
  218. include $(CLEAR_VARS)
  219. LOCAL_MODULE := selinux_policy_nonsystem
  220. # Include precompiled policy, unless told otherwise.
  221. ifneq ($(PRODUCT_PRECOMPILED_SEPOLICY),false)
  222. LOCAL_REQUIRED_MODULES += \
  223. precompiled_sepolicy \
  224. precompiled_sepolicy.plat_sepolicy_and_mapping.sha256 \
  225. precompiled_sepolicy.product_sepolicy_and_mapping.sha256 \
  226. product_sepolicy_and_mapping.sha256 \
  227. endif # ($(PRODUCT_PRECOMPILED_SEPOLICY),false)
  228. # These build targets are not used on non-Treble devices. However, we build these to avoid
  229. # divergence between Treble and non-Treble devices.
  230. LOCAL_REQUIRED_MODULES += \
  231. plat_pub_versioned.cil \
  232. vendor_sepolicy.cil \
  233. plat_sepolicy_vers.txt \
  234. LOCAL_REQUIRED_MODULES += \
  235. vendor_file_contexts \
  236. vendor_mac_permissions.xml \
  237. vendor_property_contexts \
  238. vendor_seapp_contexts \
  239. vendor_hwservice_contexts \
  240. vndservice_contexts \
  241. ifdef BOARD_ODM_SEPOLICY_DIRS
  242. LOCAL_REQUIRED_MODULES += \
  243. odm_sepolicy.cil \
  244. odm_file_contexts \
  245. odm_seapp_contexts \
  246. odm_property_contexts \
  247. odm_hwservice_contexts \
  248. odm_mac_permissions.xml
  249. endif
  250. ifdef HAS_PRODUCT_SEPOLICY
  251. LOCAL_REQUIRED_MODULES += \
  252. product_sepolicy.cil \
  253. product_file_contexts \
  254. product_hwservice_contexts \
  255. product_property_contexts \
  256. product_seapp_contexts \
  257. product_service_contexts \
  258. product_mac_permissions.xml \
  259. product_mapping_file \
  260. endif
  261. ifneq ($(TARGET_BUILD_VARIANT), user)
  262. LOCAL_REQUIRED_MODULES += \
  263. selinux_denial_metadata \
  264. endif
  265. # Builds an addtional userdebug sepolicy into the debug ramdisk.
  266. LOCAL_REQUIRED_MODULES += \
  267. userdebug_plat_sepolicy.cil \
  268. include $(BUILD_PHONY_PACKAGE)
  269. #################################
  270. include $(CLEAR_VARS)
  271. LOCAL_MODULE := sepolicy_neverallows
  272. LOCAL_MODULE_CLASS := ETC
  273. LOCAL_MODULE_TAGS := optional
  274. LOCAL_MODULE_PATH := $(TARGET_OUT)/etc/selinux
  275. include $(BUILD_SYSTEM)/base_rules.mk
  276. # sepolicy_policy.conf - All of the policy for the device. This is only used to
  277. # check neverallow rules.
  278. sepolicy_policy.conf := $(intermediates)/policy.conf
  279. $(sepolicy_policy.conf): PRIVATE_MLS_SENS := $(MLS_SENS)
  280. $(sepolicy_policy.conf): PRIVATE_MLS_CATS := $(MLS_CATS)
  281. $(sepolicy_policy.conf): PRIVATE_TARGET_BUILD_VARIANT := user
  282. $(sepolicy_policy.conf): PRIVATE_TGT_ARCH := $(my_target_arch)
  283. $(sepolicy_policy.conf): PRIVATE_TGT_WITH_ASAN := $(with_asan)
  284. $(sepolicy_policy.conf): PRIVATE_TGT_WITH_NATIVE_COVERAGE := $(with_native_coverage)
  285. $(sepolicy_policy.conf): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
  286. $(sepolicy_policy.conf): PRIVATE_SEPOLICY_SPLIT := $(PRODUCT_SEPOLICY_SPLIT)
  287. $(sepolicy_policy.conf): $(call build_policy, $(sepolicy_build_files), \
  288. $(PLAT_PUBLIC_POLICY) $(PLAT_PRIVATE_POLICY) $(PLAT_VENDOR_POLICY) \
  289. $(PRODUCT_PUBLIC_POLICY) $(PRODUCT_PRIVATE_POLICY) \
  290. $(BOARD_VENDOR_SEPOLICY_DIRS) $(BOARD_ODM_SEPOLICY_DIRS))
  291. $(transform-policy-to-conf)
  292. $(hide) sed '/^\s*dontaudit.*;/d' $@ | sed '/^\s*dontaudit/,/;/d' > [email protected]
  293. # sepolicy_policy_2.conf - All of the policy for the device. This is only used to
  294. # check neverallow rules using sepolicy-analyze, similar to CTS.
  295. sepolicy_policy_2.conf := $(intermediates)/policy_2.conf
  296. $(sepolicy_policy_2.conf): PRIVATE_MLS_SENS := $(MLS_SENS)
  297. $(sepolicy_policy_2.conf): PRIVATE_MLS_CATS := $(MLS_CATS)
  298. $(sepolicy_policy_2.conf): PRIVATE_TARGET_BUILD_VARIANT := user
  299. $(sepolicy_policy_2.conf): PRIVATE_EXCLUDE_BUILD_TEST := true
  300. $(sepolicy_policy_2.conf): PRIVATE_TGT_ARCH := $(my_target_arch)
  301. $(sepolicy_policy_2.conf): PRIVATE_TGT_WITH_ASAN := $(with_asan)
  302. $(sepolicy_policy_2.conf): PRIVATE_TGT_WITH_NATIVE_COVERAGE := $(with_native_coverage)
  303. $(sepolicy_policy_2.conf): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
  304. $(sepolicy_policy_2.conf): PRIVATE_SEPOLICY_SPLIT := $(PRODUCT_SEPOLICY_SPLIT)
  305. $(sepolicy_policy_2.conf): $(call build_policy, $(sepolicy_build_files), \
  306. $(PLAT_PUBLIC_POLICY) $(PLAT_PRIVATE_POLICY) $(PLAT_VENDOR_POLICY) \
  307. $(PRODUCT_PUBLIC_POLICY) $(PRODUCT_PRIVATE_POLICY) \
  308. $(BOARD_VENDOR_SEPOLICY_DIRS) $(BOARD_ODM_SEPOLICY_DIRS))
  309. $(transform-policy-to-conf)
  310. $(hide) sed '/^\s*dontaudit.*;/d' $@ | sed '/^\s*dontaudit/,/;/d' > [email protected]
  311. $(LOCAL_BUILT_MODULE): PRIVATE_SEPOLICY_1 := $(sepolicy_policy.conf)
  312. $(LOCAL_BUILT_MODULE): PRIVATE_SEPOLICY_2 := $(sepolicy_policy_2.conf)
  313. $(LOCAL_BUILT_MODULE): $(sepolicy_policy.conf) $(sepolicy_policy_2.conf) \
  314. $(HOST_OUT_EXECUTABLES)/checkpolicy $(HOST_OUT_EXECUTABLES)/sepolicy-analyze
  315. ifneq ($(SELINUX_IGNORE_NEVERALLOWS),true)
  316. $(hide) $(CHECKPOLICY_ASAN_OPTIONS) $(HOST_OUT_EXECUTABLES)/checkpolicy -M -c \
  317. $(POLICYVERS) -o [email protected] $(PRIVATE_SEPOLICY_1)
  318. $(hide) $(HOST_OUT_EXECUTABLES)/sepolicy-analyze [email protected] neverallow -w -f $(PRIVATE_SEPOLICY_2) || \
  319. ( echo "" 1>&2; \
  320. echo "sepolicy-analyze failed. This is most likely due to the use" 1>&2; \
  321. echo "of an expanded attribute in a neverallow assertion. Please fix" 1>&2; \
  322. echo "the policy." 1>&2; \
  323. exit 1 )
  324. endif # ($(SELINUX_IGNORE_NEVERALLOWS),true)
  325. $(hide) touch [email protected]
  326. $(hide) mv [email protected] $@
  327. sepolicy_policy.conf :=
  328. sepolicy_policy_2.conf :=
  329. built_sepolicy_neverallows := $(LOCAL_BUILT_MODULE)
  330. ##################################
  331. # reqd_policy_mask - a policy.conf file which contains only the bare minimum
  332. # policy necessary to use checkpolicy. This bare-minimum policy needs to be
  333. # present in all policy.conf files, but should not necessarily be exported as
  334. # part of the public policy. The rules generated by reqd_policy_mask will allow
  335. # the compilation of public policy and subsequent removal of CIL policy that
  336. # should not be exported.
  337. reqd_policy_mask.conf := $(intermediates)/reqd_policy_mask.conf
  338. $(reqd_policy_mask.conf): PRIVATE_MLS_SENS := $(MLS_SENS)
  339. $(reqd_policy_mask.conf): PRIVATE_MLS_CATS := $(MLS_CATS)
  340. $(reqd_policy_mask.conf): PRIVATE_TARGET_BUILD_VARIANT := $(TARGET_BUILD_VARIANT)
  341. $(reqd_policy_mask.conf): PRIVATE_TGT_ARCH := $(my_target_arch)
  342. $(reqd_policy_mask.conf): PRIVATE_TGT_WITH_ASAN := $(with_asan)
  343. $(reqd_policy_mask.conf): PRIVATE_TGT_WITH_NATIVE_COVERAGE := $(with_native_coverage)
  344. $(reqd_policy_mask.conf): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
  345. $(reqd_policy_mask.conf): PRIVATE_SEPOLICY_SPLIT := $(PRODUCT_SEPOLICY_SPLIT)
  346. $(reqd_policy_mask.conf): PRIVATE_COMPATIBLE_PROPERTY := $(PRODUCT_COMPATIBLE_PROPERTY)
  347. $(reqd_policy_mask.conf): $(call build_policy, $(sepolicy_build_files), $(REQD_MASK_POLICY))
  348. $(transform-policy-to-conf)
  349. # b/37755687
  350. CHECKPOLICY_ASAN_OPTIONS := ASAN_OPTIONS=detect_leaks=0
  351. reqd_policy_mask.cil := $(intermediates)/reqd_policy_mask.cil
  352. $(reqd_policy_mask.cil): $(reqd_policy_mask.conf) $(HOST_OUT_EXECUTABLES)/checkpolicy
  353. @mkdir -p $(dir $@)
  354. $(hide) $(CHECKPOLICY_ASAN_OPTIONS) $(HOST_OUT_EXECUTABLES)/checkpolicy -C -M -c \
  355. $(POLICYVERS) -o $@ $<
  356. reqd_policy_mask.conf :=
  357. ##################################
  358. # pub_policy - policy that will be exported to be a part of non-platform
  359. # policy corresponding to this platform version. This is a limited subset of
  360. # policy that would not compile in checkpolicy on its own. To get around this
  361. # limitation, add only the required files from private policy, which will
  362. # generate CIL policy that will then be filtered out by the reqd_policy_mask.
  363. pub_policy.conf := $(intermediates)/pub_policy.conf
  364. $(pub_policy.conf): PRIVATE_MLS_SENS := $(MLS_SENS)
  365. $(pub_policy.conf): PRIVATE_MLS_CATS := $(MLS_CATS)
  366. $(pub_policy.conf): PRIVATE_TARGET_BUILD_VARIANT := $(TARGET_BUILD_VARIANT)
  367. $(pub_policy.conf): PRIVATE_TGT_ARCH := $(my_target_arch)
  368. $(pub_policy.conf): PRIVATE_TGT_WITH_ASAN := $(with_asan)
  369. $(pub_policy.conf): PRIVATE_TGT_WITH_NATIVE_COVERAGE := $(with_native_coverage)
  370. $(pub_policy.conf): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
  371. $(pub_policy.conf): PRIVATE_SEPOLICY_SPLIT := $(PRODUCT_SEPOLICY_SPLIT)
  372. $(pub_policy.conf): PRIVATE_COMPATIBLE_PROPERTY := $(PRODUCT_COMPATIBLE_PROPERTY)
  373. $(pub_policy.conf): $(call build_policy, $(sepolicy_build_files), \
  374. $(PLAT_PUBLIC_POLICY) $(PRODUCT_PUBLIC_POLICY) $(REQD_MASK_POLICY))
  375. $(transform-policy-to-conf)
  376. pub_policy.cil := $(intermediates)/pub_policy.cil
  377. $(pub_policy.cil): PRIVATE_POL_CONF := $(pub_policy.conf)
  378. $(pub_policy.cil): PRIVATE_REQD_MASK := $(reqd_policy_mask.cil)
  379. $(pub_policy.cil): $(HOST_OUT_EXECUTABLES)/checkpolicy \
  380. $(HOST_OUT_EXECUTABLES)/build_sepolicy $(pub_policy.conf) $(reqd_policy_mask.cil)
  381. @mkdir -p $(dir $@)
  382. $(hide) $(CHECKPOLICY_ASAN_OPTIONS) $< -C -M -c $(POLICYVERS) -o $@ $(PRIVATE_POL_CONF)
  383. $(hide) $(HOST_OUT_EXECUTABLES)/build_sepolicy -a $(HOST_OUT_EXECUTABLES) filter_out \
  384. -f $(PRIVATE_REQD_MASK) -t $@
  385. pub_policy.conf :=
  386. ##################################
  387. plat_pub_policy.conf := $(intermediates)/plat_pub_policy.conf
  388. $(plat_pub_policy.conf): PRIVATE_MLS_SENS := $(MLS_SENS)
  389. $(plat_pub_policy.conf): PRIVATE_MLS_CATS := $(MLS_CATS)
  390. $(plat_pub_policy.conf): PRIVATE_TARGET_BUILD_VARIANT := $(TARGET_BUILD_VARIANT)
  391. $(plat_pub_policy.conf): PRIVATE_TGT_ARCH := $(my_target_arch)
  392. $(plat_pub_policy.conf): PRIVATE_TGT_WITH_ASAN := $(with_asan)
  393. $(plat_pub_policy.conf): PRIVATE_TGT_WITH_NATIVE_COVERAGE := $(with_native_coverage)
  394. $(plat_pub_policy.conf): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
  395. $(plat_pub_policy.conf): PRIVATE_SEPOLICY_SPLIT := $(PRODUCT_SEPOLICY_SPLIT)
  396. $(plat_pub_policy.conf): PRIVATE_COMPATIBLE_PROPERTY := $(PRODUCT_COMPATIBLE_PROPERTY)
  397. $(plat_pub_policy.conf): $(call build_policy, $(sepolicy_build_files), \
  398. $(PLAT_PUBLIC_POLICY) $(REQD_MASK_POLICY))
  399. $(transform-policy-to-conf)
  400. plat_pub_policy.cil := $(intermediates)/plat_pub_policy.cil
  401. $(plat_pub_policy.cil): PRIVATE_POL_CONF := $(plat_pub_policy.conf)
  402. $(plat_pub_policy.cil): PRIVATE_REQD_MASK := $(reqd_policy_mask.cil)
  403. $(plat_pub_policy.cil): $(HOST_OUT_EXECUTABLES)/checkpolicy \
  404. $(HOST_OUT_EXECUTABLES)/build_sepolicy $(plat_pub_policy.conf) $(reqd_policy_mask.cil)
  405. @mkdir -p $(dir $@)
  406. $(hide) $(CHECKPOLICY_ASAN_OPTIONS) $< -C -M -c $(POLICYVERS) -o $@ $(PRIVATE_POL_CONF)
  407. $(hide) $(HOST_OUT_EXECUTABLES)/build_sepolicy -a $(HOST_OUT_EXECUTABLES) filter_out \
  408. -f $(PRIVATE_REQD_MASK) -t $@
  409. plat_pub_policy.conf :=
  410. ##################################
  411. include $(CLEAR_VARS)
  412. LOCAL_MODULE := sectxfile_nl
  413. LOCAL_MODULE_CLASS := ETC
  414. LOCAL_MODULE_TAGS := optional
  415. # Create a file containing newline only to add between context config files
  416. include $(BUILD_SYSTEM)/base_rules.mk
  417. $(LOCAL_BUILT_MODULE):
  418. @mkdir -p $(dir $@)
  419. $(hide) echo > $@
  420. built_nl := $(LOCAL_BUILT_MODULE)
  421. #################################
  422. include $(CLEAR_VARS)
  423. LOCAL_MODULE := plat_sepolicy.cil
  424. LOCAL_MODULE_CLASS := ETC
  425. LOCAL_MODULE_TAGS := optional
  426. LOCAL_MODULE_PATH := $(TARGET_OUT)/etc/selinux
  427. include $(BUILD_SYSTEM)/base_rules.mk
  428. # plat_policy.conf - A combination of the private and public platform policy
  429. # which will ship with the device. The platform will always reflect the most
  430. # recent platform version and is not currently being attributized.
  431. plat_policy.conf := $(intermediates)/plat_policy.conf
  432. $(plat_policy.conf): PRIVATE_MLS_SENS := $(MLS_SENS)
  433. $(plat_policy.conf): PRIVATE_MLS_CATS := $(MLS_CATS)
  434. $(plat_policy.conf): PRIVATE_TARGET_BUILD_VARIANT := $(TARGET_BUILD_VARIANT)
  435. $(plat_policy.conf): PRIVATE_TGT_ARCH := $(my_target_arch)
  436. $(plat_policy.conf): PRIVATE_TGT_WITH_ASAN := $(with_asan)
  437. $(plat_policy.conf): PRIVATE_TGT_WITH_NATIVE_COVERAGE := $(with_native_coverage)
  438. $(plat_policy.conf): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
  439. $(plat_policy.conf): PRIVATE_SEPOLICY_SPLIT := $(PRODUCT_SEPOLICY_SPLIT)
  440. $(plat_policy.conf): PRIVATE_COMPATIBLE_PROPERTY := $(PRODUCT_COMPATIBLE_PROPERTY)
  441. $(plat_policy.conf): $(call build_policy, $(sepolicy_build_files), \
  442. $(PLAT_PUBLIC_POLICY) $(PLAT_PRIVATE_POLICY))
  443. $(transform-policy-to-conf)
  444. $(hide) sed '/^\s*dontaudit.*;/d' $@ | sed '/^\s*dontaudit/,/;/d' > [email protected]
  445. $(LOCAL_BUILT_MODULE): PRIVATE_ADDITIONAL_CIL_FILES := \
  446. $(call build_policy, $(sepolicy_build_cil_workaround_files), $(PLAT_PRIVATE_POLICY))
  447. $(LOCAL_BUILT_MODULE): PRIVATE_NEVERALLOW_ARG := $(NEVERALLOW_ARG)
  448. $(LOCAL_BUILT_MODULE): $(plat_policy.conf) $(HOST_OUT_EXECUTABLES)/checkpolicy \
  449. $(HOST_OUT_EXECUTABLES)/secilc \
  450. $(call build_policy, $(sepolicy_build_cil_workaround_files), $(PLAT_PRIVATE_POLICY)) \
  451. $(built_sepolicy_neverallows)
  452. @mkdir -p $(dir $@)
  453. $(hide) $(CHECKPOLICY_ASAN_OPTIONS) $(HOST_OUT_EXECUTABLES)/checkpolicy -M -C -c \
  454. $(POLICYVERS) -o [email protected] $<
  455. $(hide) cat $(PRIVATE_ADDITIONAL_CIL_FILES) >> [email protected]
  456. $(hide) $(HOST_OUT_EXECUTABLES)/secilc -m -M true -G -c $(POLICYVERS) $(PRIVATE_NEVERALLOW_ARG) [email protected] -o /dev/null -f /dev/null
  457. $(hide) mv [email protected] $@
  458. built_plat_cil := $(LOCAL_BUILT_MODULE)
  459. plat_policy.conf :=
  460. #################################
  461. include $(CLEAR_VARS)
  462. LOCAL_MODULE := userdebug_plat_sepolicy.cil
  463. LOCAL_MODULE_CLASS := ETC
  464. LOCAL_MODULE_TAGS := optional
  465. LOCAL_MODULE_PATH := $(TARGET_DEBUG_RAMDISK_OUT)
  466. include $(BUILD_SYSTEM)/base_rules.mk
  467. # userdebug_plat_policy.conf - the userdebug version plat_sepolicy.cil
  468. userdebug_plat_policy.conf := $(intermediates)/userdebug_plat_policy.conf
  469. $(userdebug_plat_policy.conf): PRIVATE_MLS_SENS := $(MLS_SENS)
  470. $(userdebug_plat_policy.conf): PRIVATE_MLS_CATS := $(MLS_CATS)
  471. $(userdebug_plat_policy.conf): PRIVATE_TARGET_BUILD_VARIANT := userdebug
  472. $(userdebug_plat_policy.conf): PRIVATE_TGT_ARCH := $(my_target_arch)
  473. $(userdebug_plat_policy.conf): PRIVATE_TGT_WITH_ASAN := $(with_asan)
  474. $(userdebug_plat_policy.conf): PRIVATE_TGT_WITH_NATIVE_COVERAGE := $(with_native_coverage)
  475. $(userdebug_plat_policy.conf): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
  476. $(userdebug_plat_policy.conf): PRIVATE_SEPOLICY_SPLIT := $(PRODUCT_SEPOLICY_SPLIT)
  477. $(userdebug_plat_policy.conf): PRIVATE_COMPATIBLE_PROPERTY := $(PRODUCT_COMPATIBLE_PROPERTY)
  478. $(userdebug_plat_policy.conf): $(call build_policy, $(sepolicy_build_files), \
  479. $(PLAT_PUBLIC_POLICY) $(PLAT_PRIVATE_POLICY))
  480. $(transform-policy-to-conf)
  481. $(hide) sed '/^\s*dontaudit.*;/d' $@ | sed '/^\s*dontaudit/,/;/d' > [email protected]
  482. $(LOCAL_BUILT_MODULE): PRIVATE_ADDITIONAL_CIL_FILES := \
  483. $(call build_policy, $(sepolicy_build_cil_workaround_files), $(PLAT_PRIVATE_POLICY))
  484. $(LOCAL_BUILT_MODULE): PRIVATE_NEVERALLOW_ARG := $(NEVERALLOW_ARG)
  485. $(LOCAL_BUILT_MODULE): $(userdebug_plat_policy.conf) $(HOST_OUT_EXECUTABLES)/checkpolicy \
  486. $(HOST_OUT_EXECUTABLES)/secilc \
  487. $(call build_policy, $(sepolicy_build_cil_workaround_files), $(PLAT_PRIVATE_POLICY)) \
  488. $(built_sepolicy_neverallows)
  489. @mkdir -p $(dir $@)
  490. $(hide) $(CHECKPOLICY_ASAN_OPTIONS) $(HOST_OUT_EXECUTABLES)/checkpolicy -M -C -c \
  491. $(POLICYVERS) -o [email protected] $<
  492. $(hide) cat $(PRIVATE_ADDITIONAL_CIL_FILES) >> [email protected]
  493. $(hide) $(HOST_OUT_EXECUTABLES)/secilc -m -M true -G -c $(POLICYVERS) $(PRIVATE_NEVERALLOW_ARG) [email protected] -o /dev/null -f /dev/null
  494. $(hide) mv [email protected] $@
  495. userdebug_plat_policy.conf :=
  496. #################################
  497. include $(CLEAR_VARS)
  498. ifdef HAS_PRODUCT_SEPOLICY
  499. LOCAL_MODULE := product_sepolicy.cil
  500. LOCAL_MODULE_CLASS := ETC
  501. LOCAL_MODULE_TAGS := optional
  502. LOCAL_MODULE_PATH := $(TARGET_OUT_PRODUCT)/etc/selinux
  503. include $(BUILD_SYSTEM)/base_rules.mk
  504. # product_policy.conf - A combination of the private and public product policy
  505. # which will ship with the device. Product policy is not attributized.
  506. product_policy.conf := $(intermediates)/product_policy.conf
  507. $(product_policy.conf): PRIVATE_MLS_SENS := $(MLS_SENS)
  508. $(product_policy.conf): PRIVATE_MLS_CATS := $(MLS_CATS)
  509. $(product_policy.conf): PRIVATE_TARGET_BUILD_VARIANT := $(TARGET_BUILD_VARIANT)
  510. $(product_policy.conf): PRIVATE_TGT_ARCH := $(my_target_arch)
  511. $(product_policy.conf): PRIVATE_TGT_WITH_ASAN := $(with_asan)
  512. $(product_policy.conf): PRIVATE_TGT_WITH_NATIVE_COVERAGE := $(with_native_coverage)
  513. $(product_policy.conf): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
  514. $(product_policy.conf): PRIVATE_SEPOLICY_SPLIT := $(PRODUCT_SEPOLICY_SPLIT)
  515. $(product_policy.conf): PRIVATE_COMPATIBLE_PROPERTY := $(PRODUCT_COMPATIBLE_PROPERTY)
  516. $(product_policy.conf): $(call build_policy, $(sepolicy_build_files), \
  517. $(PLAT_PUBLIC_POLICY) $(PLAT_PRIVATE_POLICY) \
  518. $(PRODUCT_PUBLIC_POLICY) $(PRODUCT_PRIVATE_POLICY))
  519. $(transform-policy-to-conf)
  520. $(hide) sed '/dontaudit/d' $@ > [email protected]
  521. $(LOCAL_BUILT_MODULE): PRIVATE_NEVERALLOW_ARG := $(NEVERALLOW_ARG)
  522. $(LOCAL_BUILT_MODULE): PRIVATE_PLAT_CIL := $(built_plat_cil)
  523. $(LOCAL_BUILT_MODULE): $(product_policy.conf) $(HOST_OUT_EXECUTABLES)/checkpolicy \
  524. $(HOST_OUT_EXECUTABLES)/build_sepolicy $(HOST_OUT_EXECUTABLES)/secilc $(built_plat_cil)
  525. @mkdir -p $(dir $@)
  526. $(hide) $(CHECKPOLICY_ASAN_OPTIONS) $(HOST_OUT_EXECUTABLES)/checkpolicy -M -C -c \
  527. $(POLICYVERS) -o $@ $<
  528. $(hide) $(HOST_OUT_EXECUTABLES)/build_sepolicy -a $(HOST_OUT_EXECUTABLES) filter_out \
  529. -f $(PRIVATE_PLAT_CIL) -t $@
  530. # Line markers (denoted by ;;) are malformed after above cmd. They are only
  531. # used for debugging, so we remove them.
  532. $(hide) grep -v ';;' $@ > [email protected]
  533. $(hide) mv [email protected] $@
  534. # Combine plat_sepolicy.cil and product_sepolicy.cil to make sure that the
  535. # latter doesn't accidentally depend on vendor/odm policies.
  536. $(hide) $(HOST_OUT_EXECUTABLES)/secilc -m -M true -G -c $(POLICYVERS) \
  537. $(PRIVATE_NEVERALLOW_ARG) $(PRIVATE_PLAT_CIL) $@ -o /dev/null -f /dev/null
  538. built_product_cil := $(LOCAL_BUILT_MODULE)
  539. product_policy.conf :=
  540. endif # ifdef HAS_PRODUCT_SEPOLICY
  541. #################################
  542. include $(CLEAR_VARS)
  543. LOCAL_MODULE := plat_sepolicy_vers.txt
  544. LOCAL_MODULE_CLASS := ETC
  545. LOCAL_MODULE_TAGS := optional
  546. LOCAL_PROPRIETARY_MODULE := true
  547. LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc/selinux
  548. include $(BUILD_SYSTEM)/base_rules.mk
  549. $(LOCAL_BUILT_MODULE) : PRIVATE_PLAT_SEPOL_VERS := $(BOARD_SEPOLICY_VERS)
  550. $(LOCAL_BUILT_MODULE) :
  551. mkdir -p $(dir $@)
  552. echo $(PRIVATE_PLAT_SEPOL_VERS) > $@
  553. #################################
  554. include $(CLEAR_VARS)
  555. LOCAL_MODULE := plat_mapping_file
  556. LOCAL_MODULE_STEM := $(PLATFORM_SEPOLICY_VERSION).cil
  557. LOCAL_MODULE_CLASS := ETC
  558. LOCAL_MODULE_TAGS := optional
  559. LOCAL_MODULE_PATH := $(TARGET_OUT)/etc/selinux/mapping
  560. include $(BUILD_SYSTEM)/base_rules.mk
  561. # auto-generate the mapping file for current platform policy, since it needs to
  562. # track platform policy development
  563. $(LOCAL_BUILT_MODULE) : PRIVATE_VERS := $(PLATFORM_SEPOLICY_VERSION)
  564. $(LOCAL_BUILT_MODULE) : $(plat_pub_policy.cil) $(HOST_OUT_EXECUTABLES)/version_policy
  565. @mkdir -p $(dir $@)
  566. $(hide) $(HOST_OUT_EXECUTABLES)/version_policy -b $< -m -n $(PRIVATE_VERS) -o $@
  567. built_plat_mapping_cil := $(LOCAL_BUILT_MODULE)
  568. #################################
  569. include $(CLEAR_VARS)
  570. ifdef HAS_PRODUCT_SEPOLICY
  571. LOCAL_MODULE := product_mapping_file
  572. LOCAL_MODULE_STEM := $(PLATFORM_SEPOLICY_VERSION).cil
  573. LOCAL_MODULE_CLASS := ETC
  574. LOCAL_MODULE_TAGS := optional
  575. LOCAL_MODULE_PATH := $(TARGET_OUT_PRODUCT)/etc/selinux/mapping
  576. include $(BUILD_SYSTEM)/base_rules.mk
  577. $(LOCAL_BUILT_MODULE) : PRIVATE_VERS := $(PLATFORM_SEPOLICY_VERSION)
  578. $(LOCAL_BUILT_MODULE) : PRIVATE_PLAT_MAPPING_CIL := $(built_plat_mapping_cil)
  579. $(LOCAL_BUILT_MODULE) : $(pub_policy.cil) $(HOST_OUT_EXECUTABLES)/version_policy \
  580. $(built_plat_mapping_cil)
  581. @mkdir -p $(dir $@)
  582. # Generate product mapping file as mapping file of all public sepolicy minus
  583. # plat_mapping_file.
  584. $(hide) $(HOST_OUT_EXECUTABLES)/version_policy -b $< -m -n $(PRIVATE_VERS) -o $@
  585. $(hide) $(HOST_OUT_EXECUTABLES)/build_sepolicy -a $(HOST_OUT_EXECUTABLES) filter_out \
  586. -f $(PRIVATE_PLAT_MAPPING_CIL) -t $@
  587. built_product_mapping_cil := $(LOCAL_BUILT_MODULE)
  588. endif # HAS_PRODUCT_SEPOLICY
  589. #################################
  590. include $(CLEAR_VARS)
  591. # plat_pub_versioned.cil - the exported platform policy associated with the version
  592. # that non-platform policy targets.
  593. LOCAL_MODULE := plat_pub_versioned.cil
  594. LOCAL_MODULE_CLASS := ETC
  595. LOCAL_MODULE_TAGS := optional
  596. LOCAL_PROPRIETARY_MODULE := true
  597. LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc/selinux
  598. include $(BUILD_SYSTEM)/base_rules.mk
  599. $(LOCAL_BUILT_MODULE) : PRIVATE_VERS := $(BOARD_SEPOLICY_VERS)
  600. $(LOCAL_BUILT_MODULE) : PRIVATE_TGT_POL := $(pub_policy.cil)
  601. $(LOCAL_BUILT_MODULE) : PRIVATE_DEP_CIL_FILES := $(built_plat_cil) $(built_product_cil)\
  602. $(built_plat_mapping_cil) $(built_product_mapping_cil)
  603. $(LOCAL_BUILT_MODULE) : $(pub_policy.cil) $(HOST_OUT_EXECUTABLES)/version_policy \
  604. $(HOST_OUT_EXECUTABLES)/secilc $(built_plat_cil) $(built_product_cil) \
  605. $(built_plat_mapping_cil) $(built_product_mapping_cil)
  606. @mkdir -p $(dir $@)
  607. $(HOST_OUT_EXECUTABLES)/version_policy -b $< -t $(PRIVATE_TGT_POL) -n $(PRIVATE_VERS) -o $@
  608. $(hide) $(HOST_OUT_EXECUTABLES)/secilc -m -M true -G -N -c $(POLICYVERS) \
  609. $(PRIVATE_DEP_CIL_FILES) $@ -o /dev/null -f /dev/null
  610. built_pub_vers_cil := $(LOCAL_BUILT_MODULE)
  611. #################################
  612. include $(CLEAR_VARS)
  613. # vendor_policy.cil - the vendor sepolicy. This needs attributization and to be combined
  614. # with the platform-provided policy. It makes use of the reqd_policy_mask files from private
  615. # policy and the platform public policy files in order to use checkpolicy.
  616. LOCAL_MODULE := vendor_sepolicy.cil
  617. LOCAL_MODULE_CLASS := ETC
  618. LOCAL_MODULE_TAGS := optional
  619. LOCAL_PROPRIETARY_MODULE := true
  620. LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc/selinux
  621. include $(BUILD_SYSTEM)/base_rules.mk
  622. vendor_policy.conf := $(intermediates)/vendor_policy.conf
  623. $(vendor_policy.conf): PRIVATE_MLS_SENS := $(MLS_SENS)
  624. $(vendor_policy.conf): PRIVATE_MLS_CATS := $(MLS_CATS)
  625. $(vendor_policy.conf): PRIVATE_TARGET_BUILD_VARIANT := $(TARGET_BUILD_VARIANT)
  626. $(vendor_policy.conf): PRIVATE_TGT_ARCH := $(my_target_arch)
  627. $(vendor_policy.conf): PRIVATE_TGT_WITH_ASAN := $(with_asan)
  628. $(vendor_policy.conf): PRIVATE_TGT_WITH_NATIVE_COVERAGE := $(with_native_coverage)
  629. $(vendor_policy.conf): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
  630. $(vendor_policy.conf): PRIVATE_SEPOLICY_SPLIT := $(PRODUCT_SEPOLICY_SPLIT)
  631. $(vendor_policy.conf): PRIVATE_COMPATIBLE_PROPERTY := $(PRODUCT_COMPATIBLE_PROPERTY)
  632. $(vendor_policy.conf): $(call build_policy, $(sepolicy_build_files), \
  633. $(PLAT_PUBLIC_POLICY) $(PRODUCT_PUBLIC_POLICY) $(REQD_MASK_POLICY) $(PLAT_VENDOR_POLICY) \
  634. $(BOARD_VENDOR_SEPOLICY_DIRS))
  635. $(transform-policy-to-conf)
  636. $(hide) sed '/^\s*dontaudit.*;/d' $@ | sed '/^\s*dontaudit/,/;/d' > [email protected]
  637. $(LOCAL_BUILT_MODULE): PRIVATE_POL_CONF := $(vendor_policy.conf)
  638. $(LOCAL_BUILT_MODULE): PRIVATE_REQD_MASK := $(reqd_policy_mask.cil)
  639. $(LOCAL_BUILT_MODULE): PRIVATE_BASE_CIL := $(pub_policy.cil)
  640. $(LOCAL_BUILT_MODULE): PRIVATE_VERS := $(BOARD_SEPOLICY_VERS)
  641. $(LOCAL_BUILT_MODULE): PRIVATE_DEP_CIL_FILES := $(built_plat_cil) $(built_product_cil)\
  642. $(built_pub_vers_cil) $(built_plat_mapping_cil) $(built_product_mapping_cil)
  643. $(LOCAL_BUILT_MODULE): PRIVATE_FILTER_CIL := $(built_pub_vers_cil)
  644. $(LOCAL_BUILT_MODULE): $(HOST_OUT_EXECUTABLES)/build_sepolicy \
  645. $(vendor_policy.conf) $(reqd_policy_mask.cil) $(pub_policy.cil) \
  646. $(built_plat_cil) $(built_product_cil) $(built_pub_vers_cil) \
  647. $(built_plat_mapping_cil) $(built_product_mapping_cil)
  648. @mkdir -p $(dir $@)
  649. $(hide) $(HOST_OUT_EXECUTABLES)/build_sepolicy -a $(HOST_OUT_EXECUTABLES) build_cil \
  650. -i $(PRIVATE_POL_CONF) -m $(PRIVATE_REQD_MASK) -c $(CHECKPOLICY_ASAN_OPTIONS) \
  651. -b $(PRIVATE_BASE_CIL) -d $(PRIVATE_DEP_CIL_FILES) -f $(PRIVATE_FILTER_CIL) \
  652. -t $(PRIVATE_VERS) -p $(POLICYVERS) -o $@
  653. built_vendor_cil := $(LOCAL_BUILT_MODULE)
  654. vendor_policy.conf :=
  655. #################################
  656. include $(CLEAR_VARS)
  657. ifdef BOARD_ODM_SEPOLICY_DIRS
  658. # odm_policy.cil - the odm sepolicy. This needs attributization and to be combined
  659. # with the platform-provided policy. It makes use of the reqd_policy_mask files from private
  660. # policy and the platform public policy files in order to use checkpolicy.
  661. LOCAL_MODULE := odm_sepolicy.cil
  662. LOCAL_MODULE_CLASS := ETC
  663. LOCAL_MODULE_TAGS := optional
  664. LOCAL_PROPRIETARY_MODULE := true
  665. LOCAL_MODULE_PATH := $(TARGET_OUT_ODM)/etc/selinux
  666. include $(BUILD_SYSTEM)/base_rules.mk
  667. odm_policy.conf := $(intermediates)/odm_policy.conf
  668. $(odm_policy.conf): PRIVATE_MLS_SENS := $(MLS_SENS)
  669. $(odm_policy.conf): PRIVATE_MLS_CATS := $(MLS_CATS)
  670. $(odm_policy.conf): PRIVATE_TARGET_BUILD_VARIANT := $(TARGET_BUILD_VARIANT)
  671. $(odm_policy.conf): PRIVATE_TGT_ARCH := $(my_target_arch)
  672. $(odm_policy.conf): PRIVATE_TGT_WITH_ASAN := $(with_asan)
  673. $(odm_policy.conf): PRIVATE_TGT_WITH_NATIVE_COVERAGE := $(with_native_coverage)
  674. $(odm_policy.conf): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
  675. $(odm_policy.conf): PRIVATE_SEPOLICY_SPLIT := $(PRODUCT_SEPOLICY_SPLIT)
  676. $(odm_policy.conf): PRIVATE_COMPATIBLE_PROPERTY := $(PRODUCT_COMPATIBLE_PROPERTY)
  677. $(odm_policy.conf): $(call build_policy, $(sepolicy_build_files), \
  678. $(PLAT_PUBLIC_POLICY) $(PRODUCT_PUBLIC_POLICY) $(REQD_MASK_POLICY) $(PLAT_VENDOR_POLICY) \
  679. $(BOARD_VENDOR_SEPOLICY_DIRS) $(BOARD_ODM_SEPOLICY_DIRS))
  680. $(transform-policy-to-conf)
  681. $(hide) sed '/^\s*dontaudit.*;/d' $@ | sed '/^\s*dontaudit/,/;/d' > [email protected]
  682. $(LOCAL_BUILT_MODULE): PRIVATE_POL_CONF := $(odm_policy.conf)
  683. $(LOCAL_BUILT_MODULE): PRIVATE_REQD_MASK := $(reqd_policy_mask.cil)
  684. $(LOCAL_BUILT_MODULE): PRIVATE_BASE_CIL := $(pub_policy.cil)
  685. $(LOCAL_BUILT_MODULE): PRIVATE_VERS := $(BOARD_SEPOLICY_VERS)
  686. $(LOCAL_BUILT_MODULE): PRIVATE_DEP_CIL_FILES := $(built_plat_cil) $(built_product_cil) \
  687. $(built_pub_vers_cil) $(built_plat_mapping_cil) $(built_product_mapping_cil)\
  688. $(built_vendor_cil)
  689. $(LOCAL_BUILT_MODULE) : PRIVATE_FILTER_CIL_FILES := $(built_pub_vers_cil) $(built_vendor_cil)
  690. $(LOCAL_BUILT_MODULE): $(HOST_OUT_EXECUTABLES)/build_sepolicy \
  691. $(odm_policy.conf) $(reqd_policy_mask.cil) $(pub_policy.cil) \
  692. $(built_plat_cil) $(built_product_cil) $(built_pub_vers_cil) \
  693. $(built_plat_mapping_cil) $(built_product_mapping_cil) $(built_vendor_cil)
  694. @mkdir -p $(dir $@)
  695. $(hide) $(HOST_OUT_EXECUTABLES)/build_sepolicy -a $(HOST_OUT_EXECUTABLES) build_cil \
  696. -i $(PRIVATE_POL_CONF) -m $(PRIVATE_REQD_MASK) -c $(CHECKPOLICY_ASAN_OPTIONS) \
  697. -b $(PRIVATE_BASE_CIL) -d $(PRIVATE_DEP_CIL_FILES) -f $(PRIVATE_FILTER_CIL_FILES) \
  698. -t $(PRIVATE_VERS) -p $(POLICYVERS) -o $@
  699. built_odm_cil := $(LOCAL_BUILT_MODULE)
  700. odm_policy.conf :=
  701. odm_policy_raw :=
  702. endif
  703. #################################
  704. include $(CLEAR_VARS)
  705. LOCAL_MODULE := precompiled_sepolicy
  706. LOCAL_MODULE_CLASS := ETC
  707. LOCAL_MODULE_TAGS := optional
  708. LOCAL_PROPRIETARY_MODULE := true
  709. ifeq ($(BOARD_USES_ODMIMAGE),true)
  710. LOCAL_MODULE_PATH := $(TARGET_OUT_ODM)/etc/selinux
  711. else
  712. LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc/selinux
  713. endif
  714. include $(BUILD_SYSTEM)/base_rules.mk
  715. all_cil_files := \
  716. $(built_plat_cil) \
  717. $(built_plat_mapping_cil) \
  718. $(built_pub_vers_cil) \
  719. $(built_vendor_cil)
  720. ifdef HAS_PRODUCT_SEPOLICY
  721. all_cil_files += \
  722. $(built_product_cil) \
  723. $(built_product_mapping_cil) \
  724. endif
  725. ifdef BOARD_ODM_SEPOLICY_DIRS
  726. all_cil_files += $(built_odm_cil)
  727. endif
  728. $(LOCAL_BUILT_MODULE): PRIVATE_CIL_FILES := $(all_cil_files)
  729. $(LOCAL_BUILT_MODULE): PRIVATE_NEVERALLOW_ARG := $(NEVERALLOW_ARG)
  730. $(LOCAL_BUILT_MODULE): $(HOST_OUT_EXECUTABLES)/secilc $(all_cil_files) $(built_sepolicy_neverallows)
  731. $(hide) $(HOST_OUT_EXECUTABLES)/secilc -m -M true -G -c $(POLICYVERS) $(PRIVATE_NEVERALLOW_ARG) \
  732. $(PRIVATE_CIL_FILES) -o $@ -f /dev/null
  733. built_precompiled_sepolicy := $(LOCAL_BUILT_MODULE)
  734. all_cil_files :=
  735. #################################
  736. # Precompiled sepolicy is loaded if and only if:
  737. # - plat_sepolicy_and_mapping.sha256 equals
  738. # precompiled_sepolicy.plat_sepolicy_and_mapping.sha256
  739. # AND
  740. # - product_sepolicy_and_mapping.sha256 equals
  741. # precompiled_sepolicy.product_sepolicy_and_mapping.sha256
  742. # See system/core/init/selinux.cpp for details.
  743. #################################
  744. include $(CLEAR_VARS)
  745. LOCAL_MODULE := plat_sepolicy_and_mapping.sha256
  746. LOCAL_MODULE_CLASS := ETC
  747. LOCAL_MODULE_TAGS := optional
  748. LOCAL_MODULE_PATH = $(TARGET_OUT)/etc/selinux
  749. include $(BUILD_SYSTEM)/base_rules.mk
  750. $(LOCAL_BUILT_MODULE): $(built_plat_cil) $(built_plat_mapping_cil)
  751. cat $^ | sha256sum | cut -d' ' -f1 > $@
  752. #################################
  753. include $(CLEAR_VARS)
  754. LOCAL_MODULE := product_sepolicy_and_mapping.sha256
  755. LOCAL_MODULE_CLASS := ETC
  756. LOCAL_MODULE_TAGS := optional
  757. LOCAL_MODULE_PATH = $(TARGET_OUT_PRODUCT)/etc/selinux
  758. include $(BUILD_SYSTEM)/base_rules.mk
  759. $(LOCAL_BUILT_MODULE): $(built_product_cil) $(built_product_mapping_cil)
  760. cat $^ | sha256sum | cut -d' ' -f1 > $@
  761. #################################
  762. # SHA-256 digest of the plat_sepolicy.cil and plat_mapping_file against
  763. # which precompiled_policy was built.
  764. #################################
  765. include $(CLEAR_VARS)
  766. LOCAL_MODULE := precompiled_sepolicy.plat_sepolicy_and_mapping.sha256
  767. LOCAL_MODULE_CLASS := ETC
  768. LOCAL_MODULE_TAGS := optional
  769. ifeq ($(BOARD_USES_ODMIMAGE),true)
  770. LOCAL_MODULE_PATH := $(TARGET_OUT_ODM)/etc/selinux
  771. else
  772. LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc/selinux
  773. endif
  774. include $(BUILD_SYSTEM)/base_rules.mk
  775. $(LOCAL_BUILT_MODULE): PRIVATE_CIL_FILES := $(built_plat_cil) $(built_plat_mapping_cil)
  776. $(LOCAL_BUILT_MODULE): $(built_precompiled_sepolicy) $(built_plat_cil) $(built_plat_mapping_cil)
  777. cat $(PRIVATE_CIL_FILES) | sha256sum | cut -d' ' -f1 > $@
  778. #################################
  779. # SHA-256 digest of the product_sepolicy.cil and product_mapping_file against
  780. # which precompiled_policy was built.
  781. #################################
  782. include $(CLEAR_VARS)
  783. LOCAL_MODULE := precompiled_sepolicy.product_sepolicy_and_mapping.sha256
  784. LOCAL_MODULE_CLASS := ETC
  785. LOCAL_MODULE_TAGS := optional
  786. ifeq ($(BOARD_USES_ODMIMAGE),true)
  787. LOCAL_MODULE_PATH := $(TARGET_OUT_ODM)/etc/selinux
  788. else
  789. LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc/selinux
  790. endif
  791. include $(BUILD_SYSTEM)/base_rules.mk
  792. $(LOCAL_BUILT_MODULE): PRIVATE_CIL_FILES := $(built_product_cil) $(built_product_mapping_cil)
  793. $(LOCAL_BUILT_MODULE): $(built_precompiled_sepolicy) $(built_product_cil) $(built_product_mapping_cil)
  794. cat $(PRIVATE_CIL_FILES) | sha256sum | cut -d' ' -f1 > $@
  795. #################################
  796. include $(CLEAR_VARS)
  797. # build this target so that we can still perform neverallow checks
  798. LOCAL_MODULE := sepolicy
  799. LOCAL_MODULE_CLASS := ETC
  800. LOCAL_MODULE_TAGS := optional
  801. LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
  802. include $(BUILD_SYSTEM)/base_rules.mk
  803. all_cil_files := \
  804. $(built_plat_cil) \
  805. $(built_plat_mapping_cil) \
  806. $(built_pub_vers_cil) \
  807. $(built_vendor_cil)
  808. ifdef HAS_PRODUCT_SEPOLICY
  809. all_cil_files += \
  810. $(built_product_cil) \
  811. $(built_product_mapping_cil) \
  812. endif
  813. ifdef BOARD_ODM_SEPOLICY_DIRS
  814. all_cil_files += $(built_odm_cil)
  815. endif
  816. $(LOCAL_BUILT_MODULE): PRIVATE_CIL_FILES := $(all_cil_files)
  817. $(LOCAL_BUILT_MODULE): PRIVATE_NEVERALLOW_ARG := $(NEVERALLOW_ARG)
  818. $(LOCAL_BUILT_MODULE): $(HOST_OUT_EXECUTABLES)/secilc $(HOST_OUT_EXECUTABLES)/sepolicy-analyze $(all_cil_files) \
  819. $(built_sepolicy_neverallows)
  820. @mkdir -p $(dir $@)
  821. $(hide) $< -m -M true -G -c $(POLICYVERS) $(PRIVATE_NEVERALLOW_ARG) $(PRIVATE_CIL_FILES) -o [email protected] -f /dev/null
  822. $(hide) $(HOST_OUT_EXECUTABLES)/sepolicy-analyze [email protected] permissive > [email protected]
  823. $(hide) if [ "$(TARGET_BUILD_VARIANT)" = "user" -a -s [email protected] ]; then \
  824. echo "==========" 1>&2; \
  825. echo "ERROR: permissive domains not allowed in user builds" 1>&2; \
  826. echo "List of invalid domains:" 1>&2; \
  827. cat [email protected] 1>&2; \
  828. exit 1; \
  829. fi
  830. $(hide) mv [email protected] $@
  831. built_sepolicy := $(LOCAL_BUILT_MODULE)
  832. all_cil_files :=
  833. #################################
  834. include $(CLEAR_VARS)
  835. # keep concrete sepolicy for neverallow checks
  836. # If SELINUX_IGNORE_NEVERALLOWS is set, we use sed to remove the neverallow lines before compiling.
  837. LOCAL_MODULE := sepolicy.recovery
  838. LOCAL_MODULE_STEM := sepolicy
  839. LOCAL_MODULE_CLASS := ETC
  840. LOCAL_MODULE_TAGS := optional
  841. LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)
  842. include $(BUILD_SYSTEM)/base_rules.mk
  843. sepolicy.recovery.conf := $(intermediates)/sepolicy.recovery.conf
  844. $(sepolicy.recovery.conf): PRIVATE_MLS_SENS := $(MLS_SENS)
  845. $(sepolicy.recovery.conf): PRIVATE_MLS_CATS := $(MLS_CATS)
  846. $(sepolicy.recovery.conf): PRIVATE_TARGET_BUILD_VARIANT := $(TARGET_BUILD_VARIANT)
  847. $(sepolicy.recovery.conf): PRIVATE_TGT_ARCH := $(my_target_arch)
  848. $(sepolicy.recovery.conf): PRIVATE_TGT_WITH_ASAN := $(with_asan)
  849. $(sepolicy.recovery.conf): PRIVATE_TGT_WITH_NATIVE_COVERAGE := $(with_native_coverage)
  850. $(sepolicy.recovery.conf): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
  851. $(sepolicy.recovery.conf): PRIVATE_TGT_RECOVERY := -D target_recovery=true
  852. $(sepolicy.recovery.conf): $(call build_policy, $(sepolicy_build_files), \
  853. $(PLAT_PUBLIC_POLICY) $(PLAT_PRIVATE_POLICY) \
  854. $(PRODUCT_PUBLIC_POLICY) $(PRODUCT_PRIVATE_POLICY) \
  855. $(PLAT_VENDOR_POLICY) $(BOARD_VENDOR_SEPOLICY_DIRS) \
  856. $(BOARD_ODM_SEPOLICY_DIRS))
  857. $(transform-policy-to-conf)
  858. $(hide) sed '/^\s*dontaudit.*;/d' $@ | sed '/^\s*dontaudit/,/;/d' > [email protected]
  859. ifeq ($(SELINUX_IGNORE_NEVERALLOWS),true)
  860. $(hide) sed -z 's/\n\s*neverallow[^;]*;/\n/g' $@ > [email protected]
  861. $(hide) mv [email protected] $@
  862. endif
  863. $(LOCAL_BUILT_MODULE): $(sepolicy.recovery.conf) $(HOST_OUT_EXECUTABLES)/checkpolicy \
  864. $(HOST_OUT_EXECUTABLES)/sepolicy-analyze
  865. @mkdir -p $(dir $@)
  866. $(hide) $(CHECKPOLICY_ASAN_OPTIONS) $(HOST_OUT_EXECUTABLES)/checkpolicy -M -c \
  867. $(POLICYVERS) -o [email protected] $<
  868. $(hide) $(HOST_OUT_EXECUTABLES)/sepolicy-analyze [email protected] permissive > [email protected]
  869. $(hide) if [ "$(TARGET_BUILD_VARIANT)" = "user" -a -s [email protected] ]; then \
  870. echo "==========" 1>&2; \
  871. echo "ERROR: permissive domains not allowed in user builds" 1>&2; \
  872. echo "List of invalid domains:" 1>&2; \
  873. cat [email protected] 1>&2; \
  874. exit 1; \
  875. fi
  876. $(hide) mv [email protected] $@
  877. sepolicy.recovery.conf :=
  878. ##################################
  879. # SELinux policy embedded into CTS.
  880. # CTS checks neverallow rules of this policy against the policy of the device under test.
  881. ##################################
  882. include $(CLEAR_VARS)
  883. LOCAL_MODULE := general_sepolicy.conf
  884. LOCAL_MODULE_CLASS := ETC
  885. LOCAL_MODULE_TAGS := tests
  886. include $(BUILD_SYSTEM)/base_rules.mk
  887. $(LOCAL_BUILT_MODULE): PRIVATE_MLS_SENS := $(MLS_SENS)
  888. $(LOCAL_BUILT_MODULE): PRIVATE_MLS_CATS := $(MLS_CATS)
  889. $(LOCAL_BUILT_MODULE): PRIVATE_TARGET_BUILD_VARIANT := user
  890. $(LOCAL_BUILT_MODULE): PRIVATE_TGT_ARCH := $(my_target_arch)
  891. $(LOCAL_BUILT_MODULE): PRIVATE_WITH_ASAN := false
  892. $(LOCAL_BUILT_MODULE): PRIVATE_SEPOLICY_SPLIT := cts
  893. $(LOCAL_BUILT_MODULE): PRIVATE_COMPATIBLE_PROPERTY := cts
  894. $(LOCAL_BUILT_MODULE): PRIVATE_EXCLUDE_BUILD_TEST := true
  895. $(LOCAL_BUILT_MODULE): $(call build_policy, $(sepolicy_build_files), \
  896. $(PLAT_PUBLIC_POLICY) $(PLAT_PRIVATE_POLICY))
  897. $(transform-policy-to-conf)
  898. $(hide) sed '/^\s*dontaudit.*;/d' $@ | sed '/^\s*dontaudit/,/;/d' > [email protected]
  899. ##################################
  900. # TODO - remove this. Keep around until we get the filesystem creation stuff taken care of.
  901. #
  902. include $(CLEAR_VARS)
  903. LOCAL_MODULE := file_contexts.bin
  904. LOCAL_MODULE_CLASS := ETC
  905. LOCAL_MODULE_TAGS := optional
  906. LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
  907. include $(BUILD_SYSTEM)/base_rules.mk
  908. # The file_contexts.bin is built in the following way:
  909. # 1. Collect all file_contexts files in THIS repository and process them with
  910. # m4 into a tmp file called file_contexts.local.tmp.
  911. # 2. Collect all device specific file_contexts files and process them with m4
  912. # into a tmp file called file_contexts.device.tmp.
  913. # 3. Run checkfc -e (allow no device fc entries ie empty) and fc_sort on
  914. # file_contexts.device.tmp and output to file_contexts.device.sorted.tmp.
  915. # 4. Concatenate file_contexts.local.tmp and file_contexts.device.tmp into
  916. # file_contexts.concat.tmp.
  917. # 5. Run checkfc and sefcontext_compile on file_contexts.concat.tmp to produce
  918. # file_contexts.bin.
  919. #
  920. # Note: That a newline file is placed between each file_context file found to
  921. # ensure a proper build when an fc file is missing an ending newline.
  922. local_fc_files := $(call build_policy, file_contexts, $(PLAT_PRIVATE_POLICY))
  923. ifdef HAS_PRODUCT_SEPOLICY
  924. local_fc_files += $(call build_policy, file_contexts, $(PRODUCT_PRIVATE_POLICY))
  925. endif
  926. ifneq ($(filter address,$(SANITIZE_TARGET)),)
  927. local_fc_files += $(wildcard $(addsuffix /file_contexts_asan, $(PLAT_PRIVATE_POLICY)))
  928. endif
  929. ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
  930. local_fc_files += $(wildcard $(addsuffix /file_contexts_overlayfs, $(PLAT_PRIVATE_POLICY)))
  931. endif
  932. ifeq ($(TARGET_FLATTEN_APEX),true)
  933. apex_fc_files := $(wildcard $(LOCAL_PATH)/apex/*-file_contexts)
  934. $(foreach _input,$(apex_fc_files),\
  935. $(eval _output := $(intermediates)/$(notdir $(_input))-flattened)\
  936. $(eval _apex_name := $(patsubst %-file_contexts,%,$(notdir $(_input))))\
  937. $(eval $(call build_flattened_apex_file_contexts,$(_input),$(_apex_name),$(_output),local_fc_files))\
  938. )
  939. endif
  940. local_fcfiles_with_nl := $(call add_nl, $(local_fc_files), $(built_nl))
  941. file_contexts.local.tmp := $(intermediates)/file_contexts.local.tmp
  942. $(file_contexts.local.tmp): $(local_fcfiles_with_nl)
  943. @mkdir -p $(dir $@)
  944. $(hide) m4 --fatal-warnings -s $^ > $@
  945. device_fc_files := $(call build_vendor_policy, file_contexts)
  946. ifdef BOARD_ODM_SEPOLICY_DIRS
  947. device_fc_files += $(call build_odm_policy, file_contexts)
  948. endif
  949. device_fcfiles_with_nl := $(call add_nl, $(device_fc_files), $(built_nl))
  950. file_contexts.device.tmp := $(intermediates)/file_contexts.device.tmp
  951. $(file_contexts.device.tmp): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
  952. $(file_contexts.device.tmp): $(device_fcfiles_with_nl)
  953. @mkdir -p $(dir $@)
  954. $(hide) m4 --fatal-warnings -s $(PRIVATE_ADDITIONAL_M4DEFS) $^ > $@
  955. file_contexts.device.sorted.tmp := $(intermediates)/file_contexts.device.sorted.tmp
  956. $(file_contexts.device.sorted.tmp): PRIVATE_SEPOLICY := $(built_sepolicy)
  957. $(file_contexts.device.sorted.tmp): $(file_contexts.device.tmp) $(built_sepolicy) \
  958. $(HOST_OUT_EXECUTABLES)/fc_sort $(HOST_OUT_EXECUTABLES)/checkfc
  959. @mkdir -p $(dir $@)
  960. $(hide) $(HOST_OUT_EXECUTABLES)/checkfc -e $(PRIVATE_SEPOLICY) $<
  961. $(hide) $(HOST_OUT_EXECUTABLES)/fc_sort $< $@
  962. file_contexts.concat.tmp := $(intermediates)/file_contexts.concat.tmp
  963. $(file_contexts.concat.tmp): $(file_contexts.local.tmp) $(file_contexts.device.sorted.tmp)
  964. @mkdir -p $(dir $@)
  965. $(hide) m4 --fatal-warnings -s $^ > $@
  966. $(LOCAL_BUILT_MODULE): PRIVATE_SEPOLICY := $(built_sepolicy)
  967. $(LOCAL_BUILT_MODULE): $(file_contexts.concat.tmp) $(built_sepolicy) $(HOST_OUT_EXECUTABLES)/sefcontext_compile $(HOST_OUT_EXECUTABLES)/checkfc
  968. @mkdir -p $(dir $@)
  969. $(hide) $(HOST_OUT_EXECUTABLES)/checkfc $(PRIVATE_SEPOLICY) $<
  970. $(hide) $(HOST_OUT_EXECUTABLES)/sefcontext_compile -o $@ $<
  971. built_fc := $(LOCAL_BUILT_MODULE)
  972. local_fc_files :=
  973. local_fcfiles_with_nl :=
  974. device_fc_files :=
  975. device_fcfiles_with_nl :=
  976. file_contexts.concat.tmp :=
  977. file_contexts.device.sorted.tmp :=
  978. file_contexts.device.tmp :=
  979. file_contexts.local.tmp :=
  980. ##################################
  981. ifneq ($(TARGET_BUILD_VARIANT), user)
  982. include $(CLEAR_VARS)
  983. LOCAL_MODULE := selinux_denial_metadata
  984. LOCAL_MODULE_CLASS := ETC
  985. LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc/selinux
  986. include $(BUILD_SYSTEM)/base_rules.mk
  987. bug_files := $(call build_policy, bug_map, $(LOCAL_PATH) $(PLAT_PRIVATE_POLICY) $(PLAT_VENDOR_POLICY) $(BOARD_SEPOLICY_DIRS) $(PLAT_PUBLIC_POLICY))
  988. $(LOCAL_BUILT_MODULE) : $(bug_files)
  989. @mkdir -p $(dir $@)
  990. cat $^ > $@
  991. bug_files :=
  992. endif
  993. ##################################
  994. include $(LOCAL_PATH)/file_contexts.mk
  995. ##################################
  996. include $(LOCAL_PATH)/seapp_contexts.mk
  997. ##################################
  998. include $(LOCAL_PATH)/property_contexts.mk
  999. ##################################
  1000. include $(LOCAL_PATH)/service_contexts.mk
  1001. ##################################
  1002. include $(LOCAL_PATH)/hwservice_contexts.mk
  1003. ##################################
  1004. include $(CLEAR_VARS)
  1005. LOCAL_MODULE := vndservice_contexts
  1006. LOCAL_MODULE_CLASS := ETC
  1007. LOCAL_MODULE_TAGS := optional
  1008. LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc/selinux
  1009. include $(BUILD_SYSTEM)/base_rules.mk
  1010. vnd_svcfiles := $(call build_policy, vndservice_contexts, $(PLAT_VENDOR_POLICY) $(BOARD_VENDOR_SEPOLICY_DIRS) $(REQD_MASK_POLICY))
  1011. vndservice_contexts.tmp := $(intermediates)/vndservice_contexts.tmp
  1012. $(vndservice_contexts.tmp): PRIVATE_SVC_FILES := $(vnd_svcfiles)
  1013. $(vndservice_contexts.tmp): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
  1014. $(vndservice_contexts.tmp): $(vnd_svcfiles)
  1015. @mkdir -p $(dir $@)
  1016. $(hide) m4 --fatal-warnings -s $(PRIVATE_ADDITIONAL_M4DEFS) $(PRIVATE_SVC_FILES) > $@
  1017. $(LOCAL_BUILT_MODULE): PRIVATE_SEPOLICY := $(built_sepolicy)
  1018. $(LOCAL_BUILT_MODULE): $(vndservice_contexts.tmp) $(built_sepolicy) $(HOST_OUT_EXECUTABLES)/checkfc $(ACP)
  1019. @mkdir -p $(dir $@)
  1020. sed -e 's/#.*$$//' -e '/^$$/d' $< > $@
  1021. $(hide) $(HOST_OUT_EXECUTABLES)/checkfc -e -v $(PRIVATE_SEPOLICY) $@
  1022. vnd_svcfiles :=
  1023. vndservice_contexts.tmp :=
  1024. ##################################
  1025. include $(LOCAL_PATH)/mac_permissions.mk
  1026. #################################
  1027. include $(CLEAR_VARS)
  1028. LOCAL_MODULE := sepolicy_tests
  1029. LOCAL_MODULE_CLASS := ETC
  1030. LOCAL_MODULE_TAGS := tests
  1031. include $(BUILD_SYSTEM)/base_rules.mk
  1032. all_fc_files := $(built_plat_fc) $(built_vendor_fc)
  1033. ifdef HAS_PRODUCT_SEPOLICY
  1034. all_fc_args += $(built_product_fc)
  1035. endif
  1036. ifdef BOARD_ODM_SEPOLICY_DIRS
  1037. all_fc_files += $(built_odm_fc)
  1038. endif
  1039. all_fc_args := $(foreach file, $(all_fc_files), -f $(file))
  1040. sepolicy_tests := $(intermediates)/sepolicy_tests
  1041. $(sepolicy_tests): ALL_FC_ARGS := $(all_fc_args)
  1042. $(sepolicy_tests): PRIVATE_SEPOLICY := $(built_sepolicy)
  1043. $(sepolicy_tests): $(HOST_OUT_EXECUTABLES)/sepolicy_tests $(all_fc_files) $(built_sepolicy)
  1044. @mkdir -p $(dir $@)
  1045. $(hide) $(HOST_OUT_EXECUTABLES)/sepolicy_tests -l $(HOST_OUT)/lib64/libsepolwrap.$(SHAREDLIB_EXT) \
  1046. $(ALL_FC_ARGS) -p $(PRIVATE_SEPOLICY)
  1047. $(hide) touch $@
  1048. ##################################
  1049. intermediates := $(call intermediates-dir-for,ETC,built_plat_sepolicy,,,,)
  1050. # plat_sepolicy - the current platform policy only, built into a policy binary.
  1051. # TODO - this currently excludes partner extensions, but support should be added
  1052. # to enable partners to add their own compatibility mapping
  1053. BASE_PLAT_PUBLIC_POLICY := $(filter-out $(BOARD_PLAT_PUBLIC_SEPOLICY_DIR), $(PLAT_PUBLIC_POLICY))
  1054. BASE_PLAT_PRIVATE_POLICY := $(filter-out $(BOARD_PLAT_PRIVATE_SEPOLICY_DIR), $(PLAT_PRIVATE_POLICY))
  1055. base_plat_policy.conf := $(intermediates)/base_plat_policy.conf
  1056. $(base_plat_policy.conf): PRIVATE_MLS_SENS := $(MLS_SENS)
  1057. $(base_plat_policy.conf): PRIVATE_MLS_CATS := $(MLS_CATS)
  1058. $(base_plat_policy.conf): PRIVATE_TARGET_BUILD_VARIANT := user
  1059. $(base_plat_policy.conf): PRIVATE_TGT_ARCH := $(my_target_arch)
  1060. $(base_plat_policy.conf): PRIVATE_TGT_WITH_ASAN := $(with_asan)
  1061. $(base_plat_policy.conf): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
  1062. $(base_plat_policy.conf): PRIVATE_SEPOLICY_SPLIT := true
  1063. $(base_plat_policy.conf): PRIVATE_COMPATIBLE_PROPERTY := $(PRODUCT_COMPATIBLE_PROPERTY)
  1064. $(base_plat_policy.conf): $(call build_policy, $(sepolicy_build_files), \
  1065. $(BASE_PLAT_PUBLIC_POLICY) $(BASE_PLAT_PRIVATE_POLICY))
  1066. $(transform-policy-to-conf)
  1067. $(hide) sed '/^\s*dontaudit.*;/d' $@ | sed '/^\s*dontaudit/,/;/d' > [email protected]
  1068. built_plat_sepolicy := $(intermediates)/built_plat_sepolicy
  1069. $(built_plat_sepolicy): PRIVATE_ADDITIONAL_CIL_FILES := \
  1070. $(call build_policy, $(sepolicy_build_cil_workaround_files), $(BASE_PLAT_PRIVATE_POLICY))
  1071. $(built_plat_sepolicy): PRIVATE_NEVERALLOW_ARG := $(NEVERALLOW_ARG)
  1072. $(built_plat_sepolicy): $(base_plat_policy.conf) $(HOST_OUT_EXECUTABLES)/checkpolicy \
  1073. $(HOST_OUT_EXECUTABLES)/secilc \
  1074. $(call build_policy, $(sepolicy_build_cil_workaround_files), $(BASE_PLAT_PRIVATE_POLICY)) \
  1075. $(built_sepolicy_neverallows)
  1076. @mkdir -p $(dir $@)
  1077. $(hide) $(CHECKPOLICY_ASAN_OPTIONS) $(HOST_OUT_EXECUTABLES)/checkpolicy -M -C -c \
  1078. $(POLICYVERS) -o $@ $<
  1079. $(hide) cat $(PRIVATE_ADDITIONAL_CIL_FILES) >> $@
  1080. $(hide) $(HOST_OUT_EXECUTABLES)/secilc -m -M true -G -c $(POLICYVERS) $(PRIVATE_NEVERALLOW_ARG) $@ -o $@ -f /dev/null
  1081. base_plat_pub_policy.conf := $(intermediates)/base_plat_pub_policy.conf
  1082. $(base_plat_pub_policy.conf): PRIVATE_MLS_SENS := $(MLS_SENS)
  1083. $(base_plat_pub_policy.conf): PRIVATE_MLS_CATS := $(MLS_CATS)
  1084. $(base_plat_pub_policy.conf): PRIVATE_TARGET_BUILD_VARIANT := user
  1085. $(base_plat_pub_policy.conf): PRIVATE_TGT_ARCH := $(my_target_arch)
  1086. $(base_plat_pub_policy.conf): PRIVATE_TGT_WITH_ASAN := $(with_asan)
  1087. $(base_plat_pub_policy.conf): PRIVATE_ADDITIONAL_M4DEFS := $(LOCAL_ADDITIONAL_M4DEFS)
  1088. $(base_plat_pub_policy.conf): PRIVATE_SEPOLICY_SPLIT := true
  1089. $(base_plat_pub_policy.conf): PRIVATE_COMPATIBLE_PROPERTY := $(PRODUCT_COMPATIBLE_PROPERTY)
  1090. $(base_plat_pub_policy.conf): $(call build_policy, $(sepolicy_build_files), \
  1091. $(BASE_PLAT_PUBLIC_POLICY) $(REQD_MASK_POLICY))
  1092. $(transform-policy-to-conf)
  1093. base_plat_pub_policy.cil := $(intermediates)/base_plat_pub_policy.cil
  1094. $(base_plat_pub_policy.cil): PRIVATE_POL_CONF := $(base_plat_pub_policy.conf)
  1095. $(base_plat_pub_policy.cil): PRIVATE_REQD_MASK := $(reqd_policy_mask.cil)
  1096. $(base_plat_pub_policy.cil): $(HOST_OUT_EXECUTABLES)/checkpolicy \
  1097. $(HOST_OUT_EXECUTABLES)/build_sepolicy $(base_plat_pub_policy.conf) $(reqd_policy_mask.cil)
  1098. @mkdir -p $(dir $@)
  1099. $(hide) $(CHECKPOLICY_ASAN_OPTIONS) $< -C -M -c $(POLICYVERS) -o $@ $(PRIVATE_POL_CONF)
  1100. $(hide) $(HOST_OUT_EXECUTABLES)/build_sepolicy -a $(HOST_OUT_EXECUTABLES) filter_out \
  1101. -f $(PRIVATE_REQD_MASK) -t $@
  1102. all_fc_files := $(built_plat_fc) $(built_vendor_fc)
  1103. ifdef HAS_PRODUCT_SEPOLICY
  1104. all_fc_files += $(built_product_fc)
  1105. endif
  1106. ifdef BOARD_ODM_SEPOLICY_DIRS
  1107. all_fc_files += $(built_odm_fc)
  1108. endif
  1109. all_fc_args := $(foreach file, $(all_fc_files), -f $(file))
  1110. # Tests for Treble compatibility of current platform policy and vendor policy of
  1111. # given release version.
  1112. version_under_treble_tests := 26.0
  1113. include $(LOCAL_PATH)/treble_sepolicy_tests_for_release.mk
  1114. version_under_treble_tests := 27.0
  1115. include $(LOCAL_PATH)/treble_sepolicy_tests_for_release.mk
  1116. version_under_treble_tests := 28.0
  1117. include $(LOCAL_PATH)/treble_sepolicy_tests_for_release.mk
  1118. BASE_PLAT_PUBLIC_POLICY :=
  1119. BASE_PLAT_PRIVATE_POLICY :=
  1120. base_plat_policy.conf :=
  1121. base_plat_pub_policy.conf :=
  1122. plat_sepolicy :=
  1123. #################################
  1124. include $(CLEAR_VARS)
  1125. LOCAL_MODULE := sepolicy_freeze_test
  1126. LOCAL_MODULE_CLASS := ETC
  1127. LOCAL_MODULE_TAGS := tests
  1128. include $(BUILD_SYSTEM)/base_rules.mk
  1129. base_plat_public := $(LOCAL_PATH)/public
  1130. base_plat_private := $(LOCAL_PATH)/private
  1131. base_plat_public_prebuilt := \
  1132. $(LOCAL_PATH)/prebuilts/api/$(PLATFORM_SEPOLICY_VERSION)/public
  1133. base_plat_private_prebuilt := \
  1134. $(LOCAL_PATH)/prebuilts/api/$(PLATFORM_SEPOLICY_VERSION)/private
  1135. all_frozen_files := $(call build_policy,$(sepolicy_build_files), \
  1136. $(base_plat_public) $(base_plat_private) $(base_plat_public_prebuilt) $(base_plat_private_prebuilt))
  1137. $(LOCAL_BUILT_MODULE): PRIVATE_BASE_PLAT_PUBLIC := $(base_plat_public)
  1138. $(LOCAL_BUILT_MODULE): PRIVATE_BASE_PLAT_PRIVATE := $(base_plat_private)
  1139. $(LOCAL_BUILT_MODULE): PRIVATE_BASE_PLAT_PUBLIC_PREBUILT := $(base_plat_public_prebuilt)
  1140. $(LOCAL_BUILT_MODULE): PRIVATE_BASE_PLAT_PRIVATE_PREBUILT := $(base_plat_private_prebuilt)
  1141. $(LOCAL_BUILT_MODULE): $(all_frozen_files)
  1142. ifneq ($(PLATFORM_SEPOLICY_VERSION),$(TOT_SEPOLICY_VERSION))
  1143. @diff -rq -x bug_map $(PRIVATE_BASE_PLAT_PUBLIC_PREBUILT) $(PRIVATE_BASE_PLAT_PUBLIC)
  1144. @diff -rq -x bug_map $(PRIVATE_BASE_PLAT_PRIVATE_PREBUILT) $(PRIVATE_BASE_PLAT_PRIVATE)
  1145. endif # ($(PLATFORM_SEPOLICY_VERSION),$(TOT_SEPOLICY_VERSION))
  1146. $(hide) touch $@
  1147. base_plat_public :=
  1148. base_plat_private :=
  1149. base_plat_public_prebuilt :=
  1150. base_plat_private_prebuilt :=
  1151. all_frozen_files :=
  1152. #################################
  1153. add_nl :=
  1154. build_vendor_policy :=
  1155. build_odm_policy :=
  1156. build_policy :=
  1157. built_plat_fc :=
  1158. built_product_fc :=
  1159. built_vendor_fc :=
  1160. built_odm_fc :=
  1161. built_nl :=
  1162. built_plat_cil :=
  1163. built_pub_vers_cil :=
  1164. built_plat_mapping_cil :=
  1165. built_product_mapping_cil :=
  1166. built_plat_pc :=
  1167. built_product_pc :=
  1168. built_vendor_cil :=
  1169. built_vendor_pc :=
  1170. built_vendor_sc :=
  1171. built_odm_cil :=
  1172. built_odm_pc :=
  1173. built_odm_sc :=
  1174. built_plat_sc :=
  1175. built_precompiled_sepolicy :=
  1176. built_sepolicy :=
  1177. built_sepolicy_neverallows :=
  1178. built_plat_svc :=
  1179. built_vendor_svc :=
  1180. built_plat_sepolicy :=
  1181. mapping_policy :=
  1182. my_target_arch :=
  1183. pub_policy.cil :=
  1184. reqd_policy_mask.cil :=
  1185. sepolicy_build_files :=
  1186. sepolicy_build_cil_workaround_files :=
  1187. with_asan :=
  1188. include $(call all-makefiles-under,$(LOCAL_PATH))