Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > C


HP-UX 11i Version 3: February 2007

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index


compartments — description of HP-UX compartments


The UNIX® operating system has traditionally used a single compartment model. The relatively free access in traditional single compartment systems can lead to problems with malicious software or with compromised programs. If a way to exploit a daemon process is discovered and used, an intruder gains considerable access to the system. If the daemon process is running with an effective uid of 0 while being exploited, this could translate to complete system access. With the use of compartments, you can limit access to only what the process needs, thus reducing the amount of damage malicious or exploited programs can do.

A compartment isolates a process so that it can only access objects within the same compartment, unless a compartment rule grants the process access to other compartments. Other access control methodologies, such as file permissions and ACLs, still apply.

You can override compartment restrictions with appropriate privileges. See privileges(5) for a list of privileges.

Compartments control process access to several different types of system objects. Some of these object types are persistent, and are typically referenced by name (such as files). These objects do not have a compartment directly associated with them. Instead, the rules that govern access to these objects are associated with the name of the object. Other object types are transient, lasting only as long as the process that created them, or while the system is booted. Transient objects are labeled with the compartment of the process that creates them. The rules that govern access to these objects is a direct compartment-to-compartment relationship.

Compartments govern three types of system objects: file system objects (persistent), inter-process communication (IPC) objects (transient), network objects (transient):

  • File System Objects. Includes files and directories. By default, all file system objects are accessible by any compartment. However, specific compartment configuration can define rules to restrict access to various file system objects.

  • Inter-process Communication (IPC) Objects. Enable or restrict communication between processes on a single system. The types of IPC objects are System V shared memory, System V semaphores, System V message queues, POSIX semaphores, POSIX message queues, PTYs, FIFOs, UNIX domain sockets, and processes (signal mechanism). POSIX shared memory is implemented as file system objects; hence, compartment access is controlled with file system rules. By default, processes in a given compartment cannot access IPC objects in another compartment unless explicitly configured otherwise.

  • Network Communication Objects. Includes network endpoints (sockets and streams) and network LAN interfaces. These objects are used to communicate via the TCP/IP protocol with processes on both local and remote systems. Access is controlled between a process' network endpoints and the LAN interfaces through which traffic passes to remote systems. As with IPC objects, processes in a given compartment cannot access network objects in a different compartment unless explicitly configured to do so.

    Each network LAN interface (logical/physical/virtual) can belong to a compartment of its own. For example, it is possible to set the rules such that logical interfaces lan0:1 and lan0:2 belong to different compartments.


At system start up, the compartment configuration is read from files in the /etc/cmpt directory. The configuration is placed in files ending with .rules suffix under /etc/cmpt. These files are pre-processed with cpp before they are applied. You can use cpp's mechanisms such as C/C++ comments, #ifdef, and #include to organize the files. See compartments(4) for the syntax of the configuration files.

Compartments use four types of rules: file system rules, IPC rules, network rules, miscellaneous rules.

File System Rules

File system rules govern access to the files and directories of the file system. You can restrict access to directories to the following actions:

  • nsearch: For searching a directory.

  • read: For directory listing and searching

  • create: For creation of new elements under the directory

  • unlink: For removing elements under the directory

  • Any combination of the above four

You can restrict access to files to the following actions:

  • read: For reading or executing the file

  • write: For writing the file

  • Any combination of the two

All the file system rules are inherited except the nsearch access. For instance, if /a has a permission of nsearch and create, /a/b would have a permission of create alone unless a different set of permissions is assigned to it.

IPC Rules

IPC rules govern how processes in this compartment can access other compartment's IPC mechanisms and how processes in other compartments can access this compartment's IPC mechanisms. By default, a process can access only the IPC objects in its own compartment.

Network Rules

Network rules control access between a process and a network interface, as well as between two processes using loopback communications. These rules control the direction of network traffic (incoming, outgoing, or both) between the subject compartment and the target compartment specified in the rule. Each rule specifies the direction of traffic flow, the protocol (TCP, UDP, or a raw protocol), and the target compartment (for either the network interface or a local compartment for local process communications). Optionally, the rule can filter on local and peer port numbers (for TCP and UDP only).

Compartments are associated with network endpoints when they are first created. When a process makes the system call that creates the endpoint (socket() or open()), the compartment of the process at that time is applied to the network object. (See socket(2) or open(2)). This compartment is used in all network communication access checks that the object is involved in. For TCP, rules are applied at connection establishment time. For all other network communications, each inbound and outbound packet delivery is checked against the rules.

Miscellaneous Rules

Miscellaneous rules appear within a compartment definition. These rules include the following:

Disallowed Privileges

Disallowed privileges define specific privileges that may not be obtained as a side effect of exec() calls even when the binary being executed specifies that the privilege becomes available. See exec(2). See the description of the -p and -r flags for the setfilexsec command. See setfilexsec(1M)) for information on how a process can gain privileges as a side effect of an exec() call.

Network Interface Rules

Interface rules define which network interfaces (Physical/Virtual/Logical) are in this compartment. Each network interface can belong to only one compartment, though multiple interfaces can be assigned to the same compartment. Also note that certain special logical interfaces, such as the loopback interface lo0 and tunneling interfaces, are not valid configuration parameters. These are silently ignored.


The following set of privileges (see privileges(5)) affect the operation of compartments:


Grants a process the ability to change its compartment.


Allows a process to open a file or directory for reading, executing (in the case of a file), or searching (in the case of a directory), bypassing compartment rules that would otherwise not permit the operation.


Allows a process to write into a file, or to create or delete files in a directory, bypassing compartment rules that would otherwise not permit the operation.


Allows a process to override compartment IPC and networking rules.


Allows a process to modify compartment rules on the system.

Note: These privileges are not automatically granted by default to a process with an effective uid of 0.

Default Compartments

When compartments are installed on the system, there is only one default compartment, the init compartment. When the system boots, the init process belongs to this compartment. This compartment has been defined to have access to all other compartments that are explicitly defined for the system. The init compartment need not be defined in a rules file. If you re-define the init compartment by making an explicit reference to it in a rules file, all special characteristics are lost and cannot be restored without rebooting the system.

Compartment Manipulation Commands

Several commands review and modify the compartment configuration on a system:


Queries, enables, and disables the compartments feature. See cmpt_tune(1M) for more information.


Displays compartment rules. See getrules(1M) for more information.


Parses and puts the rules into action. See setrules(1M) for more information.

Note: Currently, no command is available to modify the compartment configuration files. You must edit the configuration files directly. Once that is done, you can use the above commands to put them into action.



All files under this directory whose names end with .rules are used to create the compartment configuration. All files intended to be used to configure compartment rules on the system (except those files referred by a #include directive) must be in this directory.


Binary file containing the machine readable compartment rules. Do not edit this file directly.


File that maps compartment names to the ID numbers used internally by the system. Do not edit this file directly.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.