Reference Policy For Security Enhanced Linux: Christopher J. Pebenito, Frank Mayer, Karl Macmillan
Reference Policy For Security Enhanced Linux: Christopher J. Pebenito, Frank Mayer, Karl Macmillan
Abstract
The Reference Policy project is an effort to restructure the NSA example policy for SELinux, which has evolved
through many years of community involvement and is the basis for nearly all sample SELinux Policy in use today.
The Reference Policy is rigorously structured using modularity, layering, encapsulation, and abstraction, making it
simpler to maintain, modify, and use. The goal of this restructuring is to allow greater adaptation and adoption of
SELinux while maintaining the knowledge gained through the years of policy evolution, while increasing our ability
to validate the security properties of a given SELinux policy.
• Improved comprehension: allow policy writers The existing example policy has evolved a form of
to more easily understand the policy by ag- modularity that helps manage complexity, but in gen-
gressively adding documentation, enabling eral still leaves modules tightly coupled. For the Refer-
them to make security relevant decisions; and ence Policy we are more strict in the organization and
definition of modules, enforcing several strong rules by
• Policy configurations: supports the strict and convention.
targeted policies, MLS, and the recently added
MCS configuration [7] as build options, with- Each module has three component source files: 1) a
out requiring destructive changes to the policy private module policy (.te), 2) a set of external inter-
or multiple policy source trees. faces (.if), and 3) a file labeling policy (.fc). The pri-
vate policy file contains the declarations and rules that
3. Concepts, Rules, and Conventions are local to the module. The external interface file pro-
vides abstract access to types and attributes that are
private to the module, for other modules’ use. These the types and rules for ssh domains and keys for each
interfaces are designed to be intuitive, reflecting access role. Support macros parallel many of the “core mac-
to some set of system capabilities. A policy developer ros” in the NSA example policy, providing common
should be able to use an interface, understanding its policy patterns. Examples include domain transitions
purpose, without having to understand how the purpose and object class permission sets. Support macros are
is implemented within the module. The file labeling essentially “helper functions” that are used solely to
policy files consists of file contexts statements, if any, help simplify the private, internal implementation of a
associated with the module. module (i.e., they are never interfaces).
The encapsulation rules for a module ensures that all of The most fundamental change to the current structure is
the module’s implementation details are private to the the use of macros for gaining access to a type outside of
module itself. This allows changes to the module’s im- the module in which the type is defined. Interfaces pro-
plementation without affecting other policy modules, vide access to a module’s policy resources (i.e., to its
reducing the coupling of policy modules. privately declared types and attributes). All domains
needing a particular access will use the same interface;
The Reference Policy has several important policy writ- therefore, the policy rules required for the access will
ing rules which capture the important concepts of en- be consistent across all users of the interface. Thus
capsulation and abstraction. Perhaps the most impor- policy changes for access to a type require only a
tant rule is type and attribute identifiers are private to a change in one place, rather than requiring changes to all
module; thus, types and attributes may not be directly the modules that use the type as is common in the sam-
referenced by name outside of the module in which it is ple policy.
declared. This also means that there are no global
types or attributes. In the future it may make sense to add interface and
templates macro semantics to the base language. As
Abstraction is used to create higher-level concepts of macros, any time an interface is changed, all modules
access. This enables policy writers to make security that use this interface must be recompiled. With inter-
relevant decisions, rather than being impeded with un- faces in the language, modules will become decoupled
derstanding all of the implementation details. M4 mac- on the loadable module level, in addition to the source
ros are used to create the abstractions, though in gen- level.
eral we enforce strict conventions on the type of macros
allowed, unlike the current practice of allow any form For improved clarity, interfaces follow clear naming
of macro that M4 can support 1 . Each macro contains conventions. In particular, the module name, or abbre-
only one concept, and rules are not added for conven- viation, is prefixed to the interface name. This allows a
ience. policy writer to look a policy and easily see where all
of the interface calls are. In addition, consistent verbs
There are three types of macros supported by Reference are used to describe the access, such as read, write, and
Policy: interface, template, and support. Interface mac- delete.
ros are those that export access to a module’s internal
types and/or transform a type, e.g., making a caller’s Each interface contains two parts, the dependencies and
type a “domain.” Interfaces are one of the primary in- the access. The dependencies are contained in a
novations of Reference Policy, providing most of the gen_require() macro. This macro contains the state-
de-coupling of module implementations. Template ments that would be placed in a require block for load-
macros are a special form of interfaces that create able modules. It lists all of the types and attributes used
and/or manipulate derived types on behalf of the call- by the interface. If an object class for a user space ob-
ers. While the derived types are conceptually private to ject manager is used, such as DBUS or NSCD, the ob-
the caller, their implementation details are contained ject class and required permissions must also be listed.
wholly within the module that creates the template
macros. These macros are used , for example, to create 3.1.4. Module Template Interfaces
1
In the future, we may remove M4 all together in favor of a Template macros are the only macros that can declare
custom-made parser, primarily because M4 is too flexible and types and attributes as part of an interface, i.e., the so-
invites abuse of our modularity rules. called derived types. The module defining the template
macro is the only places where explicit access to/from specifies the categories a file has when using a MCS
the derived types can be defined. The only real differ- policy. This allows a change between a MLS and non-
ence between interface and template macros is that tem- MLS policy, for example, without modifying the pol-
plate macros use and/or create derived types on behalf icy.
of the caller. Both macros are “interfaces” to the defin-
ing module and can access the module’s private types. 5. Summary
4. Module Example The Reference Policy project has many goals, both se-
curity and functional goals, but the most important one
Below is an excerpt from the BIND DNS server, from is to make the policy simpler to understand and main-
the Reference Policy. tain. It uses layering, modularity, encapsulation, and
abstraction to structure the policy, in addition to exten-
4.2 bind.te sive documentation, to better meet these goals.
Example 1 shows the complete private policy for the Interfaces, the most fundamental change to the policy,
named domain. The policy_module() macro contains abstract the details creating higher-level concepts of
the name and version of this module, which are used in access for policy writers. Modules encapsulate all of
loadable policy modules. The next nine lines contain the implementation details for a particular subset of
the type declarations and transformation macro calls. policy since all types and attributes are only directly
The type for the domain and its entry point program are usable from a particular module, and there are no
declared and transformed using the global types or attributes. Finally, layers organize the
init_daemon_domain() macro, which is an interface modules into more meaningful groups.
from the init module. The remainder of the private
policy contains the rules for the BIND service. For 6. References
access to types not in this module, there are nine calls
to interfaces of other modules complete the policy, for [1] http://selinux.sourceforge.net and
example logging_send_syslog_msg() is an interface http://www.nsa.gov/selinux
from the logging module that allows bind to send mes-
sages to the system log daemon. [2] http://fedora.redhat.com/download
Interfaces are defined in the module .if file. In Example [4] http://serefpolicy.sourceforge.net
2, we see a use of the interface() macro to define access
to entry the named domain (i.e., a domain transition [5] Peter A. Loscocco, Stephen D. Smalley, Pat-
interface). The caller would provide the type it wants to rick A. Muckelbauer, and Ruth C. Taylor.
have the access to enter the named domain. “The Inevitability of Failure: The Flawed As-
sumption of Security in Modern Computing
In addition to the actual interfaces, the interfaces file Environments.” In Proceedings of the 21st Na-
has its inline documentation encapsulated in XML, as tional Information Systems Security Confer-
also shown in Example 2. This provides documenta- ence, pages 303-314, October 1998.
tion not only for policy writers to see when reading the
file, but the XML can also be extracted from the policy [6] Karl MacMillan. “Core Policy Management
and read by development and analysis tools. Infrastructure for SELinux.” 2005 SELinux
Symposium.
4.4. bind.fc
[7] James Morris. “A Brief Introduction to Multi-
The structure of a module’s file contexts file has not Category Security (MCS).”
been changed, as illustrated in Example 3. To facilitate http://www.livejournal.com/users/james_morri
the use of MLS and MCS policies, a gen_context() s/5583.html
macro has been added. The regular type enforcement
file context is specified as the first parameter. The sec-
ond parameter provides the level of the file when a
MLS policy is being used. An optional third parameter
policy_module(bind,1.1.0)
type named_t;
type named_exec_t;
init_daemon_domain(named_t,named_exec_t)
type named_cache_t;
files_type(named_cache_t)
type named_conf_t;
files_type(named_conf_t)
type named_zone_t;
files_type(named_zone_t)
kernel_read_system_state(named_t)
kernel_read_network_state(named_t)
corenet_non_ipsec_sendrecv(named_t)
corenet_udp_sendrecv_all_if(named_t)
corenet_udp_sendrecv_all_nodes(named_t)
corenet_udp_sendrecv_all_ports(named_t)
corenet_udp_bind_all_nodes(named_t)
corenet_udp_bind_dns_port(named_t)
logging_send_syslog_msg(named_t)
########################################
## <summary>
## Execute bind in the named domain.
## </summary>
## <param name="domain">
## Domain allowed access.
## </param>
#
interface(`bind_domtrans',`
gen_require(`
type named_t, named_exec_t;
')
domain_auto_trans($1,named_exec_t,named_t)
/etc/rndc.* -- gen_context(system_u:object_r:named_conf_t,s0)
/usr/sbin/named -- gen_context(system_u:object_r:named_exec_t,s0)
/var/named(/.*)? gen_context(system_u:object_r:named_zone_t,s0)
/var/named/slaves(/.*)? gen_context(system_u:object_r:named_cache_t,s0)
/var/named/data(/.*)? gen_context(system_u:object_r:named_cache_t,s0)