1*2d543d20SAndroid Build Coastguard WorkerCode Overview 2*2d543d20SAndroid Build Coastguard Worker============= 3*2d543d20SAndroid Build Coastguard Worker 4*2d543d20SAndroid Build Coastguard WorkerThe source for Sepolgen is divided into the python library (sepolgen) 5*2d543d20SAndroid Build Coastguard Workerand tools (e.g., audit2allow). 6*2d543d20SAndroid Build Coastguard Worker 7*2d543d20SAndroid Build Coastguard WorkerThe library is structured to give flexibility to the application using 8*2d543d20SAndroid Build Coastguard Workerit - it avoids assumptions and close coupling of components where 9*2d543d20SAndroid Build Coastguard Workerpossible. The audit2allow application demonstrates how to hook the 10*2d543d20SAndroid Build Coastguard Workercomponents together. 11*2d543d20SAndroid Build Coastguard Worker 12*2d543d20SAndroid Build Coastguard WorkerThere is a test suite in the test subdirectory. The run-tests.py 13*2d543d20SAndroid Build Coastguard Workerscript will run all of the tests. 14*2d543d20SAndroid Build Coastguard Worker 15*2d543d20SAndroid Build Coastguard WorkerThe library is is divided into several functional areas: 16*2d543d20SAndroid Build Coastguard Worker 17*2d543d20SAndroid Build Coastguard WorkerReference Policy Representation (sepolgen.refpolicy) 18*2d543d20SAndroid Build Coastguard Worker------------------------------------------------------------- 19*2d543d20SAndroid Build Coastguard Worker 20*2d543d20SAndroid Build Coastguard WorkerObjects for representing policies and the reference policy 21*2d543d20SAndroid Build Coastguard Workerinterfaces. Includes basic components (security contexts, allow rules, 22*2d543d20SAndroid Build Coastguard Workeretc.) and reference policy specific components (interfaces, modules, 23*2d543d20SAndroid Build Coastguard Workeretc.). 24*2d543d20SAndroid Build Coastguard Worker 25*2d543d20SAndroid Build Coastguard WorkerThis representation can be used as output from the parser to represent 26*2d543d20SAndroid Build Coastguard Workerthe reference policy interfaces. It can also be used to generate 27*2d543d20SAndroid Build Coastguard Workerpolicy by building up the relevant data structures and then outputting 28*2d543d20SAndroid Build Coastguard Workerthem. See sepolgen.policygen and sepolgen.output for information on how 29*2d543d20SAndroid Build Coastguard Workerthis can be done. 30*2d543d20SAndroid Build Coastguard Worker 31*2d543d20SAndroid Build Coastguard WorkerAccess (sepolgen.access, sepolgen.interfaces, sepolgen.matching) 32*2d543d20SAndroid Build Coastguard Worker------------------------------------------------------------- 33*2d543d20SAndroid Build Coastguard Worker 34*2d543d20SAndroid Build Coastguard WorkerObjects and algorithms for representing access and sets of access in 35*2d543d20SAndroid Build Coastguard Workeran abstract way and searching that access. The basic concept is that 36*2d543d20SAndroid Build Coastguard Workerof an access vector (source type, target type, object class, and 37*2d543d20SAndroid Build Coastguard Workerpermissions). These can be grouped into sets without overlapping 38*2d543d20SAndroid Build Coastguard Workeraccess. Access vectors and access vector sets can be matched against 39*2d543d20SAndroid Build Coastguard Workerother access vectors - this forms the backbone of how we turn audit 40*2d543d20SAndroid Build Coastguard Workermessages into interface calls. 41*2d543d20SAndroid Build Coastguard Worker 42*2d543d20SAndroid Build Coastguard WorkerThe highest-level form of access represented in interfaces - which 43*2d543d20SAndroid Build Coastguard Workerincludes algorithms to turn the raw output of the parser into access 44*2d543d20SAndroid Build Coastguard Workervector sets representing the access allowed by each interface. 45*2d543d20SAndroid Build Coastguard Worker 46*2d543d20SAndroid Build Coastguard WorkerParsing (sepolgen.refparser) 47*2d543d20SAndroid Build Coastguard Worker------------------------------------------------------------- 48*2d543d20SAndroid Build Coastguard Worker 49*2d543d20SAndroid Build Coastguard WorkerParser for reference policy "headers" - i.e., 50*2d543d20SAndroid Build Coastguard Worker/usr/share/selinux/devel/include. This uses the LGPL parsing library 51*2d543d20SAndroid Build Coastguard Worker[PLY](http://www.dabeaz.com/ply/) which is included in the source 52*2d543d20SAndroid Build Coastguard Workerdistribution in the files lex.py and yacc.py. It may be necessary to 53*2d543d20SAndroid Build Coastguard Workerswitch to a more powerful parsing library in the future, but for now 54*2d543d20SAndroid Build Coastguard Workerthis is fast and easy. 55*2d543d20SAndroid Build Coastguard Worker 56*2d543d20SAndroid Build Coastguard WorkerAudit Messages (sepolgen.audit) 57*2d543d20SAndroid Build Coastguard Worker------------------------------------------------------------- 58*2d543d20SAndroid Build Coastguard Worker 59*2d543d20SAndroid Build Coastguard WorkerInfrastructure for parsing SELinux related messages as produced by the 60*2d543d20SAndroid Build Coastguard Workeraudit system. This is not a general purpose audit parsing library - it 61*2d543d20SAndroid Build Coastguard Workeris only meant to capture SELinux messages - primarily access vector 62*2d543d20SAndroid Build Coastguard Workercache (AVC) messages and policy load messages. 63*2d543d20SAndroid Build Coastguard Worker 64*2d543d20SAndroid Build Coastguard WorkerPolicy Generation (sepolgen.policygen and sepolgen.output) 65*2d543d20SAndroid Build Coastguard Worker------------------------------------------------------------- 66*2d543d20SAndroid Build Coastguard Worker 67*2d543d20SAndroid Build Coastguard WorkerInfrastructure for generating policy based on required access. This 68*2d543d20SAndroid Build Coastguard Workerdeliberately only loosely coupled to the audit parsing to allow 69*2d543d20SAndroid Build Coastguard Workerrequired accesses to be feed in from anywhere. 70*2d543d20SAndroid Build Coastguard Worker 71*2d543d20SAndroid Build Coastguard WorkerObject Model (sepolgen.objectmodel) 72*2d543d20SAndroid Build Coastguard Worker------------------------------------------------------------- 73*2d543d20SAndroid Build Coastguard Worker 74*2d543d20SAndroid Build Coastguard WorkerInformation about the SELinux object classes. This is semantic 75*2d543d20SAndroid Build Coastguard Workerinformation about the object classes - including information flow. It 76*2d543d20SAndroid Build Coastguard Workeris separated to keep the core from being concerned about the details 77*2d543d20SAndroid Build Coastguard Workerof the object classes. 78