The SELinux Notebook The Foundations 3rd Edition
The SELinux Notebook The Foundations 3rd Edition
The SELinux
Notebook
The
Foundations
(3rd Edition)
Page 1
0. Notebook Information
0.1
Copyright Information
0.2
Revision History
Edition
Date
Changes
1.0
20th Nov 09
First released.
2.0
Second release.
3.0
0.3
Acknowledgements
0.4
Abbreviations
Term
Definition
apol
AV
Access Vector
Page 2
Definition
AVC
BLP
Bell-La Padula
CC
Common Criteria
CIL
CMW
DAC
F-17
Fedora 17
FLASK
Fluke
Flux
ID
Identification
LSM
LAPP
LSPP
MAC
MCS
Multi-Category Security
MLS
Multi-Level Security
NSA
OM
Object Manager
OTA
PAM
RBAC
rpm
Security Identifier
SL
Security Level
SLIDE
Super-user Identifier
TE
Type Enforcement
UID
User Identifier
XACE
Page 3
0.5
Index
0. NOTEBOOK INFORMATION..............................................................................2
0.1 COPYRIGHT INFORMATION..........................................................................................2
0.2 REVISION HISTORY................................................................................................... 2
0.3 ACKNOWLEDGEMENTS................................................................................................2
0.4 ABBREVIATIONS........................................................................................................2
0.5 INDEX..................................................................................................................... 4
1. THE SELINUX NOTEBOOK.............................................................................. 12
1.1 INTRODUCTION........................................................................................................12
1.2 THE FOUNDATIONS OVERVIEW................................................................................. 12
1.2.1 Notebook Source Overview.........................................................................13
2. SELINUX OVERVIEW........................................................................................ 14
2.1 INTRODUCTION........................................................................................................14
2.1.1 Is SELinux useful.........................................................................................14
2.2 CORE SELINUX COMPONENTS..................................................................................16
2.3 MANDATORY ACCESS CONTROL (MAC)...................................................................19
2.4 SELINUX USERS....................................................................................................20
2.5 ROLE-BASED ACCESS CONTROL (RBAC)................................................................ 21
2.6 TYPE ENFORCEMENT (TE).......................................................................................21
2.6.1 Constraints..................................................................................................22
2.7 SECURITY CONTEXT................................................................................................ 23
2.8 SUBJECTS...............................................................................................................25
2.9 OBJECTS................................................................................................................25
2.9.1 Object Classes and Permissions................................................................. 25
2.9.2 Allowing a Process Access to Resources....................................................26
2.9.3 Labeling Objects......................................................................................... 27
2.9.3.1 Labeling Extended Attribute Filesystems............................................ 28
2.9.3.1.1 Copying and Moving Files............................................................29
2.9.3.2 Labeling Subjects................................................................................. 30
2.9.4 Object Reuse............................................................................................... 30
2.10 COMPUTING SECURITY CONTEXTS...........................................................................30
2.10.1 avc_compute_create and security_compute_create................................. 31
2.10.2 avc_compute_member and security_compute_member........................... 32
2.10.3 security_compute_relabel ........................................................................34
2.11 DOMAIN AND OBJECT TRANSITIONS.........................................................................35
2.11.1 Domain Transition....................................................................................35
2.11.1.1 Type Enforcement Rules....................................................................37
2.11.2 Object Transition...................................................................................... 39
2.12 MULTI-LEVEL SECURITY AND MULTI-CATEGORY SECURITY.......................................40
2.12.1 Security Levels..........................................................................................41
2.12.1.1 MLS / MCS Range Format................................................................ 42
2.12.1.2 Translating Levels..............................................................................43
2.12.2 Managing Security Levels via Dominance Rules......................................43
2.12.3 MLS Labeled Network and Database Support..........................................45
2.12.4 Common Criteria Certification.................................................................45
2.13 TYPES OF SELINUX POLICY...................................................................................46
2.13.1 Example Policy......................................................................................... 46
Page 4
Page 5
Page 6
Page 7
Page 8
Page 9
Page 10
Page 11
Introduction
1.2
Page 13
2. SELinux Overview
2.1
Introduction
SELinux is the primary Mandatory Access Control (MAC) mechanism built into a
number of GNU / Linux distributions. SELinux originally started as the Flux
Advanced Security Kernel (FLASK) development by the Utah university Flux team
and the US Department of Defence. The development was enhanced by the NSA and
released as open source software. The history of SELinux can be found at the Flux
and NSA websites.
Each of the sections that follow will describe a component of SELinux, and hopefully
they are is some form of logical order.
Note: When SELinux is installed, there are three well defined directory locations
referenced. Two of these will change with the old and new locations as follows:
Description
Old Location
New Location
/selinux
/sys/fs/selinux
/etc/selinux No change
/etc/selinux /var/lib/selinux
Page 14
Page 15
2.2
Figure 2.1 shows a high level diagram of the SELinux core components that manage
enforcement of the policy and comprise of the following:
1. A subject that must be present to cause an action to be taken by an object
(such as read a file as information only flows when a subject is involved).
2. An Object Manager that knows the actions required of the particular resource
(such as a file) and can enforce those actions (i.e. allow it to write to a file if
permitted by the policy).
3. A Security Server that makes decisions regarding the subjects rights to
perform the requested action on the object, based on the security policy rules.
4. A Security Policy that describes the rules using the SELinux policy language.
5. An Access Vector Cache (AVC) that improves system performance by
caching security server decisions.
Subject
Requests access.
Object Manager
Knows what objects it
manages, so queries if the
action is allowed and then
enforces the security
policy decision.
Security Server
Q u e ry
pe rm issions
Answe r from
C ach e
Access Vector
Cache
Stores decisions
made by the
Security Server.
If answe r not
in cache , ask
se cu rity se rve r
Makes decisions
based on the
security policy.
Add answe r
to cach e
Security Policy
Figure 2.1: High Level Core SELinux Components - Decisions by the Security
Server are cached in the AVC to enhance performance of future requests.
Figure 2.2 shows a more complex diagram of kernel and userspace with a number of
supporting services that are used to manage the SELinux environment. This diagram
will be referenced a number of times to explain areas of SELinux, therefore starting
from the bottom:
a) In the current implementation of SELinux the security server is embedded in
the kernel with the policy being loaded from userspace via a series of
functions contained in the libselinux library (see SELinux Userspace
Libraries for details).
The object managers (OM) and access vector cache (AVC) can reside in:
Page 16
Reference Policy
Headers
Or
Reference Policy
Source
Or
Custom Policy
Source
checkmodule
semodule_package
Policy Object
Files
Optional
Configuration
Files
SELinux-aware Applications
Userspace Object Managers
Acce ss
Ve ctor
C ach e
libselinux
semodule
Manages the policy store by installing, loading, updating
and removing modules and their supporting configuration
files. Also builds the binary policy file.
Policy Files
Linux commands
Linux commands modified to
support SELinux, such as ls,
ps, pam.
semanage
Configures elements of
the policy such as login,
users, and ports.
policycoreutils
SElinux utilities, such as secon,
audit2allow and systemconfig-selinux.
T hese
hese libraries
libraries
T
are linked
linked into
into
are
SELinux
SELinux aware
aware
applications as
as
applications
required.
required.
S ELin ux Use r
S pace Se rvice s
Audit Log
Audit
Services
(xattr)
semanage.trans.LOCK
modules/active:
base.pp
commit_num
file_contexts
file_contexts.homedirs
file_contexts.template
homedir_template
netfilter_contexts
seusers.final
users_extra
l
i
b
s
e
m modules/active/modules:
amavis.pp
a amtu.pp
...
n zabbix.pp
a
g ---- Active Policy ---/etc/selinux/<SELINUXTYPE>/
e
setrans.conf
libselinux (supports security policy, xattr file attribute and process APIs)
Linux Kernel
Services
SELinux Policy
policy:
policy.24
/proc/self/task/
<tid>/attr/<attr>
Labeled File
Systems
l
i
b
s
e ---- Policy Store ----p /var/lib/selinux/<SELINUXTYPE>/
o modules:
l semanage.read.LOCK
H
o
o
k
s
contexts:
dbus_contexts
netfilter_contexts
contexts/files:
file_contexts
file_contexts.homedirs
-----------------------
SELinux
Kernel
Services
Security
Server
Loaded
Policy
/etc/selinux/config
/etc/selinux/semanage.conf
/etc/selinux/restorecond.conf
/etc/sestatus
Figure 2.2: High Level SELinux Architecture Showing the major supporting services
Page 17
Page 18
2.3
Mandatory Access Control (MAC) is a type of access control in which the operating
system is used to constrain a user or process (the subject) from accessing or
performing an operation on an object (such as a file, disk, memory etc.).
Each of the subjects and objects have a set of security attributes that can be
interrogated by the operating system to check if the requested operation can be
performed or not. For SELinux the:
Security Server within the Linux kernel authorizes access (or not) using the
security policy (or policy) that describes rules that must be enforced.
Note that the subject (and therefore the user) cannot decide to bypass the policy rules
being enforced by the MAC policy with SELinux enabled. Contrast this to standard
Linux Discretionary Access Control (DAC), which also governs the ability of subjects
to access objects, however it allows users to make policy decisions. The steps in the
decision making chain for DAC and MAC are shown in Figure 2.3.
Page 19
Kernel Space
Failed Denied Allowed
DAC Checks
LSM Hook
Allow or Deny
Access
Linux
Security
Module
SELinux Security
Server, AVC and
Policy
Figure 2.3: Processing a System Call The DAC checks are carried out first, if they
pass then the Security Server is consulted for a decision.
SELinux supports two forms of MAC:
Type Enforcement Where processes run in domains and the actions on objects
are controlled by the policy. This is the implementation used for general purpose
MAC within SELinux. The Type Enforcement section covers this in more detail.
Multi-Level Security This is an implementation based on the Bell-La Padula
(BLP) model, and used by organizations where different levels of access are
required so that restricted information (for example in some defence /
Government systems) is separated from classified information to maintain
confidentiality. This allows enforcement rules such as no write down and no
read up to be implemented in a policy by extending the security context to
include security levels. The MLS section covers this in more detail along with a
variant of MLS called Multi-Category Security (MCS).
2.4
SELinux Users
Users in GNU / Linux are generally associated to human users (such as Alice and
Bob) or operator/system functions (such as admin), while this can be implemented in
SELinux, SELinux user names are generally groups or classes of user. For example
all the standard system users could be assigned an SELinux user name of user_u
and administration staff under staff_u.
There is one special SELinux user defined that must never be associated to a GNU /
Linux user as it a special identity for system processes and objects, this user is
system_u.
Page 20
2.5
Role
unconfined_r
TE Domain
unconfined_t
This domain includes most
processes started at boot
time and logins.
Role
message_filter_r
TE Domain
ext_gateway_t
TE Domain
int_gateway_t
TE Domain
move_file_t
Figure 2.4: Role Based Access Control Showing how SELinux controls access via
user, role and domain type association.
2.6
Page 21
2.6.1 Constraints
Within a TE environment, the way that subjects are allowed to access an object is via
an allow rule, for example:
allow unconfined_t ext_gateway_t : process transition;
This states that a process running in the unconfined_t domain has permission to
transition a process to the ext_gateway_t domain. However it could be that the
policy writer wants to constrain this further and state that this can only happen if the
role of the source domain is the same as the role of the target domain. To achieve this
a constraint can be imposed using a constrain statement:
constrain process transition ( r1 == r2 );
This states that a process transition can only occur if the source role is the same as the
target role, therefore a constraint is a condition that must be satisfied in order for one
or more permissions to be granted (i.e. a constraint imposes additional restrictions on
TE rules).
There are a number of different constraint statements within the policy language to
support areas such as MLS (see the Constraint Statements and MLS Statements
sections).
Page 22
2.7
Security Context
SELinux requires a security context to be associated with every process (or subject)
and object that are used by the security server to decide whether access is allowed or
not as defined by the policy.
The security context is also known as a security label or just label that can cause
confusion as there are many types of label depending on the context (another
context!!).
Within SELinux, a security context is represented as variable-length strings that
define the SELinux user3, their role, a type identifier and an optional MCS / MLS
security range or level as follows:
user:role:type[:range]
Where:
user
role
The SELinux role. This can be associated to one or more types the
SELinux user is allowed to access.
type
range
An SELinux user id is not the same as the GNU / Linux user id. The GNU / Linux user id is
mapped to the SELinux user id by configuration files.
Page 23
CMD
pts/0
pts/0
pts/0
pts/0
bash
secure_server
secure_server
ps
/usr/message_queue/in_queue
/usr/message_queue/out_queue
Message-1
Message-2
/usr/message_queue/out_queue:
unconfined_u:object_r:out_file_t
unconfined_u:object_r:out_file_t
Message-10
Message-11
Page 24
2.8
Subjects
A subject is an active entity generally in the form of a person, process, or device that
causes information to flow among objects or changes the system state.
Within SELinux a subject is generally an active process and has a security context
associated with it, however a process can also be referred to as an object depending on
the context in which it is being taken, for example:
1. A running process (i.e. an active entity) is a subject because it causes
information to flow among objects or can change the system state.
2. The process can also be referred to as an object because each process has an
associated object class4 called process. This process object, defines what
permissions the policy is allowed to grant or deny on the active process.
An example is given of the above scenarios in the Allowing a Process Access to an
Object section.
In SELinux subjects can be:
Trusted Generally these are commands, applications etc. that have been written
or modified to support specific SELinux functionality to enforce the security
policy (e.g. the kernel, init, pam, xinetd and login). However, it can also cover any
application that the organisation is willing to trust as a part of the overall system.
Although (depending on your paranoia level), the best policy is to trust nothing
until it has been verified that it conforms to the security policy. Generally these
trusted applications would run in either their own domain (e.g. the audit daemon
could run under auditd_t) or grouped together (e.g. the semanage(8) and
semodule(8) commands could be grouped under semanage_t).
Untrusted Everything else.
2.9
Objects
The object class and its associated permissions are explained in the Process Object Class section.
Also known in SELinux as Access Vectors (AV).
Page 25
File name:
/etc/selinux/config
write
Security Context:
append
system_u:object_r:selinux_config_t
Permissions
read
etc.
Figure 2.5: Object Class = file and permissions the policy rules would define
those permissions allowed for each process that needs access to the
/etc/selinux/config file.
The objective of the policy is to enable the user of the object (the subject) access to
the minimum permissions needed to complete the task (i.e. do not allow write
permission if only reading information).
These object classes and their associated permissions are built into the GNU / Linux
kernel and user space object managers by developers and are therefore not generally
updated by policy writers.
The object classes consist of kernel object classes (for handling files, sockets etc.)
plus userspace object classes for userspace object managers (for services such as XWindows or dbus). The number of object classes and their permissions can vary
depending on the features configured in the GNU / Linux release. All the known
object classes and permissions are described in Appendix A - Object Classes and
Permissions.
Page 26
Where:
allow
unconfined_t
transition
unconfined_t
Subject the
process
transition
ext_gateway_t
(Permission)
Figure 2.6: The allow rule Showing that the subject (the processes running
in the unconfined_t domain) has been given the transition permission on the
ext_gateway_t process object.
It should be noted that there is more to a domain transition than described above, for a
more detailed explanation, see the Domain Transition section.
Page 27
6
7
These file systems store the security context in an attribute associated with the file.
Note that this file contains the contexts of all files in all extended attribute filesystems for the
policy. However within a modular policy each module describes its own file context information,
that is then used to build this file.
Page 28
copy a file takes on label of new directory unless the Z option is used.
Page 29
On a running GNU / Linux system, processes inherit the security context of the parent
process. If the new process being spawned has permission to change its context, then
a type transition is allowed that is discussed in the Domain Transition section.
The Initial Boot - Loading the Policy section discusses how GNU / Linux is initialised
and the processes labeled for the login process.
The policy language supports a number of statements to either assign label
components or labels to processes such as:
user, role and type statements.
and manage their scope:
role allow and constrain
and manage their transition:
type_transition, role_transition and range_transition
Page 30
2.10.1
The table below8 shows how the components from the source context scon, target
context tcon and class tclass are used to compute the new context newcon
(referenced by SIDs for avc_compute_create(3). The following notes also
apply:
a) Any valid policy role_transition, type_transition and
range_transition enforcement rules will influence the final outcome as
shown.
b) For kernels less than 2.6.39 the context generated will depend on whether the
class is process or any other class.
c) For kernels 2.6.39 and above the following also applies:
i. Those classes suffixed by socket will also be included in the
process class outcome.
ii. If a valid role_transition rule for tclass, then use that instead
of the default object_r. Also requires policy version 26 or greater see security_policyvers(3).
iii. If the type_transition rule is classed as the 'file name transition
rule' (i.e. it has an object_name parameter), then provided the
object name in the rule matches the last component of the objects name
(in this case a file or directory name), then use the rules
default_type (note CIL uses the filetransition rule). Also
requires policy version 25 or greater.
d) For kernels 3.5 and above with policy version 27 or greater, the
default_user, default_role, default_range statements will
influence the user, role and range of the computed context for the
specified class tclass. With policy version 28 or greater the
8
The table only contains the kernel version, the text gives the policy version also required.
Page 31
role
type
range
If there is a valid
type_transition
rule then use the rules
default_type
OR
If kernel >= 3.5 with
default_type tclass
source rule then use scon
type
OR
If kernel >= 3.5 with
default_type tclass
target rule then use tcon
type
OR
If kernel >= 2.6.39 and
tclass is process or
*socket, then use scon
type
OR
If kernel <= 2.6.38 and
tclass is process, then
use scon type
ELSE
Use tcon type
If there is a valid
range_transition
rule then use the rules new_range
OR
If kernel >= 3.5 with
default_range tclass
source low rule then use
scon low
OR
If kernel >= 3.5 with
default_range tclass
source high rule then use
scon high
OR
If kernel >= 3.5 with
default_range tclass
source low_high rule then
use scon range
OR
If kernel >= 3.5 with
default_range tclass
target low rule then use
tcon low
OR
If kernel >= 3.5 with
default_range tclass
target high rule then use
tcon high
OR
If kernel >= 3.5 with
default_range tclass
target low_high rule then
use tcon range
OR
If kernel >= 2.6.39 and tclass
is process or *socket, then
use scon range
OR
If kernel <= 2.6.38 and tclass
is process, then use scon
range
ELSE
Use scon low
2.10.2
there is a valid
role_transition
rule then use the rules
new_role
OR
If kernel >= 3.5 with
default_role tclass
source rule then use scon
role
OR
If kernel >= 3.5 with
default_role tclass
target rule then use tcon
role
OR
If kernel >= 2.6.39 and
tclass is process or
*socket, then use scon
role
OR
If kernel <= 2.6.38 and
tclass is process, then
use scon role
ELSE
Use object_r
The table below9 shows how the components from the source context, scon target
context, tcon and class, tclass are used to compute the new context newcon
(referenced by SIDs for avc_compute_member(3). The following notes also
apply:
The table only contains the kernel version, the text gives the policy version also required.
Page 32
role
type
range
If there is a valid
type_member
rule then use the rules
member_type
OR
If kernel >= 3.5 with
default_type tclass
source rule then use scon
type
OR
If kernel >= 3.5 with
default_type tclass
target rule then use tcon
type
OR
If kernel >= 2.6.39 and
tclass is process or
*socket, then use scon
type
OR
If kernel <= 2.6.38 and
tclass is process, then
use scon type
ELSE
Use tcon type
Page 33
2.10.3
security_compute_relabel
The table below10 shows how the components from the source context, scon target
context, tcon and class, tclass are used to compute the new context newcon for
security_compute_relabel(3). The following notes also apply:
a) Any valid policy type_change enforcement rules will influence the final
outcome shown in the table.
b) For kernels less than 2.6.39 the context generated will depend on whether the
class is process or any other class.
c) For kernels 2.6.39 and above, those classes suffixed by socket are also
included in the process class outcome.
d) For kernels 3.5 and above with policy version 28 or greater, the
default_user, default_role, default_range statements will
influence the user, role and range of the computed context for the
specified class tclass. With policy version 28 or greater the
default_type statement can also influence the type in the computed
context.
10
The table only contains the kernel version, the text gives the policy version also required.
Page 34
role
type
range
If there is a valid
type_change
rule then use the rules
change_type
OR
If kernel >= 3.5 with
default_type tclass
source rule then use scon
type
OR
If kernel >= 3.5 with
default_type tclass
target rule then use tcon
type
OR
If kernel >= 2.6.39 and
tclass is process or
*socket, then use scon
type
OR
If kernel <= 2.6.38 and
tclass is process, then
use scon type
ELSE
Use tcon type
2.11.1
Domain Transition
A domain transition is where a process in one domain starts a new process in another
domain under a different security context. There are two ways a process can define a
domain transition:
Page 35
2. SELinux-aware applications can specify the domain of the new process using
the libselinux API call setexeccon(3). To achieve this the SELinuxaware application must also have the setexec permission, for example:
allow crond_t self : process setexec;
However, before any domain transition can take place the policy must specify that:
1. The source domain has permission to transition into the target domain.
2. The application binary file needs to be executable in the source domain.
3. The application binary file needs an entry point into the target domain.
The following is a type_transition statement taken from the example loadable
module message filter ext_gateway.conf (described in the source tarball) that
will be used to explain the transition process11:
type_transition | source_domain | target_type
: class
| target_domain;
-------------------------------------------------------------------------------type_transition
unconfined_t
secure_services_exec_t : process
ext_gateway_t;
3. The executable file needs an entry point into the ext_gateway_t (target)
domain:
11
For reference, the external gateway uses a server application called secure_server that is
transitioned to the ext_gateway_t domain from the unconfined_t domain. The
secure_server executable is labeled secure_services_exec_t.
Page 36
These are shown in Figure 2.7 where unconfined_t forks a child process, that
then execs the new program into a new domain called ext_gateway_t. Note that
because the type_transition statement is being used, the transition is
automatically carried out by the SELinux enabled kernel.
Process
system_u:system_r:unconfined_t
unconfined_t
Pare nt Proce ss
fork ()
system_u:system_r:unconfined_t
allow unconfined_t ext_gateway_t : process
unconfined_t
C hild Proce ss
execve ()
transition
type_transition unconfined_t
secure_services_exec_t : process ext_gateway_t;
system_u:system_r:ext_gateway_t
allow unconfined_t secure_services_exec_t : file
allow ext_gateway_t secure_services_exec_t : file
ext_gateway_t
Ne w program
(secure_server)
execute
read
getattr
entrypoint
Figure 2.7: Domain Transition Where the secure_server is executed within the
unconfined_t domain and then transitioned to the ext_gateway_t domain.
2.11.1.1
However, when linking these two loadable modules into the policy, the following
error was given:
Page 37
This happened because the type enforcement rules will only allow a single default
type for a given source and target (see the Type Enforcement Rules section). In the
above case there were two type_transition statements with the same source
and target, but different default domains. The ext_gateway.conf module had the
following statements:
# Allow the client/server to transition for the gateways:
allow unconfined_t ext_gateway_t : process { transition };
allow unconfined_t secure_services_exec_t : file { read execute getattr };
allow ext_gateway_t secure_services_exec_t : file { entrypoint };
type_transition unconfined_t secure_services_exec_t : process ext_gateway_t;
While the allow rules are valid to enable the transitions to proceed, the two
type_transition statements had different default types (or target domains),
that break the type enforcement rule.
It was decided to resolve this by:
1. Keeping the type_transition rule for the default type of
ext_gateway_t and allow the secure server process to be execed from
unconfined_t as shown in Figure 2.7, by simply running the command
from the prompt as follows:
# Run the external gateway secure server application on port 9999 and
# let the policy transition the process to the ext_gateway_t domain:
secure_server 99999
2. Use the SELinux runcon(1) command to ensure that the internal gateway
runs in the correct domain by running runcon from the prompt as follows:
# Run the internal gateway secure server application on port 1111 and
# use runcon to transition the process to the int_gateway_t domain:
runcon -t int_gateway_t -r message_filter_r secure_server 1111
# Note The role is required as a role transition that is defined in the
# policy.
2.11.2
Object Transition
An object transition is where a new object requires a different label to that of its
parent. For example a file is being created that requires a different label to that of its
parent directory. This can be achieved automatically using a type_transition
statement as follows:
type_transition ext_gateway_t in_queue_t:file in_file_t;
.
..
However the requirement is that files in the in_queue directory must be labeled
in_file_t. To achieve this the files created must be relabeled to in_file_t by
using a type_transition rule as follows:
# type_transition | source_domain | target_type : object | default_type;
----------------------------------------------------------------------type_transition
ext_gateway_t
in_queue_t : file
in_file_t;
Page 39
3. The policy can then ensure (via the SELinux kernel services) that files created
in the in_queue are relabeled:
type_transition ext_gateway_t in_queue_t : file in_file_t;
An example output from a directory listing shows the resulting file labels:
ls -Za /usr/message_queue/in_queue
drwxr-xr-x root root unconfined_u:object_r:in_queue_t
drwxr-xr-x root root system_u:object_r:unconfined_t
-rw-r--r-- root root unconfined_u:object_r:in_file_t
-rw-r--r-- root root unconfined_u:object_r:in_file_t
.
..
Message-1
Message-2
Page 40
Security
Levels
Files
Confidential
Restricted
Unclassified
Process
Secret
Data Flows
File B
Label = Confidential
Write only
File C
Label = Restricted
Read only
File D
Label = Unclassified
Read only
Process
Label = Confidential
No
No
Read
Write
Up
Down
Figure 2.8: Security Levels and Data Flows This shows how the process can only
Read Down and Write Up within an MLS enabled system.
To achieve this level of control, the MLS extensions to SELinux make use of
constraints similar to those described in the type enforcement Constraints section,
except that the statement is called mlsconstrain.
However, as always life is not so simple as:
1. Processes and objects can be given a range that represents the low and high
security levels.
2. The security level can be more complex, in that it is a hierarchical sensitivity
and zero or more non-hierarchical categories.
3. Allowing a process access to an object is managed by dominance rules
applied to the security levels.
4. Trusted processes can be given privileges that will allow them to bypass the
BLP rules and basically do anything (that the security policy allowed of
course).
5. Some objects do not support separate read / write functions as they need to
read / respond in cases such as networks.
The sections that follow discuss the format of a security level and range, and how
these are managed by the constraints mechanism within SELinux using the
dominance rules.
2.12.1
Security Levels
Table 1 shows the components that make up a security level and how two security
levels form a range for the fourth and optional [:range] of the security context
within an MLS / MCS environment.
The table also adds terminology in general use as other terms can be used that have
the same meanings.
Page 41
Sensitivity Label
Consisting of a classification and
compartment.
Range
Low
High
SystemLow
SystemHigh
Table 1: Level, Label, Category or Compartment this table shows the meanings
depending on the context being discussed.
The format used in the policy language statements is fully described in the MLS
Statements section, however a brief overview follows.
2.12.1.1
The following components (shown in bold) are used to define the MLS / MCS
security levels within the security context:
user:role:type:sensitivity[:category,...] - sensitivity [:category,...]
---------------------------------------------------------------------
|
level
| - |
level
|
|
|
|
range
|
Where:
sensitivity
Page 42
level
2.12.1.2
Translating Levels
When writing policy for MLS / MCS security level components it is usual to use an
abbreviated form such as s0, s1 etc. to represent sensitivities and c0, c1 etc. to
represent categories. This is done simply to conserve space as they are held on files as
extended attributes and also in memory. So that these labels can be represented in
human readable form, a translation service is provided via the setrans.conf
configuration file that is used by the mcstransd(8) daemon. For example s0 =
Unclassified, s15 = Top Secret and c0 = Finance, c100 = Spy Stories. The
semanage(8) command can be used to set up this translation and is shown in the
setrans.conf configuration file section.
2.12.2
Category
s3
Secret
s2
Confidential
s1
Restricted
s1:c0
s0
Unclassified
s0:c0
Sensitivity
c1
c2
c3
c4
s3:c0
s2:c
1
Security Level
s2:c
2
s2:c3
c5
c6
s3:c
5
s3:c
6
s2:c4
c7
s2:c7
s1:c
1
s1:c7
s0:c3
s0:c7
File Labels
A process running with a range of s0 s3:c1.c5 has access to the files
within the grey boxed area.
(sensitivity:category)
aka: classification
s3:c5
s1:c1
s0:c3
Dominates
Dominated By
Dominated By
# Read Down
Figure 2.9: Showing the mlsconstrain Statements controlling Read Down &
Write Up This ties in with Table 2 that shows a process running with a security
range of s0 s3:c1.c5.
Page 44
2.12.3
Networking for MLS is supported via the NetLabel CIPSO (commercial IP security
option) service as discussed in the SELinux Networking Support section.
PostgreSQL supports labeling for MLS database services as discussed in the SEPostgreSQL section.
2.12.4
While the Common Criteria certification process is beyond the scope of this
Notebook, it is worth highlighting that specific Red Hat GNU / Linux versions of
software, running on specific hardware platforms with SELinux / MLS policy
enabled, have passed the Common Criteria evaluation process. Note, for the
evaluation (and deployment) the software and hardware are tied together, therefore
whenever an update is carried out, an updated certificate should be obtained.
The Red Hat evaluation process cover the:
Labeled Security Protection Profile (LSPP ) This describes how systems that
implement security labels (i.e. MLS) should function.
An interesting point:
Both Red Hat Linux 5.1 and Microsoft Server 2003 (with XP) have both been
certified to EAL4+ , however while the evaluation levels may be the same the
Protection Profiles that they were evaluated under were: Microsoft CAPP
Page 45
2.13.1
Example Policy
The Example policy is the name used to describe the original SELinux policy source
used to build a monolithic12 policy produced by the NSA and is now superseded by
the Reference Policy.
2.13.2
Reference Policy
Note that this section only gives an introduction to the reference policy, the
installation, configuration and building of a policy using the source code is contained
in The Reference Policy section.
The Reference Policy is now the standard policy source used to build SELinux
policies, and its main aim is to provide a single source tree with supporting
documentation that can be used to build policies for different purposes such as:
confining important daemons, supporting MLS / MCS and locking down systems so
that all processes are under SELinux control.
The Reference Policy is now used by all major distributions of SELinux, however
each distribution makes its own specific changes to support their version of the
Reference Policy. For example, the F-17 distribution is based on a specific build of
the standard Reference Policy that is then modified and distributed by Red Hat as an
RPM.
12
The term monolithic generally means a single policy source is used to create the binary policy
file that is then loaded as the policy using the checkpolicy(8) command. However the term
is sometimes used to refer to the binary policy file (as it is one file that describes the policy).
Page 46
2.13.3
2.13.4
Custom Policy
Page 47
2.13.5
Monolithic Policy
A Monolithic policy is an SELinux policy that is compiled from one source file called
(by convention) policy.conf (i.e. it does not use the Loadable Module Policy
statements and infrastructure which therefore makes it suitable for embedded systems
as there is no policy store overhead).
An example monolithic policy is the NSAs original Example Policy. A simple
monolithic policy is shown in the Building the Monolithic Policy section and Table
14 shows the order of language statements that can be in a source file.
Monolithic policies are compiled using the checkpolicy (8) SELinux command.
The Reference Policy supports the building of monolithic policies.
In some cases the policy binary file (see the Binary Policy section) is also called a
monolithic policy.
2.13.6
Optional Policy
The loadable module policy infrastructure supports an optional policy statement that
allows policy rules to be defined but only enabled in the binary policy once the
conditions have been satisfied.
Example loadable modules with optional statements are used in the message filter
example contained in the Notebook source tarball.
2.13.7
Conditional Policy
Page 48
The conditional policy language statements are the bool Statement that defines the
boolean flag identifier and its initial status, and the if Statement that allows certain
rules to be executed depending on the state of the boolean value or values.
2.13.8
Binary Policy
The binary policy is the policy file that is loaded into the kernel and is always located
at /etc/selinux/<SELINUXTYPE>/policy/policy.<version>. Where
<SELINUXTYPE> is the policy name specified in the SELinux configuration file
/etc/selinux/config and <version> is the SELinux policy version.
The binary policy can be built from source files supplied by the Example Policy, the
Reference Policy or custom built source files as described in the in the "Sample
Policy Source" Notebook.
An example /etc/selinux/config file is shown below where the
SELINUXTYPE=targeted entry identifies the policy name that will be used to
locate and load the active policy:
SELINUX=permissive
SELINUXTYPE=targeted
From the above example, the actual binary policy file would be located at
/etc/selinux/targeted/policy and be called policy.26 (as version 26
is supported by F-16):
/etc/selinux/targeted/policy/policy.26
2.13.9
Policy Versions
SELinux has a policy database (defined the libsepol library) that describes the
format of data held within a binary policy, however, if any new features are added to
SELinux (generally language extensions) this can result in a change to the policy
database. Whenever the policy database is updated, the policy version is incremented.
The sestatus(8) command will show the maximum policy version number
supported by the kernel in its output as follows:
SELinux status:
SELinuxfs mount:
Current mode:
enabled
/sys/fs/selinux
enforcing
Page 49
permissive
26
modular-test
The F-16 kernel policy version is 26 with Table 3 describing the different versions.
There is also another version that applies to the modular policy, however the main
policy database version is the one that is generally quoted (some SELinux utilities
give both version numbers).
policy db
Version
modular db
Version
Description
15
16
17
18
19
20
21
22
23
24
9 / 10
25
11
26
12/13
14
Separate tunables.
27
15
Support setting object defaults for the user, role and range
components when computing a new context. Requires
kernel 3.5 minimum.
Page 50
modular db
Version
Description
28
16
29
16
enabled
/sys/fs/selinux
permissive
enforcing
26
modular-test
Page 51
2.15.1
Table 4 describes the general format of AVC audit messages in the audit.log
when access has been denied or an audit event has been specifically requested. Other
types of events are shown in the section that follows.
13
For example if the iptables are loaded and there are SECMARK security contexts present, but the
contexts are invalid (i.e. not in the policy), then the event is logged in the messages log and
nothing will appear in the audit log.
Page 52
Description
type
msg
This will contain the audit keyword with a reference number (e.g.
msg=audit(1243332701.744:101))
avc
pid
comm
If a task, then log the process id (pid) and the name of the
executable file (comm).
key
capabilit
y
path
If a File System event then log the relevant information. Note that
the name field may not always be present.
name
dev
ino
laddr
lport
faddr
Page 53
Description
fport
path
saddr
src
daddr
dest
netif
sauid
hostname
addr
terminal
resid
restype
scontext
tcontext
tclass
Table 4: AVC Audit Message Description The keywords in bold are in all AVC
audit messages, the others depend on the type of event being audited.
Example audit.log denied and granted events are shown in the following
examples:
# This is an example denied message - note that there are two
# type=AVC calls, but only one corresponding type=SYSCALL entry.
type=AVC msg=audit(1242575005.122:101): avc: denied { rename } for pid=2508
comm="canberra-gtk-pl" name="c73a516004b572d8c845c74c49b2511d:runtime.tmp"
dev=dm-0 ino=188999 scontext=test_u:staff_r:oddjob_mkhomedir_t:s0
tcontext=test_u:object_r:gnome_home_t:s0 tclass=lnk_file
type=AVC msg=audit(1242575005.122:101): avc: denied { unlink } for pid=2508
comm="canberra-gtk-pl" name="c73a516004b572d8c845c74c49b2511d:runtime" dev=dm-0
ino=188578 scontext=test_u:staff_r:oddjob_mkhomedir_t:s0
tcontext=system_u:object_r:gnome_home_t:s0 tclass=lnk_file
type=SYSCALL msg=audit(1242575005.122:101): arch=40000003 syscall=38 success=yes
exit=0 a0=82d2760 a1=82d2850 a2=da6660 a3=82cb550 items=0 ppid=2179 pid=2508
auid=500 uid=500 gid=500 euid=500 suid=500 fsuid=500 egid=500 sgid=500 fsgid=500
tty=(none) ses=1 comm="canberra-gtk-pl" exe="/usr/bin/canberra-gtk-play"
subj=test_u:staff_r:oddjob_mkhomedir_t:s0 key=(null)
Page 54
2.15.2
Change enforcement mode - MAC_STATUS - This was generated when the SELinux
enforcement mode was changed:
type=MAC_STATUS msg=audit(1336836093.835:406): enforcing=1 old_enforcing=0
auid=0 ses=2
type=SYSCALL msg=audit(1336836093.835:406): arch=c000003e syscall=1 success=yes
exit=1 a0=3 a1=7fffe743f9e0 a2=1 a3=0 items=0 ppid=2047 pid=5591 auid=0 uid=0
gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=2
comm="setenforce" exe="/usr/sbin/setenforce"
subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null)
Page 55
Page 56
These events were generated by the X-Windows Selection Manager demo that is in
the Notebook source tarball. Note that the event type=TRUSTED_APP, with the
actual event embedded as additional text in the message (using
audit_log_user_avc_message(3)).
type=TRUSTED_APP msg=audit(1336317006.208:327): pid=0 uid=0 auid=0 ses=2
subj=unconfined_u:unconfined_r:selmgr_t:s0-s0:c0.c1023 msg='X-Selection Manager:
The requested paste from scontext 'unconfined_u:unconfined_r:text_test1_t:s0s0:c20.c29' to tcontext 'unconfined_u:unconfined_r:text_test1_t:s0-s0:c20.c29'
has been accepted : exe="/usr/local/bin/selmgr" sauid=0 hostname=? addr=?
terminal=pts/0'
2.16 Polyinstantiation
GNU / Linux supports the polyinstantiation of directories that can be utilised by
SELinux via the Pluggable Authentication Module (PAM) that is explained in the
next section. The Polyinstantiation of directories in an SELinux system [Ref. 5]
also gives a more detailed overview of the subject.
Polyinstantiation of objects is also supported for X-windows selections and properties
that are discussed in the X-windows section. Note that sockets are not yet supported.
Page 57
functions
and
policy
rule
to
support
2.16.1
Polyinstantiated Objects
2.16.2
Page 58
instance-prefix
/tmp-inst/
/var/tmp/tmp-inst/
$HOME/$USER.inst/
method
level
level
level
list_of_uids
root,adm
root,adm
Once these files have been configured and a user logs in (although not root or adm
in the above example), the PAM pam_namespace module would unshare the
current namespace from the parent and mount namespaces according to the rules
defined in the namespace.conf file. The F-17 configuration also includes an
/etc/security/namespace.init script that is used to initialise the
namespace every time a new directory instance is set up. This script receives four
parameters: the polyinstantiated directory path, the instance directory path, a flag to
indicate if a new instance, and the user name. If a new instance is being set up, the
directory permissions are set and the restorecon(8) command is run to set the
correct file contexts.
2.16.2.1
Where:
polydir
Page 59
2.16.2.2
Example Configurations
This section shows two sample namespace.conf configurations, the first uses the
method=user and the second method=context. It should be noted that while
polyinstantiation is enabled, the full path names will not be visible, it is only when
polyinstantiation is disabled that the directories become visible.
Example 1 - method=user:
1. Set the /etc/security/namespace.conf entries as follows:
#polydir
/tmp
/var/tmp
$HOME
instance-prefix
/tmp-inst/
/var/tmp/tmp-inst/
$HOME/$USER.inst/
method
user
user
user
list_of_uids
root,adm
root,adm
2. Login as a normal user (rch in this example) and the PAM / Namespace
process will build the following polyinstantiated directories:
# The directories will contain the user name as a part of
# the polyinstantiated directory name as follows:
# /tmp
/tmp/tmp-inst/rch
# /var/tmp:
/var/tmp/tmp-inst/rch
# $HOME
/home/rch/rch.inst/rch
Example 2 - method=context:
1. Set the /etc/security/namespace.conf entries as follows:
#polydir
/tmp
/var/tmp
$HOME
instance-prefix
/tmp-inst/
/var/tmp/tmp-inst/
$HOME/$USER.inst/
method
context
context
context
list_of_uids
root,adm
root,adm
2. Login as a normal user (rch in this example) and the PAM / Namespace
process will build the following polyinstantiated directories:
# The directories will contain the security context and
Page 60
2.16.3
The X-Windows SELinux object manager and XACE (X Access Control Extension)
supports x_selection and x_property polyinstantiated objects as discussed in
the SELinux X-windows Support section.
2.16.4
The reference policy files.te and files.if modules (in the kernel layer)
support polyinstantiated directories. There is also a global tunable (a boolean called
allow_polyinstantiation) that can be used to set this functionality on or off
during login. By default this boolean is set false (off).
The polyinstantiation of X-Windows objects (x_selection and x_property)
are not currently supported by the reference policy, however there is a selection
manager example in the Notebook source tarball.
Page 61
Where:
service
type
control
This entry states how the module should behave when the
requested task fails. There can be two formats: a single
keyword such as required, optional, and include; or
multiple space separated entries enclosed in square brackets
consisting of :
[value1=action1 value2=action2 ..]
Both formats are shown in the example file below, however
see the pam.conf man pages for the gory details.
module-path
Either the full path name of the module or its location relative
to /lib/security (but does depend on the system
architecture).
arguments
An example PAM configuration file is as follows, although note that the service
parameter is actually the file name because F-17 uses the /etc/pam.d directory
configuration (in this case gdm for the Gnome login service).
# /etc/pam.d/gdm configuration rule entry.
# SERVICE = file name (gdm)
# TYPE
CONTROL
PATH
ARGUMENTS
Page 62
The core services are provided by PAM, however other library modules can be
written to manage specific services such as support for SELinux. The SELinux PAM
modules use the libselinux API to obtain its configuration information and the
three SELinux PAM entries highlighted in the above configuration file perform the
following functions:
pam_selinux_permit.so - Allows pre-defined users the ability to logon
without a password provided that SELinux is in enforcing mode (see the
/etc/security/sepermit.conf file section).
pam_selinux.so open - Allows a security context to be set up for the user at
initial logon (as all programs execed from here will use this context). How the
context is retrieved is described in the seusers configuration file section.
pam_selinux.so close - This will reset the login programs context to the
context defined in the policy.
Page 63
2.18.1
The LSM is the Linux security framework that allows 3 rd party access control
mechanisms to be linked into the GNU / Linux kernel. Currently there are five 3 rd
party services that utilise the LSM:
1. SELinux - the subject of this Notebook.
2. AppArmor is a MAC service based on pathnames and does not require
labelling or relabelling of filesystems. See http://wiki.apparmor.net for details.
3. Simplified Mandatory Access Control
http://www.schaufler-ca.com/ for details.
Kernel
(SMACK).
See
See
Insert security function hooks and security data structures in the various kernel
services to allow access control to be applied over and above that already
implemented via DAC. The type of service that have hooks inserted are shown
in Table 5 with an example task and program execution shown in the Fork
Walk-thorough and Process Transition Walk-thorough sections.
Allow registration and initialisation services for the 3rd party security modules.
It should be noted that the LSM does not provide any security services itself, only the
hooks and structures for supporting 3rd party modules. If no 3rd party module is
loaded, the capabilities module becomes the default module thus allowing standard
DAC access control.
Page 64
Filesystem operations
Inode operations
File operations
Task operations
Netlink messaging
Socket operations
XFRM operations
Memory Segments
Semaphores
Capability
Sysctl
Syslog
Audit
Table 5: LSM Hooks - These are the kernel services that LSM has inserted security
hooks and structures to allow access control to be managed by 3rd party modules (see
./linux-3.3/include/linux/security.h).
/proc/self/attr/ Permissions
File Name
Function
current
-rw-rw-rw-
exec
-rw-rw-rw-
Used to set the security context for the next exec call.
fscreate
-rw-rw-rw-
keycreate
-rw-rw-rw-
Used to set the security context for keys that are cached in the
kernel.
prev
-r--r--r--
sockcreate
-rw-rw-rw-
Table 6: /proc Filesystem attribute files - These files are used by the kernel services
and libselinux (for userspace) to manage setting and reading of security contexts
within the LSM defined data structures.
The major kernel source files (relative to ./linux-3.3/security) that form the
LSM are shown in Table 7. However there is one major header file
(include/linux/security.h) that describes all the LSM security hooks and
structures.
Name
Function
capability.c
commoncap.c
device_cgroup.c
inode.c
This allows the 3rd party security module to initialise a security filesystem.
In the case of SELinux this would be /sys/fs/selinux that is defined
in the selinux/selinuxfs.c source file.
security.c
Contains the LSM framework initialisation services that will set up the
hooks described in security.h and those in the capability source files.
It also provides functions to initialise 3rd party modules.
lsm_audit.c
min_addr.c
Page 65
2.18.2
This section does not go into detail of all the SELinux module functionality as [Ref 6]
does this, however it attempts to highlight the way some areas work by using the fork
and transition process example described in the Domain Transition section and also
by describing the boot process.
The major kernel SELinux source files (relative to ./linux3.3/security/selinux) that form the SELinux security module are shown
inTable 8. The diagrams shown in Figure 2.2 and Figure 2.12 can be used to see how
some of these kernel source modules fit together.
Name
Function
avc.c
Access Vector Cache functions and structures. The function calls are for
the kernel services, however they have been ported to form the
libselinux userspace library.
exports.c
hooks.c
Contains all the SELinux functions that are called by the kernel resources
via the security_ops function table (they form the kernel resource
object managers). There are also support functions for managing process
execs, managing SID allocation and removal, interfacing into the AVC
and Security Server.
netif.c
These manage the mapping between labels and SIDs for the net*
language statements when they are declared in the active policy.
netnode.c
netport.c
netlabel.c
netlink.c
nlmsgtab.c
selinuxfs.c
xfrm.c
include/classmap.h classmap.h contains all the kernel security classes and permissions.
include/initial_si initial_sid_to_string.h contains the initial SID contexts.
These are used to build the flask.h and av_permissions.h
d_to_string.h
kernel configuration files when the kernel is being built (using the
genheaders script defined in the selinux/Makefile).
These files are built this way now to support the new security class
mapping structure to remove the need for fixed class to SID mapping.
ss/avtab.c
ss/conditional.c
ss/ebitmap.c
ss/hashtab.c
Hash table.
ss/mls.c
Page 66
Function
ss/policydb.c
Defines the structure of the policy database. See the SELinux Policy
Module Primer [Ref. 4] article for details on the structure.
ss/services.c
ss/sidtab.c
The SID table contains the security context indexed by its SID value.
ss/status.c
ss/symtab.c
Table 8: The core SELinux source modules - The .h files and those in the
include directory have a number of useful comments.
2.18.2.1
This section walks through the the fork system call shown in Figure 2.7 starting at
the kernel hooks that link to the SELinux services. The way the SELinux hooks are
initialised into the LSM security_ops and secondary_ops function tables are
also described.
Using Figure 2.10, the major steps to check whether the unconfined_t process
has permission to use the fork permission are:
1. The kernel/fork.c has a hook that links it to the LSM function
security_task_create() that is called to check access permissions.
2. Because the SELinux module has been initialised as the security module, the
security_ops table has been set to point to the SELinux
selinux_task_create() function in hooks.c.
3. The selinux_task_create() function will first call the capabilities
code in capability.c via the secondary_ops function table to check
the DAC permission.
4. This is simply a return 0;, therefore no error would be generated.
5. The selinux_task_create() function will then check whether the task
has permission via the task_has_perm(current_process,
current_process, PROCESS__FORK) function.
6. This will result in a call to the AVC via the avc_has_perm() function in
avc.c that checks whether the permission has been granted or not. First (via
avc_has_perm_noaudit()) the cache is checked to for an entry.
Assuming that there is no entry in the AVC, then the
security_compute_av() function in services.c is called.
7. The security_compute_av() function will search the SID table for
source and target entries, and if found will then call the
context_struct_compute_av() function.
Page 67
enforcement
rules
(ALLOW,
Page 68
kernel/fork.c
/*
* This creates a new process as a copy of the old one, but does not actually
* start it yet. It copies the registers, and all the appropriate parts of the
* process environment (as per the clone flags). The actual kick-off is left to
* the caller.
*/
static struct task_struct *copy_process(unsigned long clone_flags, ...)
{
int retval;
struct task_struct *p;
int cgroup_callbacks_done = 0;
if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
.....
.....
8 retval
= security_task_create(clone_flags);
if (retval)
goto fork_out;
1
security_task_create->selinux_task_create
selinux/hooks.c
selinux/ss/services.c
selinux/avc.c
6
3
security_task_create->cap_task_create
capability.c
static int cap_task_create (unsigned long clone_flags)
{
4
return 0;
}
Figure 2.10: Hooks for the fork system call - This describes the steps required to
check access permissions for Object Class process and permission fork.
Page 69
This section walks through the execve() and checking whether a process transition
to the ext_gateway_t domain is allowed, and if so obtain a new SID for the
context (unconfined_u:message_filter_r:ext_gateway_t) as shown
in Figure 2.7.
The process starts with the Linux operating system issuing a do_execve()14 call
from the CPU specific architecture code to execute a new program (for example, from
arch/ia64/kernel/process.c). The do_execve() function is located in
the fs/exec.c source code module and does the loading and final exec as
described below.
do_execve() has a number of calls to security_bprm_* functions that are a
part of the LSM (see security.h), and are hooked by SELinux during the
initialisation process (in hooks.c). Table 9 briefly describes these
security_bprm functions that are hooks for validating program loading and
execution (although see security.h or [Ref. 6] for greater detail).
LSM / SElinux Function Name
Description
security_bprm_alloc->
selinux_bprm_alloc_security
security_bprm_free->
selinux_bprm_free_security
security_bprm_apply_creds->
selinux_bprm_apply_creds
security_bprm_post_apply_creds->
selinux_bprm_post_apply_creds
security_bprm_secureexec->
selinux_bprm_secureexec
security_bprm_set->
selinux_bprm_set_security
security_bprm_check->
selinux_bprm_check_security
This function call will pass over the file name to be run and its environment + arguments. Note
that for loading shared libraries the exec_mmap function is used.
Page 70
Search the SID table for the source and target SIDs.
vi. Check
if
any
MLS
attributes
by
calling
mls_compute_sid() in mls.c. It also checks whether
MLS is enabled or not, if so sets up MLS contexts.
vii. Check whether the contexts are valid by calling
compute_sid_handle_invalid_context() that will
also log an audit message if the context is invalid.
viii. Finally obtains a SID for the new context by calling
sidtab_context_to_sid() in sidtab.c that will
search the SID table (see Figure 2.12) and insert a new entry if
okay or log a kernel event if invalid.
d) The selinux_bprm_set_security() function will then
continue by checking via the avc_has_perm() function (in
avc.c) whether the file_execute_no_trans is set (in this case
it is not), therefore the process_transition and
file_entrypoint permissions are checked (in this case they are),
therefore the new SID is set, the bsec->set flag is set to 1 so that
Page 71
Page 72
fs/exec.c
int do_execve(filename,argv,envp,regs)
{
...
bprm = kzalloc(sizeof(*bprm), GFP_KERNEL);
...
file = open_exec(filename);
...
sched_exec();
...
retval = security_bprm_alloc(bprm);
...
retval = prepare_binprm(bprm);
...
...
retval = copy_strings(bprm->envc, envp, bprm);
...
current->flags &= ~PF_KTHREAD;
retval = search_binary_handler(bprm,regs);
if (retval >= 0) {
/* execve success */
security_bprm_free(bprm);
.....
if (displaced)
put_files_struct(displaced);
return retval;
}
...
return retval;
}
2
security_bprm_alloc->selinux_bprm_alloc_security
static int selinux_bprm_alloc_security(struct linux_binprm *bprm)
{
struct bprm_security_struct *bsec;
bsec = kzalloc(sizeof(struct bprm_security_struct), GFP_KERNEL);
if (!bsec)
return -ENOMEM;
bsec->sid = SECINITSID_UNLABELED;
bsec->set = 0;
bprm->security = bsec;
return 0;
}
security_bprm_free->selinux_bprm_free_security
static void selinux_bprm_free_security(struct linux_binprm *bprm)
{
kfree(bprm->security);
bprm->security = NULL;
}
security_bprm_set->selinux_bprm_set_security
2a
2b
if (tsec->exec_sid) {
newsid = tsec->exec_sid;
tsec->exec_sid = 0;
} else {
/* Check for a default transition on this program. */
rc = security_transition_sid(tsec->sid, isec->sid,
SECCLASS_PROCESS, &newsid);
if (rc)
return rc;
}
AVC_AUDIT_DATA_INIT(&ad, FS);
...
if (tsec->sid == newsid) {
rc = avc_has_perm(tsec->sid, isec->sid,
SECCLASS_FILE, FILE__EXECUTE_NO_TRANS, &ad);
if (rc)
return rc;
} else {
/* Check permissions for the transition. */
rc = avc_has_perm(tsec->sid, newsid,
SECCLASS_PROCESS, PROCESS__TRANSITION, &ad);
if (rc)
return rc;
rc = avc_has_perm(newsid, isec->sid,
SECCLASS_FILE, FILE__ENTRYPOINT, &ad);
if (rc)
return rc;
...
}
ss/services.c
security_transition_sid()
Check if transition required
2c
security_compute_sid()
Compute the new SID
bsec->set = 1;
return 0;
ss/mls.c
mls_compute_sid()
Check if MLS if so add MLS context
ss/sidtab.c
sidtab_context_to_sid()
Add new SID to table
avc.c
2d
avc_has_perms()
Check that the transition and entrypoint permissions are
valid. Add decision to cache if not already present.
Figure 2.11: Process Transition - This shows the major steps required to check if a
transition is allowed from the unconfined_t domain to the ext_gateway_t domain.
Page 73
/proc
Kernel Services
These are the
Linux kernel
resources such as
files, sockets,
memory
management that
need access
decisions made.
Security Services
Linux Security Module Framework
include/
linux/
security.h
security.c
fork.c
security_task_create (clone_flags)
selinux_task_create
load new
program
NetLink Services
(selinux/ss/services.c)
(selinux/netlink.c)
Constraints Table
avc_has_perms
security_compute_av
capabilities.c
do_execve (...)
execute new
program
Expression T ype
Constraint Attribute
Constraint Operator
(linked to AV T able)
class
role
role_transition
role_allow
type
user
boolean
level
category
range_transition
avc_insert
services.c
exec.c
Expression
State
IF list
(linked to AV T able)
ELSE list
(linked to AV T able)
selinux_bprm_alloc_security
selinux_bprm_set_security
selinux_bprm_apply_creds
selinux_bprm_secureexec
selinux_bprm_free_security
selinux_inode_permission
Manages the
permissions granted
or denied in a cache
to speed decisions
security_transition_sid
AV table
allow Rules:
source_type, target_type, class, permissions;
---------------------------------------------------type_transition Rules:
source_type, target_type, class, default_type;
Figure 2.12: The Main LSM / SELinux Modules The fork and exec functions link to Figure 2.7 where the transition process is described.
Page 74
2.18.2.3
SELinux Filesystem
Table 10 shows the information contained in the SELinux filesystem (selinuxfs) /sys/fs/selinux (or /selinux on older systems)
where the SELinux kernel exports information regarding its configuration and active policy. selinuxfs is a read/write interface used by
SELinux library functions such as the libselinux library for userspace SELinux-aware applications and object managers. Note while it is
possible for userspace applications to read/write to this interface, it is not recommended - use the libselinux library.
Permissions
Comments
Directory
This is the root directory where the SELinux kernel exports relevant information regarding its
configuration and active policy for use by the libselinux library.
access
-rw-rw-rw-
checkreqprot
-rw-r--r--
commit_pending_bools
--w-------
context
-rw-rw-rw-
/sys/fs/selinux
Page 75
Comments
create
-rw-rw-rw-
deny_unknown
-r--r--r--
reject_unknown
-r--r--r--
disable
--w-------
enforce
-rw-r--r--
load
-rw-------
member
-rw-rw-rw-
mls
-r--r--r--
15
This is also set in the UNK_PERMS entry of the Reference Policy build.conf file. The entry in semanage.conf will over-ride the build.conf entry.
Page 76
Comments
null
crw-rw-rw-
The SELinux equivalent of /dev/null for file descriptors that have been redirected by
SELinux.
policyvers
-r--r--r--
relabel
-rw-rw-rw-
status
-r--r--r--
This can be used to obtain enforcing mode and policy load changes with much less over-head
than using the libselinux netlink / call backs. This was added for Object Managers that
have high volumes of AVC requests so they can quickly check whether to invalidate their
cache or not.
The status structure indicates the following:
version - Version number of the status structure. This will increase as other entries are
added.
sequence - This is incremented for each event with an even number meaning that the
events are stable. An odd number indicates that one of the events is changing and therefore
the userspace application should wait before reading the status of any event.
enforcing - 0 = Permissive mode, 1 = enforcing mode.
policyload - This contains the policy load sequence number and should be read and
stored, then compared to detect a policy reload.
deny_unknown - 0 = Allow and 1 = Deny unknown object classes / permissions. This is
the same as the deny_unknown entry above.
user
-rw-rw-rw-
Page 77
Permissions
Comments
Directory
This directory contains information regarding the kernel AVC that can be displayed by the
avcstat command.
cache_stats
-r--r--r--
cache_threshold
-rw-r--r--
The default value is 512, however caching can be turned off (but performance suffers) by:
/sys/fs/selinux/avc
Directory
This directory contains one file for each boolean defined in the active policy.
-rw-r--r--
Each file contains the current and pending status of the boolean (0 = false or 1 = true). The
getsebool(8), setsebool(8) and sestatus -b commands use this interface via the
libselinux library functions.
Directory
This directory contains one file for each initial SID defined in the active policy.
-r--r--r--
Each file contains the initial context of the initial SID as defined in the active policy (e.g.
any_socket was assigned system_u:object_r:unconfined_t).
Directory
This directory contains the policy capabilities that have been configured by default in the
kernel via the policycap Statement in the active policy. These are generally new features that
can be enabled for testing by using the policycap Statement in policy.
network_peer_controls
-r--r--r--
For the F-17 Reference Policy this file contains 1 (true) which means that the following
network_peer_controls are enabled by default:
node: sendto recvfrom
netif: ingress egress
peer: recv
open_perms
-r--r--r--
For the F-17 Reference Policy this file contains 1 (true) which means that open permissions
are enabled by default on the following objects: dir, file, fifo_file, chr_file,
blk_file.
ptrace_child
-r--r--r--
This will be enabled kernel 3.4 to allow finer control of ptrace. Requires policy support and the
security class permission ptrace_child.
hash_stats
/sys/fs/selinux/booleans
secmark_audit
......
......
/sys/fs/selinux/initial_contexts
any_socket
devnull
.....
/sys/fs/selinux/policy_capabilities
Page 78
Comments
/sys/fs/selinux/class
Directory
This directory contains a list of classes and their permissions as defined within the policy.
/sys/fs/selinux/class/appletalk_socket
Directory
Each class has its own directory where each one is named using the appropriate class statement
from the policy (i.e. class appletalk_socket). Each directory contains the following:
-r--r--r--
Directory
This directory contains one file for each permission defined in the policy.
-r--r--r--
Each file is named by the permission assigned in the policy and contains a number that
represents its position in the list (e.g. accept is the 14th permission listed in
av_permission.h for appletalk_socket and therefore contains '14'.
index
/sys/fs/selinux/class/appletalk_socket/perms
accept
append
bind
....
Page 79
The SELinux filesystem that interfaces to the SELinux kernel security server.
The proc filesystem that maintains process state information and security
contexts - see proc(5).
The general category of functions available in libselinux are shown in Table 11,
with Appendix B giving a complete list of functions and source code examples
available in the Notebook tarball.
Function Category
Description
Boolean Services
Manage booleans.
Compute Labeling
File Labeling
Netlink Services
Process Labeling
Page 80
2.20.1
compat_net Controls
These labeling services make use of the Network Labeling Statements to label
network object nodes, interfaces and ports with a security context that are then used to
enforce controls. The Network Labeling Statements section defines each of the
statements with examples of their usage.
Figure 2.13 shows how these network statements are used and the type of allow rules
that would be required.
Interface
netifcon eth0 system_u:object_r:ext_interface_t
system_u:object_r:ext_interface_t
Node IP Address
nodecon 172.16.96.30 255.255.255.0 system_u:object_r:ext_node_t
Port
portcon tcp 9999 system_u:object_r:ext_gateway_port_t
tcp_socket
Policy:
allow ext_gateway_t
allow ext_gateway_t
allow ext_gateway_t
node_bind name_bind
Figure 2.13: compat_net Controls Showing the policy statements and rules
required to allow communications.
Page 82
2.20.2
SECMARK
SECMARK makes use of the standard kernel NetFilter framework that underpins the
GNU / Linux IP networking sub-system. NetFilter automatically inspects all incoming
and outgoing packets and can place controls on interfaces, IP addresses (nodes) and
ports with the added advantage of connection tracking. The SECMARK and
CONNSECMARK are security extensions to the Netfilter iptables that allow
security contexts to be added to packets (SECMARK) or sessions
(CONNSECMARK) such as those used by ftp (as some applications within a single
session can use a number of different ports, some fixed and others dynamically
allocated).
The NetFilter framework is used to inspect and tag packets with labels as defined
within the iptables and then use the security framework (e.g. SELinux) to enforce
the policy rules. Therefore SECMARK services are not SELinux specific as other
security modules that use the LSM infrastructure could also implement the same
services (e.g. SMACK).
While the implementation of iptables / NetFilter is beyond the scope of this
Notebook, there are tutorials available 16. Figure 2.14 shows the basic structure with
the process working as follows:
16
17
A table called the security table is used to define the parameters that identify
and mark packets that can then be tracked as the packet travels through the
networking sub-system. These marks are called SECMARK and
CONNSECMARK.
Page 83
Receive
Send
Policy:
allow ext_gateway_t ext_gateway_packet_t:packet { send recv };
iptables -t security -A INPUT -p tcp --dport 9999 -j As packets are sent, they
are marked and either
SECMARK --selctx
ACCEPTed or
system_u:object_r:ext_gateway_packet_t
DROPed
OUTPUT
system_u:object_r:ext_gateway_packet_t
Route
Forward
Network Interface
2.20.3
The tables will not load correctly if the policy does not allow the iptables domain to relabel the
security table entries unless permissive mode is enabled (i.e. iptables must have the relabel
permission for each entry in the table).
Page 84
network_peer_control
tcp_socket:
peer:
NetLabel Command:
netlabelctl unlbl add interface:lo address:127.0.0.1 \
label:system_u:object_r:netlabel_peer_t
Figure 2.15: Fallback Labeling Showing the differences between the policy
capability network_peer_controls set to 0 and 1.
2.20.4
NetLabel - CIPSO
To allow security levels to be passed over a network between MLS systems 19, the
CIPSO protocol is used that is defined in the CIPSO Internet Draft document (this is
an obsolete document, however the protocol is still in use). The protocol defines how
security levels are encoded in the IP packet header.
The protocol is implemented by the NetLabel service (see the netlabelctl(8)
man page) and can be used by other security modules that use the LSM infrastructure.
The NetLabel implementation supports:
1. Tag Type 1 bit mapped format that allows a maximum of 256 sensitivity
levels and 240 categories to be mapped.
2. A non-translation option where labels are passed to / from systems unchanged
(for host to host communications as show in Figure 2.16).
MLS Host 1
MLS Host 2
Note only the security levels are passed over as the SELinux security context is not part of a
standard MLS system (as SELinux supports two MAC services: Type Enforcement and MLS).
Page 85
MLS Gateway
(Guard)
MLS Host 1
MLS Host 2
2.20.5
Labeled IPSec
Labeled IPSec has been built into the standard GNU / Linux IPSec services as
described in the Leveraging IPSec for Distributed Authorization [Ref. 11]
document. Figure 2.18 shows the basic components that form the IPSec service where
it is generally used to set up either an encrypted tunnel between two machines 20 or an
encrypted transport session. The extensions defined in [Ref. 11] describe how the
security context is used and negotiated between the two systems (called security
associations (SAs) in IPSec terminology).
C lie nt
Application
Security Policy
Database (SPD)
setkey
racoon
Internet Key
Exchange (IKE)
racoon
setkey
Manages
configuration
Manages key
exchange
Manages key
exchange
Manages
configuration
Security
Association
Database (SAD)
Security
Association
Database (SAD)
Encrypted
communications
channel
S e rve r
Application
Security Policy
Database (SPD)
Figure 2.18: IPSec communications The SPD contains information regarding the
security contexts to be used. These are exchanged between the two systems as part of
the channel set-up.
Basically what happens is as follows21:
1. The security policy database (SPD) defines the security communications
characteristics to be used between the two systems. This is populated using the
setkey(8) utility with an example shown in the Configuration Example
section.
2. The SAs have their configuration parameters such as protocols used for
securing packets, encryption algorithms and how long the keys are valid held
in the Security Association database (SAD). For Labeled IPSec the security
context (or labels) is also defined within the SAD. SAs can be negotiated
20
21
Page 86
recvfrom
sendto
setcontext
There are worked examples of Labeled IPSec sessions showing manual and
racoon24 configuration in the Notebook source tarball.
There is a further example in the Secure Networking with SELinux [Ref. 13]
article.
2.20.5.1
Configuration Example
23
24
This is the Internet Key Exchange (IKE) daemon that exchanges encryption keys securely and also
supports Labeled IPSec parameter exchanges.
The GNU / Linux version supports a number of secure protocols, see the setkey man page for
details.
Unfortunately racoon core dumps when using non MCS/MLS policies.
Page 87
# SAin
spdadd 172.16.96.30 172.16.96.31 any
-ctx 1 1 system_u:object_r:ext_gateway_t
-P in ipsec esp/transport//require;
# SAout
spdadd 172.16.96.31 172.16.96.30 any
-ctx 1 1 system_u:object_r:ext_gateway_t
-P out ipsec esp/transport//require;
To manually load the above configuration file that populates the SPD and SAD 25 the
following command would be used:
setkey f <SPD_configuration_file>
26
27
If using racoon, the SAs would be negotiated using information from the SPD on each machine,
with the SAD then being populated by racoon calling the setkey services.
KVM (Kernel-based Virtual Machine) and Xen are classed as 'bare metal' hypervisors and they
rely on other services to manage the overall VM environment. QEMU (Quick Emulator) is an
emulator that emulates the BIOS and I/O device functionality and can be used standalone or with
KVM and Xen.
These can be generated using the VVM by selecting the 'Create a new virtual machine' menu item.
A simple Linux kernel was used to generate these and is available at: http://wiki.qemu.org/Testing
(the linux-0.2.img.bz2 disk image). This image was renamed to reflect each test, for
example 'Dynamic_VM1.img'.
Page 88
2.21.1
KVM is a kernel loadable module that uses the Linux kernel as a hypervisor and
makes use of a modified QEMU emulator to support the hardware I/O emulation. The
Kernel-based Virtual Machine [Ref. 21] document gives a good overview of how
KVM and QEMU are implemented. It also provides an introduction to virtualisation
in general. Note that KVM requires virtulisation support in the CPU (Intel-VT or
AMD-V extensions).
The SELinux support for VMs is implemented by the libvirt sub-system that is
used to manage the VM images using a Virtual Machine Manager, and as KVM is
based on Linux it has SELinux support by default. There are also Reference Policy
modules to support the overall infrastructure (KVM support is in various kernel and
system modules with a virt module supporting the libvirt services). Figure 2.19
shows a high level overview with two VMs running in their own domains. The
libvirt Support section shows how to configure these and their VM image files.
Virtual Machine
Manager
VM Guest 1
VM Guest 2
svirt_t:s0:c1,c2
svirt_t:s0:c7,c8
Linux Guest
operating system
Windows Guest
operating system
--------------------------QEMU
--------------------------QEMU
libvirtd
Manages the
QEMU
images, assigns
security labels, start libvirt
and stop VMs etc. Driver
2.21.2
libvirt Support
The Svirt project added security hooks into the libvirt library that is used by the
libvirtd daemon. This daemon is used by a number of VM products (such as
KVM, QEMU and Xen) to start their VMs running as guest operating systems.
The VM supplier can implement any security mechanism they require using a product
specific libvirt driver that will load and manage the images. The SELinux
implementation supports four methods of labeling VM images, processes and their
Page 89
2.21.3
VM Image Labeling
2.21.3.1
Dynamic Labeling
The default mode is where each VM is run under its own dynamically configured
domain and image file therefore isolating the VMs from each other (i.e. every time the
VM is run a different and unique MCS label will be generated to confine each VM to
its own domain). This mode is implemented as follows:
a) An
initial
context
for
the
process
is
obtained
from
/etc/selinux/<SELINUXTYPE>/contexts/virtual_domain_context
(the default is system_u:system_r:svirt_t:s0).
the
file
b) An initial context for the image file label is obtained from the
/etc/selinux/<SELINUXTYPE>/contexts/virtual_image_context
file.
The default is system_u:system_r:svirt_image_t:s0 that allows
read/write of image files.
c) When the image is used to start the VM, a random MCS level is generated
and added to the process context and the image file context. The process and
image files are then transitioned to the context by the libselinux API
calls
setfilecon
and
setexeccon
respectively
(see
security_selinux.c in the libvirt source). The following example
shows two running VM sessions each having different labels:
VM Name
Dynamic_VM1
Process system_u:system_r:svirt_t:s0:c585,c813
File
Dynamic_VM2
system_u:system_r:svirt_image_t:s0:c585,c813
Process system_u:system_r:svirt_t:s0:c535,c601
File
system_u:system_r:svirt_image_t:s0:c535,c601
The running image ls -Z and ps -eZ are as follows, and for completeness
an ls -Z is shown when both VMs have been stopped:
# Both VMs running:
ls -Z /var/lib/libvirt/images
system_u:object_r:svirt_image_t:s0:c585,c813 Dynamic_VM1.img
system_u:object_r:svirt_image_t:s0:c535,c601 Dynamic_VM2.img
ps -eZ | grep qemu
system_u:system_r:svirt_t:s0:c585,c813 8707 ? 00:00:44 qemu-system-x86
system_u:system_r:svirt_t:s0:cc535,c601 8796 ? 00:00:37 qemu-system-x86
28
The various images would have been labeled by the virt module installation process (see the
virt.fc module file or the policy file_contexts file libvirt entries). If not, then need to
ensure it is relabeled by the most appropriate SELinux tool.
Page 90
# Both VMs stopped (note that the categories are now missing AND
# the type has changed from svirt_image_t to virt_image_t):
ls -Z /var/lib/libvirt/images
system_u:object_r:virt_image_t:s0 Dynamic_VM1.img
system_u:object_r:virt_image_t:s0 Dynamic_VM2.img
2.21.3.2
Static Labeling
It is possible to set static labels on each image file, however a consequence of this is
that the image cannot be cloned using the VMM, therefore an image for each VM will
be required. This is the method used to configure VMs on MLS systems as there is a
known label that would define the security level. With this method it is also possible
to configure two or more VMs with the same security context so that they can share
resources.
If using the Virtual Machine Manager GUI, then by default it will start each VM
running as they are built, therefore they need to be stopped and then configured for
static labels, the image file will also need to be relabeled. An example VM
configuration follows where the VM has been created as Static_VM1 using the F17 targeted policy in enforcing mode (just so all errors are flagged during the
build):
a) Once the VM has been built, it will need to be stopped from the
Static_VM1 Virtual Machine screen. Display the Security menu
and select selinux as the Model and check the Static check box. The
required security context can then be set; for this example svirt_t has been
chosen as it is a valid context (however it will not run as explained in the text):
Page 91
Page 92
There are a number of ways to fix this, such as adding an allow rule or
changing the image file label. In this example the image file label will be
changed using chcon as follows:
# This command is executed from /var/lib/libvirt/images
#
# This sets the correct type:
chcon -t svirt_image_t Static_VM1.img
Optionally, the image can also be relabeled so that the [level] is the same
as the process using chcon as follows:
# This command is executed from /var/lib/libvirt/images
#
# Set the MCS label to match the process (optional step):
chcon -l s0:c1022,c1023 Static_VM1.img
c) Now that the image has been relabeled, the VM can now be started.
The following example shows two static VMs (one is configured for
unconfined_t that is allowed to run under the targeted policy):
VM Name
Object
Static_VM1 Process
File
Static_VM2 Process
File
The running image ls -Z and ps -eZ are as follows, and for completeness an ls
-Z is shown when both VMs have been stopped:
# Both VMs running (Note that Static_VM2 did not have file level reset):
ls -Z /var/lib/libvirt/images
system_u:object_r:svirt_image_t:s0:c1022,c1023 Static_VM1.img
system_u:object_r:virt_image_t:s0 Static_VM2.img
ps -eZ | grep qemu
system_u:system_r:svirt_t:s0:c585,c813 6707 ? 00:00:45 qemu-system-x86
system_u:system_r:unconfined_t:s0:c11,c22 6796 ? 00:00:26 qemu-system-x86
# Both VMs stopped (note that Static_VM1.img was relabeled svirt_image_t
# to enable it to run, however Static_VM2.img is still labeled
# virt_image_t and runs okay. This is because the process is run as
# unconfined_t that is allowed to use virt_image_t):
system_u:object_r:svirt_image_t:s0:c1022,c1023 Static_VM1.img
system_u:object_r:virt_image_t:s0 Static_VM2.img
Page 93
Share Image
If the disk image has been set to shared, then a dynamically allocated level will be
generated for each VM process instance, however there will be a single instance of
the disk image.
The Virtual Machine Manager can be used to set the image as shareable by checking
the Shareable box as shown in Figure 2.22.
As the two VMs will share the same image, the Shareable_VM service needs to be
cloned and the VM resource name selected was Shareable_VM-clone.
Page 94
The resource XML file <disk> contents generated are shown - note that it has the
same source file name as the Shareable_VM.xml above.
# /etc/libvirt/qemu/Shareable_VM-clone.xml:
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/var/lib/libvirt/images/Shareable_VM.img'/>
<target dev='hda' bus='ide'/>
<shareable/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
With the targeted policy on F-16 the shareable option gave a error when the VMs
were run as follows:
Could not allocate dynamic translator buffer
The audit log contained the following AVC message:
type=AVC msg=audit(1326028680.405:367): avc: denied
{ execmem } for pid=5404 comm="qemu-system-x86"
scontext=system_u:system_r:svirt_t:s0:c121,c746
tcontext=system_u:system_r:svirt_t:s0:c121,c746 tclass=process
To overcome this error, the following module was created and installed by:
cat /var/log/audit/audit.log | audit2allow -M qemu_execmem >
qemu_execmem.te
# Once generated, the module needs to be activated by:
semodule -i qemu_execmem.pp
Page 95
Now that the image has been configured as shareable, the following initialisation
process will take place:
a) An
initial
context
for
the
process
is
obtained
from
/etc/selinux/<SELINUXTYPE>/contexts/virtual_domain_context
(the default is system_u:system_r:svirt_t:s0).
the
file
b) An initial context for the image file label is obtained from the
/etc/selinux/<SELINUXTYPE>/contexts/virtual_image_context
file.
The default is system_u:system_r:svirt_image_t:s0 that allows
read/write of image files.
c) When the image is used to start the VM a random MCS level is generated and
added to the process context (but not the image file). The process is then
transitioned to the appropriate context by the libselinux API calls
setfilecon and setexeccon respectively. The following example
shows each VM having the same file label but different process labels:
VM Name
Object
Security context
Shareable_VM Process
system_u:system_r:svirt_t:s0:c231,c245
Shareable_VM Process
-clone
system_u:system_r:svirt_t:s0:c695,c894
File
system_u:system_r:svirt_image_t:s0
The running image ls -Z and ps -eZ are as follows and for completeness
an ls -Z is shown when both VMs have been stopped:
# Both VMs running and sharing same image:
ls -Z /var/lib/libvirt/images
system_u:object_r:svirt_image_t:s0 Shareable_VM.img
# but with separate processes:
ps -eZ | grep qemu
system_u:system_r:svirt_t:s0:c231,c254
system_u:system_r:svirt_t:s0:c695,c894
# Both VMs stopped (note that the type has remained as svirt_image_t)
ls -Z /var/lib/libvirt/images
system_u:object_r:svirt_image_t:s0 Shareable_VM.img
2.21.3.4
Readonly Image
Changes to qemu means that the readonly option on IDE drives has been dropped
(see
http://lists.gnu.org/archive/html/qemu-devel/2011-08/msg00799.html).
The
consequences of this is that while the Virtual Machine Manager will allow it to be set,
when running the image a message is generated stating "Can't use a read-only device".
A bug report has been generated asking that libvirt be changed to allow the
security service (i.e. SELinux) to still manage the read-only option and not pass the
readonly=on flag, if set to qemu (see https://bugzilla.redhat.com/show_bug.cgi?
id=732461).
Page 96
2.21.4
Xen Support
This is not supported by SELinux in the usual way as it is built into the actual Xen
software as a 'Flask/TE' extension29 for the XSM (Xen Security Module). Also the
Xen implementation has its own built-in policy (xen.te) and supporting definitions
for access vectors, security classes and initial SIDs for the policy. These Flask/TE
components run in Domain 0 as part of the domain management and control
supporting the Virtual Machine Monitor (VMM) as shown in Figure 2.23.
Domain 0
Modified Linux
Kernel to control
Domain U Guests
Flask/TE
Module
Xen Security
Module
Domain U
Domain U
Guest
Linux
(with SELinux
Enforcement if
required)
Guest
Windows
29
This is a version of the SELinux security server, avc etc. that has been specifically ported for the
Xen implementation.
Page 97
2.22.1
Notebook Examples
There are three sample X-widows applications in the source code tarball in the xwindows directory that use the XSELinux features:
1. A test tool to set and retrieve context information using the XSELinux
functions that form part of the object manager (these are listed in Table 12).
This tool will also allow properties to be created and display window IDs. The
following screen shot shows all the options available:
Page 98
2.22.2
Infrastructure Overview
It is important to note that the X-Windows OM operates on the low level window
objects of the X-server. A windows manager (such as Gnome or twm) would then sit
above this, however they (the windows manager or even the lower level Xlib) would
not be aware of the policy being enforced by SELinux. Therefore there can be
situations where X-Windows applications get bitter & twisted at the denial of a
service. This can result in either opening the policy more than desired, or just letting
the application keep aborting, or modifying the application.
Page 99
x_contexts
File
X-Server
XSELinux Object
Manager
(X-Extension)
Initialise extension + Atoms:
libselinux
Library
_SELINUX_CONTEXT and
_SELINUX_CLIENT_CONTEXT .
XACE interfaces
and tables such as:
Policy
User-space
AVC
XSELinuxGet/Set. Functions.
Netlink
SELinux
Security
Server
Access Vector
Cache (AVC)
Linux Security
Module (LSM)
X-Client
X-Client
------------------Xlib
X-Protocol over
TCP/IP or Streams
------------------Xlib
Function Dispatch
Table and
Resource Table
XACE Interface
User-space
Kernel Resources
and supporting
Object Managers
Kernel-space
Figure 2.24: X-Server and XSELinux Object Manager Showing the supporting services. The kernel space services are discussed in the
Linux Security Module and SELinux section.
Page 100
Polyinstantiation
Page 101
either
The source tarball has a simple 'Selection Manager' to show polyinstantiation using
the X-Windows selection30 mechanism.
Note that the current Reference Policy does not implement polyinstantiation, instead
the MLS policy uses mlsconstrain rules to limit the scope of properties and
selections.
2.22.3
Configuration Information
2.22.3.1
If the boolean is set to false, the x-server log will indicate that "SELinux: Disabled
by boolean". Important note - If the boolean is not present in a policy then the object
manager will always be enabled (therefore if not required then either do not include
the object manager in the X-server build or add the boolean to the policy and set it to
false).
2.22.3.2
The object manager is treated as an X-server extension and its major opcode can be
queried using Xlib XQueryExtension function as follows:
/* Get the SELinux Extension opcode */
if (!XQueryExtension (dpy, "SELinux", &opcode, &event, &error)) {
perror ("XSELinux extension not available");
exit (1);
}
else
printf ("XQueryExtension for XSELinux Extension - Opcode: %d
Events: %d Error: %d \n", opcode, event, error);
/* Have XSELinux Object Manager */
30
If there is no entry, the object manager will follow the current SELinux enforcement
mode.
2.22.3.4
The x_contexts file contains default context information that is required by the
OM to initialise the service and then label objects as they are created. The policy will
also need to be aware of the context information being used as it will use this to
enforce policy or transition new objects. A typical entry is as follows:
# object_type object_name context
selection
PRIMARY
system_u:object_r:clipboard_xselection_t:s0
The object_name can contain '*' for 'any' or '?' for 'substitute'.
The OM uses the selabel functions (such as selabel_lookup(3)) that are a
part of libselinux to fetch the relevant information from the x_contexts file.
The valid object_type entries are client, property, poly_property,
extension, selection, poly_selection and events.
The object_name entries can be any valid X-server resource name that is defined
in the X-server source code and can typically be found in the protocol.txt and
BuiltInAtoms source files (in the dix directory of the xorg-server source
package), or user generated via the Xlib libraries (e.g. XInternAtom).
Notes:
1. The way the XSELinux extension code works (see xselinux_label.c SELinuxAtomToSIDLookup) is that non-poly entries are searched for
first, if an entry is not found then it searches for a matching poly entry.
Page 103
object_name
*
context
system_u:object_r:remote_t:s0
A full description of the x_contexts file format is given in the x_contexts File
section.
Page 104
2.22.4
Function Name
Minor Parameters
Opcode
Comments
XSELinuxQueryVersion
None
XSELinuxSetDeviceCreateContext
Context+Len
XSELinuxGetDeviceCreateContext
None
XSELinuxSetDeviceContext
DeviceID + Context+Len Sets the context for creating the specified DeviceID object.
XSELinuxGetDeviceContext
DeviceID
XSELinuxSetWindowCreateContext
Context+Len
XSELinuxGetWindowCreateContext
None
XSELinuxGetWindowContext
WindowID
XSELinuxSetPropertyCreateContext
Context + Len
XSELinuxGetPropertyCreateContext
None
XSELinuxSetPropertyUseContext
10
Context + Len
XSELinuxGetPropertyUseContext
11
None
XSELinuxGetPropertyContext
12
WindowID + AtomID
XSELinuxGetPropertyDataContext
13
WindowID + AtomID
XSELinuxListProperties
14
WindowID
Lists the object and data contexts of properties associated with the selected
WindowID.
XSELinuxSetSelectionCreateContext
15
Context+Len
XSELinuxGetSelectionCreateContext
16
None
XSELinuxSetSelectionUseContext
17
Context+Len
XSELinuxGetSelectionUseContext
18
None
Page 105
Minor Parameters
Opcode
Comments
XSELinuxGetSelectionContext
19
AtomID
XSELinuxGetSelectionDataContext
20
AtomID
Retrieves the context of the selection data from the current selection owner
(x_application_data object).
XSELinuxListSelections
21
None
Lists the selection atom object and data contexts associated with this display. The
main difference in the listings is that when (for example) the PRIMARY selection
atom is polyinstantiated, multiple entries can returned. One has the context of the
atom itself, and one entry for each process (or x-client) that has an active
polyinstantiated entry, for example:
Atom: PRIMARY - label defined in the x_contexts file (this is also for non-poly listing):
Object Context: system_u:object_r:primary_xselection_t
Data Context:
system_u:object_r:primary_xselection_t
Atom: PRIMARY - Labels for client 1:
Object Context: system_u:object_r:x_select_paste1_t
Data Context:
system_u:object_r:x_select_paste1_t
Atom: PRIMARY - Labels for client 2:
Object Context: system_u:object_r:x_select_paste2_t
Data Context:
system_u:object_r:x_select_paste2_t
XSELinuxGetClientContext
22
ResourceID
Table 12: The XSELinux Extension Functions - Supported by the object manager as X-protocol extensions. Note that some functions will
return the default contexts, while others (2, 6, 9, 11, 16, 18) will not return a value unless one has been set the the appropriate function (1, 5, 8,
10, 15, 17) by an SELinux-aware application.
Page 106
see
There
is
also
a
good
use-case
with
solutions
at:
http://opensource.com/education/12/8/harvard-goes-paas-selinux-sandbox that
involves uploading information to web servers and access by staff and
students.
2. GUI
sandboxing
using
the
Xephyr
http://danwalsh.livejournal.com/31146.html).
(sandbox-X
see
This will allow isolation of X applications via nested Xephyr servers. For
example running:
sandbox -t sandbox_web_t -i /path/to/user/home/dir/.mozilla -W metacity -X firefox
Linux Containers do not provide a virtual machine, but a virtual environment that has its own
process and network space.
Page 107
To run in enforcing mode, the following policy module was added for the
targeted policy:
module lxc_example 1.0.0;
require {
type svirt_t, virtd_lxc_t, root_t, bin_t, proc_net_t;
type cache_home_t, user_home_t, boot_t, user_tmp_t;
class unix_stream_socket { connectto };
class chr_file { open read write ioctl getattr setattr };
class file { read write open getattr entrypoint };
class process { transition sigchld execmem };
class filesystem getattr;
}
allow
allow
allow
allow
allow
allow
allow
allow
allow
allow
allow
allow
2.24 SE-PostgreSQL
This section gives an overview of PostgreSQL version 9.1 with the sepgsql
extension to support SELinux labeling. It assumes some basic knowledge of
PostgreSQL that can be found at: http://wiki.postgresql.org/wiki/Main_Page
It is important to note that PostgreSQL from version 9.1 has the necessary
infrastructure to support labeling of database objects via external 'providers'. The
sepgsql extension has been added as the SELinux labeling provider. This is not
installed by default but as an option as outlined in the sections that follow. Because of
these changes the original version 9.0 patches are no longer supported (i.e. the SEPostgreSQL database engine is replaced by PostgreSQL database engine 9.1 plus the
Page 108
2.24.1
Notebook Examples
2.24.2
sepgsql Overview
Page 109
schema (db_schema)
security_label = 'unconfined_u:object_r:sepgsql_schema_t:s10'
table (db_table)
security_label = 'unconfined_u:object_r:sepgsql_table_t:s0:c20'
column 1 (db_column)
column 2 (db_column)
security_label =
'unconfined_u:object_r:sep
gsql_table_t:s0:c30'
security_label =
'unconfined_u:object_r:se
pgsql_table_t:s0:c40'
r1:c1 data
r1:c2 data
r2:c1 data
r2:c2 data
r3:c1 data
r3:c2 data
row 1 (db_tuple)
security_label =
'unconfined_u:object_r:sepg
sql_table_t:s0:c100'
row 2 (db_tuple)
security_label =
'unconfined_u:object_r:sepg
sql_table_t:s0:c110'
row 3 (db_tuple)
security_label =
'unconfined_u:object_r:sepg
sql_table_t:s0:c120'
Page 110
Database Client
(e.g. psql)
SQL Query /
Results
Database
(filestore)
SQL Engine
SE-PostgreSQL
Object Manager
Check
P ermissions
(sepgsql extension)
libselinux
Kernel
Resources
LSM
Kernel AVC
Security
Server
SELinux
Policy
2.24.3
Installing SE-PostgreSQL
Page 111
Page 112
2.24.4
The 'SECURITY LABEL' SQL command has been added to PostgreSQL to allow
security providers to label or change a label on database objects. The command
format is:
SECURITY LABEL [ FOR provider ] ON
{
TABLE object_name |
COLUMN table_name.column_name |
AGGREGATE agg_name (agg_type [, ...] ) |
DATABASE object_name |
DOMAIN object_name |
EVENT TRIGGER object_name |
FOREIGN TABLE object_name
FUNCTION function_name ( [ [ argmode ] [ argname ] argtype
[, ...] ] ) |
LARGE OBJECT large_object_oid |
[ PROCEDURAL ] LANGUAGE object_name |
ROLE object_name |
SCHEMA object_name |
SEQUENCE object_name |
TABLESPACE object_name |
TYPE object_name |
VIEW object_name
} IS 'label'
The full syntax is defined at http://www.postgresql.org/docs/devel/static/sql-securitylabel.html and also in the security_label(7) man page. Some examples taken
from the Notebook tarball are:
--- These set the security label on objects (default provider
--- is SELinux):
SECURITY LABEL ON SCHEMA test_ns IS
'unconfined_u:object_r:sepgsql_schema_t:s0:c10';
SECURITY LABEL ON TABLE test_ns.info IS
'unconfined_u:object_r:sepgsql_table_t:s0:c20';
SECURITY LABEL ON COLUMN test_ns.info.user_name IS
'unconfined_u:object_r:sepgsql_table_t:s0:c30';
SECURITY LABEL ON COLUMN test_ns.info.email_addr IS
'unconfined_u:object_r:sepgsql_table_t:s0:c40';
2.24.5
sepgsql_mcstrans_in(text
con)
Page 113
2.24.6
for
supporting
The postgresql.conf file supports the following additional entries to enable and
manage SE-PostgreSQL:
1. This entry is mandatory to enable the sepgsql extention to be loaded:
shared_preload_libraries = sepgsql
2. These
entries
are
optional
and
default
to
'off'.
The
'custom_variable_classes' entry must contain 'sepgsql' to enable
these to be configured.
# This entry allows sepgsql customised entries:
custom_variable_classes = sepgsql
# These are the possible entries:
# This enables sepgsql to always run in permissive mode:
sepgsql.permissive = on
# This enables printing of audit messages regardless of
# the policy setting:
sepgsql.debug_audit = on
To view these settings the SHOW SQL statement can be used (psql output
shown):
SHOW sepgsql.permissive;
sepgsql.permissive
--------------on
(1 row)
SHOW sepgsql.debug_audit;
sepgsql.debug_audit
--------------on
(1 row)
Page 114
2.24.7
SE-PostgreSQL manages its own AVC audit entries in the standard PostgreSQL log
normally located within the /var/lib/pgsql/data/pg_log directory and by
default only errors are logged (Note that there are no SE-PostgreSQL AVC entries
added to the standard audit.log). The 'sepgsql.debug_audit = on' can be
set to log all audit events.
2.24.8
Internal Tables
To support the overall database operation PostgreSQL has internal tables in the
system catalog that hold information relating to user databases, tables etc. This section
will only highlight the pg_seclabel table that holds the security label and other
references. The pg_seclabel is described in Table 13 that has been taken from
http://www.postgresql.org/docs/9.1/static/catalog-pg-seclabel.html.
Name
Type
References
Comment
objoid
oid
classoid
oid
pg_class.oid
objsubid int4
provider text
label
text
The first entry is the schema, the second entry is the table itself, and the third and
fourth entries are columns 1 and 2.
There is also a built-in 'view' to show additional detail regarding security labels called
'pg_seclabels'. Using 'SELECT * FROM pg_seclabels;' command, the
entries shown above become:
objoid | classoid | objsubid | objtype | objnamespace | objname
| provider |
label
-------+----------+----------+-----------+--------------+------------------------+----------+---------------------------------------------16390 |
2615 |
0 | schema
|
16390 | test_ns
| selinux | unconfined_u:object_r:sepgsql_schema_t:s0:c10
16391 |
1259 |
0 | table
|
16390 | test_ns.info
| selinux | unconfined_u:object_r:sepgsql_table_t:s0:c20
16391 |
1259 |
1 | column
|
16390 | test_ns.info.user_name | selinux | unconfined_u:object_r:sepgsql_table_t:s0:c30
16391 |
1259 |
2 | column
|
16390 | test_ns.info.email_addr| selinux | unconfined_u:object_r:sepgsql_table_t:s0:c40
Page 115
The A secure web application platform powered by SELinux [Ref. 20] document
gives a good overview of the LAPP architecture.
2.25.1
mod_selinux Overview
What the mod_selinux module achieves is to allow a web application (or a 'request
handler') to be launched by Apache with a security context based on policy rather than
that of the web server process itself, for example:
1. A user sends an HTTP request to Apache that requires the services of a web
application (Apache may or may not apply HTTP authentication).
2. Apache receives the request and launches the web application instance to
perform the task:
32
This is similar to the LAMP (Linux, Apache, MySQL, PHP/Perl/Python) stack, however MySQL
is not SELinux-aware.
Page 116
2.25.2
Bounds Overview
Because multiple threads share the same memory segment, SELinux was unable to
check the information flows between these different threads when using setcon(3)
in pre 2.6.28 kernels. This meant that if a thread (the parent) should launch another
thread (a child) with a different security context, SELinux could not enforce the
different permissions.
To resolve this issue the typebounds statement was introduced with kernel support
in 2.6.28 that stops a child thread (the 'bounded domain') having greater privileges
than the parent thread (the 'bounding domain') i.e. the child thread must have equal or
less permissions than the parent.
For example the following typebounds statement and allow rules:
#
parent | child
#
domain | domain
typebounds httpd_t
httpd_child_t;
allow httpd_t
etc_t : file { getattr read };
allow httpd_child_t etc_t : file { read write };
State that the parent domain (httpd_t) has file : { getattr read }
permissions. However the child domain (httpd_child_t) has been given
file : { read write }. At run-time, this would not be allowed by the kernel
because the parent does not have write permission, thus ensuring the child domain
will always have equal or less privileges than the parent.
When setcon(3) is used to set a different context on a new thread without an
associated typebounds policy statement, then the call will return 'Operation not
permitted' and an SELINUX_ERR entry will be added to the audit log stating
'op=security_bounded_transition result=denied' with the old and
new context strings.
Should there be a valid typebounds policy statement and the child domain
exercises a privilege greater that that of the parent domain, the operation will be
denied and an SELINUX_ERR entry will be added to the audit log stating
33
It is also possible to obtain the domain from a PostgreSQL table (this is how the demo in the
Notebook tarball obtains the context).
Page 117
Notebook Examples
The Notebook source tarball contains two demonstrations using setcon(3) with
threads and how the typebounds statement is used to allow a thread to be executed.
These are located in the libselinux/examples directory and are:
a) setcon_thread1_example.c - this example calls setcon in the main
process loop but also starts a thread. If the setcon_example.conf policy
module
has
been
been
loaded
and
a
context
of
"unconfined_u:unconfined_r:user_t:s0" selected, then an error message
should be displayed as follows:
setcon_raw - ERROR: Operation not permitted
This is because the setcon function cannot be run in a threaded environment
without
a
typebounds
statement.
Now
load
the
setcon_thread_example.conf policy module and then re-run the
example, it should now complete without error.
b) setcon_thread2_example.c - this functions as example 1, however it
calls setcon from a thread.
Page 118
Introduction
This section explains each SELinux configuration file with its format, example
content and where applicable, any supporting SELinux commands or libselinux
library API function names.
Where configuration files have specific man pages, these are noted by adding the man
page section (e.g. semanage.config(5)).
This Notebook classifies the types of configuration file used in SELinux as follows:
1. Global Configuration files that affect the active policy and their supporting
SELinux-aware applications, utilities or commands. These can be located in
/etc/selinux or other places depending on the application. This
Notebook will only refer to the commonly used configuration files.
2. Files specific to a named policy configuration. These are located at
/etc/selinux/<SELINUXTYPE> for the run time configuration and
/var/lib/selinux/<SELINUXTYPE> for the run time policy store
(although on some systems the policy store files may still be located at
/etc/selinux/<SELINUXTYPE>/modules).
These two areas are described as follows:
a. The Policy Store Configuration files are private34 and managed by
the semanage(8) and semodule(8) commands35. These are used
to build the majority of the Policy Configuration files.
b. The Policy Configuration files that are used when the policy is
activated.
However note that there can be multiple named policy configuration areas on a
system.
3. SELinux Kernel Configuration files located under the /sys/fs/selinux
directory and reflect the current configuration of SELinux and the active
policy. This area is used extensively by the libselinux library for
userspace object managers and other SELinux-aware applications. These files
and directories should not be updated by users (the majority are read only
anyway), however they can be read to check various configuration parameters.
When these configuration files are used to configure a security context with a policy
that supports MCS / MLS, then the appropriate level or range should be added
(generally an object like a file has a single level, and process (a subject) has a
single level or a range, although directories can have a range if they support
polyinstantiation).
34
35
Page 119
3.2
Listed in the sections that follow are the common configuration files used by SELinux
and are therefore not policy specific.
Where:
SELINUX
SELINUXTYPE
SETLOCALDEFS
Page 120
AUTORELABEL
Page 121
Where:
module-store
source
libsemanage manipulates a
source SELinux policy.
/foo/bar
expand-check
file-mode
Page 122
save-linked
disablegenhomedircon
handle-unknown
bzip-blocksize
bzip-small
usepasswd
Page 123
target-platform
mls
[verify kernel]
Page 124
3.2.4
/etc/selinux/newrole_pam.conf
The daemon uses functions in libselinux such as matchpathcon(3) to manage the context
updates.
Page 125
Page 126
3.3
Because there can be multiple policy stores on a system, each file discussed in this
section is relative to the policy name as follows:
/var/lib/selinux/<policy_name>
The Policy Store files in the /var/lib/selinux/<policy_name>/modules
area are either installed, updated or built by the semodule(8) and semanage(8)
commands, and as a part of the process, relevant files are copied to the Policy
Configuration files area.
The files present in each <policy_name> policy store will vary from policy to
policy as different items could be configured for each one.
Generally if a file has the extension .local, then it has been generated by
semanage and used to update the binary policy located at
/etc/selinux/<policy_name>/policy.
All files can have comments inserted where each line must have the # symbol to
indicate the start of a comment.
Page 127
the
policies
The way these two files are built is as follows (and shown in Figure 3.1):
homedir_template - Any line in the file_contexts.template file
that has the keywords HOME_ROOT or HOME_DIR are extracted and added to the
homedir_template file. This is because these keywords are used to identify
entries that are associated to a users home directory area. These lines can also
have the ROLE keyword declared.
The homedir_template file will then be used by genhomedircon(8)37 to
generate individual SELinux user entries in the file_contexts.homedirs
file as discussed in the ./modules/active/file_contexts.homedirs
section.
file_contexts - All other lines are extracted and added to the
file_contexts file as they are files not associated to a users home directory.
37
The genhomedircon command has now been built into the libsemanage library as a
function to build the file_contexts.homedirs file via semanage(8).
Page 128
file_contexts
genhomedircon
file_contexts.
homedirs
Figure 3.1: File Context Configuration Files - The two files copied to the policy
area will be used by the file labeling utilities to relabel files.
The format of the file_contexts.template file is as follows:
Each line within the file consists of either type of entry:
pathname_regexp opt_security_context
Or
pathname_regexp file_type opt_security_context
Where:
pathname_regexp
file_type
-b - Block Device
-c - Character Device
-d - Directory
-p - Named Pipe
-l - Symbolic Link
-s - Socket
-- - Ordinary file
b.
HOME_DIR
ROLE
It is used for files and directories within the users home directory
area when relabeling takes place to allow the domain context to be
based on a specific role (or any identifier !!) to allow easier
identification in log files.
It can be added by the semanage user command as follows:
# Add prefix for SELinux user:
semanage user a R staff_r P group1 group1_u
# Add login user:
semanage login a s group1_u rch
The
usage
is
similar
to
the
Reference
Policy
per_role_template (<param name="userdomain_prefix">) that
is an optional component of the external interface file (see the
ftp.if or ssh.if files in the Reference Policy source).
USER
This keyword will be replaced by the users GNU / Linux user id.
Page 130
/.*
/a?quota\.(user|group) -/xen(/.*)?
/dev/mcdx?
-b
HOME_DIR/.+
/var/log/.*
/tmp/gconfd-USER/.*
-/var/log/sxid\.log.*
-/var/log/messages[^/]*
/var/run/wnn-unix(/.*)
HOME_DIR/\.ircmotd
-HOME_ROOT/lost\+found/.*
HOME_DIR/\.config/gtk-.*
system_u:object_r:default_t
system_u:object_r:quota_db_t
system_u:object_r:xen_image_t
system_u:object_r:removable_device_t
system_u:object_r:user_home_t
system_u:object_r:var_log_t
system_u:object_r:gconf_tmp_t
system_u:object_r:sxid_log_t
system_u:object_r:var_log_t
system_u:object_r:canna_var_run_t
system_u:object_r:ROLE_irc_home_t
<<none>>
system_u:object_r:gnome_home_t
same
as
the
The USER keyword is replaced by the users GNU / Linux user id when the file
labeling utilities are run.
Example file_contexts contents:
#
#
#
#
#
#
/.*
/a?quota\.(user|group)
/xen(/.*)?
/dev/mcdx?
/var/log/.*
/tmp/gconfd-USER/.*
/var/log/sxid\.log.*
/var/log/messages[^/]*
/var/run/wnn-unix(/.*)
system_u:object_r:default_t
-- system_u:object_r:quota_db_t
system_u:object_r:xen_image_t
-b system_u:object_r:removable_device_t
system_u:object_r:var_log_t
-- system_u:object_r:gconf_tmp_t
-- system_u:object_r:sxid_log_t
system_u:object_r:var_log_t
system_u:object_r:canna_var_run_t
Page 131
system_u:object_r:default_t:s0
-- system_u:object_r:quota_db_t:s0
-l system_u:object_r:mnt_t:s0
<<none>>
-c system_u:object_r:mouse_device_t:s0
-c system_u:object_r:tty_device_t:s0
-b system_u:object_r:fixed_disk_device_t:s15:c0.c255
system_u:object_r:xserver_log_t:s0
-c system_u:object_r:fixed_disk_device_t:s15:c0.c255
-d system_u:object_r:tmp_t:s0-s15:c0.c255
-d system_u:object_r:devpts_t:s0-s15:c0.c255
-d system_u:object_r:var_log_t:s0-s15:c0.c255
-d system_u:object_r:tmp_t:s0-s15:c0.c255
-d system_u:object_r:var_run_t:s0-s15:c0.c255
-d system_u:object_r:tmp_t:s0-s15:c0.c255
format
as
the
HOME_DIR/.+
HOME_DIR/\.ircmotd
-HOME_ROOT/lost\+found/.*
HOME_DIR/\.config/gtk-.*
system_u:object_r:user_home_t
system_u:object_r:ROLE_irc_home_t
<<none>>
system_u:object_r:gnome_home_t
Page 132
#
# User-specific file contexts, generated via libsemanage
# use semanage command to manage system users to change the file_context
#
# Home Context for user user_u
/home/.+
system_u:object_r:user_home_t
/home/\.ircmotd
-- system_u:object_r:user_irc_home_t
/home/lost\+found/.*
<<none>>
/home/\.config/gtk-.*
system_u:object_r:gnome_home_t
# Home Context for user root
/root/.+
system_u:object_r:user_home_t
/root/\.ircmotd
-- system_u:object_r:user_irc_home_t
/root/lost\+found/.*
<<none>>
/root/\.config/gtk-.*
system_u:object_r:gnome_home_t
38
This uses SECMARK labeling that has been utilised by SELinux as described in the SELinux
Networking Support section.
Page 133
3.3.10
modules/active/policy.kern File
This is the binary policy file built by either the semanage(8) or semodule(8)
commands (depending on the configuration action), that is then becomes the
./policy/policy.[ver] binary policy that will be loaded into the kernel.
3.3.11
The seusers.final file maps GNU / Linux users to SELinux users and becomes
the policies seusers39 file as discussed in the ./seusers section. The
seusers.final file is built or modified when:
1. Building a policy where an optional seusers file has been included in the
base package via the semodule_package(8) command (signified by the
s flag) as follows40:
semodule_package -o base.pp -m base.mod s seusers ...
This action will update the seusers file that would then be used to produce
the seusers.final file with both policy and locally defined user mapping.
It is also possible to associate a GNU / Linux group of users to an SELinux
user as follows:
semanage login -a s staff_u %staff_group
Where:
user_id
seuser_id
range
39
40
The Reference Policy Makefile Rules.modular script uses this method to install the initial
seusers file.
Page 134
Page 135
show
example
Execute an semanage user command that will add a new SELinux user
and associated prefix, and show the resulting users_extra,
users_extra.local and users.local files.
users_extra
and
Note that each line of the users.local file contains a user statement that
is defined in the policy language user Statement section, and will be built
into the policy via the semanage command.
41
The Reference Policy Makefile Rules.modular script uses this method to install the initial
users_extra file.
Page 136
Where:
user
seuser_id
prefix
prefix_id
user_u
staff_u
sysadm_u
root
test_u
prefix
prefix
prefix
prefix
prefix
user;
user;
user;
user;
staff;
Page 137
3.3.13
modules/active/booleans.local File
This file is created and updated by the semanage boolean command and holds
boolean value as requested. It should be noted that instead of using this file, the
command allows a different file to be specified (see semanage(8)).
Example semanage boolean command to modify a boolean value:
# This command will add an entry in the booleans.local
# file and set the boolean value to 'off':
semanage boolean m -0 ext_gateway_audit
3.3.14
modules/active/file_contexts.local File
This file is created and updated by the semanage fcontext command. It is used
to hold file context information on files and directories that were not delivered by the
core policy (i.e. they are not defined in any of the *.fc files delivered in the base and
loadable modules).
The semanage command will add the information to the policy stores
file_contexts.local file
and then
copy this
file
to the
./contexts/files/file_contexts.local file, where it will be used when
the file context utilities are run.
The format of the file_contexts.local file is the same as the
./modules/active/file_contexts.template file.
Example semanage fcontext command to add a new entry:
# This command will add an entry in the file_contexts.local
# file:
semanage fcontext a t user_t /usr/move_file
# Note that the type (-t flag) must exist in the policy
# otherwise the command will fail.
Page 138
3.3.15
system_u:object_r:user_t
modules/active/interfaces.local File
This file is created and updated by the semanage interface command to hold
network interface information that was not delivered by the core policy (i.e. they are
not defined in base.conf file). The new interface information is then built into the
policy by the semanage(8) command.
Each line of the file contains a netifcon statement that is defined along with
examples in the netifcon Statement section.
3.3.16
modules/active/nodes.local File
This file is created and updated by the semanage node command to hold network
address information that was not delivered by the core policy (i.e. they are not defined
in base.conf file). The new node information is then built into the policy by the
semanage(8) command.
Each line of the file contains a nodecon statement that is defined along with
examples in the policy language nodecon Statement section.
3.3.17
modules/active/ports.local File
This file is created and updated by the semanage port command to hold network
port information that was not delivered by the core policy (i.e. they are not defined in
base.conf file). The new port information is then built into the policy by the
semanage(8) command.
Each line of the file contains a portcon statement that is defined along with
examples in the policy language portcon Statement section.
3.3.18
Page 139
3.4
1.1.0
1.1.0
1.1.0
1.0.0
Disabled
Each file discussed in this section is relative to the policy name as follows:
/etc/selinux/<policy_name>
The majority of files are installed by the Reference Policy, semanage(8) or
semanage(8) commands. It is possible to build custom monolithic policies that
only use the files installed in this area (i.e. do not use semanage or semodule).
For example the simple monolithic policy described in the Notebook source tarball
could run at init 3 (i.e. no X-Windows) and only require the following
configuration files:
./policy/policy.26 The binary policy loaded into the kernel.
./context/files/file_contexts To allow the filesystem to be
relabeled.
If the simple policy is to run at init 5, (i.e. with X-Windows) then an additional
two files are required:
./context/dbus_contexts To allow the dbus messaging service to run
under SELinux.
./context/x_contexts To allow the X-Windows service to run under
SELinux.
Using the GNU / Linux user_id, lookup the seuser_id from this file. If
an entry cannot be found, then use the __default__ entry.
To determine the remaining context to be used as the security context, read the
./contexts/users/[seuser_id] file. If this file is not present, then:
Check
for
a
default
context
in
the
./contexts/default_contexts file. If no default context is
found, then:
Page 140
or
Both files have the same format and contain one or more boolean names. The format
is:
boolean_name value
Where:
boolean_name
value
new_name
Where:
policy_bool_name
The policy boolean name.
new_name
The new boolean name.
Example:
# ./booleans.subs
# policy_boll_name
allow_auditadm_exec_content
allow_console_login
allow_cvs_read_shadow
allow_daemons_dump_core
new_name
auditadm_exec_content
login_console_enabled
cvs_read_shadow
daemons_dump_core
When
security_get_boolean_names(3)
or
security_set_boolean(3) is called with a boolean name and the subs file is
present, the name will be looked up and if using the new_name, then the
policy_bool_name will be used (as that is what is defined in the active policy).
Supporting libselinux API functions are:
selinux_booleans_subs_path
security_get_boolean_names
security_set_boolean
Page 142
Page 143
Page 144
Where:
color
color_name
color_mask
context_component
string
fg_color_name
Page 145
black = #000000
green = #008000
yellow = #ffff00
blue = #0000ff
white = #ffffff
red = #ff0000
orange = #ffa500
tan = #D2B48C
= black green
= white green
= black tan
= white blue
= black red
= black orange
black yellow
Page 146
Where:
type
Page 147
Where:
role:type
range
system_r:system_crond_t:s0
user_r:user_t:s0
user_r:user_t:s0
user_r:user_t:s0
sysadm_r:sysadm_t:s0
user_r:user_t:s0
Page 148
An example use in this Notebook (to get over a small feature) is that when the initial
basic policy was built, no default_contexts file entries were required as only
one role:type of unconfined_r:unconfined_t had been defined,
therefore the login process did not need to decide anything (as the only user context
was unconfined_u:unconfined_r:unconfined_t).
However when adding the loadable module that used another type
(ext_gateway_t)
but
with
the
same
role
and
user
(e.g.
unconfined_u:unconfined_r:ext_gateway_t), then it was found that the
login process would always set the logged in user context to
unconfined_u:unconfined_r:ext_gateway_t (i.e. the login application
now had a choice and choose the wrong one, probably because the types are sorted
and e comes before u).
The end result was that as soon as enforcing mode was set, the system got bitter and
twisted. To resolve this the default_contexts file entries were set to:
unconfined_r:unconfined_t
unconfined_r:unconfined_t
The
login
process
could
now
set
the
context
correctly
to
unconfined_r:unconfined_t. Note that adding the same entry to the
contexts/users/unconfined_u configuration file instead could also have
achieved this.
Page 149
3.4.10
contexts/default_type File
Where:
role:type
3.4.11
contexts/failsafe_context File
Where:
role:type[:range]
Page 150
3.4.12
contexts/initrc_context File
Where:
security_context The file contains one line that consists of a full
security context, including the MLS / MCS level or
range if applicable.
Example file contents:
# ./contexts/initrc_context - Taken from the standard reference
# policy.
system_u:system_r:initrc_t
# ./contexts/initrc_context - Taken from the MLS reference
# policy. Note that the init process has full access via the
# range s0-s15:c0.c255.
system_u:system_r:initrc_t:s0-s15:c0.c255
Page 151
3.4.13
contexts/netfilter_contexts File
This file will support the Secmark labeling for Netfilter / iptable rule matching of
network
packets,
however
it
is
currently
unused
(see
the
./modules/active/netfilter_contexts & netfilter.local file
section for further information).
Supporting libselinux API functions are:
selinux_context_path
selinux_netfilter_context_path
3.4.14
contexts/removable_context File
Where:
security_context The file contains one line that consists of a full
security context, including the MLS / MCS level or
range if applicable.
Example file contents:
# ./contexts/removable_contexts - Taken from the standard
# reference policy.
system_u:object_r:removable_t
# ./contexts/removable_contexts - Taken from the MLS/MCS
# reference policy.
system_u:object_r:removable_t:s0
3.4.15
contexts/securetty_types File
Where:
type
Zero or more type entries that are defined in the policy for
tty devices.
object_name
context
Where:
object_type
object_name
Page 153
3.4.17
object_name
my_database
*
*.*
context
system_u:object_r:my_sepgsql_db_t:s0
system_u:object_r:sepgsql_db_t:s0
system_u:object_r:sepgsql_schema_t:s0
contexts/userhelper_context File
This file contains the default security context used by the system-config-*
applications when running from root.
The file format is as follows:
security_context
Where:
security_context The file contains one line that consists of a full
security context, including the MLS / MCS level or
range if applicable.
Example file contents:
# ./contexts/userhelper_context - Taken from the standard
# reference policy.
system_u:sysadm_r:sysadm_t
# ./contexts/userhelper_context - Taken from the MLS/MCS
# reference policy.
system_u:sysadm_r:sysadm_t:s0
3.4.18
contexts/virtual_domain_context File
Page 154
3.4.19
contexts/virtual_image_context File
3.4.20
contexts/x_contexts File
The x_contexts(5) file provides the default security contexts for the X-Windows
SELinux security extension. The usage is discussed in the X-windows SELinux
Support section and examples of how to add additional entries is shown in the XWindows section of the Notebook source tarball. The MCS / MLS version of the file
has the appropriate level or range information added.
A typical entry is as follows:
# object_type object_name
selection
PRIMARY
context
system_u:object_r:clipboard_xselection_t
Where:
object_type
Page 155
context
Page 156
system_u:object_r:client_xevent_t
system_u:object_r:client_xevent_t
system_u:object_r:client_xevent_t
system_u:object_r:client_xevent_t
system_u:object_r:xevent_t
3.4.21
contexts/files/file_contexts File
42
As each module would have its own file_contexts component that is either added or
removed from the policies overall /etc/selinux/[policy_name]/contexts/
files/file_contexts file.
Page 157
3.4.22
contexts/files/file_contexts.local File
3.4.23
contexts/files/file_contexts.homedirs File
Page 158
3.4.25
contexts/files/media File
The media(5) file is used to map media types to a file context. If the media_id
cannot be found in this file, then the default context in the
./contexts/removable_contexts is used instead.
The file format is as follows:
media_id file_context
Where:
media_id
file_context
3.4.26
contexts/users/[seuser_id] File
These optional files are named after the SELinux user they represent (e.g.
seuser_id = user_u). Each file has the same format as the
contexts/default_contexts file and is used to assign the correct context to
the SELinux user (generally during login). The user_contexts(5) man page
also decribes these entries.
Example file contents:
# ./contexts/users/user_u - Taken from the standard reference
# policy.
Page 159
system_r:local_login_t
system_r:remote_login_t
system_r:sshd_t
system_r:crond_t
user_r:user_t
user_r:user_t
user_r:user_t
user_r:user_t
user_r:user_t:s0
user_r:user_t:s0
user_r:user_t:s0
user_r:user_t:s0
user_r:user_t:s0
user_r:user_t:s0
user_r:user_t:s0
3.4.27
logins/<linuxuser_id> File
These optional files are used by SELinux-aware login applications such as PAM
(using the pam_selinux module) to obtain an SELinux user name and level based
on the GNU / Linux login id and service name. It has been implemented for SELinuxaware applications such as FreeIPA (Identity, Policy Audit - see
http://freeipa.org/page/Main_Page for details). The service_seusers(5) man
page also decribes these entries.
The file name is based on the GNU/Linux user that is used at log in time (e.g. ipa).
If getseuser(3) fails to find an entry, then the seusers file is used to retrieve
default information.
The file format is as follows:
service_name:seuser_id:level
Where:
service_name
seuser_id
level
Page 160
3.4.28
users/local.users File
Page 161
Introduction
The Notebook tarball contains CIL language examples that will compile as explained
in the Notebook Example Policy section.
Current
allow
allow
roleallow
allow (role)
dominance
dominance
roledominance
dominance (role)
roletransition
role_transition
b) Additional CIL statements have been defined to allow clarity, for example:
typeattributeset
classpermissionset
classmap
classmapping
43
From the resulting base.conf and loadable module sources in the ./tmp directory after a
make load had been executed for a reference policy standard build and where applicable an
mls build.
Page 162
blockinherit.cil
Need to include the cil-base.cil module when building this example to declare
the user, role, type and range.
This example defines three nested blocks each declaring a different class
with two permissions and an allow rule. Three new namespaces are then created
and the respective levels (1, 2, 3) are then inherited by each new namespace.
Using APOL, sedispol or sesearch 9 allow rules will be found:
Page 163
Three
allow
allow
allow
;
;
;
;
;
{
Three allow rules from the new_namespace1 that inherited the three nested blocks:
allow new_namespace1.level1_t new_namespace1.level1_t : new_namespace1.file { open execute } ;
allow new_namespace1.level2.level2_t new_namespace1.level2.level2_t : new_namespace1.level2.socket { recv_msg send_msg }
allow new_namespace1.level2.level3.level3_t new_namespace1.level2.level3.level3_t : new_namespace1.level2.level3.ipc
create destroy } ;
; Two allow rules from the new_namespace2 that inherited the two lower nested blocks:
; allow new_namespace2.level2_t new_namespace2.level2_t : new_namespace2.socket { recv_msg send_msg } ;
; allow new_namespace2.level3.level3_t new_namespace2.level3.level3_t : new_namespace2.level3.ipc { create destroy } ;
; One allow rule from the new_namespace3 that inherited the last nested block:
; allow new_namespace3.level3_t new_namespace3.level3_t : new_namespace3.ipc { create destroy } ;
(block level1
(type level1_t)
(class file (open execute))
(allow level1_t self (file (open execute)))
(block level2
(type level2_t)
(class socket (recv_msg send_msg))
(allow level2_t self (socket (recv_msg send_msg)))
(block level3
(type level3_t)
(class ipc (create destroy))
(allow level3_t self (ipc (create destroy)))
) ; End level3 block
) ; End level2 block
) ; End level1 block
(block new_namespace1
(blockinherit level1)
) ; End new_namespace1 namespace
(block new_namespace2
(blockinherit level1.level2)
) ; End new_namespace2 namespace
(block new_namespace3
(blockinherit level1.level2.level3)
) ; End new_namespace3 namespace
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Page 164
g) Directly generate the binary policy file and other configuration files - currently
the file_contexts file.
h) Support transformation services such as delete, transform and inherit with
except.
4.2
45
It is important to note that the Reference Policy, builds policy using makefiles and support macros
within its own source file structure. However, the end result of the make process is that there can
be three possible types of source file built (depending on the MONOLITHIC=Y/N build option).
These files contain the policy language statements and rules that are finally complied into a binary
policy.
This does not include the file_contexts file as it does not contain policy statements, only
default security contexts (labels) that will be used by files and directories.
Page 165
M/O
m
Module Entries
module Statement
M/O
o
Initial SIDs
Access Vectors
(permissions)
MLS sensitivity, category
and level Statements
MLS Constraints
m
m
require Statement
Policy Capability
Statements
Attributes
Booleans
o
o
Attributes
Booleans
o
o
m
m
o
o
Policy Rules
Users
o
m
Policy Rules
Users
o
o
Constraints
Default SID labeling
fs_use_xattr
Statements
o
m
fs_use_task and
fs_use_trans
Statements
genfscon Statements
o
o
Table 14: Base and Module Policy Statements A Monolithic source file would
contain the same statements as the Base Module. The Mandatory policy entries are
noted (the type, role and user require at least one entry each).
The language grammar defines what statements and rules can be used within the
different types of source file. To highlight these rules, the following table is included
in each statement and rule section to show what circumstances each one is valid
within a policy source file:
Page 166
Base Policy
Module Policy
Yes/No
Yes/No
Yes/No
Where:
Monolithic Policy
Base Policy
Module Policy
Table 16 shows a cross reference matrix of statements and rules allowed in each type
of policy source file.
optional Statement
require Statement
Yes/No
Yes/No
Yes/No
Where:
Conditional Policy
(if) Statement
optional Statement
require Statement
Table 16 shows a cross reference matrix of statements and rules allowed in each of
the above policy statements.
Page 167
Therefore when comparing the actual source code with a compiled binary using
(for example) apol(8), sedispol or sedismod, the results will differ
(however the resulting policy rules will be the same).
5. Some statements can be added to a policy (via the policy store) using the
semanage(8) command. Examples of these are shown where applicable,
however the semanage man page should be consulted for all the possible
command line options.
6. Table 15 lists words reserved for the SELinux policy language.
alias
allow
and
attribute
attribute_role
auditallow
auditdeny
bool
category
cfalse
class
clone
common
constrain
ctrue
dom
domby
dominance
dontaudit
else
equals
false
filename
filesystem
fscon
fs_use_task
fs_use_trans
fs_use_xattr
genfscon
h1
h2
identifier
if
incomp
inherits
iomemcon
Page 168
ipv4_addr
ipv6_addr
l1
l2
level
mlsconstrain
mlsvalidatetrans
module
netifcon
neverallow
nodecon
not
notequal
number
object_r
optional
or
path
pcidevicecon
permissive
pirqcon
policycap
portcon
r1
r2
r3
range
range_transition
require
role
roleattribute
roles
role_transition
sameuser
sensitivity
sid
source
t1
t2
t3
target
true
type
typealias
typeattribute
typebounds
type_change
type_member
types
type_transition
u1
u2
u3
user
validatetrans
version_identifier
xor
default_user
default_role
default_type
default_range
low
high
low_high
Base
Policy
Module
Policy
Conditional
Statements
optional
Statement
require
Statement46
allow
Yes
Yes
Yes
Yes
Yes
No
allow - Role
Yes
Yes
Yes
No
Yes
No
attribute
Yes
Yes
Yes
No
Yes
Yes
attribute_role
Yes
Yes
Yes
No
Yes
Yes
auditallow
Yes
Yes
Yes
Yes
Yes
No
auditdeny
Yes
Yes
Yes
Yes
Yes
No
bool
Yes
Yes
Yes
No
Yes
Yes
category
Yes
Yes
No
No
No
Yes
class
Yes
Yes
No
No
No
Yes
common
Yes
Yes
No
No
No
No
constrain
Yes
Yes
No
No
No
No
Statement / Rule
(Deprecated)
46
Page 169
Monolithic
Policy
Base
Policy
Module
Policy
Conditional
Statements
optional
Statement
require
Statement
default_user
Yes
Yes
No
No
No
No
default_role
Yes
Yes
No
No
No
No
default_type
Yes
Yes
No
No
No
No
default_range
Yes
Yes
No
No
No
No
dominance - MLS
Yes
Yes
No
No
No
No
dominance - Role
Yes
Yes
Yes
No
Yes
No
dontaudit
Yes
Yes
Yes
Yes
Yes
No
fs_use_task
Yes
Yes
No
No
No
No
fs_use_trans
Yes
Yes
No
No
No
No
fs_use_xattr
Yes
Yes
No
No
No
No
genfscon
Yes
Yes
No
No
No
No
if
Yes
Yes
Yes
No
Yes
No
level
Yes
Yes
No
No
No
No
mlsconstrain
Yes
Yes
No
No
No
No
mlsvalidatetrans
Yes
Yes
No
No
No
No
module
No
No
Yes
No
No
No
netifcon
Yes
Yes
No
No
No
No
No
Yes
No
(Deprecated)
neverallow
Yes
Yes
Yes
nodecon
Yes
Yes
No
No
No
No
optional
No
Yes
Yes
Yes
Yes
Yes
permissive
Yes
Yes
Yes
Yes
Yes
No
policycap
Yes
Yes
No
No
No
No
portcon
Yes
Yes
No
No
No
No
range_transition
Yes
Yes
Yes
No
Yes
No
Yes
No
require
No
Yes
role
Yes
roleattribute
48
47
49
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
No
Yes
No
role_transition
Yes
Yes
Yes
No
Yes
No
sensitivity
Yes
Yes
No
No
No
Yes
sid
Yes
Yes
No
No
No
No
type
Yes
Yes
Yes
No
No
Yes
type_change
Yes
Yes
Yes
Yes
Yes
No
type_member
Yes
Yes
Yes
Yes
Yes
No
Yes
No
type_transition
Yes
Yes
Yes
Yes
typealias
Yes
Yes
Yes
No
Yes
No
typeattribute
Yes
Yes
Yes
No
Yes
No
50
47
neverallow statements are allowed in modules, however to detect these the semanage.conf
file must have the expand-check=1 entry present.
48
49
50
Page 170
Base
Policy
Module
Policy
Conditional
Statements
optional
Statement
require
Statement
typebounds
Yes
Yes
Yes
No
Yes
No
user
Yes
Yes
Yes
No
Yes
Yes
validatetrans
Yes
Yes
No
No
No
No
Statement / Rule
Table 16: The policy language statements and rules that are allowed within each
type of policy source file - The left hand side of the table shows what Policy
Language Statements and Rules are allowed within each type of policy source file.
The right hand side of the table shows whether the statement is valid within the
if / else construct, optional {rule_list}, or require
{rule_list} statement.
4.3
These statements share the same namespace, therefore the general convention is to
use _t as the final two characters of a type identifier to differentiate it from an
attribute identifier as shown in the following examples:
# Statement Identifier Comment
#------------------------------------------type
bin_t;
# A type identifier ends with _t
attribute file_type; # An attribute identifier ends with
# anything else
Page 171
Or
type type_id, attribute_id;
Or
type type_id alias alias_id;
Or
type type_id alias alias_id, attribute_id;
Where:
type
type_id
alias
alias_id
attribute_id
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
No
No
Yes
Examples:
Page 172
Where:
Page 173
attribute_id
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
No
Yes
Yes
Examples:
# Using the attribute statement to declare attributes domain,
# daemon, file_type and non_security_file_type:
attribute
attribute
attribute
attribute
domain;
daemon;
file_type;
non_security_file_type;
Where:
typeattribute
type_id
attribute_id
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
No
Yes
No
Examples:
# Using the typeattribute statement to associate a previously
Page 174
Where:
typealias
type_id
alias
alias_id
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
No
Yes
No
Page 175
4.4
Default Rules
These rules allow a default user, role, type and/or range to be used when computing a
context for a new object. These require policy version 27 or 28 with kernels 3.5 or
greater.
Where:
default_user
class
default
Page 176
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Example:
# When computing the context for a new file object, the user
# will be obtained from the target context.
default_user file target;
# When computing the context for a new x_selection or x_property
# object, the user will be obtained from the source context.
default_user { x_selection x_property } source;
Where:
default_role
class
default
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Page 177
Where:
default_type
class
default
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Example:
# When computing the context for a new file object, the type
# will be obtained from the target context.
default_type file target;
# When computing the context for a new x_selection or x_property
# object, the type will be obtained from the source context.
default_type { x_selection x_property } source;
Page 178
Where:
default_range
class
default
entry
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Example:
# When computing the context for a new file object, the lower
# level will be taken from the target context range.
default_range file target low;
# When computing the context for a new x_selection or x_property
# object, the range will be obtained from the source context.
default_type { x_selection x_property } source low_high;
Page 179
4.5
Policy versions 25 and above also support a 'name transition' rule, however, this is not
allowed inside conditionals and currently only supports the file class:
type_transition source_type target_type : class default_type object_name;
Where:
type_transition
source_type
target_type
default_type
object_name
Page 180
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
Yes
No
Page 181
Note that to be able to create the new file object with the
wtmp_t type, the following minimum permissions need to be
granted in the policy using allow rules (as shown in the
allow Rule section).
Where:
type_change
source_type
target_type
Page 182
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
Yes
Yes
No
Examples:
# Using the type_change statement to show that when relabeling a
# character file with type sysadm_devpts_t on behalf of
# auditadm_t, the type auditadm_devpts_t should be used:
type_change auditadm_t sysadm_devpts_t:chr_file auditadm_devpts_t;
#
#
#
#
Where:
type_member
source_type
target_type
Page 183
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
Yes
Yes
No
Example:
#
#
#
#
4.6
bounds Statements
Where:
typebounds
bounding_domain
bounded_domain
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
No
Yes
No
Page 184
This example has been taken from [Ref. 20] and states that:
The httpd_child_t cannot have file:{write} due to lack of
permissions on httpd_t which is the parent. It means the
child domains will always have equal or less privileges
than the parent.
4.7
The AV rules define what access control privileges are allowed for processes. There
are four types of AV rule: allow, dontaudit, auditallow, and neverallow
as explained in the sections that follow with a number of examples to cover all the
scenarios. There is also an auditdeny rule, however it is no longer used in the
Reference Policy and has been replaced by the dontaudit rule.
The general format of an AV rule is that the source_type is the identifier of a
process that is attempting to access an object identifier target_type, that has an
object class of class, and perm_set defines the access permissions
source_type is allowed.
The common format of the Access Vector Rule is:
rule_name source_type target_type : class perm_set;
Where:
rule_name
source_type
target_type
perm_set
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
allow = Yes
auditallow = Yes
dontaudit = Yes
neverallow = No
allow = Yes
auditallow = Yes
dontaudit = Yes
neverallow = Yes
allow = No
auditallow = No
dontaudit = No
neverallow = No
Page 186
#
#
#
#
#
#
#
#
Page 187
Using the neverallow rule to state that no allow rule may ever
grant mmap_zero permissions any type associated to the domain
attribute except those associated to the mmap_low_domain_type
attribute (as these have been excluded by the negative
operator (-)):
4.8
User Statement
Where:
51
neverallow statements are allowed in modules, however to detect these the semanage.conf
file must have the expand-check=1 entry present.
Page 188
seuser_id
roles
role_id
level
mls_level
range
mls_range
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
No
Yes
Yes
Example:
# Using the user statement to define an SELinux user user_u that
# has been assigned the role of user_r. The SELinux user_u is a
# generic user identity for Linux users who have no specific
# SELinux user identity defined.
#
user user_u roles { user_r };
MLS Examples:
#
#
#
#
#
Page 189
This command will produce the following files in the default <policy_name>
policy store and then activate the policy:
/etc/selinux/<policy_name>/modules/active/users.local:
# This file is auto-generated by libsemanage
# Do not edit directly.
user mque_u roles { unconfined_r } ;
/etc/selinux/<policy_name>/modules/active/users_extra:
# This file is auto-generated by libsemanage
# Do not edit directly.
user mque_u prefix user;
/etc/selinux/<policy_name>/modules/active/users_extra.local:
# This file is auto-generated by libsemanage
# Do not edit directly.
user mque_u prefix user;
4.9
Role Statements
Policy version 26 introduced two new role statements aimed at replacing the role
dominance rule by making role relationships easier to understand. These new
statements: attribute_role and roleattribute, are similar in operation to
the attribute and typeattribute statements used for types and are defined
in this section with examples.
Where:
role
role_id
types
type_id
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
No
Yes
Yes
Examples:
# Using the role statement to define standard roles in the
# Reference Policy.
role
role
role
role
role
role
system_r;
sysadm_r;
staff_r;
user_r;
secadm_r;
auditadm_r;
Page 191
Where:
attribute_role
attribute_id
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
No
Yes
Yes
Examples:
# Using the attribute_role statement to declare attributes that
# can then refers to a list of roles. Note that there are no
# roles associated with them yet.
attribute_role role_list_1;
attribute_role srole_list_2;
Where:
Page 192
role_id
attribute_id
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
No
Yes
No
Examples:
# Using the roleattribute statement to associate a previously
# declared role of service_r to a previously declared
# role_list_1 attribute_role.
attribute_role role_list_1;
role service_r;
# The association using the roleattribute statement:
roleattribute service_r role_list_1;
The role allow rule checks whether a request to change roles is allowed, if it is, then
there may be a further request for a role_transition so that the process runs
with the new role or role set.
Note that the role allow rule has the same keyword as the allow AV rule.
The statement definition is:
allow from_role_id to_role_id;
Where:
allow
from_role_id
to_role_id
Page 193
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
No
Yes
No
Example:
#
#
#
#
4.10.2
role_transition Rule
Where:
role_transition
current_role_id
type_id
class
new_role_id
Page 194
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
No
Yes
No
Example:
#
#
#
#
#
#
#
#
#
#
#
#
#
4.10.3
This rule has been deprecated and therefore should not be used. The role
dominance rule allows the dom_role_id to dominate the role_id (consisting
of one or more roles). The dominant role will automatically inherit all the type
associations of the other roles.
Notes:
1. There is another dominance rule for MLS (see the MLS dominance
Statement).
2. The role dominance rule is not used by the Reference Policy as the policy
manages role dominance using the constrain Statement.
3. Note the usage of braces {} and the ; in the statement.
The statement definition is:
dominance { role dom_role_id { role role_id; } }
Where:
Page 195
role
dom_role_id
role_id
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
No
Yes
No
Example:
# This shows the dominance role rule, note however that it
# has been deprecated and should not be used.
dominance { role message_filter_r { role unconfined_r };}
Table 16 shows what policy statements or rules are valid within the if / else
construct under the Conditional Statements column.
The bool statement default value can be changed when a policy is active by using
the setsebool command as follows:
#
#
#
#
Page 196
The getsebool command can be used to query the current bool statement value
as follows:
# This command will list all bool values in the active policy:
getsebool a
# This command will show the current allow_daemons_use_tty bool
# value in the active policy:
getsebool allow_daemons_use_tty
4.11.1
bool Statement
The bool statement is used to specify a boolean identifier and its initial state (true
or false) that can then be used with the if Statement to form a conditional policy
as described in the Conditional Policy section.
The statement definition is:
bool bool_id default_value;
Where:
bool
bool_id
default_value
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
No
Yes
Yes
Examples:
# Using the bool statement to allow unconfined executables to
# make their memory heap executable or not. As the value is
# false, then by default they cannot make their heap executable.
bool allow_execheap false;
Page 197
4.11.2
if Statement
The if statement is used to form a conditional block of statements and rules that are
enforced depending on whether one or more boolean identifiers (defined by the bool
Statement) evaluate to TRUE or FALSE. An if / else construct is also supported.
The only statements and rules allowed within the if / else construct are:
allow, auditallow, auditdeny, dontaudit, type_member,
type_transition (except 'file_name_transition'), type_change and
require.
The statement definition is:
if (conditional_expression) { true_list } [ else
{ false_list } ]
Where:
if
The if keyword.
else
false_list
Page 198
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
No As this is a Conditional
Statement and cannot be nested.
Yes
No
Examples:
# An example showing a boolean and supporting if statement.
bool allow_execmem false;
# The bool allow_execmem is FALSE therefore the allow statement
# is not executed:
if (allow_execmem) {
allow sysadm_t self:process execmem;
}
# An example showing two booleans and a supporting if statement.
bool allow_execmem false;
bool allow_execstack true;
# The bool allow_execmem is FALSE and allow_execstack is TRUE
# therefore the allow statement is not executed:
if (allow_execmem && allow_execstack) {
allow sysadm_t self:process execstack;
}
Page 199
constrain Statement
The constrain statement allows further restriction on permissions for the specified
object classes by using boolean expressions covering: source and target types, roles
and users as described in the examples.
The statement definition is:
constrain class perm_set expression;
Where:
constrain
class
perm_set
expression
Where:
u1, r1, t1 = Source user, role, type
u2, r2, t2 = Target user, role, type
and:
op : == | !=
role_op : == | != | eq | dom | domby | incomp
names : name | { name_list }
name_list : name | name_list name
Page 200
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Examples:
These examples have been taken
./policy/constraints file.
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
from
the
Reference
Policy
source
or
or
or
Page 201
4.12.2
validatetrans Statement
Only file related object classes are currently supported by this statement and it is used
to control the ability to change the objects security context.
Note there are no validatetrans statements specified within the Reference
Policy source.
The statement definition is:
validatetrans class expression;
Where:
validatetrans
class
expression
Page 202
Where:
u1, r1, t1 = Old user, role, type
u2, r2, t2 = New user, role, type
u3, r3, t3 = Process user, role, type
and:
op : == | !=
role_op : == | != | eq | dom | domby | incomp
names : name | { name_list }
name_list : name | name_list name
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Examples:
Page 203
4.13.1
fs_use_xattr Statements
Where:
fs_use_xattr
fs_name
fs_context
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Example:
# These statements define file systems that support extended
# attributes (security.selinux).
fs_use_xattr encfs system_u:object_r:fs_t;
fs_use_xattr ext2 system_u:object_r:fs_t;
fs_use_xattr ext3 system_u:object_r:fs_t;
MLS Examples:
# These statements define file systems that support extended
# attributes (security.selinux).
fs_use_xattr encfs system_u:object_r:fs_t:s0;
fs_use_xattr ext2 system_u:object_r:fs_t:s0;
fs_use_xattr ext3 system_u:object_r:fs_t:s0;
4.13.2
fs_use_task Statement
Page 204
Where:
fs_use_task
fs_name
fs_context
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Example:
# These statements define the file systems that support pseudo
# filesystems that represent objects like pipes and sockets, so
# that these objects are labeled with the same type as the
# creating task.
#
fs_use_task eventpollfs system_u:object_r:fs_t;
fs_use_task pipefs system_u:object_r:fs_t;
fs_use_task sockfs system_u:object_r:fs_t;
MLS Example:
# These statements define the file systems that support pseudo
# filesystems that represent objects like pipes and sockets, so
# that these objects are labeled with the same type as the
# creating task.
#
fs_use_task eventpollfs system_u:object_r:fs_t:s0;
fs_use_task pipefs system_u:object_r:fs_t:s0;
fs_use_task sockfs system_u:object_r:fs_t:s0;
4.13.3
fs_use_trans Statement
Page 205
Where:
fs_use_trans
fs_name
fs_context
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Example:
# These statements define pseudo filesystems such as devpts
# and tmpfs where objects are labeled with a derived context.
#
fs_use_trans mqueue system_u:object_r:tmpfs_t;
fs_use_trans shm system_u:object_r:tmpfs_t;
fs_use_trans tmpfs system_u:object_r:tmpfs_t;
fs_use_trans devpts system_u:object_r:devpts_t;
MLS Example:
# These statements define pseudo filesystems such as devpts
# and tmpfs where objects are labeled with a derived context.
#
fs_use_trans mqueue system_u:object_r:tmpfs_t:s0;
fs_use_trans shm system_u:object_r:tmpfs_t:s0;
fs_use_trans tmpfs system_u:object_r:tmpfs_t:s0;
fs_use_trans devpts system_u:object_r:devpts_t:s0;
4.13.4
genfscon Statements
Where:
genfscon
fs_name
partial_path
fs_context
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Examples:
# The following examples show those filesystems that only
# support a single security context across the filesystem.
genfscon
genfscon
genfscon
genfscon
msdos / system_u:object_r:dosfs_t
iso9660 / system_u:object_r:iso9660_t
usbfs / system_u:object_r:usbfs_t
selinuxfs / system_u:object_r:security_t
# The following show some example /proc entries that can have
# directories added to the path.
genfscon
genfscon
genfscon
genfscon
proc
proc
proc
proc
/ system_u:object_r:proc_t
/sysvipc system_u:object_r:proc_t
/fs/openafs system_u:object_r:proc_afs_t
/kmsg system_u:object_r:proc_kmsg_t
MLS Examples:
# The following examples show those filesystems that only
# support a single security context across the filesystem
# with the MLS levels added.
genfscon
genfscon
genfscon
genfscon
msdos / system_u:object_r:dosfs_t:s0
iso9660 / system_u:object_r:iso9660_t:s0
usbfs / system_u:object_r:usbfs_t:s0
selinuxfs / system_u:object_r:security_t:s0
# The following show some example /proc entries. Note that the
# /kmsg has the highest sensitivity level assigned (s15) because
# it is a trusted process.
genfscon proc / system_u:object_r:proc_t:s0
genfscon proc /sysvipc system_u:object_r:proc_t:s0
Page 207
4.14.1
IP Address Formats
4.14.1.1
4.14.1.2
IPv6 addresses are written as eight groups of four hexadecimal digits, where each
group is separated by a colon (:) as follows:
2001:0db8:85a3:0000:0000:8a2e:0370:7334
To shorten the writing and presentation of addresses, the following rules apply:
a) Any leading zeros in a group may be replaced with a single 0 as shown:
Page 208
b) Any leading zeros in a group may be omitted and be replaced with two colons
(::), however this is only allowed once in an address as follows:
2001:db8:85a3::8a2e:370:7334
Or
::1
d) An undetermined IPv6 address i.e. all bits are zero is written as:
::
4.14.2
netifcon Statement
The netifcon statement is used to label network interface objects (e.g. eth0).
It is also possible to use the semanage interface command to associate the
interface to a security context.
The statement definition is:
netifcon netif_id netif_context packet_context
Where:
netifcon
netif_id
netif_context
packet_context
Page 209
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Examples:
# The following netifcon statement has been taken from the
# MLS policy that shows an interface name of lo with the same
# security context assigned to both the interface and packets.
netifcon lo system_u:object_r:lo_netif_t:s0 - s15:c0.c255
system_u:object_r:unlabeled_t:s0 - s15:c0.c255
This command will produce the following file in the default <policy_name>
policy store and then activate the policy:
/etc/selinux/<policy_name>/modules/active/interfaces.local:
# This file is auto-generated by libsemanage
# Do not edit directly.
netifcon eth0 system_u:object_r:unconfined_t system_u:object_r:unconfined_t
4.14.3
nodecon Statement
The nodecon statement is used to label network address objects that represent IPv4
or IPv6 IP addresses and network masks.
It is also possible to add SELinux these outside the policy using the semanage
node command that will associate the node to a security context.
The statement definition is:
nodecon subnet netmask node_context
Where:
nodecon
subnet
netmask
Page 210
node_context
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Examples:
# The Standard Reference Policy nodecon statement for the IPv4
# Local Host:
nodecon 127.0.0.1 255.255.255.255 system_u:object_r:lo_node_t
# The equivalent MLS Reference Policy nodecon statement for the
# IPv4 Local Host:
nodecon 127.0.0.1 255.255.255.255 system_u:object_r:lo_node_t:
s0 - s15:c0.c255
This command will produce the following file in the default <policy_name>
policy store and then activate the policy:
/etc/selinux/<policy_name>/modules/active/nodes.local:
# This file is auto-generated by libsemanage
# Do not edit directly.
nodecon ipv4 127.0.0.2 255.255.255.255 system_u:object_r:unconfined_t
4.14.4
portcon Statement
Where:
portcon
protocol
port_number
port_context
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Examples:
# The Standard Reference Policy portcon statements:
portcon tcp 20 system_u:object_r:ftp_data_port_t
portcon tcp 21 system_u:object_r:ftp_port_t
portcon tcp 600-1023 system_u:object_r:hi_reserved_port_t
portcon udp 600-1023 system_u:object_r:hi_reserved_port_t
portcon tcp 1-599 system_u:object_r:reserved_port_t
portcon udp 1-599 system_u:object_r:reserved_port_t
# The equivalent MLS Reference Policy portcon statements:
portcon tcp 20 system_u:object_r:ftp_data_port_t:s0
portcon tcp 21 system_u:object_r:ftp_port_t:s0
portcon tcp 600-1023 system_u:object_r:hi_reserved_port_t:s0
portcon udp 600-1023 system_u:object_r:hi_reserved_port_t:s0
portcon tcp 1-599 system_u:object_r:reserved_port_t:s0
portcon udp 1-599 system_u:object_r:reserved_port_t:s0
This command will produce the following file in the default <policy_name>
policy store and then activate the policy:
/etc/selinux/<policy_name>/modules/active/ports.local:
# This file is auto-generated by libsemanage
# Do not edit directly.
portcon udp 1234 system_u:object_r:unconfined_t
Page 212
These consist of a mandatory hierarchical sensitivity and optional nonhierarchical categorys. The combination of the two comprise a level or security
level as shown in Table 17. Depending on the circumstances, there can be one level
defined or a range as shown in Table 17.
Security Level (or Level)
Consisting of a sensitivity and zero or
more category entries:
Range
Low
sensitivity [: category, ... ]
High
SystemLow
SystemHigh
Table 17: Sensitivity and Category = Security Level this table shows the
meanings depending on the context being discussed.
To make the security levels more meaningful, it is possible to use the setransd
daemon to translate these to human readable formats. The semanage(8) command
will allow this mapping to be defined as discussed in the ./setrans.conf file
section.
4.15.1
sensitivity Statement
The sensitivity statement defines the MLS policy sensitivity identifies and
optional alias identifiers.
The statement definition is:
Page 213
Or
sensitivity sens_id alias alias_id [ alias_id ];
Where:
sensitivity
sens_id
alias
alias_id
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
Yes
Examples:
# The MLS Reference Policy default is to assign 16 sensitivity
# identifiers (s0 to s15):
sensitivity s0;
....
sensitivity s15;
# The policy does not specify any alias entries, however a valid
# example would be:
sensitivity s0 alias secret wellmaybe ornot;
4.15.2
When more than one sensitivity Statement is defined within a policy, then a
dominance statement is required to define the actual hierarchy between all
sensitivities.
The statement definition is:
dominance { sens_id ... }
Where:
dominance
sens_id
Page 214
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Example:
# The MLS Reference Policy dominance statement defines s0 as the
# lowest and s15 as the highest sensitivity level:
dominance { s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15
4.15.3
category Statement
The category statement defines the MLS policy category identifiers 52 and optional
alias identifiers.
The statement definition is:
category cat_id;
Or
category cat_id alias alias_id;
Where:
category
cat_id
alias
alias_id
52
SELinux use the term category or categories while some MLS systems and documentation use
the term compartment or compartments, however they have the same meaning.
Page 215
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
Yes
Examples:
# The MLS Reference Policy default is to assign 256 category
# identifiers (c0 to c255):
category c0;
...
category c255;
# The policy does not specify any alias entries, however a valid
# example would be:
category c0 alias planning development benefits;
4.15.4
level Statement
The level statement enables the previously declared sensitivity and category
identifiers to be combined into a Security Level.
Note there must only be one level statement for each sensitivity Statement.
The statement definition is:
level sens_id [ :category_id ];
Where:
level
sens_id
category_id
Page 216
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Examples:
# The MLS Reference Policy default is to assign each Security
# Level with the complete set of categories (i.e. the inclusive
# set from c0 to c255):
level s0:c0.c255;
...
level s15:c0.c255;
4.15.5
range_transition Statement
Where:
range_transition
source_type
target_type
new_range
Page 217
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
No
Yes
No
Examples:
#
#
#
#
4.15.5.1
The MLS range is appended to a number of statements and defines the lowest and
highest security levels. The range can also consist of a single level as discussed at
the start of the MLS section.
The definition is:
low_level
Or
low_level high_level
Where:
low_level
high_level
Page 218
4.15.6
mlsconstrain Statement
Where:
mlsconstrain
class
perm_set
expression
Where:
u1, r1, t1, l1, h1 = Source user, role, type, low level, high level
u2, r2, t2, l2, h2 = Target user, role, type, low level, high level
and:
op : == | !=
role_mls_op : == | != | eq | dom | domby | incomp
names : name | { name_list }
name_list : name | name_list name
Page 219
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Examples:
These examples have been taken from the Reference Policy source ./policy/mls
constraints file (the mcs file supports the MCS constraints).
These are built into the policy at build time and add constraints to many of the object
classes.
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
4.15.7
mlsvalidatetrans Statement
Where:
Page 220
class
expression
Where:
u1, r1, t1, l1, h1 = Old user, role, type, low level, high level
u2, r2, t2, l2, h2 = New user, role, type, low level, high level
u3, r3, t3, l3, h3 = Process user, role, type, low level, high level
and:
op : == | !=
role_mls_op : == | != | eq | dom | domby | incomp
names : name | { name_list }
name_list : name | name_list name
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Examples:
This example has been taken from the Reference Policy source ./policy/mls file.
Page 221
4.16.1
module Statement
This statement is mandatory for loadable modules (non-base) and must be the first
line of any module policy source file. The identifier should not conflict with other
module names within the overall policy, otherwise it will over-write an existing
module when loaded via the semodule command. The semodule -l command
can be used to list all active modules within the policy.
The statement definition is:
module module_name version_number;
Where:
module
module_name
version_number
Page 222
Base Policy
Module Policy
No
No
Yes
optional Statement
require Statement
No
No
No
Example:
# Using the module statement to define a loadable module called
# bind with a version 1.0.0:
module bind 1.8.0;
4.16.2
require Statement
Where:
require
require_list
Page 223
Base Policy
Module Policy
No
Yes
optional Statement
require Statement
Yes
No
Examples:
# A series of require statements showing various entries:
require {
role system_r;
class security { compute_av compute_create compute_member
check_context load_policy compute_relabel compute_user
setenforce setbool setsecparam setcheckreqprot };
class capability2 { mac_override mac_admin };
}
#
require {
attribute direct_run_init, direct_init, direct_init_entry;
type initrc_t;
role system_r;
attribute daemon;
}
#
require {
type nscd_t, nscd_var_run_t;
class nscd { getserv getpwd getgrp gethost shmempwd shmemgrp
shmemhost shmemserv };
}
4.16.3
optional Statement
The optional statement is used to indicate what policy statements may or may not
be present in the final compiled policy. The statements will be included in the policy
only if all statements within the optional { rule list } can be expanded
successfully, this is generally achieved by using a require Statement at the start of
the list.
The statement definition is:
optional { rule_list }
Or
Page 224
Where:
optional
rule_list
else
rule_list
Base Policy
Module Policy
No
Yes
Yes
optional Statement
require Statement
Yes
Yes
Yes
Examples:
# Use of optional block in a base policy source file.
optional {
require {
type unconfined_t;
} # end require
allow acct_t unconfined_t:fd use;
} # end optional
# Use of optional / else blocks in a base policy source file.
optional {
require {
type ping_t, ping_exec_t;
} # end require
allow dhcpc_t ping_exec_t:file { getattr read execute };
.....
require {
type netutils_t, netutils_exec_t;
} # end require
allow dhcpc_t netutils_exec_t:file { getattr read execute };
.....
type_transition dhcpc_t netutils_exec_t:process netutils_t;
...
} else {
allow dhcpc_t self:capability setuid;
.....
} # end optional
Page 225
4.16.4
policycap Statement
Where:
policycap
capability
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Example:
# This statement enables the network_peer_controls to be enabled
# for use by the policy.
#
policycap network_peer_controls;
4.16.5
permissive Statement
Page 226
Where:
permissive
type_id
Base Policy
Module Policy
Yes
Yes
Yes
optional Statement
require Statement
No
Yes
No
Example:
# This is the simple statement that would allow permissive mode
# to be set on the httpd_t domain, however this statement is
# generally built into a loadable policy module so that the
# permissive mode can be easily removed by removing the module.
#
permissive httpd_t;
This command will produce the following module in the default <policy_name>
policy store and then activate the policy:
/etc/selinux/<policy_name>/modules/active/modules/permissive_unconfined_t.pp
Page 227
4.17.1
Object Classes
A list of object classes used by Fedora can be found in the Reference Policy source in
the ./policy/flask/security_classes file.
Object classes are defined within a policy as follows:
The statement definition is:
class class_id
Where:
class
class_id
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
Yes
Example:
# Define the PostgreSQL db_tuple object class
#
class db_tuple
4.17.2
Permissions
Page 228
Where:
class
class_id
inherits
common_set
perm_set
Note:
There must be at least one common_set or one perm_set defined within the
statement.
The statement is valid in:
Monolithic Policy
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
Yes
Examples:
# The following example shows the db_tuple object class being
# allocated two permissions:
class db_tuple { relabelfrom relabelto }
#
#
#
#
Page 229
A list of common permissions used by the Reference Policy are listed in the
./policy/flask/access_vectors file.
New or updated common permissions would only be updated by those who produce
kernel or user space object managers.
The statement definition is:
common common_id { perm_set }
Where:
common
common_id
perm_set
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Example:
# Define the common PostgreSQL permissions
#
common database { create drop getattr setattr relabelfrom
relabelto }
4.18.1
sid Statement
The sid statement declares the actual SID identifier and is defined at the start of a
policy source file.
The statement definition is:
sid sid_id
Where:
sid
Page 230
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Example:
This example has been taken from
../policy/flask/initial_sids file.
the
Reference
Policy
source
4.18.2
The sid context statement is used to add an initial security context to the SID that is
used when SELinux initialises, or as a default if an object is not labeled correctly.
sid sid_id context
Where:
sid
sid_id
context
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Examples:
# These statements add an initial security context to an object
# that is used when SELinux initialises or as a default if a
Page 231
4.19.1
iomemcon Statement
The sid statement declares the actual SID identifier and is defined at the start of a
policy source file.
The statement definition is:
iomemcon addr context;
Where:
iomemcon
addr
context
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Example:
iomemcon 0xfebd9 system_u:object_r:nicP_t;
Page 232
4.19.2
ioportcon Statement
The sid statement declares the actual SID identifier and is defined at the start of a
policy source file.
The statement definition is:
ioportcon port context;
Where:
ioportcon
port
The port to apply the context. This may also be a range that
consists of a start and end port number separated by a hypen
('-').
context
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Example:
ioportcon 0xeac0 system_u:object_r:nicP_t;
ioportcon 0xecc0-0xecdf system_u:object_r:nicP_t;
4.19.3
pcidevicecon Statement
The sid statement declares the actual SID identifier and is defined at the start of a
policy source file.
The statement definition is:
pcidevicecon pci_id context;
Where:
pcidevicecon
pci_id
context
Page 233
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Example:
pcidevicecon 0xc800 system_u:object_r:nicP_t;
4.19.4
pirqcon Statement
The sid statement declares the actual SID identifier and is defined at the start of a
policy source file.
The statement definition is:
pirqcon irq context;
Where:
pirqcon
irq
context
Base Policy
Module Policy
Yes
Yes
No
optional Statement
require Statement
No
No
No
Example:
pirqcon 33 system_u:object_r:nicP_t;
Page 234
Introduction
The Reference Policy is now the standard policy source used to build SELinux
policies. This provides a single source tree with supporting documentation that can be
used to build policies for different purposes such as: confining important daemons,
supporting MLS / MCS type policies and locking down systems so that all processes
are under SELinux control.
This section details how the Reference Policy is:
1. Constructed and types of policy builds supported.
2. Installation as a full Reference Policy source or as Header files.
3. Modifying the configuration files to build new policies.
4. Adding new modules to the build.
53
Page 235
5.2
Important notes - Strictly speaking the Reference Policy should refer to the policy
taken
from
the
master
repository
(see
http://oss.tresys.com/projects/refpolicy/wiki/RepositoryCheckout) or the latest
released version (see http://oss.tresys.com/projects/refpolicy/wiki/DownloadRelease).
However most Linux distributors take a released version and then tailor it to their
specific requirements. Therefore as this Notebook is based on Fedora 16, then this is
the Reference Policy version that will be discussed (if refering to the master
Reference Policy, then the word master will be used).
The Reference Policy54 can be used to build two different formats of a policy:
1. Loadable Module Policy A policy that has a base module for core services
and has the ability to load / unload modules to support applications as required
55
. This is now the standard used by GNU / Linux distributions.
2. Monolithic Policy A policy that has all the required policy information in a
single base policy.
Each of the policy types are built using module files that define the specific rules
required by the policy as detailed in the Reference Policy Module Files section. Note
that the monolithic policy is built using the the same module files, however they are
all assembled into a single base source file.
There are tools such as SLIDE (SELinux integrated development environment) that
can be used to make the task of policy development and testing easier when using the
Reference Policy source or headers. SLIDE is an Eclipse plugin and details can be
found at:
http://oss.tresys.com/projects/slide
The full source code and details are at the following site: http://oss.tresys.com/projects/refpolicy.
These can be installed by system administrators as required. The dynamic loading / unloading of
policies as applications are loaded is not yet supported.
Page 236
This
package contains the html policy documentation that is located at
/usr/share/doc/selinux-policy-3.10.0/html
selinux-policy-minimum-3.10.0-86.fc16.noarch
selinux-policy-mls-3.10.0-86.fc16.noarch
selinux-policy-targeted-3.10.0-86.fc16.noarch
These three packages contain policy configuration files and policy
modules (*.pp files) for the particular policy type to be installed. The
files
are
used
to
build
the
policy
type
in
/usr/share/selinux/<policy_name> and then install the policy
in the /etc/selinux/<policy_name> directory.
Normally only one policy would be installed and active, however for
development purposes all three can be installed.
56
Note that Red Hat pre-configure MCS support within all their policies.
Page 237
Page 238
Page 239
')
########################################
## <summary>
## Execute ada in the ada domain, and
## allow the specified role the ada domain.
## </summary>
## <param name="domain">
## <summary>
## Domain allowed access.
## </summary>
## </param>
## <param name="role">
## <summary>
## The role to be allowed the ada domain.
## </summary>
## </param>
## <param name="terminal">
## <summary>
## The type of the terminal allow the ada domain to use.
## </summary>
## </param>
#
interface(`ada_run',`
gen_require(`
type ada_t;
')
')
ada_domtrans($1)
role $2 types ada_t;
Page 240
5.3
This section will explain the source layout and configuration files, with the actual
installation and building covered in the Installing and Building the Reference Policy
Source section.
The source has a README file containing information on the configuration and
installation processes that has been used within this section (and updated with the
authors comments as necessary). There is also a VERSION file that contains the
Reference Policy release date which can be used to obtain the original source from the
repository located at:
http://oss.tresys.com/projects/refpolicy
Reference Policy Files and Directories Describes the files and their location.
Source Installation and Build Make Options Describes the make targets.
Page 241
Modular Policy Build Process Describes how the various source files are
linked together to form a base policy module (base.conf) during the build
process.
The Installing and Building the Reference Policy Source section then describes how
the initial source is installed and configured to allow a version of the F-16 targeted
policy to be built.
Page 242
build.conf
appconfig-mcs
appconfig-mls
appconfigstandard
local.users
doc
templates
Makefile
man
ru
policy
Rules.
monolithic
Application
specific
configuration
files
html template
files
example files +
dtd
man
Rules.
modular
SELinux Policy
config
flask
Reference
P olicy man
pages
flask config
files
admin
apps
kernel
roles
services
modules
support
+
Policy
configuration
files
support
Policy support
scripts
Reference
P olicy macros
/etc/selinux/<policy_name>/modules:
semanage.read.LOCK
semanage.trans.LOCK
/etc/selinux/[policy_name]/modules/active:
base.pp
commit_num
file_contexts
file_contexts.homedirs
file_contexts.template
homedir_template
netfilter_contexts
seusers.final
users_extra
/etc/selinux/<policy_name>/modules/active/modules:
amavis.pp
amtu.pp
...
zabbix.pp
/etc/selinux/<policy_name>/contexts:
dbus_contexts
netfilter_contexts
/etc/selinux/<policy_name>/contexts/files:
file_contexts
file_contexts.homedirs
/etc/selinux/<policy_name>/policy:
policy.23
------------------------------------
/etc/selinux/config
/etc/selinux/semanage.conf
/etc/selinux/restorecond.conf
/etc/sestatus
/etc/selinux/<policy_name>/setrans.conf
Figure 5.2: The Reference Policy Source Tree When building a modular policy, files are added to the policy store. For monolithic builds the
policy store is not used.
Page 243
Comments
Rules.modular
Rules.monolithic
build.conf
config/appconfig-<type>
config/local.users
doc/html/*
When make html has been executed, contains the inpolicy XML documentation, presented in web page
form
doc/policy.dtd
doc/policy.xml
doc/templates/*
support/*
policy/flask/initial_sids
policy/flask/access_vectors
Page 244
Comments
prefixes for access vectors may be defined at the
beginning of the file. After the common prefixes are
defined, an access vector may be defined for each
security class.
The file usage in policy generation is described in the
Modular Policy Build Structure section.
policy/modules/*
policy/booleans.conf
policy/constraints
policy/global_booleans
policy/global_tunables
policy/mcs
policy/mls
Page 245
Comments
configuration.
The file usage in policy generation is described in the
Modular Policy Build Structure section.
policy/modules.conf
policy/policy_capabilities
policy/rolemap
policy/users
policy/support/*
securetty_types
setrans.conf
This file defines the policy type to be built that will influence its name and where the
source will be located once it is finally installed. It also configures the MCS / MLS
sensitivity and category maximum values. An example file content is shown in the
Installing and Building the Reference Policy Source section where it is used to install
and then build the policy.
Table 19 explains the fields that can be defined within this file, however there are a
number of m4 macro parameters that are set up when this file is read by the build
process makefiles. These definitions are shown in Table 20 and are also used within
the module source files to control how the policy is built with examples shown in the
ifdef / ifndef Parameters section.
Option
Type
Comments
OUTPUT_POLICY
Integer
Page 246
Type
Comments
monolithic policy. This option has no effect on modular
policy.
TYPE
String
NAME
String
(optional)
DISTRO
String
(optional)
UNK_PERMS
String
DIRECT_INITRC
Boolean
(y|n)
MONOLITHIC
Boolean
(y|n)
UBAC
Boolean
(y|n)
CUSTOM_BUILDOPT
String
MLS_SENS
Integer
MLS_CATS
Integer
MCS_CATS
Integer
QUIET
Boolean
(y|n)
If 'y' the build system will only display status messages and
error messages. This option has no effect on policy.
Page 247
From build.conf
entry
Comments
enable_mls
TYPE
enable_mcs
TYPE
enable_ubac
UBAC
mls_num_sens
MLS_SENS
mls_num_cats
MLS_CATS
mcs_num_cats
MCS_CATS
distro_$(DISTRO)
DISTRO
direct_sysadm_daemon
DIRECT_INITRC
hide_broken_symtoms
Table 20: m4 parameters set at build time - These have been extracted from the
Reference Policy Makefile file.
5.3.3.2 Reference Policy Build Options policy/modules.conf
This file controls what modules are built within the policy with example entries as
follows:
# Layer: kernel
# Module: kernel
# Required in base
#
# Policy for kernel threads, proc filesystem,and unlabeled processes and
# objects.
#
kernel = base
# Module: amanda
#
# Automated backup program.
#
amanda = module
# Layer: admin
# Module: ddcprobe
#
# ddcprobe retrieves monitor and graphics card information
#
ddcprobe = off
As can be seen the only active line (those without comments57) is:
<module_name> = base | module | off
Where:
module_name The name of the module to be included within the build.
base
57
The comments are also important as they form part of the documentation when it is generated by
the make html target.
Page 248
off
Generally it is up to the policy distributor to decide which modules are in the base and
those that are loadable, however there are some modules that MUST be in the base
module. To highlight this there is a special entry at the start of the modules interface
file (.if) that has the entry <required val=true> as shown below (taken
from the kernel.if file):
## <summary>
## Policy for kernel threads, proc filesystem,
## and unlabeled processes and objects.
## </summary>
## <required val="true">
## This module has initial SIDs.
## </required>
The modules.conf file will also reflect that a module is required in the base by
adding a comment Required in base when the make conf target is
executed (as all the .if files are checked during this process and the
modules.conf file updated).
# Layer: kernel
# Module: kernel
# Required in base
#
# Policy for kernel threads, proc filesystem,and unlabeled processes and
objects.
#
kernel = base
There are 12 modules in the F-16 reference policy source marked as required and
are shown in Table 21.
Layer
Module Name
Comments
kernel
corecommands
kernel
corenetwork
kernel
devices
This module creates the device node concept and provides the
policy for many of the device files. Notable exceptions are the
mass storage and terminal devices that are covered by other
modules (that is a char or block device file, usually in /dev). All
types that are used to label device nodes should use the dev_node
macro.
Additionally this module controls access to three things:
Page 249
Module Name
Comments
1.
2.
3.
domain
kernel
files
kernel
filesystem
kernel
kernel
kernel
mcs
kernel
mls
kernel
selinux
kernel
terminal
kernel
ubac
Page 250
Comments
conf
clean
bare
Do the clean make target and also delete configuration files, web page
documentation, and policy.xml.
html
install-appconfig
Comments
base
Compile and package the base module. This is the default target for
modular policies.
modules
MODULENAME.pp
all
Compile and package the base module and all Reference Policy modules
configured to be built as loadable modules.
install
Compile, package, and install the base module and Reference Policy
modules configured to be built as loadable modules.
load
Compile, package, and install the base module and Reference Policy
modules configured to be built as loadable modules, then insert them into
the module store.
validate
install-headers
Page 251
Make Target
policy
Comments
install
load
Compile and install the policy and file contexts, then load the policy.
enableaudit
relabel
checklabels
Check the labels on the filesystem, and report when a file would be
relabeled, but do not change its label.
restorelabels
Compile a policy locally for development and testing. This is the default
target for monolithic policies.
global_booleans
global_tunables
Page 252
./policy/tmp
File Name
flask/security_classes
pre_te_files.conf
flask/access_vectors
mls or mcs
modules/*/*.te
modules/*/*.if
58
59
flask/initial_sids
policy_capabilities
all_attrs_types.conf
Page 253
./policy/tmp
File Name
global_bools.conf
global_tunables.conf
global_bools.conf
base modules
only_te_rules.conf
users
all_post.conf
constraints
modules/*/*.te
modules/*/*.te
modules/*/*.if
modules/*/*.te
modules/*/*.if
modules/*/*.fc
base.fc.tmp
seusers
seusers
These are the commands used to compile, link and load the base policy module:
checkmodule base.conf o tmp/base.mod
semodule_package -o base.conf -m base_mod -f base_fc -u users_extra -s tmp/seusers
semodule -s $(NAME) -b base.pp) -i and each module .pp file
Figure 5.3: Base Module Build This shows the temporary build files used to build
the base module base.conf as a part of the make process. Note that the
modules marked as base in modules.conf are built here.
Base Policy Component Description
./policy/tmp
File Name
modules/*/<module_name>.te
modules/*/<module_name>.if
<module_name>.tmp
tmp/<module_name>.tmp
<module_name>.mod
Page 254
modules/*/<module_name>.fc
base.fc.tmp
Each module is packaged and loaded with the base module using the following commands:
semodule_package -o base.conf -m base_mod -f base_fc -u users_extra -s tmp/seusers
semodule -s $(NAME) -b base.pp) -i and each module .pp file
Figure 5.4: Module Build This shows the module files and the temporary build
files used to build each module as a part of the make process (i.e. those modules
marked as module in modules.conf).
5.4
This section explains how to install the F-16 reference policy source that is distributed
by Red Hat (however the same principle is followed for the source taken directly from
the Tresys repository, except that it will not build a compatible policy to that
discussed in this section).
Any F-16 policy source rpm will suffice and can be obtained from the
http://koji.fedoraproject.org web site, however it is assumed that the
source rpm is:
selinux-policy-3.10.0-86.fc16.src.rpm
The objective of this exercise is to show that the policy built from the above source
rpm is an exact replica of the targeted policy distributed as header files in the F-16
targeted rpm:
selinux-policy-targeted-3.10.0-86.fc16.noarch.rpm
Page 255
booleans-mls.conf
customizable_types
modules-minimum.conf
policy-F16.patch
securetty_types-targeted
setrans-minimum.conf
users-minimum
booleans-targeted.conf
file_contexts.subs_dist
modules-mls.conf
securetty_types-minimum
serefpolicy-3.10.0
setrans-mls.conf
users-mls
The files with minimum, targeted, and mls within their names are the specific
configuration files used within the Reference Policy for that particular Red Hat policy
type.
The latest patches now need to be applied to the source tree as follows:
cd serefpolicy-3.10.0
patch -p1 <../policy-F16.patch
The config.tgz is Red Hat's updated configuration files this will need to be
unpacked and replace the original set of files:
# Unpack the archive:
cd ..
tar xzf config.tgz
# move to source directory:
cd serefpolicy-3.10.0
# save the old files:
mv config config.org
# and copy over the new Red Hat files
cp -r ../config config
# But also need two files from original location:
cp config.org/appconfig-mcs/sepgsql_contexts config/appconfig-mcs
cp config.org/appconfig-mcs/x_contexts config/appconfig-mcs
Page 256
booleans-targeted.conf
./serefpolicy-3.10.0/policy/booleans.conf
customizable_types
./serefpolicy-3.10.0/config/appconfig-mcs/
customizable_types
file_contexts.subs_dist
./serefpolicy-3.10.0/config/appconfigmcs/file_contexts.subs_dist
modules-targeted.conf
./serefpolicy-3.10.0/policy/modules.conf
securetty_types-targeted
./serefpolicy-3.10.0/config/appconfig-mcs/
securetty_types
setrans-targeted.conf
./serefpolicy-3.10.0/config/appconfig-mcs/
setrans.conf
users-targeted.conf
./serefpolicy-3.10.0/policy/users
Table 25: Red Hat specific policy configuration files This example builds a
targeted policy.
The serefpolicy-3.10.0 directory will now contain the source code with the
latest patches for this release (3.10.0-86) of the Red Hat Reference Policy and the
correct configuration files for a targeted policy.
The ./serefpolicy-3.10.0/build.conf must now be modified to allow the
source to be installed in its final location and have the correct parameters set for the
build. The entries that need to be updated in the build.conf file are highlighted
below60:
#
# Policy build options
#
# Policy version
# By default, checkpolicy will create the highest version policy it supports.
# Setting this will override the version. This only has an effect for
# monolithic policies.
#OUTPUT_POLICY = 18
# Policy Type
# standard, mls, mcs. Note Red Hat always build the MCS Policy Type
# as their targeted version.
TYPE = mcs
# Policy Name
# If set, this will be used as the policy name. Otherwise the policy type
# will be used for the name. This entry is also used by the
# make install-src process
# to copy the source to the /etc/selinux/targeted-86/src/policy directory.
NAME = targeted-86
#
#
#
#
#
60
Distribution
Some distributions have portions of policy for programs or configurations
specific to the distribution. Setting this will enable options for the
distribution. redhat, gentoo, debian, suse, and rhel4 are current options.
Fedora users should enable redhat.
The README file in this directory contains helpful information on installation of the source,
headers, documentation etc. The only point the README will not cover are the Red Hat specific
configuration files that need to be copied over as shown in Table 25.
Page 257
The policy source is now in a position to be installed at its default location that will be
derived from the NAME = targeted-86 entry and will therefore be located at:
/etc/selinux/targeted-86/src/policy
This will copy the source code to its final location making any directories required.
Once the copy process is complete the policy can be built and the modules loaded into
the policy store61 by running the following commands:
# Go to the source location:
cd /etc/selinux/targeted-86/src/policy
# To ensure a clean source build:
make clean
61
Note that the term load is not loading the policy as the active policy, but just building the base
policy + the modules and installing them ready to be activated if required
Page 258
# Build the policy modules and load into the policy store:
make load
The policy will now be built as a targeted policy that will be an exact copy of the
policy distributed in the following rpm:
selinux-policy-targeted-3.10.0-86.fc16.noarch.rpm
Finally copy over files that are not automatically managed by the build process. These
are held in the config/appconfig-mcs directory:
cp
cp
config/appconfig-mcs/setrans.conf /etc/selinux/targeted-86
config/appconfig-mcs/file_contexts.subs_dist
/etc/selinux/targeted-86/contexts/files
Note that the binaries would not be an exact comparison due to time stamps etc.,
therefore the SETools sediffx utility should be run against the two binary policies62
which should show that they are the same and give the results shown in Figure 5.5.
Policy:
/etc/selinux/targeted/policy/policy.26
Policy Version & Type: v.26 (binary, mls)
Policy:
/etc/selinux/targeted-86/policy/policy.26
Policy Version & Type: v.26 (binary, mls)
Number of Rules:
allow: 91628
auditallow: 103
dontaudit 7002
neverallow: not calculated
type_change: 62
type_member: 46
type_transition: 14467
Number of Rules:
allow: 91628
auditallow: 103
dontaudit 7002
neverallow: not calculated
type_change: 62
type_member: 46
type_transition: 14467
Number of Roles: 13
Number of Roles: 13
62
Be aware that comparing these two policies on a low specification machine will take hours. It is
best to select a few items for comparison first.
Page 259
allow: 290
role_transition 0
Number of Users: 9
Number of Users: 9
Total Differences: 0
Figure 5.5: The two targeted policies should be the same using sediffx
During reboot, the system will be relabeled and the policy loaded (hopefully with no
errors).
5.5
This method of building policy and adding new modules is used for distributions that
do not require access to the source code.
Note that the Reference Policy header and the Red Hat F-16 policy header
installations are slightly different as described below.
Page 260
directory.
e) Copy the module interface files (.if) to the relevant module
directories at:
/usr/share/selinux/<policy_name>/include/modules.
The directory structure for the targeted-86 build generated above (edited for
readability) would be:
# The policy packages:
targeted-86/abrt.pp
....
targeted-86/base.pp
# Build / Configuration files:
targeted-86/include/build.conf
targeted-86/include/Makefile
targeted-86/include/rolemap # Note this file is not used by F-16
# XML Documentation:
targeted-86/include/global_tunables.xml
targeted-86/include/global_booleans.xml
targeted-86/include/apps.xml
targeted-86/include/roles.xml
targeted-86/include/system.xml
targeted-86/include/kernel.xml
targeted-86/include/services.xml
targeted-86/include/admin.xml
# Support Macros:
targeted-86/include/support/ipc_patterns.spt
...
...
# The module interface files in their relevant directories:
targeted-86/include/admin/acct.if
..
targeted-86/include/apps/ada.if
..
targeted-86/include/kernel/corecommands.if
..
targeted-86/include/roles/auditadm.if
..
targeted-86/include/services/abrt.if
...
targeted-86/include/system/application.if
...
Page 261
However there is another Makefile that can be installed in the users home directory
($HOME) that will call the master Makefile. This is located at
/etc/selinux/targeted-86/src/policy/doc in the reference policy
source and is called Makefile.example. This is shown below (note that it
extracts the <policy_name> from the SELinux config file):
AWK ?= gawk
NAME ?= $(shell $(AWK) -F= '/^SELINUXTYPE/{ print $$2 }'
/etc/selinux/config)
SHAREDIR ?= /usr/share/selinux
HEADERDIR := $(SHAREDIR)/$(NAME)/include
include $(HEADERDIR)/Makefile
Table 26 shows the make targets for modules built from headers.
Make Target
MODULENAME.pp
Comments
all
load
Compile and package the modules in the current directory, then insert them
into the module store.
refresh
Attempts to reinsert all modules that are currently in the module store from
the local and system module packages.
xml
Build a policy.xml from the XML included with the base policy headers
and any XML in the modules in the current directory.
The
development
header
files
are
installed
in
the
/usr/share/selinux/devel directory by the selinux-policy3.10.0-86.fc16.noarch rpm. Red Hat also include an additional
application called policygentool that allows users to generate policy by
answering various questions. This tool is described in the Fedora 12 SELinux
User Guide [Ref. 1]. The example modules are also in this directory and the
Makefile is also slightly different to that used by the Reference Policy
source.
The documentation is supplied in the selinux-policy-doc-3.10.086.fc16.noarch type rpms and would be installed (for this version), in
the /usr/share/doc/selinux-policy-3.10.0/html directory.
Page 262
5.6
This section explains some of the support macros used to build reference policy
source modules (see Table 27 for the list). These macros are located at:
/usr/share/selinux/<policy_name>/include/support for
reference policy installed header files.
Function
policy_module
loadable_module.spt
gen_require
template
interface
optional_policy
gen_tunable
tunable_policy
gen_user
gen_context
gen_bool
Generate a boolean
gen_cats
gen_sens
gen_levels
mls_systemlow
misc_macros.spt
mls_mcs_macros.spt
mls_systemhigh
mcs_systemlow
mcs_systemhigh
Page 263
Incorrect:
policy_module (ftp, 1.7.0)
support
macros
are
located
in
the
This macro will add the module statement to a loadable module, and automatically
add a require Statement with pre-defined information for all loadable modules
Page 264
Where:
policy_module
module_name
version_number
Yes
No
No
Example Macro:
# This example is from the modules/services/ftp.te module:
#
policy_module(ftp, 1.7.0)
Expanded Macro:
# This is the expanded macro from the tmp/ftp.tmp file:
#
module ftp 1.7.0;
require {
role system_r;
class security {compute_av compute_create .... };
....
class capability2 (mac_override mac_admin };
# If MLS or MCS configured then the:
sensitivity s0;
....
category c0;
....
}
Page 265
require_statements
Yes
Yes
No
Example Macro:
# This example is from the modules/services/ftp.te module:
#
gen_require(`type ftp_script_exec_t;')
Expanded Macro:
# This is the expanded macro from the tmp/ftp.tmp file:
#
require {
type ftp_script_exec_t;
}
For use within module files to insert an optional block that will be expanded by
the build process only if the modules containing the access or template interface calls
that follow are present. If one module is present and the other is not, then the optional
statements are not included (need to check).
The macro definition is:
optional_policy(`optional_statements`)
Where:
optional_policy
optional_statements
Yes
Yes
No
Example Macro:
Page 266
')
optional_policy(`
logrotate_exec(ftpd_t)
')
Expanded Macro:
# This is the expanded macro from the tmp/ftp.tmp file showing
# the policy language statements with both optional levels
# expanded.
#
##### Start optional_policy - Level 1 ###########
optional {
##### begin corecmd_exec_shell(ftpd_t)
require {
type bin_t, shell_exec_t;
} # end require
allow ftpd_t bin_t:dir { getattr search };
allow ftpd_t bin_t:dir { getattr search read lock ioctl };
allow ftpd_t bin_t:dir { getattr search };
allow ftpd_t bin_t:lnk_file { getattr read };
allow ftpd_t shell_exec_t:file { { getattr read execute ioctl } ioctl lock
execute_no_trans };
##### end corecmd_exec_shell(ftpd_t)
##### begin files_read_usr_files(ftpd_t)
require {
type usr_t;
} # end require
allow ftpd_t usr_t:dir { getattr search read lock ioctl };
allow ftpd_t usr_t:dir { getattr search };
allow ftpd_t usr_t:file { getattr read lock ioctl };
allow ftpd_t usr_t:dir { getattr search };
allow ftpd_t usr_t:lnk_file { getattr read };
##### end files_read_usr_files(ftpd_t)
##### begin cron_system_entry(ftpd_t,ftpd_exec_t)
require {
type crond_t, system_crond_t;
} # end require
allow system_crond_t ftpd_exec_t:file { getattr read execute };
allow system_crond_t ftpd_t:process transition;
dontaudit system_crond_t ftpd_t:process { noatsecure siginh rlimitinh };
type_transition system_crond_t ftpd_exec_t:process ftpd_t;
# cjp: perhaps these four rules from the old
# domain_auto_trans are not needed?
allow ftpd_t system_crond_t:fd use;
allow ftpd_t system_crond_t:fifo_file { getattr read write append ioctl
lock };
allow ftpd_t system_crond_t:process sigchld;
allow ftpd_t crond_t:fifo_file { getattr read write append ioctl lock };
allow ftpd_t crond_t:fd use;
allow ftpd_t crond_t:process sigchld;
role system_r types ftpd_t;
##### end cron_system_entry(ftpd_t,ftpd_exec_t)
##### Start optional_policy - Level 2 ##########
optional {
##### begin logrotate_exec(ftpd_t)
require {
Page 267
This macro defines booleans that are global in scope. The corresponding
tunable_policy macro contains the supporting statements allowed or not
depending on the value of the boolean. These entries are extracted as a part of the
build process (by the make conf target) and added to the global_tunables file
where they can then be used to alter the default values for the make load or make
install targets.
Note that the comments shown in the example MUST be present as they are used to
describe the function and are extracted for the documentation.
The macro definition is:
gen_tunable(boolean_name,boolean_value)
Where:
gen_tunable
boolean_name
boolean_value
Yes
Yes
No
Example Macro:
# This example is from the modules/services/ftp.te module:
#
## <desc>
## <p>
## Allow ftp servers to use nfs
## for public file transfer services.
## </p>
## </desc>
gen_tunable(allow_ftpd_use_nfs, false)
Expanded Macro:
# This is the expanded macro from the tmp/ftp.tmp file:
Page 268
This macro contains the statements allowed or not depending on the value of the
boolean defined by the gen_tunable macro.
The macro definition is:
tunable_policy(`gen_tunable_id,`tunable_policy_rules`)
Where:
tunable_policy
gen_tunable_id
Yes
Yes
No
Example Macro:
# This example is from the modules/services/ftp.te module
# showing the use of the boolean with the && operator.
#
tunable_policy(`allow_ftpd_use_nfs && allow_ftpd_anon_write',`
fs_manage_nfs_files(ftpd_t)
')
Expanded Macro:
# This is the expanded macro from the tmp/ftp.tmp file.
#
if (allow_ftpd_use_nfs && allow_ftpd_anon_write) {
##### begin fs_manage_nfs_files(ftpd_t)
require {
type nfs_t;
} # end require
allow ftpd_t nfs_t:dir { read getattr lock search ioctl
add_name remove_name write };
allow ftpd_t nfs_t:file { create open getattr setattr read
write append rename link unlink ioctl lock };
Page 269
Access interface macros are defined in the interface module file (.if) and form
the interface through which other modules can call on the modules services (as shown
in Figure 5.7 and described in the Module Expansion section.
The macro definition is:
interface(`name`,`interface_rules`)
Where:
interface
name
interface_rules
No
Yes
No
Page 270
A template interface is used to help create a domain and set up the appropriate rules
and statements to run an application / process. The basic idea is to set up an
application in a domain that is suitable for the defined SELinux user and role to
access but not others. Should a different user / role need to access the same
application, another domain would be allocated (these are known as derived
domains as the domain name is derived from caller information).
Page 271
Note that the comments shown in the example MUST be present as they are used to
describe the function and are extracted for the documentation.
The macro definition is:
template(`name`,`template_rules`)
Where:
template
name
template_rules
No
Yes
No
Example Macro:
# This example is from the modules/apps/openoffice.if module
# showing the openoffice_per_role_template template interface.
#
#######################################
## <summary>
## The per role template for the openoffice module.
## </summary>
## <desc>
## <p>
## This template creates a derived domains which are used
## for openoffice applications.
## </p>
## </desc>
## <param name="userdomain_prefix">
## <summary>
Page 272
Expanded Macro:
#
#
#
#
#
Page 273
This macro is used to generate a valid security context and can be used in any of the
module files. Its most general use is in the .fc file where it is used to set the files
security context.
The macro definition is:
gen_context(context[,mls | mcs])
Where:
gen_context
context
mls | mcs
Yes
Yes
Yes
Example Macro:
# This example shows gen_context being used to generate a
# security context for the security initial sid in the
# selinux.te module:
sid security gen_context(system_u:object_r:security_t:mls_systemhigh)
Expanded Macro:
# This is the expanded entry built into the base.conf source
# file for an MLS policy:
sid security system_u:object_r:security_t:s15:c0.c255
Page 274
HOME_DIR/.gnome2(/.*)?
gen_context(system_u:object_r:gnome_home_t,s0)
HOME_DIR/\.config/gtk-.*
gen_context(system_u:object_r:gnome_home_t,s0)
HOME_DIR/\.gconf(d)?(/.*)?
gen_context(system_u:object_r:gconf_home_t,s0)
HOME_DIR/\.local.*
gen_context(system_u:object_r:gconf_home_t,s0)
/tmp/gconfd-USER/.* -gen_context(system_u:object_r:gconf_tmp_t,s0)
HOME_DIR/.pulse(/.*)?
gen_context(system_u:object_r:gnome_home_t,s0)
system_u:object_r:gnome_home_t:s0
This macro is used to generate a valid user statement and add an entry in the
users_extra configuration file if it exists.
The macro definition is:
gen_user(username, prefix, role_set, mls_defaultlevel,
mls_range, [mcs_categories])
Where:
gen_user
username
prefix
Page 275
mls_defaultlevel
mls_range
mcs_categories
Yes
No
No
Example Macro:
# This example has been taken from the policy/policy/users file:
#
gen_user(root, user, unconfined_r sysadm_r staff_r
ifdef(`enable_mls',`secadm_r auditadm_r') system_r, s0, s0 mls_systemhigh, mcs_allcats)
Expanded Macro:
# The expanded gen_user macro from the base.conf for an MLS
# build. Note that the prefix is not present. This is added to
# the users_extra file as shown below.
#
user root roles { unconfined_r sysadm_r staff_r secadm_r
auditadm_r system_r } level s0 range s0 - s15:c0.c1023;
# users_extra file entry:
#
user root prefix user;
Page 276
Where:
gen_bool
name
default_value
The macro is only valid in the global_booleans file but the boolean declared can
be used in the following module types:
Private Policy File (.te)
Yes
Yes
No
Expanded Macro:
# This has been taken from the base.conf source file after
# expansion by the build process of the modutils.te module.
#
if( ! secure_mode_insmod ) {
##### begin kernel_domtrans_to(insmod_t,insmod_exec_t)
allow kernel_t insmod_exec_t:file { getattr read execute };
allow kernel_t insmod_t:process transition;
dontaudit kernel_t insmod_t:process { noatsecure siginh
rlimitinh };
type_transition kernel_t insmod_exec_t:process insmod_t;
allow insmod_t kernel_t:fd use;
allow insmod_t kernel_t:fifo_file { getattr read write append
ioctl lock };
allow insmod_t kernel_t:process sigchld;
##### end kernel_domtrans_to(insmod_t,insmod_exec_t)
}
Page 277
This macro will generate a category statement for each category defined. These are
then used in the base.conf / policy.conf source file and also inserted into
each module by the policy_module Macro. The policy/policy/mcs and
mls configuration files are the only files that contain this macro in the current
reference policy.
The macro definition is:
gen_cats(mcs_num_cats | mls_num_cats)
Where:
gen_cats
mcs_num_cats
mls_num_cats
na
na
na
Example Macro:
# This example is from the policy/policy/mls configuration file.
#
gen_cats(mls_num_cats)
Expanded Macro:
# This example has been extracted from the base.conf source
# file.
category c0;
category c1;
...
category c1023;
This macro will generate a sensitivity statement for each sensitivity defined.
These are then used in the base.conf / policy.conf source file and also
inserted into each module by the policy_module Macro. The
Page 278
Where:
gen_sens
mls_num_sens
na
na
na
Example Macro:
# This example is from the policy/policy/mls configuration file.
#
gen_cats(mls_num_sens)
Expanded Macro:
# This example has been extracted from the base.conf source
# file.
sensitivity s0;
sensitivity s1;
...
sensitivity s15;
This macro will generate a level statement for each level defined. These are then
used in the base.conf / policy.conf source file. The policy/policy/mcs
and mls configuration files are the only files that contain this macro in the current
reference policy.
The macro definition is:
gen_levels(mls_num_sens,mls_num_cats)
Where:
Page 279
mls_num_sens
mls_num_cats
mcs_num_cats
The macro is valid in:
Private Policy File (.te)
na
na
na
Example Macro:
# This example is from the policy/policy/mls configuration file.
#
gen_levels(mls_num_sens,mls_num_cats)
Expanded Macro:
# This example has been extracted from the base.conf source
# file. Note that the all categories are allocated to each
# sensitivity.
level s0:c0.c1023;
level s1:c0.c1023;
...
level s15:c0.c1023;
Page 280
This is used within modules as shown in the example. The parameter is set up by the
Makefile at the start of the build process.
Example Macro:
# This example is from the modules/kernel/domain.te module.
#
ifdef(`hide_broken_symptoms',`
cron_dontaudit_rw_tcp_sockets(domain)
allow domain domain:key { link search };
')
These are used within modules as shown in the example. The parameters are set up by
the Makefile with information taken from the build.conf file at the start of the
build process.
Example Macros:
# This example is from the modules/kernel/kernel.te module.
#
ifdef(`enable_mls',`
role secadm_r;
role auditadm_r;
')
# This example is from the modules/kernel/kernel.if module.
#
ifdef(`enable_mcs',`
range_transition kernel_t $2:process $3;
')
ifdef(`enable_mls',`
range_transition kernel_t $2:process $3;
mls_rangetrans_target($1)
')
5.6.4.3 enable_ubac
5.6.4.4 direct_sysadm_daemon
This is used within modules as shown in the example. The parameter is set up by the
Makefile with information taken from the build.conf file at the start of the
build process (if DIRECT_INITRC = y).
Example Macros:
# This example is from the modules/system/selinuxutil.te module.
#
ifndef(`direct_sysadm_daemon',`
ifdef(`distro_gentoo',`
# Gentoo integrated run_init:
init_script_file_entry_type(run_init_t)
')
')
# This example is from the modules/system/userdomain.te module.
#
ifdef(`direct_sysadm_daemon',`
domain_system_change_exemption($1_t)
')
5.7
The objective of this section is to show how the modules are expanded by the
reference policy build process to form files that can then be compiled and then loaded
into the policy store by using the make MODULENAME.pp target.
Page 282
make ada
semodule -i ada.pp
Page 283
Figure 5.7: The Resulting Code - The expanded code in the Module Expansion
section.
Page 284
Page 285
Page 286
Page 287
optional {
# start optional #6
##### begin unconfined_domain_noaudit(ada_t)
require {
class dbus { acquire_svc send_msg };
class nscd { getpwd getgrp gethost getstat admin shmempwd shmemgrp
shmemhost getserv shmemserv };
class passwd { passwd chfn chsh rootok crontab };
} # end require
# Use any Linux capability.
allow ada_t self:capability { chown dac_override dac_read_search fowner fsetid
kill setgid setuid setpcap linux_immutable net_bind_service net_broadcast
net_admin net_raw ipc_lock ipc_owner sys_module sys_rawio sys_chroot sys_ptrace
sys_pacct sys_admin sys_boot sys_nice sys_resource sys_time sys_tty_config mknod
lease audit_write audit_control setfcap };
allow ada_t self:fifo_file { create open getattr setattr read write append
rename link unlink ioctl lock };
# Transition to myself, to make get_ordered_context_list happy.
allow ada_t self:process transition;
# Write access is for setting attributes under /proc/self/attr.
allow ada_t self:file { getattr read write append ioctl lock };
allow ada_t self:dir { read getattr lock search ioctl add_name remove_name
write };
# Userland object managers
allow ada_t self:nscd { getpwd getgrp gethost getstat admin shmempwd shmemgrp
shmemhost getserv shmemserv };
allow ada_t self:dbus { acquire_svc send_msg };
allow ada_t self:passwd { passwd chfn chsh rootok crontab };
allow ada_t self:association { sendto recvfrom setcontext polmatch };
##### begin kernel_unconfined(ada_t)
require {
attribute kern_unconfined;
} # end require
typeattribute ada_t kern_unconfined;
##### end kernel_unconfined(ada_t)
##### begin corenet_unconfined(ada_t)
require { attribute corenet_unconfined_type;
} # end require
typeattribute ada_t corenet_unconfined_type;
##### end corenet_unconfined(ada_t)
##### begin dev_unconfined(ada_t)
require {
attribute devices_unconfined_type;
} # end require
typeattribute ada_t devices_unconfined_type;
##### end dev_unconfined(ada_t)
##### begin domain_unconfined(ada_t)
require {
attribute set_curr_context;
attribute can_change_object_identity;
attribute unconfined_domain_type;
attribute process_uncond_exempt;
} # end require
typeattribute ada_t unconfined_domain_type;
# pass constraints
typeattribute ada_t can_change_object_identity;
typeattribute ada_t set_curr_context;
typeattribute ada_t process_uncond_exempt;
##### end domain_unconfined(ada_t)
##### begin domain_dontaudit_read_all_domains_state(ada_t)
require {
attribute domain;
} # end require
Page 288
Page 289
require {
bool allow_execstack;
} # end require
if (allow_execstack) {
# Allow making the stack executable via mprotect;
# execstack implies execmem;
allow ada_t self:process { execstack execmem };
#
auditallow ada_t self:process execstack;}
optional { # start optional #7
##### begin auth_unconfined(ada_t)
require {
attribute can_read_shadow_passwords;
attribute can_write_shadow_passwords;
attribute can_relabelto_shadow_passwords;
} # end require
typeattribute ada_t can_read_shadow_passwords;typeattribute ada_t
can_write_shadow_passwords;typeattribute ada_t can_relabelto_shadow_passwords;
##### end auth_unconfined(ada_t) depth: 1
} # end optional #7
optional { # start optional #8
# Communicate via dbusd.
##### begin dbus_system_bus_unconfined(ada_t)
require {
type system_dbusd_t;
class dbus { acquire_svc send_msg };
} # end require
allow ada_t system_dbusd_t:dbus *;
##### end dbus_system_bus_unconfined(ada_t)
##### begin dbus_unconfined(ada_t) depth: 2
require {
attribute dbusd_unconfined;
} # end require
typeattribute ada_t dbusd_unconfined;
##### end dbus_unconfined(ada_t)
} # end optional #8
optional {# start optional #9
##### begin ipsec_setcontext_default_spd(ada_t)
require {
type ipsec_spd_t;
} # end require
allow ada_t ipsec_spd_t:association setcontext;
##### end ipsec_setcontext_default_spd(ada_t)
##### begin ipsec_match_default_spd(ada_t)
require { type ipsec_spd_t;
} # end require
allow ada_t ipsec_spd_t:association polmatch;
allow ada_t self:association sendto;
##### end ipsec_match_default_spd(ada_t)
} # end optional #9
optional { # start optional #10
# this is to handle execmod on shared
# libs with text relocations
##### begin libs_use_shared_libs(ada_t)
require { type lib_t, textrel_shlib_t;
} # end require
##### begin files_list_usr(ada_t)
require {
type usr_t;
} # end require
allow ada_t usr_t:dir { getattr search read lock ioctl };
Page 290
Page 291
Page 292
Introduction
The following definitions attempt to explain the difference between the two types of
userspace SELinux application (however the distinction can get 'blurred'):
SELinux-aware - Any application that provides support for SELinux. This
generally means that the application makes use of SELinux libraries and/or other
SELinux applications. Example SELinux-aware applications are the Pluggable
Authentication Manager (PAM(8)) and SELinux commands such as
runcon(1). It is of course possible to class an object manager as an SELinuxaware application.
Object Manager - Object Managers are a specialised form of SELinux-aware
application that are responsible for the labeling, management and enforcement 63 of
the objects under their control.
Generally the userspace Object Manager forms part of an application that can be
configured out should the base Linux OS not support SELinux.
Example userspace Object Managers are:
Therefore the basic distinction is that Object Managers manage their defined objects
on behalf of an application, whereas general SELinux-aware applications do not (they
rely on 'Object Managers' to do this e.g. the kernel based Object Managers such as
those that manage filesystem, IPC and network labeling).
6.2
The SELinux policy / security server do not themselves enforce a decision, they merely state
whether the operation is allowed or not according to the policy. It is the object manager that
enforces the decision of the policy / security server, therefore an object manager must be trusted.
This is also true of labeling - the object manager ensures that the labels are applied to their objects
as defined by the policy.
Page 293
Page 294
While this section cannot help with those points, here are some notes to help during
the design phase (also see the Implementing SELinux-aware Applications section):
1. Determine what objects are required and the access controls (permissions) that
need to be applied.
2. Does SELinux already have some of these object classes and permissions
defined. For standard Linux OS objects such as files, then these would be
available. If so, the object manager should remap them with
selinux_set_mapping(3) so only those required are available.
Page 295
Page 296
The main points to note when adding to the Reference Policy are:
1. Create sample Reference Policy policy modules (*.te, *.if and *.fc
module files) that provide rules for managing the new objects as described in:
http://selinuxproject.org/page/NB_RefPolicy#Reference_Policy_Module_
Files
The SE-PostgreSQL modules provide an example, see the
./refpolicy/policy/modules/services/postgresql.* files
in the Reference Policy source.
2. Create any new policy classes and permissions for the Reference Policy, these
will need to be built into the base module as described in the Adding New
Object Classes and Permissions section.
Note, that if no new object classes, permissions or constraints are being added
to the policy, then the Reference Policy source code does not require
modification, and supplying the module files (*.te, *.if and *.fc) should
suffice.
3. Create any constraints required as these need to be built into the base module
of
the
Reference
Policy.
They
are
added
to
the
./refpolicy/policy/constraints, mcs and mls files. Again the
SE-PostgreSQL entries in these files give examples (find the db_* class
entries).
4. Create any SELinux configuration files (context, user etc.) that need to be
added to the policy at build time.
5. Either produce an updated Reference Policy source or module patch,
depending on whether new classes/constraints have been added. Note that by
default a new module will be generated as a 'module', if it is required that the
module is in the base (unusual), then add an entry <required
val='true'> to the start of the interface file as shown below:
## <summary>
##Comment regarding interface file
## </summary>
## <required val="true">
##Comment on reason why required in base
## </required>
Page 297
# userspace
Where class is the class keyword and object_name is the name of the object.
The # userspace is used by build scripts to detect userspace objects (or more
specifically non-mandatory objects).
The permissions configuration file is at:
./refpolicy/policy/flask/access_vectors
and each entry must be added to the end of the file in the following format:
class object_name
{
perm_name
[........]
}
Where class is the class keyword, object_name is the name of the object and
perm_name is the name given to each permission in the class (there is a limit of 32
permissions within a class). It is possible to have a common permission section within
this file, see the file object entry in the access_vectors file for an example.
For reference, http://selinuxproject.org/page/Adding_New_Permissions describes how
new kernel object classes and permissions are added to the system.
Page 298
7. SEAndroid
This section gives a brief overview of SEAndroid as it stood in August 12 as this is a
new project and continually being enhanced (Android 4.1.1 with SEAndroid installs
on F-17 with no issues). It is recommended that the project web site is checked for the
latest enhancements: http://selinuxproject.org/page/SEAndroid.
There is a presentation The Case for Security Enhanced (SE)Android [Ref 22] that
gives the rationale behind the enhancements.
The http://en.wikipedia.org/wiki/Android_%28operating_system%29 site gives a
good introduction to Android and http://source.android.com gives details on
installation of the source.
7.1.1 Overview
SEAndroid enhances the Android system by adding SELinux support to the kernel
and userspace with the main objectives being to (taken from
http://selinuxproject.org/page/SEAndroid):
1. Confine privileged daemons to protect them from misuse and limit the damage
that can be done via them.
2. Sandbox and isolate apps from each other and from the system, prevent
privilege escalation by apps.
3. Allow application privileges to be controlled at installation and run-time (the
Middleware-MAC)
4. Provide a centralized, analyzable policy.
These objectives are achieved by:
Page 299
Page 300
Page 301
These contain updated board configurations to enable SELinux for the following
devices:
device/samsung/crespo - Google Nexus S
device/samsung/crespo4g - Google Nexus S 4G
device/samsung/tuna - Common Samsung Galaxy Nexus files
device/samsung/maguro - Galaxy Nexus (GSM/HSPA+) specific files
device/samsung/toro - Galaxy Nexus (CDMA/LTE) specific files
device/moto/wingray - Motorola Xoom (Wifi)
There
are
more
details
http://selinuxproject.org/page/SEAndroid#Building_for_a_Device
configuration information.
at
regarding
Page 302
7.2
Page 303
Set the security context for an Android application domain. This function is used by
the Dalvik / Zygote services to start applications in their specified domain.
Synopsis
#include <selinux/android.h>
int selinux_android_setcontext(uid_t uid, int isSystemServer,
const char *seinfo, const char *name);
Description
selinux_android_setcontext sets the security context using setcon(3).
The computed context is validated against policy and is based on the applications
username (obtained from uid), seinfo, and the (package) name information.
The username is validated against rules, and then used with the other parameters to
compute a context as described in the Context Computation section.
The isSystemServer value must match that set in the running system and be true
or false.
seinfo and name may be NULL.
64
The 'setprop
selinux.reloadpolicy
1' forces a policy reload (see
system/core/init/property_service.c - property_set()). The policy load
function will then check for a policy file in the /data/system directory first (the root directory
will be checked next if a policy file is not found).
Page 304
IF the first four chars of the username is app_, and remainder numeric,
calculate the category based on these numerics.
Example username: app_123
ELSE IF the first char of the username is u and the second char is
numeric, and it ends in numerics, calculate the category using these numerics
until an a is found. Finally reset the username to app_.
Example username: u0_a36
IF all parameters match, build context and check if valid. If valid call
setcon(3) and return, ELSE raise error, log and return.
Page 305
1000
1
(null)
(null)
(null)
1001
0
platform
com.android.phone
(null)
Page 306
1000
0
platform
com.android.seandroid_manager
(null)
10036
0
release
com.android.deskclock
(null)
These are example process contexts taken from the 'ps -Z' command:
# ps -Z
LABEL
u:r:init:s0
..
u:r:ueventd:s0
..
u:r:kernel:s0
..
u:r:servicemanager:s0
u:r:vold:s0
u:r:netd:s0
u:r:debuggerd:s0
u:r:rild:s0
u:r:surfaceflinger:s0
u:r:zygote:s0
u:r:drmserver:s0
u:r:mediaserver:s0
u:r:dbusd:s0
u:r:installd:s0
u:r:keystore:s0
u:r:qemud:s0
u:r:system:s0
..
u:r:radio:s0
..
u:r:system_app:s0
u:r:shared_app:s0:c3
u:r:release_app:s0:c28
u:r:shared_app:s0:c3
u:r:system_app:s0
USER
root
PID
1
PPID
0
NAME
/init
root
28
/sbin/ueventd
root
31
yaffs-bg-1
system
root
root
root
radio
system
root
drm
media
bluetooth
root
keystore
root
system
33
34
36
37
38
39
40
41
42
43
44
45
48
89
1
1
1
1
1
1
1
1
1
1
1
1
1
40
/system/bin/servicemanager
/system/bin/vold
/system/bin/netd
/system/bin/debuggerd
/system/bin/rild
/system/bin/surfaceflinger
zygote
/system/bin/drmserver
/system/bin/mediaserver
/system/bin/dbus-daemon
/system/bin/installd
/system/bin/keystore
/system/bin/qemud
system_server
radio
179
40
com.android.phone
system
app_3
app_28
app_3
system
220
242
302
325
362
40
40
40
40
40
com.android.settings
android.process.acore
com.android.deskclock
com.android.contacts
com.android.seandroid_manager
7.2.1.2 selinux_android_setfilecon
Set the security context on an Android application package directory. This function is
primarily used by the package installer to label application directories.
Synopsis
Page 307
Description
selinux_android_setfilecon sets the security context on the file object
using setfilecon(3). The computed context is validated against policy and is
based on the applications username (obtained from uid) and pkgname. The
pkgdir will be labeled with the computed context.
The username is validated against rules, and then used with the other parameters to
compute a context as described in the Context Computation section.
pkgname may be NULL.
If a context cannot be computed an error is returned and an entry added to the error
log.
Context Computation
Using the in memory seapp_context file entries sorted in order of precedence,
the username is checked according to the following rules to determine whether the
application is named (e.g radio), is a system app, or a standard app, and what level
may need to be applied:
IF the first four chars of the username is app_, and remainder numeric,
calculate the category based on these numerics.
Example username: app_123
ELSE IF the first char of the username is u and the second char is
numeric, and it ends in numerics, calculate the category using these numerics
until an a is found. Finally reset the username to app_.
Example username: u0_a36
Page 308
Return Value
On success, zero is returned.
On failure, -1 is returned and errno is set appropriately.
Error Log Entries
Errors will be logged in the error log when:
i. No match can be found in the seapp_context(5) file.
ii. If isSystemServer is true, a message stating that setting the system server
context failed.
iii. If isSystemServer is false, then a message stating that setting an
application context failed.
iv. If there is an sebool= entry defined, but no boolean of that name is present.
Files
pkgname is defined in the packages AndroidManifest.xml file.
The context is computed using information from the seapp_context(5) file.
Examples
These are sample application directory (data) contexts taken from /data/data
using the 'ls -Z' command:
# ls -Z /data/data
drwxr-x--x u0_a14
drwxr-x--x u0_a3
drwxr-x--x u0_a35
drwxr-x--x u0_a36
drwxr-x--x system
drwxr-x--x u0_a39
drwxr-x--x radio
drwxr-x--x u0_a3
drwxr-x--x u0_a26
drwxr-x--x u0_a3
drwxr-x--x u0_a1
drwxr-x--x u0_a1
drwxr-x--x u0_a1
drwxr-x--x u0_a1
drwxr-x--x system
drwxr-x--x radio
drwxr-x--x system
drwxr-x--x system
drwxr-x--x u0_a4
drwxr-x--x u0_a11
u0_a14
u0_a3
u0_a35
u0_a36
system
u0_a39
radio
u0_a3
u0_a26
u0_a3
u0_a1
u0_a1
u0_a1
u0_a1
system
radio
system
system
u0_a4
u0_a11
u:object_r:platform_app_data_file:s0 com.android.bluetooth
u:object_r:platform_app_data_file:s0 com.android.contacts
u:object_r:platform_app_data_file:s0 com.android.defcontainer
u:object_r:platform_app_data_file:s0 com.android.deskclock
u:object_r:system_data_file:s0 com.android.inputdevices
u:object_r:platform_app_data_file:s0 com.android.packageinstaller
u:object_r:radio_data_file:s0 com.android.phone
u:object_r:platform_app_data_file:s0 com.android.providers.applications
u:object_r:platform_app_data_file:s0 com.android.providers.calendar
u:object_r:platform_app_data_file:s0 com.android.providers.contacts
u:object_r:platform_app_data_file:s0 com.android.providers.downloads
u:object_r:platform_app_data_file:s0 com.android.providers.downloads.ui
u:object_r:platform_app_data_file:s0 com.android.providers.drm
u:object_r:platform_app_data_file:s0 com.android.providers.media
u:object_r:system_data_file:s0 com.android.providers.settings
u:object_r:radio_data_file:s0 com.android.providers.telephony
u:object_r:system_data_file:s0 com.android.seandroid_manager
u:object_r:system_data_file:s0 com.android.settings
u:object_r:platform_app_data_file:s0 com.android.systemui
u:object_r:platform_app_data_file:s0 com.android.videoeditor
Page 309
context
Where:
property_key
The key used to obtain the context and may contain '*' for wildcard matching
or '?' for substitution.
context
The security context that will be applied to the object.
Example:
##########################
# property service keys
#
#
# property_key
context
net.rmnet0
net.gprs
sys.usb.config
ril.
net.
service.
debug.
log.
service.adb.tcp.port
persist.sys.
persist.service.
persist.security.
selinux.
u:object_r:radio_prop:s0
u:object_r:radio_prop:s0
u:object_r:radio_prop:s0
u:object_r:rild_prop:s0
u:object_r:system_prop:s0
u:object_r:system_prop:s0
u:object_r:shell_prop:s0
u:object_r:shell_prop:s0
u:object_r:shell_prop:s0
u:object_r:system_prop:s0
u:object_r:system_prop:s0
u:object_r:system_prop:s0
u:object_r:system_prop:s0
u:object_r:system_prop:s0
u:object_r:system_prop:s0
u:object_r:default_prop:s0
Page 310
signature=""
Page 311
7.3
These are the additional class / permissions for SEAndroid, the policy
Class
Permission
impersonate
call
set_context_mgr
transfer
receive
Page 312
Permission
specifyids
specifyrlimits
specifycapabilities
specifyinvokewith
specifyseinfo
Class
Page 313
Introduction
This section contains a list of object classes and their associated permissions that have
been taken from the Fedora F-17 policy sources. There are also additional entries for
Xen, however the SEAndroid entries are shown in the SEAndroid Classes &
Permissions section.
All objects are kernel objects unless marked as user space objects.
In most cases the permissions are self explanatory as they are those used in the
standard Linux function calls (such as create a socket or write to a file). Some
SELinux specific permissions are:
relabelfrom
relabelto
entrypoint
Where possible the specific object class permissions are explained, however for some
permissions it is difficult to determine what they are used for (or if used at all) so a ?
has been added when doubt exists. There are lists of object classes and permissions at
the following location and would probably be more up-to-date:
http://selinuxproject.org/page/ObjectClassesPerms
8.2
The Reference Policy already contains the default object classes and permissions
required to manage the system and supporting services.
For those who write or manager SELinux policy, there is no need to define new
objects and their associated permissions as these would be done by those who actually
design and/or write object managers.
The Object Classes and Permissions sections explain how these are defined within the
SELinux Policy Language.
Page 314
8.3
Common Permissions
create
Append to file.
The rules for this permission work as follows:
If a process calls access() or faccessat() and SELinux denies their
request there will be a check for a dontaudit rule on the
audit_access permission. If there is a dontaudit rule on
audit_access an AVC event will not be written. If there is no
dontaudit rule an AVC event will be written for the permissions
requested (read, write, or exec).
Notes:
1) There will never be a denial message with the audit_access
permission as this permission does not control security decisions.
2) allow and auditallow rules with this permission are therfore
meaningless, however the kernel will accept a policy with such rules, but
they will do nothing.
Create new file.
execute
execmod
getattr
ioctl
link
lock
mounton
quotaon
Enable quotas.
read
relabelfrom
relabelto
rename
Rename file.
setattr
swapon
unlink
write
audit_access
append
Accept a connection.
Page 315
bind
Bind to a name.
connect
Initiate a connection.
create
getattr
getopt
ioctl
listen
lock
name_bind
read
recv_msg
Receive datagram.
recvfrom
relabelfrom
relabelto
send_msg
Send datagram.
sendto
setattr
Change attributes.
setopt
shutdown
Terminate connection.
write
Description (9 Permissions)
create
Create.
destroy
Destroy.
getattr
read
setattr
unix_read
Read.
unix_write
Write or append.
write
Page 316
Description (6 Permissions)
create
drop
getattr
Get metadata needed to reference an object (e.g. SELECT ... FROM ...).
relabelfrom
relabelto
setattr
add
bell
create
destroy
force_cursor
freeze
get_property
getattr
getfocus
grab
list_property
manage
read
remove
set_property
setattr
setfocus
use
write
Page 317
8.4
Class
Permissions
associate
getattr
mount
Mount filesystem.
quotaget
quotamod
relabelfrom
relabelto
remount
transition
unmount
Unmount filesystem.
Class
dir - Directory
Permissions
Inherit Common
File Permissions
add_name
open
remove_name
reparent
rmdir
Remove directory.
search
Search directory.
Class
Permissions
Inherit Common
File Permissions
entrypoint
execute_no_trans
open
Class
Permissions
Inherit Common
File Permissions
Page 318
Class
Permissions
Inherit Common
File Permissions
entrypoint
execute_no_trans
open
Class
Permissions
Inherit Common
File Permissions
open
Class
Permissions
Inherit Common
File Permissions
open
Class
Permissions
Inherit Common
File Permissions
open
Class
fd File descriptors
Permissions
use
8.5
Class
Permissions
Page 319
dccp_send
enforce_dest
rawip_recv
rawip_send
recvfrom
Network interface and address check permission for use with the
ingress permission.
sendto
Network interface and address check permission for use with the
egress permission.
tcp_recv
tcp_send
udp_recv
udp_send
Class
Permissions
dccp_recv
dccp_send
egress
Each packet leaving the system must pass an egress access control.
Also requires the node sendto permission.
ingress
Each packet entering the system must pass an ingress access control.
Also requires the node recvfrom permission.
rawip_recv
rawip_send
tcp_recv
tcp_send
udp_recv
udp_send
Class
socket Socket that is not part of any other specific SELinux socket
object class.
Permissions
Inherit Common
Socket
Permissions
Class
Permissions
Inherit Common
Socket
Permissions
Page 320
connectto
name_connect
newconn
node_bind
Bind to a node.
Class
Permissions
Inherit Common
Socket
Permissions
node_bind
Bind to a node.
Class
Permissions
Inherit Common
Socket
Permissions
node_bind
Bind to a node.
Class
Permissions
Inherit Common
Socket
Permissions
Class
Permissions
Inherit Common
Socket
Permissions
acceptfrom
connectto
newconn
Class
Inherit Common
Socket
Permissions
Class
Permissions
Inherit Common
Socket
Permissions
Permissions
polmatch
recvfrom
sendto
setcontext
Class
Type: All
Permissions
Inherit Common
Socket
Permissions
Class
Permissions
Inherit Common
Socket
Permissions
nlmsg_read
nlmsg_write
Page 322
Permissions
Inherit Common
Socket
Permissions
Class
Permissions
Inherit Common
Socket
Permissions
nlmsg_read
nlmsg_write
Class
Permissions
Inherit Common
Socket
Permissions
nlmsg_read
nlmsg_write
Class
Permissions
Inherit Common
Socket
Permissions
nlmsg_read
nlmsg_write
Class
Permissions
Page 323
Inherit Common
Socket
Permissions
Class
Permissions
Inherit Common
Socket
Permissions
Class
Permissions
Inherit Common
Socket
Permissions
nlmsg_read
nlmsg_readpriv
nlmsg_relay
nlmsg_tty_audit
nlmsg_write
Class
Permissions
Inherit Common
Socket
Permissions
nlmsg_read
nlmsg_write
Class
Permissions
Inherit Common
Socket
Permissions
Class
Page 324
Inherit Common
Socket
Permissions
peer - NetLabel and Labeled IPsec have separate access controls, the
network peer label consolidates these two access controls into a single
one (see http://paulmoore.livejournal.com/1863.html for details).
Permissions
recv
Class
Permissions
flow_in
flow_out
forward_in
forward_out
recv
relabelto
send
Class
Permissions
Inherit Common
Socket
Permissions
Class
Permissions
Inherit Common
Socket
Permissions
name_connect
node_bind
Page 325
8.6
Class
Permissions
Inherit Common
IPC Permissions
Class
sem - Semaphores
Permissions
Inherit Common
IPC Permissions
Class
Permissions
Inherit Common
IPC Permissions
enqueue
Class
Permissions
receive
send
Class
Permissions
Inherit Common
IPC Permissions
lock
8.7
Class
Permissions
dyntransition
execheap
execmem
execstack
fork
getattr
getcap
getpgid
getsched
getsession
Page 326
ptrace
rlimitinh
setcap
setcurrent
setexec
setfscreate
setkeycreate
setpgid
setrlimit
setsched
setsockcreate
share
sigchld
siginh
sigkill
signal
signull
sigstop
transition
8.8
Class
security - This is the security server object and there is only one
instance of this object (for the SELinux security server).
Permissions
check_context
compute_av
compute_create
compute_member
compute_relabel
Determines the context to use when querying the security server about a
relabeling decision (type_change).
compute_user
Determines the context to use when querying the security server about a
user decision (user).
load_policy
Load the security policy into the kernel (the security server).
setbool
setcheckreqprot
setenforce
setsecparam
Page 327
8.9
Class
system - This is the overall system object and there is only one
instance of this object.
Permissions
ipc_info
syslog_console
syslog_mod
syslog_read
Permissions
use_as_override
create_files_as
Grant a process the right to nominate a file creation label for a kernel
service to use.
Grant a process the right to nominate an alternate process SID for the
kernel to use as an override for the SELinux subjective security when
accessing information on behalf of another process.
For example, CacheFiles when accessing the cache on behalf of a process
accessing an NFS file needs to use a subjective security ID appropriate to
the cache rather than the one the calling process is using. The
cachefilesd daemon will nominate the security ID to be used.
Permissions
audit_control
audit_write
chown
dac_override
dac_read_search
fowner
fsetid
ipc_lock
ipc_owner
kill
lease
linux_immutable
mknod
Page 328
net_bind_service
Allow low port binding. Port < 1024 for TCP/UDP. VCI < 32 for ATM.
net_raw
netbroadcast
setfcap
setgid
setpcap
setuid
sys_admin
sys_boot
sys_chroot
sys_module
sys_nice
sys_pacct
sys_ptrace
sys_rawio
sys_resource
Page 329
Grant permission to set system time and to set the real-time lock.
sys_tty_config
Class
capability2
Permissions
mac_admin
mac_override
wake_alarm
epollwakeup
Permissions
add_child
blend
create
destroy
get_property
getattr
Get attributes from a drawable object. Most applications will need this so
SystemLow.
hide
list_child
Allows all child window IDs to be returned. From the root window it will
show the client that owns the window and their stacking order. If hiding
this information is required then processes should be SystemHigh.
list_property
manage
override
read
Read window contents. Note that this will also give read permission to all
child windows, therefore (for MLS), only SystemHigh processes should
have read permission on the root window.
receive
Page 330
send
set_property
Set property. Normally SystemLow for MLS systems (but could leak
information between clients running at different levels, therefore needs
investigation. Polyinstantiation may be required).
setattr
show
write
Draw within a window. Note that this will also give write permission to
all child windows, therefore (for MLS), only SystemHigh processes
should have write permission on the root window.
Class
Permissions
getattr
hide_cursor
saver_getattr
saver_hide
saver_setattr
saver_show
setattr
show_cursor
Class
Permissions
create
destroy
getattr
setattr
use
Class
Permissions
add_glyph
create
Load a font.
destroy
Free a font.
getattr
Page 331
Free glyph
use
Use a font.
Class
Permissions
add_color
create
destroy
Free a Colormap.
getattr
install
read
remove_color
Remove a colour
uninstall
use
Use a colormap
write
Class
Add a colour
each property has a name and ID (or Atom). Properties are attached to
windows and can be uniquely identified by the windowID and
propertyID. XSELinux supports polyinstantiation of properties.
Permissions
append
Append a property.
create
destroy
getattr
read
Read a property.
setattr
write
Write a property.
Class
Permissions
getattr
read
setattr
write
Class
Permissions
create
destroy
Page 332
read
setattr
use
write
Write a cursor
Class
Permissions
destroy
getattr
manage
setattr
Class
x_device - These are any other devices used by the X-server as the
Inherit Common
X_Device
Permissions
Class
Permissions
debug
getattr
grab
manage
record
setattr
Class
Permissions
query
use
Class
read
write
Class
Page 333
send
Send an event
Class
Receive an event
send
Send an event
Receive an event
Class
paste
paste_after_confirm
Class
Permissions
Inherit Common
X_Device
Permissions
Class
Permissions
Inherit Common
X_Device
Permissions
db_database
Permission
Inherit Common
Database
Permissions
access
Page 334
load_module
Class
db_table
Permission
Inherit Common
Database
Permissions
delete
insert
lock
select
update
Class
db_schema
Permission
Inherit Common
Database
Permissions
search
add_name
remove_name
Class
db_procedure
Permission
Inherit Common
Database
Permissions
entrypoint
Required for any functions defined as Trusted Procedures (see [Ref. 3]).
execute
install
Class
db_column
Permission
Inherit Common
Database
Permissions
insert
select
update
Class
db_tuple
Page 335
Permission
delete
insert
relabelfrom
relabelto
Description (7 unique)
Required to delete entries with a DELETE or TRUNCATE statement.
Required when inserting a entry with an INSERT statement, or restoring
tables with a COPY FROM statement.
The security context of an entry can be changed with an UPDATE to the
security_context column at which time relabelfrom and
relabelto permission is evaluated. The client must have
relabelfrom permission to the security context before the entry is
changed, and relabelto permission to the security context after the
entry is changed.
select
update
use
Class
db_blob
Permission
Inherit Common
Database
Permissions
export
import
read
write
Class
db_view
Permission
Inherit Common
Database
Permissions
expand
Class
Permission
Inherit Common
Database
Permissions
get_value
next_value
set_value
Page 336
Class
Permission
Inherit Common
Database
Permissions
implement
Whether the language can be implemented or not for the SQL procedure.
execute
Permissions
chfn
chsh
crontab
passwd
rootok
Class
nscd - This is a userspace object for the Name Service Cache Daemon.
Permission
admin
getgrp
gethost
getpwd
getserv
Get ?? information.
getstat
shmemgrp
shmemhost
shmempwd
shmemserv
Class
dbus - This is a userspace object for the D-BUS Messaging service that
is required to run various services.
Permission
acquire_svc
send_msg
Send a message.
Class
Page 337
translate
Class
Permission
create
Create a keyring.
link
read
Read a keyring.
search
Search a keyring.
setattr
view
View a keyring.
write
Class
blocks.
Permission
mmap_zero
Class
Permission
start
stop
status
reload
kill
Kill services.
Page 338
9.1
The Notebook source tarball contains a number of simple examples that show all the
F-17 (libselinux 2.1.6) functions. These are located in the notebooksource/libselinux/examples directory along with a README file and
simple Makefile. These examples make use of a simple shared library that must be
installed
first
(see
notebook-source/notebooktools/library/README) , this allows users to select contexts strings and other
variables from a configuration file.
Some of the examples require simple policy modules to show different results, these
are located in the notebook-source/libselinux/policy-modules
directory.
Table 33 shows the example name and the functions they use, the policy module
name is shown where applicable.
Notes:
1. The raw version of a function is always used if available as this will avoid
any confusion if the mcstrans daemon is running, the exception is for the
translation example.
2. Examples that use the binary policy file also make use of libsepol functions:
sepol_set_policydb_from_file(3)
sepol_check_context(3)
3. There are other examples (basic_...) that use the selinuxfs interface
to obtain information. These are just to show how this interface is used and
should not be implemented in production software.
.
General Context Functions
1.
context_get_components_example.c
2.
context_set_components_example.c
3.
security_canonicalize_context_example.c
(security_canonicalize_context_example.conf)
security_canonicalize_context, freecon
4.
security_check_context_example.c
security_check_context
Page 339
security_get_initial_context_example.c
6.
selinux_file_context_cmp_example.c
7.
selinux_file_context_verify_example.c
security_get_initial_context_example, freecon
selinux_file_context_cmp
selinux_file_context_verify
get_default_type_example.c
9.
get_default_context_example.c
10.
get_default_context_with_level_example.c
11.
get_default_context_with_role_example.c
12.
get_default_context_with_rolelevel_example.c
13.
get_ordered_context_list_example.c
14.
get_ordered_context_list_with_level_example.c
15.
manual_user_enter_context_example.c
16.
query_user_context_example.c
17.
getseuser_example.c
18.
getseuserbyname_example.c
get_default_type
get_default_context, freecon
get_default_context_with_level, freecon
get_default_context_with_role, freecon
get_default_context_with_rolelevel, freecon
matchpathcon_example.c
20.
matchpathcon_init_prefix_example.c
21.
matchpathcon_file_example.c
22.
matchpathcon_filespec_example1.c
23.
matchpathcon_filespec_example2.c
24.
matchpathcon_policy_file_example.c
25.
selabel_file_example.c
26.
selabel_policy_file_example.c
Page 340
27.
selabel_policy_file_log_example.c
28.
selinux_lsetfilecon_default_example.c
getfilecon_example.c
30.
setfilecon_example.c (setfilecon_example.conf)
31.
fgetfilecon_example.c
32.
fsetfilecon_example.c
33.
lgetfilecon_example.c
34.
lsetfilecon_example.c
getfilecon, freecon
selabel_db_example.c
36.
selabel_media_example.c
37.
selabel_x_example.c
38.
selinux_path_functions_example.c
39.
matchmediacon_example.c
40.
is_context_customizable_example.c
41.
selinux_check_securetty_context_example.c
is_context_customizable
selinux_check_securetty_context
selinux_raw_to_trans_context_example.c
43.
selinux_trans_to_raw_context_example.c
44.
selinux_raw_context_to_color_example1.c
45.
selinux_raw_context_to_color_example2.c
Page 341
getcon_example.c
47.
setcon_example.c (setcon_example.conf)
48.
setcon_thread1_example.c (setcon_example.conf,
setcon_thread_example.conf)
getcon, freecon
setcon, getcon, freecon, execvp
49.
setcon_thread2_example.c (setcon_example.conf,
setcon_thread_example.conf)
setcon, getcon, freecon, execvp, pthread_create
50.
getexeccon_example.c
51.
setexeccon_example.c (setexeccon_example.conf)
52.
getpidcon_example.c
53.
getprevcon_example.c
54.
rpm_execcon_example.c
getexeccon, freecon
setexeccon, getexeccon, freecon, execvp
getpidcon, freecon
getprevcon, freecon
rpm_execcon, getcon
getfscreatecon_example.c
56.
setfscreatecon_example.c
getfscreatecon, freecon
setfscreatecon, getfscreatecon, open (file), fgetfilecon, freecon
getkeycreatecon_example.c
58.
setkeycreatecon_example.c (setkeycreatecon_example.conf)
getkeycreatecon, freecon
getsockcreatecon_example.c
60.
setsockcreatecon_example.c
getsockcreatecon, freecon
getpeercon_server_example.c (getpeercon_example.conf)
62.
getpeercon_client_example.c (getpeercon_example.conf)
print_access_vector_example.c
64.
security_class_to_string_example.c
65.
security_av_perm_to_string_example.c
print_access_vector, string_to_security_class
security_class_to_string
security_av_perm_to_string, string_to_security_class
Page 342
security_av_string_example.c
67.
selinux_set_mapping_example.c
68.
selinux_set_mapping_with_errors_example.c
69.
security_class_to_string_with_class_mapping_example.c
70.
string_to_security_class_example.c
71.
string_to_av_perm_example.c
72.
selinux_check_passwd_access_example.c
73.
selinux_check_access_example.c
74.
selinux_check_access_audit_example.c
75.
security_deny_unknown_example.c
security_av_string, string_to_security_class
selinux_set_mapping, string_to_security_class, string_to_av_perm
selinux_set_mapping, string_to_security_class, string_to_av_perm,
security_class_to_string, security_av_perm_to_string
selinux_set_mapping, security_class_to_string
string_to_security_class
string_to_av_perm, sring_to_security_class, security_class_to_string
selinux_check_passwd_access, security_getenforce
selinux_check_access, security_getenforce
selinux_check_access, security_getenforce, selinux_set_callback, audit_open,
audit_log_user_avc_message
security_deny_unknown
security_compute_av_example.c
77.
security_compute_av_flags_example.c
78.
security_compute_av_mapping_example.c
security_compute_create_example.c
(security_compute_create_example.conf)
security_compute_create, string_to_security_class
80.
security_compute_member_example.c
(security_compute_member_example.conf)
security_compute_member, string_to_security_class
81.
security_compute_relabel_example.c
(security_compute_relabel_example.conf)
security_compute_relabel, string_to_security_class
82.
security_compute_user_example.c
security_compute_user, freecon, freeconary
avc_has_perm_example.c
84.
avc_compute_create_example.c
85.
avc_compute_member_example.c
Page 343
avc_has_perm_callbacks_example.c
87.
avc_has_perm_deny_unknown_example.c
Netlink Functions
88.
avc_netlink_check_nb_example.c
89.
avc_netlink_loop_example.c
90.
avc_netlink_open_example.c
91.
netlink_security_compute_av_example.c
Boolean Functions
92.
security_get_boolean_active_example.c
93.
security_get_boolean_names_example.c
94.
security_get_boolean_pending_example.c
95.
security_set_boolean_example.c
96.
security_set_boolean_list_example.c
97.
security_commit_booleans_example.c
98.
security_load_booleans_example.c
security_get_boolean_active
security_get_boolean_names
security_get_boolean_pending
security_set_boolean
security_set_boolean_list, selinux_booleans_path
security_commit_booleans
security_load_booleans, selinux_booleans_path
is_selinux_mls_enabled_example.c
100.
selinux_getenforcemode_example.c
101.
selinux_getpolicytype_example.c
is_selinux_mls_enabled
selinux_getenforcemode, selinux_path
selinux_getpolicytype
Page 344
selinux_reset_config_example.c
103.
security_load_policy_example.c
104.
selinux_init_load_policy_example.c
105.
selinux_mkload_policy_example.c
106.
is_selinux_enabled_example.c
107.
security_getenforce_example.c
108.
security_setenforce_example.c
109.
security_policyvers_example.c
110.
set_selinuxmnt_example.c
111.
security_disable_example.c
selinux_reset_config, selinux_path
security_load_policy
selinux_init_load_policy
security_getenforce
security_setenforce, security_getenforce
security_policyvers
set_selinuxmnt
security_disable
Page 345
9.2
These functions have been taken from the following header files of libselinux version 2.1.11:
/usr/include/selinux/avc.h
/usr/include/selinux/context.h
/usr/include/selinux/get_context_list.h
/usr/include/selinux/get_default_type.h
/usr/include/selinux/label.h
/usr/include/selinux/selinux.h
The appropriate man(3) pages should consulted for detailed usage, also the libselinux source code.
Num.
Function Name
Description
Header File
1.
avc_add_callback
avc.h
2.
avc_audit
Audit the granting or denial of permissions in accordance with the policy. This
function is typically called by avc_has_perm() after a permission check,
but can also be called directly by callers who use
avc_has_perm_noaudit() in order to separate the permission check
from the auditing. For example, this separation is useful when the permission
check must be performed under a lock, to allow the lock to be released before
calling the auditing code.
avc.h
3.
avc_av_stats
Log AV table statistics. Logs a message with information about the size and
distribution of the access vector table. The audit callback is used to print the
message.
avc.h
4.
avc_cache_stats
Get cache access statistics. Fill the supplied structure with information about
AVC activity since the last call to avc_init() or avc_reset().
avc.h
5.
avc_cleanup
avc.h
Page 346
Description
Header File
6.
Function Name
avc_compute_create
Compute SID for labeling a new object. Call the security server to obtain a
context for labeling a new object. Look up the context in the SID table,
making a new entry if not found.
avc.h
7.
avc_compute_member
avc.h
8.
avc_context_to_sid
avc_context_to_sid_raw
Get SID for context. Look up security context ctx in SID table, making a new
entry if ctx is not found. Store a pointer to the SID structure into the memory
referenced by sid, returning 0 on success or -1 on error with errno set.
avc.h
9.
avc_destroy
avc.h
10.
avc_entry_ref_init
avc.h
11.
avc_get_initial_sid
avc.h
12.
avc_has_perm
avc.h
13.
avc_has_perm_noaudit
avc.h
Page 347
Function Name
Description
Header File
whether the requested permissions are granted for the SID pair (ssid,
tsid), interpreting the permissions based on tclass, and call the security
server on a cache miss to obtain a new decision and add it to the cache. Update
aeref to refer to an AVC entry with the resulting decisions, and return a
copy of the decisions in avd. Return 0 if all requested permissions are
granted, -1 with errno set to EACCES if any permissions are denied, or to
another value upon other errors. This function is typically called by
avc_has_perm(), but may also be called directly to separate permission
checking from auditing, e.g. in cases where a lock must be held for the check
but should be released for the auditing.
14.
avc_init (deprecated)
Use avc_open
Initialize the AVC. Initialize the access vector cache. Return 0 on success or -1
with errno set on failure. If msgprefix is NULL, use "uavc". If any
callback structure references are NULL, use default methods for those
callbacks (see the definition of the callback structures).
avc.h
15.
avc_netlink_acquire_fd
avc.h
16.
avc_netlink_check_nb
avc.h
17.
avc_netlink_close
avc.h
18.
avc_netlink_loop
Acquire netlink socket fd. Allows the application to manage messages from
the netlink socket in its own main loop.
avc.h
19.
avc_netlink_open
Release netlink socket fd. Returns ownership of the netlink socket to the
library.
avc.h
20.
avc_netlink_release_fd
Check netlink socket for new messages. Called by the application when using
avc_netlink_acquire_fd() to process kernel netlink events.
avc.h
21.
avc_open
avc.h
22.
avc_reset
Flush the cache and reset statistics. Remove all entries from the cache and
reset all access statistics (as returned by avc_cache_stats()) to zero.
The SID mapping is not affected. Return 0 on success, -1 with errno set on
error.
avc.h
23.
avc_sid_stats
Log SID table statistics. Log a message with information about the size and
avc.h
Page 348
Function Name
Description
Header File
distribution of the SID table. The audit callback is used to print the message.
24.
avc_sid_to_context
avc_sid_to_context_raw
avc.h
25.
checkPasswdAccess (deprecated)
selinux.h
26.
context_free
context.h
27.
context_new
context.h
28.
context_range_get
context.h
29.
context_range_set
context.h
30.
context_role_get
context.h
31.
context_role_set
context.h
32.
context_str
Return a pointer to the string value of context_t. Valid until the next call to
context_str or context_free for the same context_t*.
context.h
33.
context_type_get
context.h
34.
context_type_set
context.h
35.
context_user_get
context.h
36.
context_user_set
context.h
37.
fgetfilecon
fgetfilecon_raw
Wrapper for the xattr API - Get file context, and set *con to refer to it.
Caller must free via freecon.
selinux.h
38.
fini_selinuxmnt
selinux.h
39.
freecon
Free the memory allocated for a context by any of the get* calls.
selinux.h
40.
freeconary
selinux.h
41.
fsetfilecon
selinux.h
Page 349
Function Name
fsetfilecon_raw
Description
Header File
42.
get_default_context
Get the default security context for a user session for 'user' spawned by
'fromcon' and set *newcon to refer to it. The context will be one of those
authorized by the policy, but the selection of a default is subject to user
customizable preferences. If 'fromcon' is NULL, defaults to current context.
Returns 0 on success or -1 otherwise. Caller must free via freecon.
get_context_list.h
43.
get_default_context_with_level
get_context_list.h
44.
get_default_context_with_role
get_context_list.h
45.
get_default_context_with_rolelevel
get_context_list.h
46.
get_default_type
Get the default type (domain) for 'role' and set 'type' to refer to it. Caller
must free via free(). Return 0 on success or -1 otherwise.
get_default_type.h
47.
get_ordered_context_list
Get an ordered list of authorized security contexts for a user session for 'user'
spawned by 'fromcon' and set *conary to refer to the NULL-terminated
array of contexts. Every entry in the list will be authorized by the policy, but
the ordering is subject to user customizable preferences. Returns number of
entries in *conary. If 'fromcon' is NULL, defaults to current context.
Caller must free via freeconary.
get_context_list.h
48.
get_ordered_context_list_with_level
get_context_list.h
49.
getcon
getcon_raw
Get current context, and set *con to refer to it. Caller must free via
freecon.
selinux.h
50.
getexeccon
getexeccon_raw
Get exec context, and set *con to refer to it. Sets *con to NULL if no
exec context has been set, i.e. using default. If non-NULL, caller must free
via freecon.
selinux.h
51.
getfilecon
getfilecon_raw
Wrapper for the xattr API - Get file context, and set *con to refer to it.
Caller must free via freecon.
selinux.h
52.
getfscreatecon
getfscreatecon_raw
Get fscreate context, and set *con to refer to it. Sets *con to NULL if no
fs create context has been set, i.e. using default.If non-NULL, caller must free
selinux.h
Page 350
Function Name
Description
Header File
via freecon.
53.
getkeycreatecon
getkeycreatecon_raw
Get keycreate context, and set *con to refer to it. Sets *con to NULL if
no key create context has been set, i.e. using default. If non-NULL, caller must
free via freecon.
selinux.h
54.
getpeercon
getpeercon_raw
Wrapper for the socket API - Get context of peer socket, and set *con to refer
to it. Caller must free via freecon.
selinux.h
55.
getpidcon
getpidcon_raw
Get context of process identified by pid, and set *con to refer to it. Caller
must free via freecon.
selinux.h
56.
getprevcon
getprevcon_raw
Get previous context (prior to last exec), and set *con to refer to it. Caller
must free via freecon.
selinux.h
57.
getseuser
Get the SELinux username and level to use for a given Linux username
and service. These values may then be passed into the
get_ordered_context_list* and get_default_context*
functions to obtain a context for the user. Returns 0 on success or -1 otherwise.
Caller must free the returned strings via free().
selinux.h
58.
getseuserbyname
Get the SELinux username and level to use for a given Linux
username. These values may then be passed into the
get_ordered_context_list* and get_default_context*
functions to obtain a context for the user. Returns 0 on success or -1 otherwise.
Caller must free the returned strings via free().
selinux.h
59.
getsockcreatecon
getsockcreatecon_raw
Get sockcreate context, and set *con to refer to it. Sets *con to NULL if
no socket create context has been set, i.e. using default. If non-NULL, caller
must free via freecon.
selinux.h
60.
init_selinuxmnt
There is a man page for this, however it is not a user accessable function
(internal use only - although the fini_selinuxmnt is reachable).
61.
is_context_customizable
selinux.h
62.
is_selinux_enabled
selinux.h
63.
is_selinux_mls_enabled
selinux.h
64.
lgetfilecon
lgetfilecon_raw
Wrapper for the xattr API - Get file context, and set *con to refer to it.
Caller must free via freecon.
selinux.h
Page 351
Description
Header File
65.
Function Name
lsetfilecon
lsetfilecon_raw
Wrapper for the xattr API- Set file context for symbolic link.
selinux.h
66.
manual_user_enter_context
get_context_list.h
67.
matchmediacon
Match the specified media and against the media contexts configuration and
set *con to refer to the resulting context. Caller must free con via freecon.
selinux.h
68.
matchpathcon
Match the specified pathname and mode against the file context sconfiguration
and set *con to refer to the resulting context.'mode' can be 0 to disable
mode matching. Caller must free via freecon. If matchpathcon_init
has not already been called, then this function will call it upon its first
invocation with a NULL path.
selinux.h
69.
matchpathcon_checkmatches
Check to see whether any specifications had no matches and report them. The
'str' is used as a prefix for any warning messages.
selinux.h
70.
matchpathcon_filespec_add
selinux.h
71.
matchpathcon_filespec_destroy
Destroy any inode associations that have been added, e.g. to restart for a new
filesystem.
selinux.h
72.
matchpathcon_filespec_eval
selinux.h
73.
matchpathcon_fini
selinux.h
74.
matchpathcon_index
selinux.h
75.
matchpathcon_init
Load the file contexts configuration specified by 'path' into memory for use
by subsequent matchpathcon calls. If 'path' is NULL, then load the active
file contexts configuration, i.e. the path returned by
selinux_file_context_path(). Unless the
MATCHPATHCON_BASEONLY flag has been set, this function also checks for
a 'path'.homedirs file and a 'path'.local file and loads additional
specifications from them if present.
selinux.h
Page 352
Description
Header File
76.
Function Name
matchpathcon_init_prefix
selinux.h
77.
print_access_vector
selinux.h
78.
query_user_context
Given a list of authorized security contexts for the user, query the user to
select one and set *newcon to refer to it. Caller must free via freecon.
Returns 0 on sucess or -1 otherwise.
get_context_list.h
79.
rpm_execcon
selinux.h
80.
security_av_perm_to_string
selinux.h
81.
security_av_string
Returns an access vector in a string representation. User must free the returned
string via free().
selinux.h
82.
security_canonicalize_context
security_canonicalize_context_raw
selinux.h
83.
security_check_context
security_check_context_raw
selinux.h
84.
security_class_to_string
selinux.h
85.
security_commit_booleans
selinux.h
86.
security_compute_av
security_compute_av_raw
selinux.h
87.
security_compute_av_flags
security_compute_av__flags_raw
selinux.h
Page 353
Function Name
security_compute_create
security_compute_create_raw
Description
Header File
Compute a labeling decision and set *newcon to refer to it. Caller must free
via freecon.
selinux.h
89.
security_compute_create_name
security_compute_create_name_raw
selinux.h
90.
security_compute_member
security_compute_member_raw
selinux.h
91.
security_compute_relabel
security_compute_relabel_raw
Compute a relabeling decision and set *newcon to refer to it. Caller must free
via freecon.
selinux.h
92.
security_compute_user
security_compute_user_raw
selinux.h
93.
security_deny_unknown
Compute the set of reachable user contexts and set *con to refer to the
NULL-terminated array of contexts. Caller must free via freeconary.
Get the behavior for undefined classes / permissions.
94.
security_disable
selinux.h
95.
security_get_boolean_active
selinux.h
96.
security_get_boolean_names
selinux.h
97.
security_get_boolean_pending
selinux.h
98.
security_get_initial_context
security_get_initial_context_raw
Get the context of an initial kernel security identifier by name. Caller must
free via freecon.
selinux.h
99.
security_getenforce
selinux.h
100.
security_load_booleans
Load policy boolean settings. Path may be NULL, in which case the booleans
are loaded from the active policy boolean configuration file.
selinux.h
101.
security_load_policy
selinux.h
102.
security_policyvers
selinux.h
103.
security_set_boolean
selinux.h
104.
security_set_boolean_list
selinux.h
88.
selinux.h
Page 354
Description
Header File
105.
Function Name
security_setenforce
selinux.h
106.
selabel_close
Destroy the specified handle, closing files, freeing allocated memory, etc. The
handle may not be further used after it has been closed.
label.h
107.
selabel_lookup
selabel_lookup_raw
label.h
108.
selabel_open
label.h
109.
selabel_stats
label.h
110.
selinux_binary_policy_path
Return path to the binary policy file under the policy root directory.
selinux.h
111.
selinux_booleans_path
Return path to the booleans file under the policy root directory.
selinux.h
Page 355
Function Name
selinux_check_access
Description
Header File
Used to check if the source context has the access permission for the specified
class on the target context. Note that the permission and class are reference
strings.
The aux parameter may reference supplemental auditing information.
Auditing is handled as described in avc_audit(3).
See security_deny_unknown(3) for how the deny_unknown flag
can influence policy decisions.
Check a permission in the passwd class. Return 0 if granted or -1 otherwise.
Replaced by selinux_check_access
selinux.h
113.
selinux_check_passwd_access
114.
selinux_check_securetty_context
selinux.h
115.
selinux_colors_path
selinux.h
116.
selinux_contexts_path
selinux.h
117.
selinux_customizable_types_path
selinux.h
118.
selinux_default_context_path
selinux.h
119.
selinux_default_type_path
120.
selinux_failsafe_context_path
selinux.h
121.
selinux_file_context_cmp
selinux.h
122.
selinux_file_context_homedir_path
selinux.h
123.
selinux_file_context_local_path
selinux.h
124.
selinux_file_context_path
selinux.h
125.
selinux_file_context_subs_path
selinux.h
126.
selinux_file_context_subsdist_path
selinux.h
127.
selinux_file_context_verify
Verify the context of the file 'path' against policy. Return 0 if correct.
selinux.h
128.
selinux_get_callback
Used to get a pointer to the callback function of the given type. Callback
functions are set using selinux_set_callback(3).
selinux.h
129.
selinux_getenforcemode
selinux.h
selinux.h
get_default_type.h
Page 356
Function Name
Description
Header File
selinux_getpolicytype
selinux.h
131.
selinux_homedir_context_path
Return path to file under the policy root directory. Note that this file will only
appear in older versions of policy at this location. On systems that are
managed using semanage(8) this is now in the policy store.
selinux.h
132.
selinux_init_load_policy
selinux.h
133.
selinux_lsetfilecon_default
This function sets the file context on to the system defaults returns 0 on
success.
selinux.h
134.
selinux_media_context_path
selinux.h
Page 357
Description
Header File
135.
Function Name
selinux_mkload_policy
selinux.h
136.
selinux_netfilter_context_path
selinux.h
137.
selinux_path
selinux.h
138.
selinux_policy_root
Reads the /etc/selinux/config file and returns the top level directory.
selinux.h
139.
selinux_raw_context_to_color
selinux.h
140.
selinux_raw_to_trans_context
selinux.h
141.
selinux_removable_context_path
selinux.h
142.
selinux_securetty_types_path
Return path to the securetty_types file under the policy root directory.
selinux.h
143.
selinux_sepgsql_context_path
144.
selinux_set_mapping
Userspace class mapping support that establishes a mapping from a userprovided ordering of object classes and permissions to the numbers actually
used by the loaded system policy.
selinux.h
145.
selinux_trans_to_raw_context
selinux.h
Page 358
Function Name
Description
Header File
selinux_translations_path
selinux.h
147.
selinux_user_contexts_path
selinux.h
148.
selinux_users_path
selinux.h
149.
selinux_usersconf_path
selinux.h
150.
selinux_virtual_domain_context_path
selinux.h
151.
selinux_virtual_image_context_path
selinux.h
152.
selinux_x_context_path
selinux.h
153.
set_matchpathcon_canoncon
selinux.h
154.
set_matchpathcon_flags
selinux.h
155.
set_matchpathcon_invalidcon
selinux.h
156.
set_matchpathcon_printf
selinux.h
157.
set_selinuxmnt
Set the path to the selinuxfs mount point explicitly. Normally, this is
determined automatically during libselinux initialization, but this is not
always possible, e.g. for /sbin/init which performs the initial mount of
selinux.h
Page 359
Function Name
Description
Header File
selinuxfs.
158.
setcon
setcon_raw
selinux.h
159.
setexeccon
setexeccon_raw
Set exec security context for the next execve. Call with NULL if you want
to reset to the default.
selinux.h
160.
setfilecon
setfilecon_raw
selinux.h
161.
setfscreatecon
setfscreatecon_raw
Set the fscreate security context for subsequent file creations. Call with
NULL if you want to reset to the default.
selinux.h
162.
setkeycreatecon
setkeycreatecon_raw
Set the keycreate security context for subsequent key creations. Call with
NULL if you want to reset to the default.
selinux.h
163.
setsockcreatecon
setsockcreatecon_raw
selinux.h
164.
sidget (deprecated)
Set the sockcreate security context for subsequent socket creations. Call
with NULL if you want to reset to the default.
From 2.0.86 this is a no-op.
165.
sidput (deprecated)
avc.h
166.
string_to_av_perm
selinux.h
167.
string_to_security_class
selinux.h
avc.h
Page 360
Man
Page
audit2allow
audit2why
avcstat
chcat
chcon
checkmodule
checkpolicy
fixfiles
1
8
8
8
1
8
8
8
genhomedircon
getenforce
getsebool
load_policy
1
8
8
matchpathcon
newrole
8
1
restorecon
run_init
runcon
selinuxenabled
semanage
semodule
semodule_expand
8
8
1
1
8
8
8
semodule_link
semodule_package
8
8
sestatus
setenforce
setfiles
setsebool
8
1
8
8
Purpose
Generates policy allow rules from the audit.log file.
Describes audit.log messages and why access was denied.
Displays the AVC statistics.
Change or remove a catergory from a file or user.
Changes the security context of a file.
Compiles base and loadable modules from source.
Compiles a monolithic policy from source.
Update / correct the security context of for filesystems that use
extended attributes.
Generates file configuration entries for users home directories.
This command has also been built into semanage(8), therefore
when using the policy store / loadable modules this does not need
to be used.
Shows the current enforcement state.
Shows the state of the booleans.
Loads a new policy into the kernel. Not required when using
semanage(8) / semodule(8) commands.
Show a files path and security context.
Allows users to change roles - runs a new shell with the new
security context.
Sets the security context on one or more files.
Runs an init script under the correct context.
Runs a command with the specified context.
Shows whether SELinux is enabled or not.
Used to configure various areas of a policy within a policy store.
Used to manage the installation, upgrading etc. of policy modules.
Manually expand a base policy package into a kernel binary
policy file.
Manually link a set of module packages.
Create a module package with various configuration files (file
context etc.)
Show the current status of SELinux and the loaded policy.
Sets / unsets enforcement mode.
Initialise the extended attributes of filesystems.
Sets the state of a boolean to on or off persistently across reboots
or for this session only.
Page 361
Title
Author
1.
K. Kohei
2.
J. Brindle
3.
R. Coker
4.
S. Smalley, C.
Vance, W. Salamon
5.
Iptables Tutorial
O. Andreasson
6.
J. Morris
7.
Transitioning to Secmark
Paul Moore
8.
Paul Moore
9.
Trent Jaeger
10.
IPSec HOWTO
Ralf Spenneberg
11.
J. Brindle
12.
SELinux by Example
13.
F. Mayer
K Macmillan
D Caplan
S. Hallyn
14.
E. Paris
16.
E. Walsh
17.
E. Walsh
18.
K. Kohei
19.
Red Hat
20.
Xen Project
21.
G. Coker
22.
S. Smalley
15.
Page 362
0. Preamble
The purpose of this License is to make a manual, textbook, or other functional and useful document "free" in the sense of freedom: to assure everyone the effective freedom
to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to
get credit for their work, while not being considered responsible for modifications made by others.
This License is a kind of "copyleft", which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General
Public License, which is a copyleft license designed for free software.
We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals
providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or
whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference.
2. Verbatim Copying
You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license
notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use
technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for
copies. If you distribute a large enough number of copies you must also follow the conditions in section 3.
You may also lend copies, under the same conditions stated above, and you may publicly display copies.
3. Copying In Quantity
If you publish printed copies (or copies in media that commonly have printed covers) of the Document, numbering more than 100, and the Document's license notice
requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover
Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of
the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title
of the Document and satisfy these conditions, can be treated as verbatim copying in other respects.
If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the
rest onto adjacent pages.
If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each
Opaque copy, or state in or with each Opaque copy a computer-network location from which the general network-using public has access to download using public-standard
network protocols a complete Transparent copy of the Document, free of added material. If you use the latter option, you must take reasonably prudent steps, when you
begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last
time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public.
Page 363
4. Modifications
You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under
precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever
possesses a copy of it. In addition, you must do these things in the Modified Version:
A.
Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were
any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives
permission.
B.
List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at
least five of the principal authors of the Document (all of its principal authors, if it has fewer than five), unless they release you from this requirement.
C.
State on the Title page the name of the publisher of the Modified Version, as the publisher.
D.
E.
Add an appropriate copyright notice for your modifications adjacent to the other copyright notices.
F.
Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in
the form shown in the Addendum below.
G.
Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice.
H.
I.
Preserve the section Entitled "History", Preserve its Title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified
Version as given on the Title Page. If there is no section Entitled "History" in the Document, create one stating the title, year, authors, and publisher of the
Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence.
J.
Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations
given in the Document for previous versions it was based on. These may be placed in the "History" section. You may omit a network location for a work that
was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission.
K.
For any section Entitled "Acknowledgements" or "Dedications", Preserve the Title of the section, and preserve in the section all the substance and tone of
each of the contributor acknowledgements and/or dedications given therein.
L.
Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the
section titles.
M.
Delete any section Entitled "Endorsements". Such a section may not be included in the Modified Version.
N.
Do not retitle any existing section to be Entitled "Endorsements" or to conflict in title with any Invariant Section.
O.
If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at
your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These
titles must be distinct from any other section titles.
You may add a section Entitled "Endorsements", provided it contains nothing but endorsements of your Modified Version by various partiesfor example, statements of
peer review or that the text has been approved by an organization as the authoritative definition of a standard.
You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the
Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document
already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another;
but you may replace the old one, on explicit permission from the previous publisher that added the old one.
The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any
Modified Version.
5. Combining Documents
You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you
include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its
license notice, and that you preserve all their Warranty Disclaimers.
The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant
Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or
publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the
combined work.
In the combination, you must combine any sections Entitled "History" in the various original documents, forming one section Entitled "History"; likewise combine any
sections Entitled "Acknowledgements", and any sections Entitled "Dedications". You must delete all sections Entitled "Endorsements".
6. Collections Of Documents
You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various
documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other
respects.
You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted
document, and follow this License in all other respects regarding verbatim copying of that document.
Page 364
9. Termination
You may not copy, modify, sublicense, or distribute the Document except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, or
distribute it is void, and will automatically terminate your rights under this License.
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder
explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days
after the cessation.
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is
the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of
the notice.
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have
been terminated and not permanently reinstated, receipt of a copy of some or all of the same material does not give you any rights to use it.
11. Relicensing
"Massive Multiauthor Collaboration Site" (or "MMC Site") means any World Wide Web server that publishes copyrightable works and also provides prominent facilities
for anybody to edit those works. A public wiki that anybody can edit is an example of such a server. A "Massive Multiauthor Collaboration" (or "MMC") contained in the
site means any set of copyrightable works thus published on the MMC site.
"CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0 license published by Creative Commons Corporation, a not-for-profit corporation with a principal
place of business in San Francisco, California, as well as future copyleft versions of that license published by that same organization.
"Incorporate" means to publish or republish a Document, in whole or in part, as part of another Document.
An MMC is "eligible for relicensing" if it is licensed under this License, and if all works that were first published under this License somewhere other than this MMC, and
subsequently incorporated in whole or in part into the MMC, (1) had no cover texts or invariant sections, and (2) were thus incorporated prior to November 1, 2008.
The operator of an MMC Site may republish an MMC contained in the site under CC-BY-SA on the same site at any time before August 1, 2009, provided the MMC is
eligible for relicensing.
Page 365