blob: 380faff2896978f8a38059f2620783f00835d6aa [file] [log] [blame]
Inseob Kim7e8bd1e2021-03-17 18:59:43 +09001// Copyright (C) 2021 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package selinux
16
17import (
18 "fmt"
19 "os"
Inseob Kim0a707fa2021-12-09 23:35:11 +090020 "sort"
Inseob Kim7e8bd1e2021-03-17 18:59:43 +090021 "strconv"
Inseob Kim0a707fa2021-12-09 23:35:11 +090022 "strings"
Inseob Kim7e8bd1e2021-03-17 18:59:43 +090023
24 "github.com/google/blueprint/proptools"
25
26 "android/soong/android"
27)
28
29const (
30 // TODO: sync with Android.mk
31 MlsSens = 1
32 MlsCats = 1024
33 PolicyVers = 30
34)
35
Inseob Kim0a707fa2021-12-09 23:35:11 +090036// This order should be kept. checkpolicy syntax requires it.
37var policyConfOrder = []string{
38 "security_classes",
39 "initial_sids",
40 "access_vectors",
41 "global_macros",
42 "neverallow_macros",
43 "mls_macros",
44 "mls_decl",
45 "mls",
46 "policy_capabilities",
47 "te_macros",
Inseob Kim0a707fa2021-12-09 23:35:11 +090048 "ioctl_defines",
49 "ioctl_macros",
Inseob Kim1e796342022-06-09 11:26:35 +090050 "attributes|*.te",
Inseob Kim0a707fa2021-12-09 23:35:11 +090051 "roles_decl",
52 "roles",
53 "users",
54 "initial_sid_contexts",
55 "fs_use",
56 "genfs_contexts",
57 "port_contexts",
58}
59
Inseob Kim7e8bd1e2021-03-17 18:59:43 +090060func init() {
61 android.RegisterModuleType("se_policy_conf", policyConfFactory)
Inseob Kimdf1a0de2021-03-17 19:05:02 +090062 android.RegisterModuleType("se_policy_cil", policyCilFactory)
Inseob Kimb9d05112021-09-27 13:13:46 +000063 android.RegisterModuleType("se_policy_binary", policyBinaryFactory)
Inseob Kim7e8bd1e2021-03-17 18:59:43 +090064}
65
66type policyConfProperties struct {
67 // Name of the output. Default is {module_name}
68 Stem *string
69
70 // Policy files to be compiled to cil file.
71 Srcs []string `android:"path"`
72
73 // Target build variant (user / userdebug / eng). Default follows the current lunch target
74 Build_variant *string
75
76 // Whether to exclude build test or not. Default is false
77 Exclude_build_test *bool
78
79 // Whether to include asan specific policies or not. Default follows the current lunch target
80 With_asan *bool
81
82 // Whether to build CTS specific policy or not. Default is false
83 Cts *bool
84
Inseob Kim5bbcd682021-12-28 14:57:03 +090085 // Whether to build recovery specific policy or not. Default is false
86 Target_recovery *bool
87
Inseob Kim7e8bd1e2021-03-17 18:59:43 +090088 // Whether this module is directly installable to one of the partitions. Default is true
89 Installable *bool
Inseob Kim6e384f32022-03-10 13:15:05 +090090
91 // Desired number of MLS categories. Defaults to 1024
92 Mls_cats *int64
Inseob Kim7e8bd1e2021-03-17 18:59:43 +090093}
94
95type policyConf struct {
96 android.ModuleBase
97
98 properties policyConfProperties
99
100 installSource android.Path
101 installPath android.InstallPath
102}
103
104// se_policy_conf merges collection of policy files into a policy.conf file to be processed by
105// checkpolicy.
106func policyConfFactory() android.Module {
107 c := &policyConf{}
108 c.AddProperties(&c.properties)
109 android.InitAndroidArchModule(c, android.DeviceSupported, android.MultilibCommon)
110 return c
111}
112
113func (c *policyConf) installable() bool {
114 return proptools.BoolDefault(c.properties.Installable, true)
115}
116
117func (c *policyConf) stem() string {
118 return proptools.StringDefault(c.properties.Stem, c.Name())
119}
120
121func (c *policyConf) buildVariant(ctx android.ModuleContext) string {
122 if variant := proptools.String(c.properties.Build_variant); variant != "" {
123 return variant
124 }
125 if ctx.Config().Eng() {
126 return "eng"
127 }
128 if ctx.Config().Debuggable() {
129 return "userdebug"
130 }
131 return "user"
132}
133
134func (c *policyConf) cts() bool {
135 return proptools.Bool(c.properties.Cts)
136}
137
Inseob Kim5bbcd682021-12-28 14:57:03 +0900138func (c *policyConf) isTargetRecovery() bool {
139 return proptools.Bool(c.properties.Target_recovery)
140}
141
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900142func (c *policyConf) withAsan(ctx android.ModuleContext) string {
143 isAsanDevice := android.InList("address", ctx.Config().SanitizeDevice())
144 return strconv.FormatBool(proptools.BoolDefault(c.properties.With_asan, isAsanDevice))
145}
146
147func (c *policyConf) sepolicySplit(ctx android.ModuleContext) string {
148 if c.cts() {
149 return "cts"
150 }
Inseob Kim5bbcd682021-12-28 14:57:03 +0900151 if c.isTargetRecovery() {
152 return "false"
153 }
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900154 return strconv.FormatBool(ctx.DeviceConfig().SepolicySplit())
155}
156
157func (c *policyConf) compatibleProperty(ctx android.ModuleContext) string {
158 if c.cts() {
159 return "cts"
160 }
Inseob Kim5bbcd682021-12-28 14:57:03 +0900161 if c.isTargetRecovery() {
162 return "false"
163 }
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900164 return "true"
165}
166
167func (c *policyConf) trebleSyspropNeverallow(ctx android.ModuleContext) string {
168 if c.cts() {
169 return "cts"
170 }
Inseob Kim5bbcd682021-12-28 14:57:03 +0900171 if c.isTargetRecovery() {
172 return "false"
173 }
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900174 return strconv.FormatBool(!ctx.DeviceConfig().BuildBrokenTrebleSyspropNeverallow())
175}
176
177func (c *policyConf) enforceSyspropOwner(ctx android.ModuleContext) string {
178 if c.cts() {
179 return "cts"
180 }
Inseob Kim5bbcd682021-12-28 14:57:03 +0900181 if c.isTargetRecovery() {
182 return "false"
183 }
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900184 return strconv.FormatBool(!ctx.DeviceConfig().BuildBrokenEnforceSyspropOwner())
185}
186
Hridya Valsarajua885dd82021-04-26 16:32:17 -0700187func (c *policyConf) enforceDebugfsRestrictions(ctx android.ModuleContext) string {
188 if c.cts() {
189 return "cts"
190 }
191 return strconv.FormatBool(ctx.DeviceConfig().BuildDebugfsRestrictionsEnabled())
192}
193
Inseob Kim6e384f32022-03-10 13:15:05 +0900194func (c *policyConf) mlsCats() int {
195 return proptools.IntDefault(c.properties.Mls_cats, MlsCats)
196}
197
Inseob Kim0a707fa2021-12-09 23:35:11 +0900198func findPolicyConfOrder(name string) int {
199 for idx, pattern := range policyConfOrder {
Inseob Kim1e796342022-06-09 11:26:35 +0900200 // We could use regexp but it seems like an overkill
201 if pattern == "attributes|*.te" && (name == "attributes" || strings.HasSuffix(name, ".te")) {
202 return idx
203 } else if pattern == name {
Inseob Kim0a707fa2021-12-09 23:35:11 +0900204 return idx
205 }
206 }
207 // name is not matched
208 return len(policyConfOrder)
209}
210
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900211func (c *policyConf) transformPolicyToConf(ctx android.ModuleContext) android.OutputPath {
Inseob Kim6c5fa542022-02-09 23:27:04 +0900212 conf := android.PathForModuleOut(ctx, c.stem()).OutputPath
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900213 rule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim0a707fa2021-12-09 23:35:11 +0900214
215 srcs := android.PathsForModuleSrc(ctx, c.properties.Srcs)
216 sort.SliceStable(srcs, func(x, y int) bool {
217 return findPolicyConfOrder(srcs[x].Base()) < findPolicyConfOrder(srcs[y].Base())
218 })
219
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900220 rule.Command().Tool(ctx.Config().PrebuiltBuildTool(ctx, "m4")).
221 Flag("--fatal-warnings").
222 FlagForEachArg("-D ", ctx.DeviceConfig().SepolicyM4Defs()).
223 FlagWithArg("-D mls_num_sens=", strconv.Itoa(MlsSens)).
Inseob Kim6e384f32022-03-10 13:15:05 +0900224 FlagWithArg("-D mls_num_cats=", strconv.Itoa(c.mlsCats())).
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900225 FlagWithArg("-D target_arch=", ctx.DeviceConfig().DeviceArch()).
226 FlagWithArg("-D target_with_asan=", c.withAsan(ctx)).
Inseob Kim4360c192021-03-23 20:52:53 +0900227 FlagWithArg("-D target_with_dexpreopt=", strconv.FormatBool(ctx.DeviceConfig().WithDexpreopt())).
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900228 FlagWithArg("-D target_with_native_coverage=", strconv.FormatBool(ctx.DeviceConfig().ClangCoverageEnabled() || ctx.DeviceConfig().GcovCoverageEnabled())).
229 FlagWithArg("-D target_build_variant=", c.buildVariant(ctx)).
230 FlagWithArg("-D target_full_treble=", c.sepolicySplit(ctx)).
231 FlagWithArg("-D target_compatible_property=", c.compatibleProperty(ctx)).
232 FlagWithArg("-D target_treble_sysprop_neverallow=", c.trebleSyspropNeverallow(ctx)).
233 FlagWithArg("-D target_enforce_sysprop_owner=", c.enforceSyspropOwner(ctx)).
234 FlagWithArg("-D target_exclude_build_test=", strconv.FormatBool(proptools.Bool(c.properties.Exclude_build_test))).
235 FlagWithArg("-D target_requires_insecure_execmem_for_swiftshader=", strconv.FormatBool(ctx.DeviceConfig().RequiresInsecureExecmemForSwiftshader())).
Hridya Valsarajua885dd82021-04-26 16:32:17 -0700236 FlagWithArg("-D target_enforce_debugfs_restriction=", c.enforceDebugfsRestrictions(ctx)).
Inseob Kim5bbcd682021-12-28 14:57:03 +0900237 FlagWithArg("-D target_recovery=", strconv.FormatBool(c.isTargetRecovery())).
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900238 Flag("-s").
Inseob Kim0a707fa2021-12-09 23:35:11 +0900239 Inputs(srcs).
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900240 Text("> ").Output(conf)
241
242 rule.Build("conf", "Transform policy to conf: "+ctx.ModuleName())
243 return conf
244}
245
246func (c *policyConf) DepsMutator(ctx android.BottomUpMutatorContext) {
247 // do nothing
248}
249
250func (c *policyConf) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900251 if !c.installable() {
252 c.SkipInstall()
253 }
Inseob Kim31db2742021-06-08 10:31:09 +0900254
255 c.installSource = c.transformPolicyToConf(ctx)
256 c.installPath = android.PathForModuleInstall(ctx, "etc")
257 ctx.InstallFile(c.installPath, c.stem(), c.installSource)
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900258}
259
260func (c *policyConf) AndroidMkEntries() []android.AndroidMkEntries {
261 return []android.AndroidMkEntries{android.AndroidMkEntries{
262 OutputFile: android.OptionalPathForPath(c.installSource),
263 Class: "ETC",
264 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
265 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
266 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", !c.installable())
Colin Cross6c7f9372022-01-11 19:35:43 -0800267 entries.SetPath("LOCAL_MODULE_PATH", c.installPath)
Inseob Kim7e8bd1e2021-03-17 18:59:43 +0900268 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", c.stem())
269 },
270 },
271 }}
272}
273
274func (c *policyConf) OutputFiles(tag string) (android.Paths, error) {
275 if tag == "" {
276 return android.Paths{c.installSource}, nil
277 }
278 return nil, fmt.Errorf("Unknown tag %q", tag)
279}
280
281var _ android.OutputFileProducer = (*policyConf)(nil)
Inseob Kimdf1a0de2021-03-17 19:05:02 +0900282
283type policyCilProperties struct {
284 // Name of the output. Default is {module_name}
285 Stem *string
286
287 // Policy file to be compiled to cil file.
288 Src *string `android:"path"`
289
sandrome6971f12022-05-31 08:50:55 +0000290 // If true, the input policy file is a binary policy that will be decompiled to a cil file.
291 // Defaults to false.
292 Decompile_binary *bool
293
Inseob Kimdf1a0de2021-03-17 19:05:02 +0900294 // Additional cil files to be added in the end of the output. This is to support workarounds
295 // which are not supported by the policy language.
296 Additional_cil_files []string `android:"path"`
297
298 // Cil files to be filtered out by the filter_out tool of "build_sepolicy". Used to build
299 // exported policies
300 Filter_out []string `android:"path"`
301
302 // Whether to remove line markers (denoted by ;;) out of compiled cil files. Defaults to false
303 Remove_line_marker *bool
304
305 // Whether to run secilc to check compiled policy or not. Defaults to true
306 Secilc_check *bool
307
308 // Whether to ignore neverallow when running secilc check. Defaults to
309 // SELINUX_IGNORE_NEVERALLOWS.
310 Ignore_neverallow *bool
311
312 // Whether this module is directly installable to one of the partitions. Default is true
313 Installable *bool
314}
315
316type policyCil struct {
317 android.ModuleBase
318
319 properties policyCilProperties
320
321 installSource android.Path
322 installPath android.InstallPath
323}
324
325// se_policy_cil compiles a policy.conf file to a cil file with checkpolicy, and optionally runs
326// secilc to check the output cil file. Affected by SELINUX_IGNORE_NEVERALLOWS.
327func policyCilFactory() android.Module {
328 c := &policyCil{}
329 c.AddProperties(&c.properties)
330 android.InitAndroidArchModule(c, android.DeviceSupported, android.MultilibCommon)
331 return c
332}
333
334func (c *policyCil) Installable() bool {
335 return proptools.BoolDefault(c.properties.Installable, true)
336}
337
338func (c *policyCil) stem() string {
339 return proptools.StringDefault(c.properties.Stem, c.Name())
340}
341
342func (c *policyCil) compileConfToCil(ctx android.ModuleContext, conf android.Path) android.OutputPath {
343 cil := android.PathForModuleOut(ctx, c.stem()).OutputPath
344 rule := android.NewRuleBuilder(pctx, ctx)
Inseob Kimdf1a0de2021-03-17 19:05:02 +0900345
sandrome6971f12022-05-31 08:50:55 +0000346 if proptools.Bool(c.properties.Decompile_binary) {
347 rule.Command().BuiltTool("checkpolicy").
348 Flag("-b"). // Read binary
349 Flag("-C"). // Write CIL
350 Flag("-M"). // Enable MLS
351 FlagWithArg("-c ", strconv.Itoa(PolicyVers)).
352 FlagWithOutput("-o ", cil).
353 Input(conf)
354 } else {
355 rule.Command().BuiltTool("checkpolicy").
356 Flag("-C"). // Write CIL
357 Flag("-M"). // Enable MLS
358 FlagWithArg("-c ", strconv.Itoa(PolicyVers)).
359 FlagWithOutput("-o ", cil).
360 Input(conf)
Inseob Kimdf1a0de2021-03-17 19:05:02 +0900361 }
362
363 if len(c.properties.Filter_out) > 0 {
364 rule.Command().BuiltTool("build_sepolicy").
365 Text("filter_out").
366 Flag("-f").
367 Inputs(android.PathsForModuleSrc(ctx, c.properties.Filter_out)).
368 FlagWithOutput("-t ", cil)
369 }
370
sandrome6971f12022-05-31 08:50:55 +0000371 if len(c.properties.Additional_cil_files) > 0 {
372 rule.Command().Text("cat").
373 Inputs(android.PathsForModuleSrc(ctx, c.properties.Additional_cil_files)).
374 Text(">> ").Output(cil)
375 }
376
Inseob Kimdf1a0de2021-03-17 19:05:02 +0900377 if proptools.Bool(c.properties.Remove_line_marker) {
378 rule.Command().Text("grep -v").
379 Text(proptools.ShellEscape(";;")).
380 Text(cil.String()).
381 Text(">").
382 Text(cil.String() + ".tmp").
383 Text("&& mv").
384 Text(cil.String() + ".tmp").
385 Text(cil.String())
386 }
387
388 if proptools.BoolDefault(c.properties.Secilc_check, true) {
389 secilcCmd := rule.Command().BuiltTool("secilc").
390 Flag("-m"). // Multiple decls
391 FlagWithArg("-M ", "true"). // Enable MLS
392 Flag("-G"). // expand and remove auto generated attributes
393 FlagWithArg("-c ", strconv.Itoa(PolicyVers)).
394 Inputs(android.PathsForModuleSrc(ctx, c.properties.Filter_out)). // Also add cil files which are filtered out
395 Text(cil.String()).
396 FlagWithArg("-o ", os.DevNull).
397 FlagWithArg("-f ", os.DevNull)
398
399 if proptools.BoolDefault(c.properties.Ignore_neverallow, ctx.Config().SelinuxIgnoreNeverallows()) {
400 secilcCmd.Flag("-N")
401 }
402 }
403
404 rule.Build("cil", "Building cil for "+ctx.ModuleName())
405 return cil
406}
407
408func (c *policyCil) GenerateAndroidBuildActions(ctx android.ModuleContext) {
409 if proptools.String(c.properties.Src) == "" {
410 ctx.PropertyErrorf("src", "must be specified")
411 return
412 }
413 conf := android.PathForModuleSrc(ctx, *c.properties.Src)
414 cil := c.compileConfToCil(ctx, conf)
415
Inseob Kim31db2742021-06-08 10:31:09 +0900416 if !c.Installable() {
417 c.SkipInstall()
418 }
419
Inseob Kim6cc75f42021-04-29 13:53:20 +0000420 if c.InstallInDebugRamdisk() {
421 // for userdebug_plat_sepolicy.cil
422 c.installPath = android.PathForModuleInstall(ctx)
423 } else {
424 c.installPath = android.PathForModuleInstall(ctx, "etc", "selinux")
425 }
Inseob Kimdf1a0de2021-03-17 19:05:02 +0900426 c.installSource = cil
427 ctx.InstallFile(c.installPath, c.stem(), c.installSource)
Inseob Kimdf1a0de2021-03-17 19:05:02 +0900428}
429
430func (c *policyCil) AndroidMkEntries() []android.AndroidMkEntries {
431 return []android.AndroidMkEntries{android.AndroidMkEntries{
432 OutputFile: android.OptionalPathForPath(c.installSource),
433 Class: "ETC",
434 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
435 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
436 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", !c.Installable())
Colin Cross6c7f9372022-01-11 19:35:43 -0800437 entries.SetPath("LOCAL_MODULE_PATH", c.installPath)
Inseob Kimdf1a0de2021-03-17 19:05:02 +0900438 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", c.stem())
439 },
440 },
441 }}
442}
443
444func (c *policyCil) OutputFiles(tag string) (android.Paths, error) {
445 if tag == "" {
446 return android.Paths{c.installSource}, nil
447 }
448 return nil, fmt.Errorf("Unknown tag %q", tag)
449}
450
451var _ android.OutputFileProducer = (*policyCil)(nil)
Inseob Kimb9d05112021-09-27 13:13:46 +0000452
453type policyBinaryProperties struct {
454 // Name of the output. Default is {module_name}
455 Stem *string
456
457 // Cil files to be compiled.
458 Srcs []string `android:"path"`
459
460 // Whether to ignore neverallow when running secilc check. Defaults to
461 // SELINUX_IGNORE_NEVERALLOWS.
462 Ignore_neverallow *bool
463
464 // Whether this module is directly installable to one of the partitions. Default is true
465 Installable *bool
466}
467
468type policyBinary struct {
469 android.ModuleBase
470
471 properties policyBinaryProperties
472
473 installSource android.Path
474 installPath android.InstallPath
475}
476
477// se_policy_binary compiles cil files to a binary sepolicy file with secilc. Usually sources of
478// se_policy_binary come from outputs of se_policy_cil modules.
479func policyBinaryFactory() android.Module {
480 c := &policyBinary{}
481 c.AddProperties(&c.properties)
482 android.InitAndroidArchModule(c, android.DeviceSupported, android.MultilibCommon)
483 return c
484}
485
Inseob Kim5bbcd682021-12-28 14:57:03 +0900486func (c *policyBinary) InstallInRoot() bool {
487 return c.InstallInRecovery()
488}
489
Inseob Kimb9d05112021-09-27 13:13:46 +0000490func (c *policyBinary) Installable() bool {
491 return proptools.BoolDefault(c.properties.Installable, true)
492}
493
494func (c *policyBinary) stem() string {
495 return proptools.StringDefault(c.properties.Stem, c.Name())
496}
497
498func (c *policyBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
499 if len(c.properties.Srcs) == 0 {
500 ctx.PropertyErrorf("srcs", "must be specified")
501 return
502 }
Inseob Kim3d5f9252021-12-21 20:42:35 +0900503 bin := android.PathForModuleOut(ctx, c.stem()+"_policy")
Inseob Kimb9d05112021-09-27 13:13:46 +0000504 rule := android.NewRuleBuilder(pctx, ctx)
505 secilcCmd := rule.Command().BuiltTool("secilc").
506 Flag("-m"). // Multiple decls
507 FlagWithArg("-M ", "true"). // Enable MLS
508 Flag("-G"). // expand and remove auto generated attributes
509 FlagWithArg("-c ", strconv.Itoa(PolicyVers)).
510 Inputs(android.PathsForModuleSrc(ctx, c.properties.Srcs)).
511 FlagWithOutput("-o ", bin).
512 FlagWithArg("-f ", os.DevNull)
513
514 if proptools.BoolDefault(c.properties.Ignore_neverallow, ctx.Config().SelinuxIgnoreNeverallows()) {
515 secilcCmd.Flag("-N")
516 }
Inseob Kim3d5f9252021-12-21 20:42:35 +0900517 rule.Temporary(bin)
Inseob Kimb9d05112021-09-27 13:13:46 +0000518
Inseob Kim3d5f9252021-12-21 20:42:35 +0900519 // permissive check is performed only in user build (not debuggable).
520 if !ctx.Config().Debuggable() {
521 permissiveDomains := android.PathForModuleOut(ctx, c.stem()+"_permissive")
522 rule.Command().BuiltTool("sepolicy-analyze").
523 Input(bin).
524 Text("permissive").
525 Text(" > ").
526 Output(permissiveDomains)
527 rule.Temporary(permissiveDomains)
528
529 msg := `==========\n` +
530 `ERROR: permissive domains not allowed in user builds\n` +
531 `List of invalid domains:`
532
533 rule.Command().Text("if test").
534 FlagWithInput("-s ", permissiveDomains).
535 Text("; then echo").
536 Flag("-e").
537 Text(`"` + msg + `"`).
538 Text("&& cat ").
539 Input(permissiveDomains).
540 Text("; exit 1; fi")
541 }
542
543 out := android.PathForModuleOut(ctx, c.stem())
544 rule.Command().Text("cp").
545 Flag("-f").
546 Input(bin).
547 Output(out)
548
549 rule.DeleteTemporaryFiles()
Inseob Kimb9d05112021-09-27 13:13:46 +0000550 rule.Build("secilc", "Compiling cil files for "+ctx.ModuleName())
551
552 if !c.Installable() {
553 c.SkipInstall()
554 }
555
Inseob Kim5bbcd682021-12-28 14:57:03 +0900556 if c.InstallInRecovery() {
557 // install in root
558 c.installPath = android.PathForModuleInstall(ctx)
559 } else {
560 c.installPath = android.PathForModuleInstall(ctx, "etc", "selinux")
561 }
Inseob Kim3d5f9252021-12-21 20:42:35 +0900562 c.installSource = out
Inseob Kimb9d05112021-09-27 13:13:46 +0000563 ctx.InstallFile(c.installPath, c.stem(), c.installSource)
564}
565
566func (c *policyBinary) AndroidMkEntries() []android.AndroidMkEntries {
567 return []android.AndroidMkEntries{android.AndroidMkEntries{
568 OutputFile: android.OptionalPathForPath(c.installSource),
569 Class: "ETC",
570 ExtraEntries: []android.AndroidMkExtraEntriesFunc{
571 func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
572 entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", !c.Installable())
Colin Cross6c7f9372022-01-11 19:35:43 -0800573 entries.SetPath("LOCAL_MODULE_PATH", c.installPath)
Inseob Kimb9d05112021-09-27 13:13:46 +0000574 entries.SetString("LOCAL_INSTALLED_MODULE_STEM", c.stem())
575 },
576 },
577 }}
578}
579
580func (c *policyBinary) OutputFiles(tag string) (android.Paths, error) {
581 if tag == "" {
582 return android.Paths{c.installSource}, nil
583 }
584 return nil, fmt.Errorf("Unknown tag %q", tag)
585}
586
587var _ android.OutputFileProducer = (*policyBinary)(nil)