2021-11-25 23:12:41 +01:00
|
|
|
# Copyright 2021 The Android Open Source Project
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2017-05-25 18:53:47 +02:00
|
|
|
from optparse import OptionParser
|
|
|
|
from optparse import Option, OptionValueError
|
|
|
|
import os
|
2017-09-26 21:58:29 +02:00
|
|
|
import mini_parser
|
2017-05-25 18:53:47 +02:00
|
|
|
import policy
|
2017-09-26 21:58:29 +02:00
|
|
|
from policy import MatchPathPrefix
|
2017-05-25 18:53:47 +02:00
|
|
|
import re
|
|
|
|
import sys
|
2021-12-29 05:56:14 +01:00
|
|
|
import distutils.ccompiler
|
2017-05-25 18:53:47 +02:00
|
|
|
|
2017-06-01 00:36:07 +02:00
|
|
|
DEBUG=False
|
|
|
|
|
2017-05-25 18:53:47 +02:00
|
|
|
'''
|
|
|
|
Use file_contexts and policy to verify Treble requirements
|
|
|
|
are not violated.
|
|
|
|
'''
|
2020-07-27 18:30:34 +02:00
|
|
|
coredomainAllowlist = {
|
2020-04-03 01:20:31 +02:00
|
|
|
# TODO: how do we make sure vendor_init doesn't have bad coupling with
|
|
|
|
# /vendor? It is the only system process which is not coredomain.
|
2018-01-25 20:31:09 +01:00
|
|
|
'vendor_init',
|
2020-07-27 18:30:34 +02:00
|
|
|
# TODO(b/152813275): need to avoid allowlist for rootdir
|
2020-04-03 01:20:31 +02:00
|
|
|
"modprobe",
|
|
|
|
"slideshow",
|
2017-05-25 18:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class scontext:
|
|
|
|
def __init__(self):
|
|
|
|
self.fromSystem = False
|
|
|
|
self.fromVendor = False
|
|
|
|
self.coredomain = False
|
|
|
|
self.appdomain = False
|
|
|
|
self.attributes = set()
|
|
|
|
self.entrypoints = []
|
|
|
|
self.entrypointpaths = []
|
2020-04-03 01:20:31 +02:00
|
|
|
self.error = ""
|
2017-05-25 18:53:47 +02:00
|
|
|
|
2017-06-01 00:36:07 +02:00
|
|
|
def PrintScontexts():
|
|
|
|
for d in sorted(alldomains.keys()):
|
|
|
|
sctx = alldomains[d]
|
2021-11-25 23:12:41 +01:00
|
|
|
print(d)
|
|
|
|
print("\tcoredomain="+str(sctx.coredomain))
|
|
|
|
print("\tappdomain="+str(sctx.appdomain))
|
|
|
|
print("\tfromSystem="+str(sctx.fromSystem))
|
|
|
|
print("\tfromVendor="+str(sctx.fromVendor))
|
|
|
|
print("\tattributes="+str(sctx.attributes))
|
|
|
|
print("\tentrypoints="+str(sctx.entrypoints))
|
|
|
|
print("\tentrypointpaths=")
|
2017-06-01 00:36:07 +02:00
|
|
|
if sctx.entrypointpaths is not None:
|
|
|
|
for path in sctx.entrypointpaths:
|
2021-11-25 23:12:41 +01:00
|
|
|
print("\t\t"+str(path))
|
2017-05-25 18:53:47 +02:00
|
|
|
|
|
|
|
alldomains = {}
|
|
|
|
coredomains = set()
|
|
|
|
appdomains = set()
|
|
|
|
vendordomains = set()
|
2018-02-08 18:54:59 +01:00
|
|
|
pol = None
|
2017-05-25 18:53:47 +02:00
|
|
|
|
2017-09-26 21:58:29 +02:00
|
|
|
# compat vars
|
|
|
|
alltypes = set()
|
|
|
|
oldalltypes = set()
|
|
|
|
compatMapping = None
|
2018-09-29 02:21:08 +02:00
|
|
|
pubtypes = set()
|
2017-09-26 21:58:29 +02:00
|
|
|
|
|
|
|
# Distinguish between PRODUCT_FULL_TREBLE and PRODUCT_FULL_TREBLE_OVERRIDE
|
|
|
|
FakeTreble = False
|
2017-05-25 18:53:47 +02:00
|
|
|
|
|
|
|
def GetAllDomains(pol):
|
|
|
|
global alldomains
|
|
|
|
for result in pol.QueryTypeAttribute("domain", True):
|
|
|
|
alldomains[result] = scontext()
|
|
|
|
|
|
|
|
def GetAppDomains():
|
|
|
|
global appdomains
|
|
|
|
global alldomains
|
|
|
|
for d in alldomains:
|
|
|
|
# The application of the "appdomain" attribute is trusted because core
|
|
|
|
# selinux policy contains neverallow rules that enforce that only zygote
|
|
|
|
# and runas spawned processes may transition to processes that have
|
|
|
|
# the appdomain attribute.
|
|
|
|
if "appdomain" in alldomains[d].attributes:
|
|
|
|
alldomains[d].appdomain = True
|
|
|
|
appdomains.add(d)
|
|
|
|
|
|
|
|
def GetCoreDomains():
|
|
|
|
global alldomains
|
|
|
|
global coredomains
|
|
|
|
for d in alldomains:
|
2020-04-03 01:20:31 +02:00
|
|
|
domain = alldomains[d]
|
2017-09-26 21:58:29 +02:00
|
|
|
# TestCoredomainViolations will verify if coredomain was incorrectly
|
2017-05-25 18:53:47 +02:00
|
|
|
# applied.
|
2020-04-03 01:20:31 +02:00
|
|
|
if "coredomain" in domain.attributes:
|
|
|
|
domain.coredomain = True
|
2017-05-25 18:53:47 +02:00
|
|
|
coredomains.add(d)
|
|
|
|
# check whether domains are executed off of /system or /vendor
|
2020-07-27 18:30:34 +02:00
|
|
|
if d in coredomainAllowlist:
|
2017-05-25 18:53:47 +02:00
|
|
|
continue
|
2020-04-03 01:20:31 +02:00
|
|
|
# TODO(b/153112003): add checks to prevent app domains from being
|
|
|
|
# incorrectly labeled as coredomain. Apps don't have entrypoints as
|
|
|
|
# they're always dynamically transitioned to by zygote.
|
2017-05-25 18:53:47 +02:00
|
|
|
if d in appdomains:
|
|
|
|
continue
|
2020-04-03 01:20:31 +02:00
|
|
|
# TODO(b/153112747): need to handle cases where there is a dynamic
|
|
|
|
# transition OR there happens to be no context in AOSP files.
|
|
|
|
if not domain.entrypointpaths:
|
2017-05-25 18:53:47 +02:00
|
|
|
continue
|
2020-04-03 01:20:31 +02:00
|
|
|
|
|
|
|
for path in domain.entrypointpaths:
|
|
|
|
vendor = any(MatchPathPrefix(path, prefix) for prefix in
|
|
|
|
["/vendor", "/odm"])
|
|
|
|
system = any(MatchPathPrefix(path, prefix) for prefix in
|
|
|
|
["/init", "/system_ext", "/product" ])
|
|
|
|
|
|
|
|
# only mark entrypoint as system if it is not in legacy /system/vendor
|
|
|
|
if MatchPathPrefix(path, "/system/vendor"):
|
|
|
|
vendor = True
|
|
|
|
elif MatchPathPrefix(path, "/system"):
|
|
|
|
system = True
|
|
|
|
|
|
|
|
if not vendor and not system:
|
|
|
|
domain.error += "Unrecognized entrypoint for " + d + " at " + path + "\n"
|
|
|
|
|
|
|
|
domain.fromSystem = domain.fromSystem or system
|
|
|
|
domain.fromVendor = domain.fromVendor or vendor
|
2017-05-25 18:53:47 +02:00
|
|
|
|
|
|
|
###
|
|
|
|
# Add the entrypoint type and path(s) to each domain.
|
|
|
|
#
|
|
|
|
def GetDomainEntrypoints(pol):
|
|
|
|
global alldomains
|
2017-09-26 21:58:29 +02:00
|
|
|
for x in pol.QueryExpandedTERule(tclass=set(["file"]), perms=set(["entrypoint"])):
|
2017-05-25 18:53:47 +02:00
|
|
|
if not x.sctx in alldomains:
|
|
|
|
continue
|
|
|
|
alldomains[x.sctx].entrypoints.append(str(x.tctx))
|
|
|
|
# postinstall_file represents a special case specific to A/B OTAs.
|
|
|
|
# Update_engine mounts a partition and relabels it postinstall_file.
|
|
|
|
# There is no file_contexts entry associated with postinstall_file
|
|
|
|
# so skip the lookup.
|
|
|
|
if x.tctx == "postinstall_file":
|
|
|
|
continue
|
2017-06-01 00:36:07 +02:00
|
|
|
entrypointpath = pol.QueryFc(x.tctx)
|
|
|
|
if not entrypointpath:
|
|
|
|
continue
|
|
|
|
alldomains[x.sctx].entrypointpaths.extend(entrypointpath)
|
2017-05-25 18:53:47 +02:00
|
|
|
###
|
|
|
|
# Get attributes associated with each domain
|
|
|
|
#
|
|
|
|
def GetAttributes(pol):
|
|
|
|
global alldomains
|
|
|
|
for domain in alldomains:
|
|
|
|
for result in pol.QueryTypeAttribute(domain, False):
|
|
|
|
alldomains[domain].attributes.add(result)
|
|
|
|
|
2017-09-26 21:58:29 +02:00
|
|
|
def GetAllTypes(pol, oldpol):
|
|
|
|
global alltypes
|
|
|
|
global oldalltypes
|
|
|
|
alltypes = pol.GetAllTypes(False)
|
|
|
|
oldalltypes = oldpol.GetAllTypes(False)
|
|
|
|
|
2017-05-25 18:53:47 +02:00
|
|
|
def setup(pol):
|
|
|
|
GetAllDomains(pol)
|
|
|
|
GetAttributes(pol)
|
|
|
|
GetDomainEntrypoints(pol)
|
|
|
|
GetAppDomains()
|
|
|
|
GetCoreDomains()
|
|
|
|
|
2017-09-26 21:58:29 +02:00
|
|
|
# setup for the policy compatibility tests
|
2018-09-29 02:21:08 +02:00
|
|
|
def compatSetup(pol, oldpol, mapping, types):
|
2017-09-26 21:58:29 +02:00
|
|
|
global compatMapping
|
2018-09-29 02:21:08 +02:00
|
|
|
global pubtypes
|
2017-09-26 21:58:29 +02:00
|
|
|
|
|
|
|
GetAllTypes(pol, oldpol)
|
|
|
|
compatMapping = mapping
|
2018-09-29 02:21:08 +02:00
|
|
|
pubtypes = types
|
2017-09-26 21:58:29 +02:00
|
|
|
|
|
|
|
def DomainsWithAttribute(attr):
|
|
|
|
global alldomains
|
|
|
|
domains = []
|
|
|
|
for domain in alldomains:
|
|
|
|
if attr in alldomains[domain].attributes:
|
|
|
|
domains.append(domain)
|
|
|
|
return domains
|
|
|
|
|
2017-05-25 18:53:47 +02:00
|
|
|
#############################################################
|
|
|
|
# Tests
|
|
|
|
#############################################################
|
|
|
|
def TestCoredomainViolations():
|
|
|
|
global alldomains
|
|
|
|
# verify that all domains launched from /system have the coredomain
|
|
|
|
# attribute
|
|
|
|
ret = ""
|
2020-04-03 01:20:31 +02:00
|
|
|
|
|
|
|
for d in alldomains:
|
|
|
|
domain = alldomains[d]
|
|
|
|
if domain.fromSystem and domain.fromVendor:
|
|
|
|
ret += "The following domain is system and vendor: " + d + "\n"
|
|
|
|
|
|
|
|
for domain in alldomains.values():
|
|
|
|
ret += domain.error
|
|
|
|
|
2017-05-25 18:53:47 +02:00
|
|
|
violators = []
|
|
|
|
for d in alldomains:
|
|
|
|
domain = alldomains[d]
|
|
|
|
if domain.fromSystem and "coredomain" not in domain.attributes:
|
|
|
|
violators.append(d);
|
|
|
|
if len(violators) > 0:
|
|
|
|
ret += "The following domain(s) must be associated with the "
|
|
|
|
ret += "\"coredomain\" attribute because they are executed off of "
|
|
|
|
ret += "/system:\n"
|
|
|
|
ret += " ".join(str(x) for x in sorted(violators)) + "\n"
|
|
|
|
|
|
|
|
# verify that all domains launched form /vendor do not have the coredomain
|
|
|
|
# attribute
|
|
|
|
violators = []
|
|
|
|
for d in alldomains:
|
|
|
|
domain = alldomains[d]
|
|
|
|
if domain.fromVendor and "coredomain" in domain.attributes:
|
|
|
|
violators.append(d)
|
|
|
|
if len(violators) > 0:
|
|
|
|
ret += "The following domains must not be associated with the "
|
|
|
|
ret += "\"coredomain\" attribute because they are executed off of "
|
|
|
|
ret += "/vendor or /system/vendor:\n"
|
|
|
|
ret += " ".join(str(x) for x in sorted(violators)) + "\n"
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
2017-09-26 21:58:29 +02:00
|
|
|
###
|
2018-09-29 02:21:08 +02:00
|
|
|
# Make sure that any new public type introduced in the new policy that was not
|
|
|
|
# present in the old policy has been recorded in the mapping file.
|
2017-09-26 21:58:29 +02:00
|
|
|
def TestNoUnmappedNewTypes():
|
|
|
|
global alltypes
|
|
|
|
global oldalltypes
|
|
|
|
global compatMapping
|
2018-09-29 02:21:08 +02:00
|
|
|
global pubtypes
|
2017-09-26 21:58:29 +02:00
|
|
|
newt = alltypes - oldalltypes
|
|
|
|
ret = ""
|
|
|
|
violators = []
|
|
|
|
|
|
|
|
for n in newt:
|
2018-09-29 02:21:08 +02:00
|
|
|
if n in pubtypes and compatMapping.rTypeattributesets.get(n) is None:
|
2017-09-26 21:58:29 +02:00
|
|
|
violators.append(n)
|
|
|
|
|
|
|
|
if len(violators) > 0:
|
2018-09-29 02:21:08 +02:00
|
|
|
ret += "SELinux: The following public types were found added to the "
|
|
|
|
ret += "policy without an entry into the compatibility mapping file(s) "
|
2018-09-30 02:47:10 +02:00
|
|
|
ret += "found in private/compat/V.v/V.v[.ignore].cil, where V.v is the "
|
|
|
|
ret += "latest API level.\n"
|
2019-01-07 03:17:32 +01:00
|
|
|
ret += " ".join(str(x) for x in sorted(violators)) + "\n\n"
|
|
|
|
ret += "See examples of how to fix this:\n"
|
2019-08-09 19:27:46 +02:00
|
|
|
ret += "https://android-review.googlesource.com/c/platform/system/sepolicy/+/781036\n"
|
|
|
|
ret += "https://android-review.googlesource.com/c/platform/system/sepolicy/+/852612\n"
|
2017-09-26 21:58:29 +02:00
|
|
|
return ret
|
|
|
|
|
|
|
|
###
|
|
|
|
# Make sure that any public type removed in the current policy has its
|
|
|
|
# declaration added to the mapping file for use in non-platform policy
|
|
|
|
def TestNoUnmappedRmTypes():
|
|
|
|
global alltypes
|
|
|
|
global oldalltypes
|
|
|
|
global compatMapping
|
|
|
|
rmt = oldalltypes - alltypes
|
|
|
|
ret = ""
|
|
|
|
violators = []
|
|
|
|
|
|
|
|
for o in rmt:
|
|
|
|
if o in compatMapping.pubtypes and not o in compatMapping.types:
|
|
|
|
violators.append(o)
|
|
|
|
|
|
|
|
if len(violators) > 0:
|
|
|
|
ret += "SELinux: The following formerly public types were removed from "
|
|
|
|
ret += "policy without a declaration in the compatibility mapping "
|
2018-09-30 02:47:10 +02:00
|
|
|
ret += "found in private/compat/V.v/V.v[.ignore].cil, where V.v is the "
|
|
|
|
ret += "latest API level.\n"
|
2019-01-07 03:17:32 +01:00
|
|
|
ret += " ".join(str(x) for x in sorted(violators)) + "\n\n"
|
|
|
|
ret += "See examples of how to fix this:\n"
|
2019-08-09 19:27:46 +02:00
|
|
|
ret += "https://android-review.googlesource.com/c/platform/system/sepolicy/+/822743\n"
|
2017-09-26 21:58:29 +02:00
|
|
|
return ret
|
|
|
|
|
|
|
|
def TestTrebleCompatMapping():
|
|
|
|
ret = TestNoUnmappedNewTypes()
|
|
|
|
ret += TestNoUnmappedRmTypes()
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def TestViolatorAttribute(attribute):
|
|
|
|
global FakeTreble
|
|
|
|
ret = ""
|
|
|
|
if FakeTreble:
|
|
|
|
return ret
|
|
|
|
|
|
|
|
violators = DomainsWithAttribute(attribute)
|
|
|
|
if len(violators) > 0:
|
|
|
|
ret += "SELinux: The following domains violate the Treble ban "
|
|
|
|
ret += "against use of the " + attribute + " attribute: "
|
|
|
|
ret += " ".join(str(x) for x in sorted(violators)) + "\n"
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def TestViolatorAttributes():
|
2019-05-14 02:06:50 +02:00
|
|
|
ret = ""
|
2017-09-26 21:58:29 +02:00
|
|
|
ret += TestViolatorAttribute("socket_between_core_and_vendor_violators")
|
|
|
|
ret += TestViolatorAttribute("vendor_executes_system_violators")
|
|
|
|
return ret
|
|
|
|
|
2018-02-08 18:54:59 +01:00
|
|
|
# TODO move this to sepolicy_tests
|
|
|
|
def TestCoreDataTypeViolations():
|
|
|
|
global pol
|
|
|
|
return pol.AssertPathTypesDoNotHaveAttr(["/data/vendor/", "/data/vendor_ce/",
|
|
|
|
"/data/vendor_de/"], [], "core_data_file_type")
|
|
|
|
|
2017-05-25 18:53:47 +02:00
|
|
|
###
|
|
|
|
# extend OptionParser to allow the same option flag to be used multiple times.
|
|
|
|
# This is used to allow multiple file_contexts files and tests to be
|
|
|
|
# specified.
|
|
|
|
#
|
|
|
|
class MultipleOption(Option):
|
|
|
|
ACTIONS = Option.ACTIONS + ("extend",)
|
|
|
|
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
|
|
|
|
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
|
|
|
|
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
|
|
|
|
|
|
|
|
def take_action(self, action, dest, opt, value, values, parser):
|
|
|
|
if action == "extend":
|
|
|
|
values.ensure_value(dest, []).append(value)
|
|
|
|
else:
|
|
|
|
Option.take_action(self, action, dest, opt, value, values, parser)
|
|
|
|
|
2017-09-26 21:58:29 +02:00
|
|
|
Tests = {"CoredomainViolations": TestCoredomainViolations,
|
2018-02-08 18:54:59 +01:00
|
|
|
"CoreDatatypeViolations": TestCoreDataTypeViolations,
|
2017-09-26 21:58:29 +02:00
|
|
|
"TrebleCompatMapping": TestTrebleCompatMapping,
|
|
|
|
"ViolatorAttributes": TestViolatorAttributes}
|
2017-05-25 18:53:47 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-12-29 05:56:14 +01:00
|
|
|
usage = "treble_sepolicy_tests "
|
2017-09-26 21:58:29 +02:00
|
|
|
usage += "-f nonplat_file_contexts -f plat_file_contexts "
|
|
|
|
usage += "-p curr_policy -b base_policy -o old_policy "
|
|
|
|
usage +="-m mapping file [--test test] [--help]"
|
2017-05-25 18:53:47 +02:00
|
|
|
parser = OptionParser(option_class=MultipleOption, usage=usage)
|
2017-09-26 21:58:29 +02:00
|
|
|
parser.add_option("-b", "--basepolicy", dest="basepolicy", metavar="FILE")
|
2018-09-29 02:21:08 +02:00
|
|
|
parser.add_option("-u", "--base-pub-policy", dest="base_pub_policy",
|
|
|
|
metavar="FILE")
|
2017-05-25 18:53:47 +02:00
|
|
|
parser.add_option("-f", "--file_contexts", dest="file_contexts",
|
|
|
|
metavar="FILE", action="extend", type="string")
|
2017-09-26 21:58:29 +02:00
|
|
|
parser.add_option("-m", "--mapping", dest="mapping", metavar="FILE")
|
|
|
|
parser.add_option("-o", "--oldpolicy", dest="oldpolicy", metavar="FILE")
|
|
|
|
parser.add_option("-p", "--policy", dest="policy", metavar="FILE")
|
|
|
|
parser.add_option("-t", "--test", dest="tests", action="extend",
|
2017-05-25 18:53:47 +02:00
|
|
|
help="Test options include "+str(Tests))
|
2017-09-26 21:58:29 +02:00
|
|
|
parser.add_option("--fake-treble", action="store_true", dest="faketreble",
|
|
|
|
default=False)
|
2017-05-25 18:53:47 +02:00
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
|
|
if not options.policy:
|
2017-09-26 21:58:29 +02:00
|
|
|
sys.exit("Must specify current monolithic policy file\n" + parser.usage)
|
2017-05-25 18:53:47 +02:00
|
|
|
if not os.path.exists(options.policy):
|
|
|
|
sys.exit("Error: policy file " + options.policy + " does not exist\n"
|
|
|
|
+ parser.usage)
|
|
|
|
if not options.file_contexts:
|
|
|
|
sys.exit("Error: Must specify file_contexts file(s)\n" + parser.usage)
|
|
|
|
for f in options.file_contexts:
|
|
|
|
if not os.path.exists(f):
|
|
|
|
sys.exit("Error: File_contexts file " + f + " does not exist\n" +
|
|
|
|
parser.usage)
|
|
|
|
|
2021-12-29 05:56:14 +01:00
|
|
|
libpath = os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
|
|
|
"libsepolwrap" + distutils.ccompiler.new_compiler().shared_lib_extension)
|
|
|
|
if not os.path.exists(libpath):
|
|
|
|
sys.exit("Error: libsepolwrap does not exist. Is this binary corrupted?\n")
|
|
|
|
|
2018-09-29 02:21:08 +02:00
|
|
|
# Mapping files and public platform policy are only necessary for the
|
|
|
|
# TrebleCompatMapping test.
|
2021-11-25 23:12:41 +01:00
|
|
|
if options.tests is None or options.tests == "TrebleCompatMapping":
|
2017-11-20 22:25:47 +01:00
|
|
|
if not options.basepolicy:
|
2018-09-29 02:21:08 +02:00
|
|
|
sys.exit("Must specify the current platform-only policy file\n"
|
|
|
|
+ parser.usage)
|
2017-11-20 22:25:47 +01:00
|
|
|
if not options.mapping:
|
2018-09-29 02:21:08 +02:00
|
|
|
sys.exit("Must specify a compatibility mapping file\n"
|
|
|
|
+ parser.usage)
|
2017-11-20 22:25:47 +01:00
|
|
|
if not options.oldpolicy:
|
2018-09-29 02:21:08 +02:00
|
|
|
sys.exit("Must specify the previous monolithic policy file\n"
|
|
|
|
+ parser.usage)
|
|
|
|
if not options.base_pub_policy:
|
|
|
|
sys.exit("Must specify the current platform-only public policy "
|
|
|
|
+ ".cil file\n" + parser.usage)
|
2021-12-29 05:56:14 +01:00
|
|
|
basepol = policy.Policy(options.basepolicy, None, libpath)
|
|
|
|
oldpol = policy.Policy(options.oldpolicy, None, libpath)
|
2017-11-20 22:25:47 +01:00
|
|
|
mapping = mini_parser.MiniCilParser(options.mapping)
|
2018-09-29 02:21:08 +02:00
|
|
|
pubpol = mini_parser.MiniCilParser(options.base_pub_policy)
|
|
|
|
compatSetup(basepol, oldpol, mapping, pubpol.types)
|
2017-11-20 22:25:47 +01:00
|
|
|
|
2017-09-26 21:58:29 +02:00
|
|
|
if options.faketreble:
|
|
|
|
FakeTreble = True
|
|
|
|
|
2021-12-29 05:56:14 +01:00
|
|
|
pol = policy.Policy(options.policy, options.file_contexts, libpath)
|
2017-05-25 18:53:47 +02:00
|
|
|
setup(pol)
|
|
|
|
|
2017-06-01 00:36:07 +02:00
|
|
|
if DEBUG:
|
|
|
|
PrintScontexts()
|
|
|
|
|
2017-05-25 18:53:47 +02:00
|
|
|
results = ""
|
|
|
|
# If an individual test is not specified, run all tests.
|
2017-09-26 21:58:29 +02:00
|
|
|
if options.tests is None:
|
|
|
|
for t in Tests.values():
|
|
|
|
results += t()
|
|
|
|
else:
|
|
|
|
for tn in options.tests:
|
|
|
|
t = Tests.get(tn)
|
|
|
|
if t:
|
|
|
|
results += t()
|
|
|
|
else:
|
|
|
|
err = "Error: unknown test: " + tn + "\n"
|
|
|
|
err += "Available tests:\n"
|
|
|
|
for tn in Tests.keys():
|
|
|
|
err += tn + "\n"
|
|
|
|
sys.exit(err)
|
2017-05-25 18:53:47 +02:00
|
|
|
|
|
|
|
if len(results) > 0:
|
|
|
|
sys.exit(results)
|