diff --git a/.vale.ini b/.vale.ini --- a/.vale.ini +++ b/.vale.ini @@ -1,5 +1,6 @@ StylesPath = .vale/styles MinAlertLevel = suggestion +Vocab = Terms [asciidoctor] # enable diff --git a/.vale/styles/FreeBSD/spelling-exceptions.txt b/.vale/styles/FreeBSD/spelling-exceptions.txt deleted file mode 100644 --- a/.vale/styles/FreeBSD/spelling-exceptions.txt +++ /dev/null @@ -1,79 +0,0 @@ -Accetta -Beranek -Cheriton -[Cc]hroot -DARPA -Englewood -Ethernets -Ewens -Excelan -FIFOs -Filestores -Fortran -Gandi -Gingell -Interlan -Interprocess -Karels -Kbyte -Kernighan -Macklem -Makefile -Microsystems -O'Reilly -Ousterhout -Ritchie -Rosenblum -Rozier -Sebastopol -Tevanian -Winsock -autoconfiguration -basename -chdir -checksubdir -chmod -chown -coroutine -coroutines -datagrams -deallocate -deallocation -descendents -distfile -errno -execve -fchmod -fchown -filestore -filestores -fstat -interprocess -lseek -malloc -mkdir -mknod -mmap -multiuser -noncanonical -nongraphic -pathnames -poudriere -prepended -public_html -[Qq]uarterly -readv -recv -recvfrom -recvmsg -reimplemented -rmdir -rmport -sendmsg -sendto -subhierarchies -subdirectory -unbuffered -untyped -vnode -writev diff --git a/.vale/styles/Vocab/Terms/accept.txt b/.vale/styles/Vocab/Terms/accept.txt new file mode 100644 --- /dev/null +++ b/.vale/styles/Vocab/Terms/accept.txt @@ -0,0 +1,32 @@ +(?i)bpf +APIs +Biba +DTDs +Redistributions +Safeport +[Dd]atagram +[Dd]evfs +[Mm]map +[Uu]serland +[Vv]node +demultiplexer +dereference +errno +ioctls +lookups +mbuf +multicast +multilabel +multithreaded +mutex +namespace +procfs +pluggable +statfs +syscall +sysctl\'s +tunables +uid +unloadable +vp +wakeup diff --git a/documentation/content/en/books/arch-handbook/mac/_index.adoc b/documentation/content/en/books/arch-handbook/mac/_index.adoc --- a/documentation/content/en/books/arch-handbook/mac/_index.adoc +++ b/documentation/content/en/books/arch-handbook/mac/_index.adoc @@ -1,6 +1,6 @@ --- title: Chapter 6. The TrustedBSD MAC Framework -authors: +authors: - author: Chris Costello email: chris@FreeBSD.org - author: Robert Watson @@ -64,34 +64,46 @@ [IMPORTANT] ==== -THIS DOCUMENTATION IS PROVIDED BY THE NETWORKS ASSOCIATES TECHNOLOGY, INC "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NETWORKS ASSOCIATES TECHNOLOGY, INC BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +THIS DOCUMENTATION IS PROVIDED BY THE NETWORKS ASSOCIATES TECHNOLOGY, INC "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL NETWORKS ASSOCIATES TECHNOLOGY, INC BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ==== [[mac-synopsis]] == Synopsis -FreeBSD includes experimental support for several mandatory access control policies, as well as a framework for kernel security extensibility, the TrustedBSD MAC Framework. The MAC Framework is a pluggable access control framework, permitting new security policies to be easily linked into the kernel, loaded at boot, or loaded dynamically at run-time. The framework provides a variety of features to make it easier to implement new security policies, including the ability to easily tag security labels (such as confidentiality information) onto system objects. +FreeBSD includes experimental support for several mandatory access control policies, as well as a framework for kernel security extensibility, the TrustedBSD MAC Framework. +The MAC Framework is a pluggable access control framework, permitting new security policies to be easily linked into the kernel, loaded at boot, or loaded dynamically at run-time. +The framework provides a variety of features to make it easier to implement new security policies, including the ability to easily tag security labels (such as confidentiality information) onto system objects. This chapter introduces the MAC policy framework and provides documentation for a sample MAC policy module. [[mac-introduction]] == Introduction -The TrustedBSD MAC framework provides a mechanism to allow the compile-time or run-time extension of the kernel access control model. New system policies may be implemented as kernel modules and linked to the kernel; if multiple policy modules are present, their results will be composed. The MAC Framework provides a variety of access control infrastructure services to assist policy writers, including support for transient and persistent policy-agnostic object security labels. This support is currently considered experimental. +The TrustedBSD MAC framework provides a mechanism to allow the compile-time or run-time extension of the kernel access control model. +New system policies may be implemented as kernel modules and linked to the kernel; if multiple policy modules are present, their results will be composed. +The MAC Framework provides a variety of access control infrastructure services to assist policy writers, including support for transient and persistent policy-agnostic object security labels. +This support is currently considered experimental. This chapter provides information appropriate for developers of policy modules, as well as potential consumers of MAC-enabled environments, to learn about how the MAC Framework supports access control extension of the kernel. [[mac-background]] == Policy Background -Mandatory Access Control (MAC), refers to a set of access control policies that are mandatorily enforced on users by the operating system. MAC policies may be contrasted with Discretionary Access Control (DAC) protections, by which non-administrative users may (at their discretion) protect objects. In traditional UNIX systems, DAC protections include file permissions and access control lists; MAC protections include process controls preventing inter-user debugging and firewalls. A variety of MAC policies have been formulated by operating system designers and security researches, including the Multi-Level Security (MLS) confidentiality policy, the Biba integrity policy, Role-Based Access Control (RBAC), Domain and Type Enforcement (DTE), and Type Enforcement (TE). Each model bases decisions on a variety of factors, including user identity, role, and security clearance, as well as security labels on objects representing concepts such as data sensitivity and integrity. +Mandatory Access Control (MAC), refers to a set of access control policies that are mandatorily enforced on users by the operating system. +MAC policies may be contrasted with Discretionary Access Control (DAC) protections, by which non-administrative users may (at their discretion) protect objects. +In traditional UNIX systems, DAC protections include file permissions and access control lists; MAC protections include process controls preventing inter-user debugging and firewalls. +A variety of MAC policies have been formulated by operating system designers and security researches, including the Multi-Level Security (MLS) confidentiality policy, the Biba integrity policy, Role-Based Access Control (RBAC), Domain and Type Enforcement (DTE), and Type Enforcement (TE). +Each model bases decisions on a variety of factors, including user identity, role, and security clearance, as well as security labels on objects representing concepts such as data sensitivity and integrity. -The TrustedBSD MAC Framework is capable of supporting policy modules that implement all of these policies, as well as a broad class of system hardening policies, which may use existing security attributes, such as user and group IDs, as well as extended attributes on files, and other system properties. In addition, despite the name, the MAC Framework can also be used to implement purely discretionary policies, as policy modules are given substantial flexibility in how they authorize protections. +The TrustedBSD MAC Framework is capable of supporting policy modules that implement all of these policies, as well as a broad class of system hardening policies, which may use existing security attributes, such as user and group IDs, as well as extended attributes on files, and other system properties. +In addition, despite the name, the MAC Framework can also be used to implement purely discretionary policies, as policy modules are given substantial flexibility in how they authorize protections. [[mac-framework-kernel-arch]] == MAC Framework Kernel Architecture -The TrustedBSD MAC Framework permits kernel modules to extend the operating system security policy, as well as providing infrastructure functionality required by many access control modules. If multiple policies are simultaneously loaded, the MAC Framework will usefully (for some definition of useful) compose the results of the policies. +The TrustedBSD MAC Framework permits kernel modules to extend the operating system security policy, as well as providing infrastructure functionality required by many access control modules. +If multiple policies are simultaneously loaded, the MAC Framework will usefully (for some definition of useful) compose the results of the policies. [[mac-framework-kernel-arch-elements]] === Kernel Elements @@ -116,56 +128,103 @@ The TrustedBSD MAC Framework may be directly managed using sysctl's, loader tunables, and system calls. -In most cases, sysctl's and loader tunables of the same name modify the same parameters, and control behavior such as enforcement of protections relating to various kernel subsystems. In addition, if MAC debugging support is compiled into the kernel, several counters will be maintained tracking label allocation. It is generally advisable that per-subsystem enforcement controls not be used to control policy behavior in production environments, as they broadly impact the operation of all active policies. Instead, per-policy controls should be preferred, as they provide greater granularity and greater operational consistency for policy modules. +In most cases, sysctl's and loader tunables of the same name modify the same parameters, and control behavior such as enforcement of protections relating to various kernel subsystems. +In addition, if MAC debugging support is compiled into the kernel, several counters will be maintained tracking label allocation. +It is generally advisable that per-subsystem enforcement controls not be used to control policy behavior in production environments, as they broadly impact the operation of all active policies. +Instead, per-policy controls should be preferred, as they provide greater granularity and greater operational consistency for policy modules. Loading and unloading of policy modules is performed using the system module management system calls and other system interfaces, including boot loader variables; policy modules will have the opportunity to influence load and unload events, including preventing undesired unloading of the policy. [[mac-framework-kernel-arch-synchronization]] === Policy List Concurrency and Synchronization -As the set of active policies may change at run-time, and the invocation of entry points is non-atomic, synchronization is required to prevent loading or unloading of policies while an entry point invocation is in progress, freezing the set of active policies for the duration. This is accomplished by means of a framework busy count: whenever an entry point is entered, the busy count is incremented; whenever it is exited, the busy count is decremented. While the busy count is elevated, policy list changes are not permitted, and threads attempting to modify the policy list will sleep until the list is not busy. The busy count is protected by a mutex, and a condition variable is used to wake up sleepers waiting on policy list modifications. One side effect of this synchronization model is that recursion into the MAC Framework from within a policy module is permitted, although not generally used. +As the set of active policies may change at run-time, and the invocation of entry points is non-atomic, synchronization is required to prevent loading or unloading of policies while an entry point invocation is in progress, freezing the set of active policies for the duration. +This is accomplished by means of a framework busy count: whenever an entry point is entered, the busy count is incremented; whenever it is exited, the busy count is decremented. +While the busy count is elevated, policy list changes are not permitted, and threads attempting to modify the policy list will sleep until the list is not busy. +The busy count is protected by a mutex, and a condition variable is used to wake up sleepers waiting on policy list modifications. +One side effect of this synchronization model is that recursion into the MAC Framework from within a policy module is permitted, although not generally used. -Various optimizations are used to reduce the overhead of the busy count, including avoiding the full cost of incrementing and decrementing if the list is empty or contains only static entries (policies that are loaded before the system starts, and cannot be unloaded). A compile-time option is also provided which prevents any change in the set of loaded policies at run-time, which eliminates the mutex locking costs associated with supporting dynamically loaded and unloaded policies as synchronization is no longer required. +Various optimizations are used to reduce the overhead of the busy count, including avoiding the full cost of incrementing and decrementing if the list is empty or contains only static entries (policies that are loaded before the system starts, and cannot be unloaded). +A compile-time option is also provided which prevents any change in the set of loaded policies at run-time, which eliminates the mutex locking costs associated with supporting dynamically loaded and unloaded policies as synchronization is no longer required. As the MAC Framework is not permitted to block in some entry points, a normal sleep lock cannot be used; as a result, it is possible for the load or unload attempt to block for a substantial period of time waiting for the framework to become idle. [[mac-framework-kernel-arch-label-synchronization]] === Label Synchronization -As kernel objects of interest may generally be accessed from more than one thread at a time, and simultaneous entry of more than one thread into the MAC Framework is permitted, security attribute storage maintained by the MAC Framework is carefully synchronized. In general, existing kernel synchronization on kernel object data is used to protect MAC Framework security labels on the object: for example, MAC labels on sockets are protected using the existing socket mutex. Likewise, semantics for concurrent access are generally identical to those of the container objects: for credentials, copy-on-write semantics are maintained for label contents as with the remainder of the credential structure. The MAC Framework asserts necessary locks on objects when invoked with an object reference. Policy authors must be aware of these synchronization semantics, as they will sometimes limit the types of accesses permitted on labels: for example, when a read-only reference to a credential is passed to a policy via an entry point, only read operations are permitted on the label state attached to the credential. +As kernel objects of interest may generally be accessed from more than one thread at a time, and simultaneous entry of more than one thread into the MAC Framework is permitted, security attribute storage maintained by the MAC Framework is carefully synchronized. +In general, existing kernel synchronization on kernel object data is used to protect MAC Framework security labels on the object: for example, MAC labels on sockets are protected using the existing socket mutex. +Likewise, semantics for concurrent access are generally identical to those of the container objects: for credentials, copy-on-write semantics are maintained for label contents as with the remainder of the credential structure. +The MAC Framework asserts necessary locks on objects when invoked with an object reference. +Policy authors must be aware of these synchronization semantics, as they will sometimes limit the types of accesses permitted on labels: for example, when a read-only reference to a credential is passed to a policy via an entry point, only read operations are permitted on the label state attached to the credential. [[mac-framework-kernel-arch-policy-synchronization]] === Policy Synchronization and Concurrency -Policy modules must be written to assume that many kernel threads may simultaneously enter one more policy entry points due to the parallel and preemptive nature of the FreeBSD kernel. If the policy module makes use of mutable state, this may require the use of synchronization primitives within the policy to prevent inconsistent views on that state resulting in incorrect operation of the policy. Policies will generally be able to make use of existing FreeBSD synchronization primitives for this purpose, including mutexes, sleep locks, condition variables, and counting semaphores. However, policies should be written to employ these primitives carefully, respecting existing kernel lock orders, and recognizing that some entry points are not permitted to sleep, limiting the use of primitives in those entry points to mutexes and wakeup operations. +Policy modules must be written to assume that many kernel threads may simultaneously enter one more policy entry points due to the parallel and preemptive nature of the FreeBSD kernel. +If the policy module makes use of mutable state, this may require the use of synchronization primitives within the policy to prevent inconsistent views on that state resulting in incorrect operation of the policy. +Policies will generally be able to make use of existing FreeBSD synchronization primitives for this purpose, including mutexes, sleep locks, condition variables, and counting semaphores. +However, policies should be written to employ these primitives carefully, respecting existing kernel lock orders, and recognizing that some entry points are not permitted to sleep, limiting the use of primitives in those entry points to mutexes and wakeup operations. -When policy modules call out to other kernel subsystems, they will generally need to release any in-policy locks in order to avoid violating the kernel lock order or risking lock recursion. This will maintain policy locks as leaf locks in the global lock order, helping to avoid deadlock. +When policy modules call out to other kernel subsystems, they will generally need to release any in-policy locks in order to avoid violating the kernel lock order or risking lock recursion. +This will maintain policy locks as leaf locks in the global lock order, helping to avoid deadlock. [[mac-framework-kernel-arch-registration]] === Policy Registration -The MAC Framework maintains two lists of active policies: a static list, and a dynamic list. The lists differ only with regards to their locking semantics: an elevated reference count is not required to make use of the static list. When kernel modules containing MAC Framework policies are loaded, the policy module will use `SYSINIT` to invoke a registration function; when a policy module is unloaded, `SYSINIT` will likewise invoke a de-registration function. Registration may fail if a policy module is loaded more than once, if insufficient resources are available for the registration (for example, the policy might require labeling and insufficient labeling state might be available), or other policy prerequisites might not be met (some policies may only be loaded prior to boot). Likewise, de-registration may fail if a policy is flagged as not unloadable. +The MAC Framework maintains two lists of active policies: a static list, and a dynamic list. +The lists differ only with regards to their locking semantics: an elevated reference count is not required to make use of the static list. +When kernel modules containing MAC Framework policies are loaded, the policy module will use `SYSINIT` to invoke a registration function; when a policy module is unloaded, `SYSINIT` will likewise invoke a de-registration function. +Registration may fail if a policy module is loaded more than once, if insufficient resources are available for the registration (for example, the policy might require labeling and insufficient labeling state might be available), or other policy prerequisites might not be met (some policies may only be loaded prior to boot). +Likewise, de-registration may fail if a policy is flagged as not unloadable. [[mac-framework-kernel-arch-entrypoints]] === Entry Points -Kernel services interact with the MAC Framework in two ways: they invoke a series of APIs to notify the framework of relevant events, and they provide a policy-agnostic label structure pointer in security-relevant objects. The label pointer is maintained by the MAC Framework via label management entry points, and permits the Framework to offer a labeling service to policy modules through relatively non-invasive changes to the kernel subsystem maintaining the object. For example, label pointers have been added to processes, process credentials, sockets, pipes, vnodes, Mbufs, network interfaces, IP reassembly queues, and a variety of other security-relevant structures. Kernel services also invoke the MAC Framework when they perform important security decisions, permitting policy modules to augment those decisions based on their own criteria (possibly including data stored in security labels). Most of these security critical decisions will be explicit access control checks; however, some affect more general decision functions such as packet matching for sockets and label transition at program execution. +Kernel services interact with the MAC Framework in two ways: they invoke a series of APIs to notify the framework of relevant events, and they provide a policy-agnostic label structure pointer in security-relevant objects. +The label pointer is maintained by the MAC Framework via label management entry points, and permits the Framework to offer a labeling service to policy modules through relatively non-invasive changes to the kernel subsystem maintaining the object. +For example, label pointers have been added to processes, process credentials, sockets, pipes, vnodes, Mbufs, network interfaces, IP reassembly queues, and a variety of other security-relevant structures. +Kernel services also invoke the MAC Framework when they perform important security decisions, permitting policy modules to augment those decisions based on their own criteria (possibly including data stored in security labels). +Most of these security critical decisions will be explicit access control checks; however, some affect more general decision functions such as packet matching for sockets and label transition at program execution. [[mac-framework-kernel-arch-composition]] === Policy Composition -When more than one policy module is loaded into the kernel at a time, the results of the policy modules will be composed by the framework using a composition operator. This operator is currently hard-coded, and requires that all active policies must approve a request for it to return success. As policies may return a variety of error conditions (success, access denied, object does not exist, ...), a precedence operator selects the resulting error from the set of errors returned by policies. In general, errors indicating that an object does not exist will be preferred to errors indicating that access to an object is denied. While it is not guaranteed that the resulting composition will be useful or secure, we have found that it is for many useful selections of policies. For example, traditional trusted systems often ship with two or more policies using a similar composition. +When more than one policy module is loaded into the kernel at a time, the results of the policy modules will be composed by the framework using a composition operator. +This operator is currently hard-coded, and requires that all active policies must approve a request for it to return success. +As policies may return a variety of error conditions (success, access denied, object does not exist, ...), a precedence operator selects the resulting error from the set of errors returned by policies. +In general, errors indicating that an object does not exist will be preferred to errors indicating that access to an object is denied. +While it is not guaranteed that the resulting composition will be useful or secure, we have found that it is for many useful selections of policies. +For example, traditional trusted systems often ship with two or more policies using a similar composition. [[mac-framework-kernel-arch-labels]] === Labeling Support -As many interesting access control extensions rely on security labels on objects, the MAC Framework provides a set of policy-agnostic label management system calls covering a variety of user-exposed objects. Common label types include partition identifiers, sensitivity labels, integrity labels, compartments, domains, roles, and types. By policy agnostic, we mean that policy modules are able to completely define the semantics of meta-data associated with an object. Policy modules participate in the internalization and externalization of string-based labels provides by user applications, and can expose multiple label elements to applications if desired. - -In-memory labels are stored in slab-allocated `struct label`, which consists of a fixed-length array of unions, each holding a `void *` pointer and a `long`. Policies registering for label storage will be assigned a "slot" identifier, which may be used to dereference the label storage. The semantics of the storage are left entirely up to the policy module: modules are provided with a variety of entry points associated with the kernel object life cycle, including initialization, association/creation, and destruction. Using these interfaces, it is possible to implement reference counting and other storage models. Direct access to the object structure is generally not required by policy modules to retrieve a label, as the MAC Framework generally passes both a pointer to the object and a direct pointer to the object's label into entry points. The primary exception to this rule is the process credential, which must be manually dereferenced to access the credential label. This may change in future revisions of the MAC Framework. - -Initialization entry points frequently include a sleeping disposition flag indicating whether or not an initialization is permitted to sleep; if sleeping is not permitted, a failure may be returned to cancel allocation of the label (and hence object). This may occur, for example, in the network stack during interrupt handling, where sleeping is not permitted, or while the caller holds a mutex. Due to the performance cost of maintaining labels on in-flight network packets (Mbufs), policies must specifically declare a requirement that Mbuf labels be allocated. Dynamically loaded policies making use of labels must be able to handle the case where their init function has not been called on an object, as objects may already exist when the policy is loaded. The MAC Framework guarantees that uninitialized label slots will hold a 0 or NULL value, which policies may use to detect uninitialized values. However, as allocation of Mbuf labels is conditional, policies must also be able to handle a NULL label pointer for Mbufs if they have been loaded dynamically. - -In the case of file system labels, special support is provided for the persistent storage of security labels in extended attributes. Where available, extended attribute transactions are used to permit consistent compound updates of security labels on vnodes--currently this support is present only in the UFS2 file system. Policy authors may choose to implement multilabel file system object labels using one (or more) extended attributes. For efficiency reasons, the vnode label (`v_label`) is a cache of any on-disk label; policies are able to load values into the cache when the vnode is instantiated, and update the cache as needed. As a result, the extended attribute need not be directly accessed with every access control check. +As many interesting access control extensions rely on security labels on objects, the MAC Framework provides a set of policy-agnostic label management system calls covering a variety of user-exposed objects. +Common label types include partition identifiers, sensitivity labels, integrity labels, compartments, domains, roles, and types. +By policy agnostic, we mean that policy modules are able to completely define the semantics of meta-data associated with an object. +Policy modules participate in the internalization and externalization of string-based labels provides by user applications, and can expose multiple label elements to applications if desired. + +In-memory labels are stored in slab-allocated `struct label`, which consists of a fixed-length array of unions, each holding a `void *` pointer and a `long`. +Policies registering for label storage will be assigned a "slot" identifier, which may be used to dereference the label storage. +The semantics of the storage are left entirely up to the policy module: modules are provided with a variety of entry points associated with the kernel object life cycle, including initialization, association/creation, and destruction. +Using these interfaces, it is possible to implement reference counting and other storage models. +Direct access to the object structure is generally not required by policy modules to retrieve a label, as the MAC Framework generally passes both a pointer to the object and a direct pointer to the object's label into entry points. +The primary exception to this rule is the process credential, which must be manually dereferenced to access the credential label. +This may change in future revisions of the MAC Framework. + +Initialization entry points frequently include a sleeping disposition flag indicating whether or not an initialization is permitted to sleep; if sleeping is not permitted, a failure may be returned to cancel allocation of the label (and hence object). +This may occur, for example, in the network stack during interrupt handling, where sleeping is not permitted, or while the caller holds a mutex. +Due to the performance cost of maintaining labels on in-flight network packets (Mbufs), policies must specifically declare a requirement that Mbuf labels be allocated. +Dynamically loaded policies making use of labels must be able to handle the case where their init function has not been called on an object, as objects may already exist when the policy is loaded. +The MAC Framework guarantees that uninitialized label slots will hold a 0 or NULL value, which policies may use to detect uninitialized values. +However, as allocation of Mbuf labels is conditional, policies must also be able to handle a NULL label pointer for Mbufs if they have been loaded dynamically. + +In the case of file system labels, special support is provided for the persistent storage of security labels in extended attributes. +Where available, extended attribute transactions are used to permit consistent compound updates of security labels on vnodes--currently this support is present only in the UFS2 file system. +Policy authors may choose to implement multilabel file system object labels using one (or more) extended attributes. +For efficiency reasons, the vnode label (`v_label`) is a cache of any on-disk label; policies are able to load values into the cache when the vnode is instantiated, and update the cache as needed. +As a result, the extended attribute need not be directly accessed with every access control check. [NOTE] ==== @@ -177,7 +236,11 @@ The MAC Framework implements a number of system calls: most of these calls support the policy-agnostic label retrieval and manipulation APIs exposed to user applications. -The label management calls accept a label description structure, `struct mac`, which contains a series of MAC label elements. Each element contains a character string name, and character string value. Each policy will be given the chance to claim a particular element name, permitting policies to expose multiple independent elements if desired. Policy modules perform the internalization and externalization between kernel labels and user-provided labels via entry points, permitting a variety of semantics. Label management system calls are generally wrapped by user library functions to perform memory allocation and error handling, simplifying user applications that must manage labels. +The label management calls accept a label description structure, `struct mac`, which contains a series of MAC label elements. +Each element contains a character string name, and character string value. +Each policy will be given the chance to claim a particular element name, permitting policies to expose multiple independent elements if desired. +Policy modules perform the internalization and externalization between kernel labels and user-provided labels via entry points, permitting a variety of semantics. +Label management system calls are generally wrapped by user library functions to perform memory allocation and error handling, simplifying user applications that must manage labels. The following MAC-related system calls are present in the FreeBSD kernel: @@ -191,7 +254,8 @@ * `mac_get_pid()` may be used to request the label of another process by process id. * `mac_get_link()` is identical to `mac_get_file()`, only it will not follow a symbolic link if it is the final entry in the path, so may be used to retrieve the label on a symlink. * `mac_set_link()` is identical to `mac_set_file()`, only it will not follow a symbolic link if it is the final entry in a path, so may be used to manipulate the label on a symlink. -* `mac_execve()` is identical to the `execve()` system call, only it also accepts a requested label to set the process label to when beginning execution of a new program. This change in label on execution is referred to as a "transition". +* `mac_execve()` is identical to the `execve()` system call, only it also accepts a requested label to set the process label to when beginning execution of a new program. +This change in label on execution is referred to as a "transition". * `mac_get_peer()`, actually implemented via a socket option, retrieves the label of a remote peer on a socket, if available. In addition to these system calls, the `SIOCSIGMAC` and `SIOCSIFMAC` network interface ioctls permit the labels on network interfaces to be retrieved and set. @@ -199,7 +263,9 @@ [[mac-policy-architecture]] == MAC Policy Architecture -Security policies are either linked directly into the kernel, or compiled into loadable kernel modules that may be loaded at boot, or dynamically using the module loading system calls at runtime. Policy modules interact with the system through a set of declared entry points, providing access to a stream of system events and permitting the policy to influence access control decisions. Each policy contains a number of elements: +Security policies are either linked directly into the kernel, or compiled into loadable kernel modules that may be loaded at boot, or dynamically using the module loading system calls at runtime. +Policy modules interact with the system through a set of declared entry points, providing access to a stream of system events and permitting the policy to influence access control decisions. +Each policy contains a number of elements: * Optional configuration parameters for policy. * Centralized implementation of the policy logic and parameters. @@ -229,37 +295,61 @@ }; .... -The MAC policy entry point vector, `mac__policy__ops` in this example, associates functions defined in the module with specific entry points. A complete listing of available entry points and their prototypes may be found in the MAC entry point reference section. Of specific interest during module registration are the .mpo_destroy and .mpo_init entry points. .mpo_init will be invoked once a policy is successfully registered with the module framework but prior to any other entry points becoming active. This permits the policy to perform any policy-specific allocation and initialization, such as initialization of any data or locks. .mpo_destroy will be invoked when a policy module is unloaded to permit releasing of any allocated memory and destruction of locks. Currently, these two entry points are invoked with the MAC policy list mutex held to prevent any other entry points from being invoked: this will be changed, but in the mean time, policies should be careful about what kernel primitives they invoke so as to avoid lock ordering or sleeping problems. +The MAC policy entry point vector, `mac__policy__ops` in this example, associates functions defined in the module with specific entry points. +A complete listing of available entry points and their prototypes may be found in the MAC entry point reference section. +Of specific interest during module registration are the .mpo_destroy and .mpo_init entry points. +.mpo_init will be invoked once a policy is successfully registered with the module framework but prior to any other entry points becoming active. +This permits the policy to perform any policy-specific allocation and initialization, such as initialization of any data or locks. +.mpo_destroy will be invoked when a policy module is unloaded to permit releasing of any allocated memory and destruction of locks. +Currently, these two entry points are invoked with the MAC policy list mutex held to prevent any other entry points from being invoked: this will be changed, but in the mean time, policies should be careful about what kernel primitives they invoke so as to avoid lock ordering or sleeping problems. -The policy declaration's module name field exists so that the module may be uniquely identified for the purposes of module dependencies. An appropriate string should be selected. The full string name of the policy is displayed to the user via the kernel log during load and unload events, and also exported when providing status information to userland processes. +The policy declaration's module name field exists so that the module may be uniquely identified for the purposes of module dependencies. +An appropriate string should be selected. +The full string name of the policy is displayed to the user via the kernel log during load and unload events, and also exported when providing status information to userland processes. [[mac-policy-flags]] === Policy Flags -The policy declaration flags field permits the module to provide the framework with information about its capabilities at the time the module is loaded. Currently, three flags are defined: +The policy declaration flags field permits the module to provide the framework with information about its capabilities at the time the module is loaded. +Currently, three flags are defined: MPC_LOADTIME_FLAG_UNLOADOK:: -This flag indicates that the policy module may be unloaded. If this flag is not provided, then the policy framework will reject requests to unload the module. This flag might be used by modules that allocate label state and are unable to free that state at runtime. +This flag indicates that the policy module may be unloaded. +If this flag is not provided, then the policy framework will reject requests to unload the module. +This flag might be used by modules that allocate label state and are unable to free that state at runtime. MPC_LOADTIME_FLAG_NOTLATE:: -This flag indicates that the policy module must be loaded and initialized early in the boot process. If the flag is specified, attempts to register the module following boot will be rejected. The flag may be used by policies that require pervasive labeling of all system objects, and cannot handle objects that have not been properly initialized by the policy. +This flag indicates that the policy module must be loaded and initialized early in the boot process. +If the flag is specified, attempts to register the module following boot will be rejected. +The flag may be used by policies that require pervasive labeling of all system objects, and cannot handle objects that have not been properly initialized by the policy. MPC_LOADTIME_FLAG_LABELMBUFS:: -This flag indicates that the policy module requires labeling of Mbufs, and that memory should always be allocated for the storage of Mbuf labels. By default, the MAC Framework will not allocate label storage for Mbufs unless at least one loaded policy has this flag set. This measurably improves network performance when policies do not require Mbuf labeling. A kernel option, `MAC_ALWAYS_LABEL_MBUF`, exists to force the MAC Framework to allocate Mbuf label storage regardless of the setting of this flag, and may be useful in some environments. +This flag indicates that the policy module requires labeling of Mbufs, and that memory should always be allocated for the storage of Mbuf labels. +By default, the MAC Framework will not allocate label storage for Mbufs unless at least one loaded policy has this flag set. +This measurably improves network performance when policies do not require Mbuf labeling. +A kernel option, `MAC_ALWAYS_LABEL_MBUF`, exists to force the MAC Framework to allocate Mbuf label storage regardless of the setting of this flag, and may be useful in some environments. [NOTE] ==== -Policies using the `MPC_LOADTIME_FLAG_LABELMBUFS` without the `MPC_LOADTIME_FLAG_NOTLATE` flag set must be able to correctly handle `NULL` Mbuf label pointers passed into entry points. This is necessary as in-flight Mbufs without label storage may persist after a policy enabling Mbuf labeling has been loaded. If a policy is loaded before the network subsystem is active (i.e., the policy is not being loaded late), then all Mbufs are guaranteed to have label storage. +Policies using the `MPC_LOADTIME_FLAG_LABELMBUFS` without the `MPC_LOADTIME_FLAG_NOTLATE` flag set must be able to correctly handle `NULL` Mbuf label pointers passed into entry points. +This is necessary as in-flight Mbufs without label storage may persist after a policy enabling Mbuf labeling has been loaded. +If a policy is loaded before the network subsystem is active (i.e., the policy is not being loaded late), then all Mbufs are guaranteed to have label storage. ==== [[mac-policy-entry-points]] === Policy Entry Points -Four classes of entry points are offered to policies registered with the framework: entry points associated with the registration and management of policies, entry points denoting initialization, creation, destruction, and other life cycle events for kernel objects, events associated with access control decisions that the policy module may influence, and calls associated with the management of labels on objects. In addition, a `mac_syscall()` entry point is provided so that policies may extend the kernel interface without registering new system calls. +Four classes of entry points are offered to policies registered with the framework: entry points associated with the registration and management of policies, entry points denoting initialization, creation, destruction, and other life cycle events for kernel objects, events associated with access control decisions that the policy module may influence, and calls associated with the management of labels on objects. +In addition, a `mac_syscall()` entry point is provided so that policies may extend the kernel interface without registering new system calls. -Policy module writers should be aware of the kernel locking strategy, as well as what object locks are available during which entry points. Writers should attempt to avoid deadlock scenarios by avoiding grabbing non-leaf locks inside of entry points, and also follow the locking protocol for object access and modification. In particular, writers should be aware that while necessary locks to access objects and their labels are generally held, sufficient locks to modify an object or its label may not be present for all entry points. Locking information for arguments is documented in the MAC framework entry point document. +Policy module writers should be aware of the kernel locking strategy, as well as what object locks are available during which entry points. +Writers should attempt to avoid deadlock scenarios by avoiding grabbing non-leaf locks inside of entry points, and also follow the locking protocol for object access and modification. +In particular, writers should be aware that while necessary locks to access objects and their labels are generally held, sufficient locks to modify an object or its label may not be present for all entry points. +Locking information for arguments is documented in the MAC framework entry point document. -Policy entry points will pass a reference to the object label along with the object itself. This permits labeled policies to be unaware of the internals of the object yet still make decisions based on the label. The exception to this is the process credential, which is assumed to be understood by policies as a first class security object in the kernel. +Policy entry points will pass a reference to the object label along with the object itself. +This permits labeled policies to be unaware of the internals of the object yet still make decisions based on the label. +The exception to this is the process credential, which is assumed to be understood by policies as a first class security object in the kernel. [[mac-entry-point-reference]] == MAC Policy Entry Point Reference @@ -272,7 +362,7 @@ [source,c] ---- -void mpo_init( conf); +void mpo_init( conf); struct mac_policy_conf *conf; ---- @@ -288,14 +378,16 @@ | |=== -Policy load event. The policy list mutex is held, so sleep operations cannot be performed, and calls out to other kernel subsystems must be made with caution. If potentially sleeping memory allocations are required during policy initialization, they should be made using a separate module SYSINIT(). +Policy load event. +The policy list mutex is held, so sleep operations cannot be performed, and calls out to other kernel subsystems must be made with caution. +If potentially sleeping memory allocations are required during policy initialization, they should be made using a separate module SYSINIT(). [[mpo-destroy]] ==== `mpo_destroy` [source,c] ---- -void mpo_destroy( conf); +void mpo_destroy( conf); struct mac_policy_conf *conf; ---- @@ -311,16 +403,17 @@ | |=== -Policy load event. The policy list mutex is held, so caution should be applied. +Policy load event. +The policy list mutex is held, so caution should be applied. [[mac-mpo-syscall]] ==== `mpo_syscall` [source,c] ---- -int mpo_syscall( td, - call, - arg); +int mpo_syscall( td, + call, + arg); struct thread *td; int call; void *arg; @@ -346,7 +439,10 @@ | |=== -This entry point provides a policy-multiplexed system call so that policies may provide additional services to user processes without registering specific system calls. The policy name provided during registration is used to demux calls from userland, and the arguments will be forwarded to this entry point. When implementing new services, security modules should be sure to invoke appropriate access control checks from the MAC framework as needed. For example, if a policy implements an augmented signal functionality, it should call the necessary signal access control checks to invoke the MAC framework and other registered policies. +This entry point provides a policy-multiplexed system call so that policies may provide additional services to user processes without registering specific system calls. +The policy name provided during registration is used to demultiplexer calls from userland, and the arguments will be forwarded to this entry point. +When implementing new services, security modules should be sure to invoke appropriate access control checks from the MAC framework as needed. +For example, if a policy implements an augmented signal functionality, it should call the necessary signal access control checks to invoke the MAC framework and other registered policies. [NOTE] ==== @@ -358,7 +454,7 @@ [source,c] ---- -void mpo_thread_userret( td); +void mpo_thread_userret( td); struct thread *td; ---- @@ -374,7 +470,11 @@ | |=== -This entry point permits policy modules to perform MAC-related events when a thread returns to user space, via a system call return, trap return, or otherwise. This is required for policies that have floating process labels, as it is not always possible to acquire the process lock at arbitrary points in the stack during system call processing; process labels might represent traditional authentication data, process history information, or other data. To employ this mechanism, intended changes to the process credential label may be stored in the `p_label` protected by a per-policy spin lock, and then set the per-thread `TDF_ASTPENDING` flag and per-process `PS_MACPENDM` flag to schedule a call to the userret entry point. From this entry point, the policy may create a replacement credential with less concern about the locking context. Policy writers are cautioned that event ordering relating to scheduling an AST and the AST being performed may be complex and interlaced in multithreaded applications. +This entry point permits policy modules to perform MAC-related events when a thread returns to user space, via a system call return, trap return, or otherwise. +This is required for policies that have floating process labels, as it is not always possible to acquire the process lock at arbitrary points in the stack during system call processing; process labels might represent traditional authentication data, process history information, or other data. +To employ this mechanism, intended changes to the process credential label may be stored in the `p_label` protected by a per-policy spin lock, and then set the per-thread `TDF_ASTPENDING` flag and per-process `PS_MACPENDM` flag to schedule a call to the `userret` entry point. +From this entry point, the policy may create a replacement credential with less concern about the locking context. +Policy writers are cautioned that event ordering relating to scheduling an AST and the AST being performed may be complex and interlaced in multithreaded applications. [[mac-label-ops]] === Label Operations @@ -384,7 +484,7 @@ [source,c] ---- -void mpo_init_bpfdesc_label( label); +void mpo_init_bpfdesc_label( label); struct label *label; ---- @@ -400,14 +500,15 @@ | |=== -Initialize the label on a newly instantiated bpfdesc (BPF descriptor). Sleeping is permitted. +Initialize the label on a newly instantiated bpfdesc (BPF descriptor). +Sleeping is permitted. [[mac-mpo-init-cred-label]] ==== `mpo_init_cred_label` [source,c] ---- -void mpo_init_cred_label( label); +void mpo_init_cred_label( label); struct label *label; ---- @@ -423,14 +524,15 @@ | |=== -Initialize the label for a newly instantiated user credential. Sleeping is permitted. +Initialize the label for a newly instantiated user credential. +Sleeping is permitted. [[mac-mpo-init-devfsdirent]] ==== `mpo_init_devfsdirent_label` [source,c] ---- -void mpo_init_devfsdirent_label( label); +void mpo_init_devfsdirent_label( label); struct label *label; ---- @@ -446,14 +548,15 @@ | |=== -Initialize the label on a newly instantiated devfs entry. Sleeping is permitted. +Initialize the label on a newly instantiated devfs entry. +Sleeping is permitted. [[mac-mpo-init-ifnet]] ==== `mpo_init_ifnet_label` [source,c] ---- -void mpo_init_ifnet_label( label); +void mpo_init_ifnet_label( label); struct label *label; ---- @@ -469,15 +572,16 @@ | |=== -Initialize the label on a newly instantiated network interface. Sleeping is permitted. +Initialize the label on a newly instantiated network interface. +Sleeping is permitted. [[mac-mpo-init-ipq]] ==== `mpo_init_ipq_label` [source,c] ---- -void mpo_init_ipq_label( label, - flag); +void mpo_init_ipq_label( label, + flag); struct label *label; int flag; ---- @@ -498,15 +602,18 @@ | |=== -Initialize the label on a newly instantiated IP fragment reassembly queue. The `flag` field may be one of M_WAITOK and M_NOWAIT, and should be employed to avoid performing a sleeping man:malloc[9] during this initialization call. IP fragment reassembly queue allocation frequently occurs in performance sensitive environments, and the implementation should be careful to avoid sleeping or long-lived operations. This entry point is permitted to fail resulting in the failure to allocate the IP fragment reassembly queue. +Initialize the label on a newly instantiated IP fragment reassembly queue. +The `flag` field may be one of M_WAITOK and M_NOWAIT, and should be employed to avoid performing a sleeping man:malloc[9] during this initialization call. +IP fragment reassembly queue allocation frequently occurs in performance sensitive environments, and the implementation should be careful to avoid sleeping or long-lived operations. +This entry point is permitted to fail resulting in the failure to allocate the IP fragment reassembly queue. [[mac-mpo-init-mbuf]] ==== `mpo_init_mbuf_label` [source,c] ---- -void mpo_init_mbuf_label( flag, - label); +void mpo_init_mbuf_label( flag, + label); int flag; struct label *label; ---- @@ -527,15 +634,18 @@ | |=== -Initialize the label on a newly instantiated mbuf packet header (`mbuf`). The `flag` field may be one of M_WAITOK and M_NOWAIT, and should be employed to avoid performing a sleeping man:malloc[9] during this initialization call. Mbuf allocation frequently occurs in performance sensitive environments, and the implementation should be careful to avoid sleeping or long-lived operations. This entry point is permitted to fail resulting in the failure to allocate the mbuf header. +Initialize the label on a newly instantiated mbuf packet header (`mbuf`). +The `flag` field may be one of M_WAITOK and M_NOWAIT, and should be employed to avoid performing a sleeping man:malloc[9] during this initialization call. +Mbuf allocation frequently occurs in performance sensitive environments, and the implementation should be careful to avoid sleeping or long-lived operations. +This entry point is permitted to fail resulting in the failure to allocate the mbuf header. [[mac-mpo-init-mount]] ==== `mpo_init_mount_label` [source,c] ---- -void mpo_init_mount_label( mntlabel, - fslabel); +void mpo_init_mount_label( mntlabel, + fslabel); struct label *mntlabel; struct label *fslabel; ---- @@ -556,14 +666,15 @@ | |=== -Initialize the labels on a newly instantiated mount point. Sleeping is permitted. +Initialize the labels on a newly instantiated mount point. +Sleeping is permitted. [[mac-mpo-init-mount-fs-label]] ==== `mpo_init_mount_fs_label` [source,c] ---- -void mpo_init_mount_fs_label( label); +void mpo_init_mount_fs_label( label); struct label *label; ---- @@ -579,14 +690,15 @@ | |=== -Initialize the label on a newly mounted file system. Sleeping is permitted +Initialize the label on a newly mounted file system. +Sleeping is permitted [[mac-mpo-init-pipe-label]] ==== `mpo_init_pipe_label` [source,c] ---- -void mpo_init_pipe_label( label); +void mpo_init_pipe_label( label); struct label*label; ---- @@ -602,15 +714,16 @@ | |=== -Initialize a label for a newly instantiated pipe. Sleeping is permitted. +Initialize a label for a newly instantiated pipe. +Sleeping is permitted. [[mac-mpo-init-socket]] ==== `mpo_init_socket_label` [source,c] ---- -void mpo_init_socket_label( label, - flag); +void mpo_init_socket_label( label, + flag); struct label *label; int flag; ---- @@ -631,15 +744,16 @@ | |=== -Initialize a label for a newly instantiated socket. The `flag` field may be one of M_WAITOK and M_NOWAIT, and should be employed to avoid performing a sleeping man:malloc[9] during this initialization call. +Initialize a label for a newly instantiated socket. +The `flag` field may be one of M_WAITOK and M_NOWAIT, and should be employed to avoid performing a sleeping man:malloc[9] during this initialization call. [[mac-mpo-init-socket-peer-label]] ==== `mpo_init_socket_peer_label` [source,c] ---- -void mpo_init_socket_peer_label( label, - flag); +void mpo_init_socket_peer_label( label, + flag); struct label *label; int flag; ---- @@ -660,14 +774,15 @@ | |=== -Initialize the peer label for a newly instantiated socket. The `flag` field may be one of M_WAITOK and M_NOWAIT, and should be employed to avoid performing a sleeping man:malloc[9] during this initialization call. +Initialize the peer label for a newly instantiated socket. +The `flag` field may be one of M_WAITOK and M_NOWAIT, and should be employed to avoid performing a sleeping man:malloc[9] during this initialization call. [[mac-mpo-init-proc-label]] ==== `mpo_init_proc_label` [source,c] ---- -void mpo_init_proc_label( label); +void mpo_init_proc_label( label); struct label *label; ---- @@ -683,14 +798,15 @@ | |=== -Initialize the label for a newly instantiated process. Sleeping is permitted. +Initialize the label for a newly instantiated process. +Sleeping is permitted. [[mac-mpo-init-vnode]] ==== `mpo_init_vnode_label` [source,c] ---- -void mpo_init_vnode_label( label); +void mpo_init_vnode_label( label); struct label *label; ---- @@ -706,14 +822,15 @@ | |=== -Initialize the label on a newly instantiated vnode. Sleeping is permitted. +Initialize the label on a newly instantiated vnode. +Sleeping is permitted. [[mac-mpo-destroy-bpfdesc]] ==== `mpo_destroy_bpfdesc_label` [source,c] ---- -void mpo_destroy_bpfdesc_label( label); +void mpo_destroy_bpfdesc_label( label); struct label *label; ---- @@ -729,14 +846,15 @@ | |=== -Destroy the label on a BPF descriptor. In this entry point a policy should free any internal storage associated with `label` so that it may be destroyed. +Destroy the label on a BPF descriptor. +In this entry point a policy should free any internal storage associated with `label` so that it may be destroyed. [[mac-mpo-destroy-cred]] ==== `mpo_destroy_cred_label` [source,c] ---- -void mpo_destroy_cred_label( label); +void mpo_destroy_cred_label( label); struct label *label; ---- @@ -752,14 +870,15 @@ | |=== -Destroy the label on a credential. In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. +Destroy the label on a credential. +In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. [[mac-mpo-destroy-devfsdirent]] ==== `mpo_destroy_devfsdirent_label` [source,c] ---- -void mpo_destroy_devfsdirent_label( label); +void mpo_destroy_devfsdirent_label( label); struct label *label; ---- @@ -775,14 +894,15 @@ | |=== -Destroy the label on a devfs entry. In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. +Destroy the label on a devfs entry. +In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. [[mac-mpo-destroy-ifnet-label]] ==== `mpo_destroy_ifnet_label` [source,c] ---- -void mpo_destroy_ifnet_label( label); +void mpo_destroy_ifnet_label( label); struct label *label; ---- @@ -798,14 +918,15 @@ | |=== -Destroy the label on a removed interface. In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. +Destroy the label on a removed interface. +In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. [[mac-mpo-destroy-ipq-label]] ==== `mpo_destroy_ipq_label` [source,c] ---- -void mpo_destroy_ipq_label( label); +void mpo_destroy_ipq_label( label); struct label *label; ---- @@ -821,14 +942,15 @@ | |=== -Destroy the label on an IP fragment queue. In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. +Destroy the label on an IP fragment queue. +In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. [[mac-mpo-destroy-mbuf-label]] ==== `mpo_destroy_mbuf_label` [source,c] ---- -void mpo_destroy_mbuf_label( label); +void mpo_destroy_mbuf_label( label); struct label *label; ---- @@ -844,14 +966,15 @@ | |=== -Destroy the label on an mbuf header. In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. +Destroy the label on an mbuf header. +In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. [[mac-mpo-destroy-mount-label]] ==== `mpo_destroy_mount_label` [source,c] ---- -void mpo_destroy_mount_label( label); +void mpo_destroy_mount_label( label); struct label *label; ---- @@ -867,15 +990,16 @@ | |=== -Destroy the labels on a mount point. In this entry point, a policy module should free the internal storage associated with `mntlabel` so that they may be destroyed. +Destroy the labels on a mount point. +In this entry point, a policy module should free the internal storage associated with `mntlabel` so that they may be destroyed. [[mac-mpo-destroy-mount]] ==== `mpo_destroy_mount_label` [source,c] ---- -void mpo_destroy_mount_label( mntlabel, - fslabel); +void mpo_destroy_mount_label( mntlabel, + fslabel); struct label *mntlabel; struct label *fslabel; ---- @@ -896,14 +1020,15 @@ | |=== -Destroy the labels on a mount point. In this entry point, a policy module should free the internal storage associated with `mntlabel` and `fslabel` so that they may be destroyed. +Destroy the labels on a mount point. +In this entry point, a policy module should free the internal storage associated with `mntlabel` and `fslabel` so that they may be destroyed. [[mac-mpo-destroy-socket]] ==== `mpo_destroy_socket_label` [source,c] ---- -void mpo_destroy_socket_label( label); +void mpo_destroy_socket_label( label); struct label *label; ---- @@ -919,14 +1044,15 @@ | |=== -Destroy the label on a socket. In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. +Destroy the label on a socket. +In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. [[mac-mpo-destroy-socket-peer-label]] ==== `mpo_destroy_socket_peer_label` [source,c] ---- -void mpo_destroy_socket_peer_label( peerlabel); +void mpo_destroy_socket_peer_label( peerlabel); struct label *peerlabel; ---- @@ -942,14 +1068,15 @@ | |=== -Destroy the peer label on a socket. In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. +Destroy the peer label on a socket. +In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. [[mac-mpo-destroy-pipe-label]] ==== `mpo_destroy_pipe_label` [source,c] ---- -void mpo_destroy_pipe_label( label); +void mpo_destroy_pipe_label( label); struct label *label; ---- @@ -965,14 +1092,15 @@ | |=== -Destroy the label on a pipe. In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. +Destroy the label on a pipe. +In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. [[mac-mpo-destroy-proc-label]] ==== `mpo_destroy_proc_label` [source,c] ---- -void mpo_destroy_proc_label( label); +void mpo_destroy_proc_label( label); struct label *label; ---- @@ -988,14 +1116,15 @@ | |=== -Destroy the label on a process. In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. +Destroy the label on a process. +In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. [[mac-mpo-destroy-vnode-label]] ==== `mpo_destroy_vnode_label` [source,c] ---- -void mpo_destroy_vnode_label( label); +void mpo_destroy_vnode_label( label); struct label *label; ---- @@ -1011,15 +1140,16 @@ | |=== -Destroy the label on a vnode. In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. +Destroy the label on a vnode. +In this entry point, a policy module should free any internal storage associated with `label` so that it may be destroyed. [[mac-mpo-copy-mbuf-label]] ==== `mpo_copy_mbuf_label` [source,c] ---- -void mpo_copy_mbuf_label( src, - dest); +void mpo_copy_mbuf_label( src, + dest); struct label *src; struct label *dest; ---- @@ -1047,8 +1177,8 @@ [source,c] ---- -void mpo_copy_pipe_label( src, - dest); +void mpo_copy_pipe_label( src, + dest); struct label *src; struct label *dest; ---- @@ -1076,8 +1206,8 @@ [source,c] ---- -void mpo_copy_vnode_label( src, - dest); +void mpo_copy_vnode_label( src, + dest); struct label *src; struct label *dest; ---- @@ -1105,10 +1235,10 @@ [source,c] ---- -int mpo_externalize_cred_label( label, - element_name, - sb, - *claimed); +int mpo_externalize_cred_label( label, + element_name, + sb, + *claimed); struct label *label; char *element_name; struct sbuf *sb; @@ -1139,17 +1269,22 @@ | |=== -Produce an externalized label based on the label structure passed. An externalized label consists of a text representation of the label contents that can be used with userland applications and read by the user. Currently, all policies' `externalize` entry points will be called, so the implementation should check the contents of `element_name` before attempting to fill in `sb`. If `element_name` does not match the name of your policy, simply return 0. Only return nonzero if an error occurs while externalizing the label data. Once the policy fills in `element_data`, `*claimed` should be incremented. +Produce an externalized label based on the label structure passed. +An externalized label consists of a text representation of the label contents that can be used with userland applications and read by the user. +Currently, all policies' `externalize` entry points will be called, so the implementation should check the contents of `element_name` before attempting to fill in `sb`. +If `element_name` does not match the name of your policy, simply return 0. +Only return nonzero if an error occurs while externalizing the label data. +Once the policy fills in `element_data`, `*claimed` should be incremented. [[mac-mpo-externalize-ifnet-label]] ==== `mpo_externalize_ifnet_label` [source,c] ---- -int mpo_externalize_ifnet_label( label, - element_name, - sb, - *claimed); +int mpo_externalize_ifnet_label( label, + element_name, + sb, + *claimed); struct label *label; char *element_name; struct sbuf *sb; @@ -1180,17 +1315,22 @@ | |=== -Produce an externalized label based on the label structure passed. An externalized label consists of a text representation of the label contents that can be used with userland applications and read by the user. Currently, all policies' `externalize` entry points will be called, so the implementation should check the contents of `element_name` before attempting to fill in `sb`. If `element_name` does not match the name of your policy, simply return 0. Only return nonzero if an error occurs while externalizing the label data. Once the policy fills in `element_data`, `*claimed` should be incremented. +Produce an externalized label based on the label structure passed. +An externalized label consists of a text representation of the label contents that can be used with userland applications and read by the user. +Currently, all policies' `externalize` entry points will be called, so the implementation should check the contents of `element_name` before attempting to fill in `sb`. +If `element_name` does not match the name of your policy, simply return 0. +Only return nonzero if an error occurs while externalizing the label data. +Once the policy fills in `element_data`, `*claimed` should be incremented. [[mac-mpo-externalize-pipe-label]] ==== `mpo_externalize_pipe_label` [source,c] ---- -int mpo_externalize_pipe_label( label, - element_name, - sb, - *claimed); +int mpo_externalize_pipe_label( label, + element_name, + sb, + *claimed); struct label *label; char *element_name; struct sbuf *sb; @@ -1221,17 +1361,22 @@ | |=== -Produce an externalized label based on the label structure passed. An externalized label consists of a text representation of the label contents that can be used with userland applications and read by the user. Currently, all policies' `externalize` entry points will be called, so the implementation should check the contents of `element_name` before attempting to fill in `sb`. If `element_name` does not match the name of your policy, simply return 0. Only return nonzero if an error occurs while externalizing the label data. Once the policy fills in `element_data`, `*claimed` should be incremented. +Produce an externalized label based on the label structure passed. +An externalized label consists of a text representation of the label contents that can be used with userland applications and read by the user. +Currently, all policies' `externalize` entry points will be called, so the implementation should check the contents of `element_name` before attempting to fill in `sb`. +If `element_name` does not match the name of your policy, simply return 0. +Only return nonzero if an error occurs while externalizing the label data. +Once the policy fills in `element_data`, `*claimed` should be incremented. [[mac-mpo-externalize-socket-label]] ==== `mpo_externalize_socket_label` [source,c] ---- -int mpo_externalize_socket_label( label, - element_name, - sb, - *claimed); +int mpo_externalize_socket_label( label, + element_name, + sb, + *claimed); struct label *label; char *element_name; struct sbuf *sb; @@ -1262,17 +1407,22 @@ | |=== -Produce an externalized label based on the label structure passed. An externalized label consists of a text representation of the label contents that can be used with userland applications and read by the user. Currently, all policies' `externalize` entry points will be called, so the implementation should check the contents of `element_name` before attempting to fill in `sb`. If `element_name` does not match the name of your policy, simply return 0. Only return nonzero if an error occurs while externalizing the label data. Once the policy fills in `element_data`, `*claimed` should be incremented. +Produce an externalized label based on the label structure passed. +An externalized label consists of a text representation of the label contents that can be used with userland applications and read by the user. +Currently, all policies' `externalize` entry points will be called, so the implementation should check the contents of `element_name` before attempting to fill in `sb`. +If `element_name` does not match the name of your policy, simply return 0. +Only return nonzero if an error occurs while externalizing the label data. +Once the policy fills in `element_data`, `*claimed` should be incremented. [[mac-mpo-externalize-socket-peer-label]] ==== `mpo_externalize_socket_peer_label` [source,c] ---- -int mpo_externalize_socket_peer_label( label, - element_name, - sb, - *claimed); +int mpo_externalize_socket_peer_label( label, + element_name, + sb, + *claimed); struct label *label; char *element_name; struct sbuf *sb; @@ -1303,17 +1453,22 @@ | |=== -Produce an externalized label based on the label structure passed. An externalized label consists of a text representation of the label contents that can be used with userland applications and read by the user. Currently, all policies' `externalize` entry points will be called, so the implementation should check the contents of `element_name` before attempting to fill in `sb`. If `element_name` does not match the name of your policy, simply return 0. Only return nonzero if an error occurs while externalizing the label data. Once the policy fills in `element_data`, `*claimed` should be incremented. +Produce an externalized label based on the label structure passed. +An externalized label consists of a text representation of the label contents that can be used with userland applications and read by the user. +Currently, all policies' `externalize` entry points will be called, so the implementation should check the contents of `element_name` before attempting to fill in `sb`. +If `element_name` does not match the name of your policy, simply return 0. +Only return nonzero if an error occurs while externalizing the label data. +Once the policy fills in `element_data`, `*claimed` should be incremented. [[mac-mpo-externalize-vnode-label]] ==== `mpo_externalize_vnode_label` [source,c] ---- -int mpo_externalize_vnode_label( label, - element_name, - sb, - *claimed); +int mpo_externalize_vnode_label( label, + element_name, + sb, + *claimed); struct label *label; char *element_name; struct sbuf *sb; @@ -1344,17 +1499,22 @@ | |=== -Produce an externalized label based on the label structure passed. An externalized label consists of a text representation of the label contents that can be used with userland applications and read by the user. Currently, all policies' `externalize` entry points will be called, so the implementation should check the contents of `element_name` before attempting to fill in `sb`. If `element_name` does not match the name of your policy, simply return 0. Only return nonzero if an error occurs while externalizing the label data. Once the policy fills in `element_data`, `*claimed` should be incremented. +Produce an externalized label based on the label structure passed. +An externalized label consists of a text representation of the label contents that can be used with userland applications and read by the user. +Currently, all policies' `externalize` entry points will be called, so the implementation should check the contents of `element_name` before attempting to fill in `sb`. +If `element_name` does not match the name of your policy, simply return 0. +Only return nonzero if an error occurs while externalizing the label data. +Once the policy fills in `element_data`, `*claimed` should be incremented. [[mac-mpo-internalize-cred-label]] ==== `mpo_internalize_cred_label` [source,c] ---- -int mpo_internalize_cred_label( label, - element_name, - element_data, - claimed); +int mpo_internalize_cred_label( label, + element_name, + element_data, + claimed); struct label *label; char *element_name; char *element_data; @@ -1385,17 +1545,19 @@ | |=== -Produce an internal label structure based on externalized label data in text format. Currently, all policies' `internalize` entry points are called when internalization is requested, so the implementation should compare the contents of `element_name` to its own name in order to be sure it should be internalizing the data in `element_data`. Just as in the `externalize` entry points, the entry point should return 0 if `element_name` does not match its own name, or when data can successfully be internalized, in which case `*claimed` should be incremented. +Produce an internal label structure based on externalized label data in text format. +Currently, all policies' `internalize` entry points are called when internalization is requested, so the implementation should compare the contents of `element_name` to its own name in order to be sure it should be internalizing the data in `element_data`. +Just as in the `externalize` entry points, the entry point should return 0 if `element_name` does not match its own name, or when data can successfully be internalized, in which case `*claimed` should be incremented. [[mac-mpo-internalize-ifnet-label]] ==== `mpo_internalize_ifnet_label` [source,c] ---- -int mpo_internalize_ifnet_label( label, - element_name, - element_data, - claimed); +int mpo_internalize_ifnet_label( label, + element_name, + element_data, + claimed); struct label *label; char *element_name; char *element_data; @@ -1426,17 +1588,19 @@ | |=== -Produce an internal label structure based on externalized label data in text format. Currently, all policies' `internalize` entry points are called when internalization is requested, so the implementation should compare the contents of `element_name` to its own name in order to be sure it should be internalizing the data in `element_data`. Just as in the `externalize` entry points, the entry point should return 0 if `element_name` does not match its own name, or when data can successfully be internalized, in which case `*claimed` should be incremented. +Produce an internal label structure based on externalized label data in text format. +Currently, all policies' `internalize` entry points are called when internalization is requested, so the implementation should compare the contents of `element_name` to its own name in order to be sure it should be internalizing the data in `element_data`. +Just as in the `externalize` entry points, the entry point should return 0 if `element_name` does not match its own name, or when data can successfully be internalized, in which case `*claimed` should be incremented. [[mac-mpo-internalize-pipe-label]] ==== `mpo_internalize_pipe_label` [source,c] ---- -int mpo_internalize_pipe_label( label, - element_name, - element_data, - claimed); +int mpo_internalize_pipe_label( label, + element_name, + element_data, + claimed); struct label *label; char *element_name; char *element_data; @@ -1467,17 +1631,19 @@ | |=== -Produce an internal label structure based on externalized label data in text format. Currently, all policies' `internalize` entry points are called when internalization is requested, so the implementation should compare the contents of `element_name` to its own name in order to be sure it should be internalizing the data in `element_data`. Just as in the `externalize` entry points, the entry point should return 0 if `element_name` does not match its own name, or when data can successfully be internalized, in which case `*claimed` should be incremented. +Produce an internal label structure based on externalized label data in text format. +Currently, all policies' `internalize` entry points are called when internalization is requested, so the implementation should compare the contents of `element_name` to its own name in order to be sure it should be internalizing the data in `element_data`. +Just as in the `externalize` entry points, the entry point should return 0 if `element_name` does not match its own name, or when data can successfully be internalized, in which case `*claimed` should be incremented. [[mac-mpo-internalize-socket-label]] ==== `mpo_internalize_socket_label` [source,c] ---- -int mpo_internalize_socket_label( label, - element_name, - element_data, - claimed); +int mpo_internalize_socket_label( label, + element_name, + element_data, + claimed); struct label *label; char *element_name; char *element_data; @@ -1508,17 +1674,19 @@ | |=== -Produce an internal label structure based on externalized label data in text format. Currently, all policies' `internalize` entry points are called when internalization is requested, so the implementation should compare the contents of `element_name` to its own name in order to be sure it should be internalizing the data in `element_data`. Just as in the `externalize` entry points, the entry point should return 0 if `element_name` does not match its own name, or when data can successfully be internalized, in which case `*claimed` should be incremented. +Produce an internal label structure based on externalized label data in text format. +Currently, all policies' `internalize` entry points are called when internalization is requested, so the implementation should compare the contents of `element_name` to its own name in order to be sure it should be internalizing the data in `element_data`. +Just as in the `externalize` entry points, the entry point should return 0 if `element_name` does not match its own name, or when data can successfully be internalized, in which case `*claimed` should be incremented. [[mac-mpo-internalize-vnode-label]] ==== `mpo_internalize_vnode_label` [source,c] ---- -int mpo_internalize_vnode_label( label, - element_name, - element_data, - claimed); +int mpo_internalize_vnode_label( label, + element_name, + element_data, + claimed); struct label *label; char *element_name; char *element_data; @@ -1549,12 +1717,19 @@ | |=== -Produce an internal label structure based on externalized label data in text format. Currently, all policies' `internalize` entry points are called when internalization is requested, so the implementation should compare the contents of `element_name` to its own name in order to be sure it should be internalizing the data in `element_data`. Just as in the `externalize` entry points, the entry point should return 0 if `element_name` does not match its own name, or when data can successfully be internalized, in which case `*claimed` should be incremented. +Produce an internal label structure based on externalized label data in text format. +Currently, all policies' `internalize` entry points are called when internalization is requested, so the implementation should compare the contents of `element_name` to its own name in order to be sure it should be internalizing the data in `element_data`. +Just as in the `externalize` entry points, the entry point should return 0 if `element_name` does not match its own name, or when data can successfully be internalized, in which case `*claimed` should be incremented. [[mac-label-events]] === Label Events -This class of entry points is used by the MAC framework to permit policies to maintain label information on kernel objects. For each labeled kernel object of interest to a MAC policy, entry points may be registered for relevant life cycle events. All objects implement initialization, creation, and destruction hooks. Some objects will also implement relabeling, allowing user processes to change the labels on objects. Some objects will also implement object-specific events, such as label events associated with IP reassembly. A typical labeled object will have the following life cycle of entry points: +This class of entry points is used by the MAC framework to permit policies to maintain label information on kernel objects. +For each labeled kernel object of interest to a MAC policy, entry points may be registered for relevant life cycle events. +All objects implement initialization, creation, and destruction hooks. +Some objects will also implement relabeling, allowing user processes to change the labels on objects. +Some objects will also implement object-specific events, such as label events associated with IP reassembly. +A typical labeled object will have the following life cycle of entry points: [.programlisting] .... @@ -1569,17 +1744,26 @@ Label destruction o .... -Label initialization permits policies to allocate memory and set initial values for labels without context for the use of the object. The label slot allocated to a policy will be zeroed by default, so some policies may not need to perform initialization. +Label initialization permits policies to allocate memory and set initial values for labels without context for the use of the object. +The label slot allocated to a policy will be zeroed by default, so some policies may not need to perform initialization. -Label creation occurs when the kernel structure is associated with an actual kernel object. For example, Mbufs may be allocated and remain unused in a pool until they are required. mbuf allocation causes label initialization on the mbuf to take place, but mbuf creation occurs when the mbuf is associated with a datagram. Typically, context will be provided for a creation event, including the circumstances of the creation, and labels of other relevant objects in the creation process. For example, when an mbuf is created from a socket, the socket and its label will be presented to registered policies in addition to the new mbuf and its label. Memory allocation in creation events is discouraged, as it may occur in performance sensitive ports of the kernel; in addition, creation calls are not permitted to fail so a failure to allocate memory cannot be reported. +Label creation occurs when the kernel structure is associated with an actual kernel object. +For example, Mbufs may be allocated and remain unused in a pool until they are required. +mbuf allocation causes label initialization on the mbuf to take place, but mbuf creation occurs when the mbuf is associated with a datagram. +Typically, context will be provided for a creation event, including the circumstances of the creation, and labels of other relevant objects in the creation process. +For example, when an mbuf is created from a socket, the socket and its label will be presented to registered policies in addition to the new mbuf and its label. +Memory allocation in creation events is discouraged, as it may occur in performance sensitive ports of the kernel; in addition, creation calls are not permitted to fail so a failure to allocate memory cannot be reported. -Object specific events do not generally fall into the other broad classes of label events, but will generally provide an opportunity to modify or update the label on an object based on additional context. For example, the label on an IP fragment reassembly queue may be updated during the MAC_UPDATE_IPQ entry point as a result of the acceptance of an additional mbuf to that queue. +Object specific events do not generally fall into the other broad classes of label events, but will generally provide an opportunity to modify or update the label on an object based on additional context. +For example, the label on an IP fragment reassembly queue may be updated during the MAC_UPDATE_IPQ entry point as a result of the acceptance of an additional mbuf to that queue. Access control events are discussed in detail in the following section. Label destruction permits policies to release storage or state associated with a label during its association with an object so that the kernel data structures supporting the object may be reused or released. -In addition to labels associated with specific kernel objects, an additional class of labels exists: temporary labels. These labels are used to store update information submitted by user processes. These labels are initialized and destroyed as with other label types, but the creation event is MAC_INTERNALIZE, which accepts a user label to be converted to an in-kernel representation. +In addition to labels associated with specific kernel objects, an additional class of labels exists: temporary labels. +These labels are used to store update information submitted by user processes. +These labels are initialized and destroyed as with other label types, but the creation event is MAC_INTERNALIZE, which accepts a user label to be converted to an in-kernel representation. [[mac-fs-label-event-ops]] ==== File System Object Labeling Event Operations @@ -1589,12 +1773,12 @@ [source,c] ---- -void mpo_associate_vnode_devfs( mp, - fslabel, - de, - delabel, - vp, - vlabel); +void mpo_associate_vnode_devfs( mp, + fslabel, + de, + delabel, + vp, + vlabel); struct mount *mp; struct label *fslabel; struct devfs_dirent *de; @@ -1642,10 +1826,10 @@ [source,c] ---- -int mpo_associate_vnode_extattr( mp, - fslabel, - vp, - vlabel); +int mpo_associate_vnode_extattr( mp, + fslabel, + vp, + vlabel); struct mount *mp; struct label *fslabel; struct vnode *vp; @@ -1676,17 +1860,20 @@ | |=== -Attempt to retrieve the label for `vp` from the file system extended attributes. Upon success, the value `0` is returned. Should extended attribute retrieval not be supported, an accepted fallback is to copy `fslabel` into `vlabel`. In the event of an error, an appropriate value for `errno` should be returned. +Attempt to retrieve the label for `vp` from the file system extended attributes. +Upon success, the value `0` is returned. +Should extended attribute retrieval not be supported, an accepted fallback is to copy `fslabel` into `vlabel`. +In the event of an error, an appropriate value for `errno` should be returned. [[mac-mpo-associate-vnode-singlelabel]] ===== `mpo_associate_vnode_singlelabel` [source,c] ---- -void mpo_associate_vnode_singlelabel( mp, - fslabel, - vp, - vlabel); +void mpo_associate_vnode_singlelabel( mp, + fslabel, + vp, + vlabel); struct mount *mp; struct label *fslabel; struct vnode *vp; @@ -1724,9 +1911,9 @@ [source,c] ---- -void mpo_create_devfs_device( dev, - devfs_dirent, - label); +void mpo_create_devfs_device( dev, + devfs_dirent, + label); dev_t dev; struct devfs_dirent *devfs_dirent; struct label *label; @@ -1752,17 +1939,18 @@ | |=== -Fill out the label on a devfs_dirent being created for the passed device. This call will be made when the device file system is mounted, regenerated, or a new device is made available. +Fill out the label on a devfs_dirent being created for the passed device. +This call will be made when the device file system is mounted, regenerated, or a new device is made available. [[mac-mpo-create-devfs-directory]] ===== `mpo_create_devfs_directory` [source,c] ---- -void mpo_create_devfs_directory( dirname, - dirnamelen, - devfs_dirent, - label); +void mpo_create_devfs_directory( dirname, + dirnamelen, + devfs_dirent, + label); char *dirname; int dirnamelen; struct devfs_dirent *devfs_dirent; @@ -1789,19 +1977,20 @@ | |=== -Fill out the label on a devfs_dirent being created for the passed directory. This call will be made when the device file system is mounted, regenerated, or a new device requiring a specific directory hierarchy is made available. +Fill out the label on a devfs_dirent being created for the passed directory. +This call will be made when the device file system is mounted, regenerated, or a new device requiring a specific directory hierarchy is made available. [[mac-mpo-create-devfs-symlink]] ===== `mpo_create_devfs_symlink` [source,c] ---- -void mpo_create_devfs_symlink( cred, - mp, - dd, - ddlabel, - de, - delabel); +void mpo_create_devfs_symlink( cred, + mp, + dd, + ddlabel, + de, + delabel); struct ucred *cred; struct mount *mp; struct devfs_dirent *dd; @@ -1849,14 +2038,14 @@ [source,c] ---- -int mpo_create_vnode_extattr( cred, - mp, - fslabel, - dvp, - dlabel, - vp, - vlabel, - cnp); +int mpo_create_vnode_extattr( cred, + mp, + fslabel, + dvp, + dlabel, + vp, + vlabel, + cnp); struct ucred *cred; struct mount *mp; struct label *fslabel; @@ -1907,17 +2096,19 @@ | |=== -Write out the label for `vp` to the appropriate extended attribute. If the write succeeds, fill in `vlabel` with the label, and return 0. Otherwise, return an appropriate error. +Write out the label for `vp` to the appropriate extended attribute. +If the write succeeds, fill in `vlabel` with the label, and return 0. +Otherwise, return an appropriate error. [[mac-mpo-create-mount]] ===== `mpo_create_mount` [source,c] ---- -void mpo_create_mount( cred, - mp, - mnt, - fslabel); +void mpo_create_mount( cred, + mp, + mnt, + fslabel); struct ucred *cred; struct mount *mp; struct label *mnt; @@ -1948,17 +2139,18 @@ | |=== -Fill out the labels on the mount point being created by the passed subject credential. This call will be made when a new file system is mounted. +Fill out the labels on the mount point being created by the passed subject credential. +This call will be made when a new file system is mounted. [[mac-mpo-create-root-mount]] ===== `mpo_create_root_mount` [source,c] ---- -void mpo_create_root_mount( cred, - mp, - mntlabel, - fslabel); +void mpo_create_root_mount( cred, + mp, + mntlabel, + fslabel); struct ucred *cred; struct mount *mp; struct label *mntlabel; @@ -1975,17 +2167,18 @@ 3+|See <>. |=== -Fill out the labels on the mount point being created by the passed subject credential. This call will be made when the root file system is mounted, after mpo_create_mount;. +Fill out the labels on the mount point being created by the passed subject credential. +This call will be made when the root file system is mounted, after `mpo_create_mount;`. [[mac-mpo-relabel-vnode]] ===== `mpo_relabel_vnode` [source,c] ---- -void mpo_relabel_vnode( cred, - vp, - vnodelabel, - newlabel); +void mpo_relabel_vnode( cred, + vp, + vnodelabel, + newlabel); struct ucred *cred; struct vnode *vp; struct label *vnodelabel; @@ -2023,10 +2216,10 @@ [source,c] ---- -int mpo_setlabel_vnode_extattr( cred, - vp, - vlabel, - intlabel); +int mpo_setlabel_vnode_extattr( cred, + vp, + vlabel, + intlabel); struct ucred *cred; struct vnode *vp; struct label *vlabel; @@ -2057,17 +2250,18 @@ | |=== -Write out the policy from `intlabel` to an extended attribute. This is called from `vop_stdcreatevnode_ea`. +Write out the policy from `intlabel` to an extended attribute. +This is called from `vop_stdcreatevnode_ea`. [[mac-mpo-update-devfsdirent]] ===== `mpo_update_devfsdirent` [source,c] ---- -void mpo_update_devfsdirent( devfs_dirent, - direntlabel, - vp, - vnodelabel); +void mpo_update_devfsdirent( devfs_dirent, + direntlabel, + vp, + vnodelabel); struct devfs_dirent *devfs_dirent; struct label *direntlabel; struct vnode *vp; @@ -2099,7 +2293,9 @@ | |=== -Update the `devfs_dirent` label from the passed devfs vnode label. This call will be made when a devfs vnode has been successfully relabeled to commit the label change such that it lasts even if the vnode is recycled. It will also be made when a symlink is created in devfs, following a call to `mac_vnode_create_from_vnode` to initialize the vnode label. +Update the `devfs_dirent` label from the passed devfs vnode label. +This call will be made when a devfs vnode has been successfully relabeled to commit the label change such that it lasts even if the vnode is recycled. +It will also be made when a symlink is created in devfs, following a call to `mac_vnode_create_from_vnode` to initialize the vnode label. [[mac-ipc-label-ops]] ==== IPC Object Labeling Event Operations @@ -2109,10 +2305,10 @@ [source,c] ---- -void mpo_create_mbuf_from_socket( so, - socketlabel, - m, - mbuflabel); +void mpo_create_mbuf_from_socket( so, + socketlabel, + m, + mbuflabel); struct socket *so; struct label *socketlabel; struct mbuf *m; @@ -2143,16 +2339,17 @@ | |=== -Set the label on a newly created mbuf header from the passed socket label. This call is made when a new datagram or message is generated by the socket and stored in the passed mbuf. +Set the label on a newly created mbuf header from the passed socket label. +This call is made when a new datagram or message is generated by the socket and stored in the passed mbuf. [[mac-mpo-create-pipe]] ===== `mpo_create_pipe` [source,c] ---- -void mpo_create_pipe( cred, - pipe, - pipelabel); +void mpo_create_pipe( cred, + pipe, + pipelabel); struct ucred *cred; struct pipe *pipe; struct label *pipelabel; @@ -2178,16 +2375,17 @@ | |=== -Set the label on a newly created pipe from the passed subject credential. This call is made when a new pipe is created. +Set the label on a newly created pipe from the passed subject credential. +This call is made when a new pipe is created. [[mac-mpo-create-socket]] ===== `mpo_create_socket` [source,c] ---- -void mpo_create_socket( cred, - so, - socketlabel); +void mpo_create_socket( cred, + so, + socketlabel); struct ucred *cred; struct socket *so; struct label *socketlabel; @@ -2213,17 +2411,18 @@ | |=== -Set the label on a newly created socket from the passed subject credential. This call is made when a socket is created. +Set the label on a newly created socket from the passed subject credential. +This call is made when a socket is created. [[mac-mpo-create-socket-from-socket]] ===== `mpo_create_socket_from_socket` [source,c] ---- -void mpo_create_socket_from_socket( oldsocket, - oldsocketlabel, - newsocket, - newsocketlabel); +void mpo_create_socket_from_socket( oldsocket, + oldsocketlabel, + newsocket, + newsocketlabel); struct socket *oldsocket; struct label *oldsocketlabel; struct socket *newsocket; @@ -2261,10 +2460,10 @@ [source,c] ---- -void mpo_relabel_pipe( cred, - pipe, - oldlabel, - newlabel); +void mpo_relabel_pipe( cred, + pipe, + oldlabel, + newlabel); struct ucred *cred; struct pipe *pipe; struct label *oldlabel; @@ -2302,10 +2501,10 @@ [source,c] ---- -void mpo_relabel_socket( cred, - so, - oldlabel, - newlabel); +void mpo_relabel_socket( cred, + so, + oldlabel, + newlabel); struct ucred *cred; struct socket *so; struct label *oldlabel; @@ -2343,10 +2542,10 @@ [source,c] ---- -void mpo_set_socket_peer_from_mbuf( mbuf, - mbuflabel, - oldlabel, - newlabel); +void mpo_set_socket_peer_from_mbuf( mbuf, + mbuflabel, + oldlabel, + newlabel); struct mbuf *mbuf; struct label *mbuflabel; struct label *oldlabel; @@ -2377,17 +2576,18 @@ | |=== -Set the peer label on a stream socket from the passed mbuf label. This call will be made when the first datagram is received by the stream socket, with the exception of Unix domain sockets. +Set the peer label on a stream socket from the passed mbuf label. +This call will be made when the first datagram is received by the stream socket, with the exception of Unix domain sockets. [[mac-mpo-set-socket-peer-from-socket]] ===== `mpo_set_socket_peer_from_socket` [source,c] ---- -void mpo_set_socket_peer_from_socket( oldsocket, - oldsocketlabel, - newsocket, - newsocketpeerlabel); +void mpo_set_socket_peer_from_socket( oldsocket, + oldsocketlabel, + newsocket, + newsocketpeerlabel); struct socket *oldsocket; struct label *oldsocketlabel; struct socket *newsocket; @@ -2418,7 +2618,8 @@ | |=== -Set the peer label on a stream UNIX domain socket from the passed remote socket endpoint. This call will be made when the socket pair is connected, and will be made for both endpoints. +Set the peer label on a stream UNIX domain socket from the passed remote socket endpoint. +This call will be made when the socket pair is connected, and will be made for both endpoints. [[mac-net-labeling-event-ops]] ==== Network Object Labeling Event Operations @@ -2428,9 +2629,9 @@ [source,c] ---- -void mpo_create_bpfdesc( cred, - bpf_d, - bpflabel); +void mpo_create_bpfdesc( cred, + bpf_d, + bpflabel); struct ucred *cred; struct bpf_d *bpf_d; struct label *bpflabel; @@ -2456,15 +2657,16 @@ | |=== -Set the label on a newly created BPF descriptor from the passed subject credential. This call will be made when a BPF device node is opened by a process with the passed subject credential. +Set the label on a newly created BPF descriptor from the passed subject credential. +This call will be made when a BPF device node is opened by a process with the passed subject credential. [[mac-mpo-create-ifnet]] ===== `mpo_create_ifnet` [source,c] ---- -void mpo_create_ifnet( ifnet, - ifnetlabel); +void mpo_create_ifnet( ifnet, + ifnetlabel); struct ifnet *ifnet; struct label *ifnetlabel; ---- @@ -2485,17 +2687,18 @@ | |=== -Set the label on a newly created interface. This call may be made when a new physical interface becomes available to the system, or when a pseudo-interface is instantiated during the boot or as a result of a user action. +Set the label on a newly created interface. +This call may be made when a new physical interface becomes available to the system, or when a pseudo-interface is instantiated during the boot or as a result of a user action. [[mac-mpo-create-ipq]] ===== `mpo_create_ipq` [source,c] ---- -void mpo_create_ipq( fragment, - fragmentlabel, - ipq, - ipqlabel); +void mpo_create_ipq( fragment, + fragmentlabel, + ipq, + ipqlabel); struct mbuf *fragment; struct label *fragmentlabel; struct ipq *ipq; @@ -2533,10 +2736,10 @@ [source,c] ---- -void mpo_create_create_datagram_from_ipq( ipq, - ipqlabel, - datagram, - datagramlabel); +void mpo_create_create_datagram_from_ipq( ipq, + ipqlabel, + datagram, + datagramlabel); struct ipq *ipq; struct label *ipqlabel; struct mbuf *datagram; @@ -2574,10 +2777,10 @@ [source,c] ---- -void mpo_create_fragment( datagram, - datagramlabel, - fragment, - fragmentlabel); +void mpo_create_fragment( datagram, + datagramlabel, + fragment, + fragmentlabel); struct mbuf *datagram; struct label *datagramlabel; struct mbuf *fragment; @@ -2615,10 +2818,10 @@ [source,c] ---- -void mpo_create_mbuf_from_mbuf( oldmbuf, - oldmbuflabel, - newmbuf, - newmbuflabel); +void mpo_create_mbuf_from_mbuf( oldmbuf, + oldmbuflabel, + newmbuf, + newmbuflabel); struct mbuf *oldmbuf; struct label *oldmbuflabel; struct mbuf *newmbuf; @@ -2649,17 +2852,18 @@ | |=== -Set the label on the mbuf header of a newly created datagram from the mbuf header of an existing datagram. This call may be made in a number of situations, including when an mbuf is re-allocated for alignment purposes. +Set the label on the mbuf header of a newly created datagram from the mbuf header of an existing datagram. +This call may be made in a number of situations, including when an mbuf is re-allocated for alignment purposes. [[mac-mpo-create-mbuf-linklayer]] ===== `mpo_create_mbuf_linklayer` [source,c] ---- -void mpo_create_mbuf_linklayer( ifnet, - ifnetlabel, - mbuf, - mbuflabel); +void mpo_create_mbuf_linklayer( ifnet, + ifnetlabel, + mbuf, + mbuflabel); struct ifnet *ifnet; struct label *ifnetlabel; struct mbuf *mbuf; @@ -2690,17 +2894,18 @@ | |=== -Set the label on the mbuf header of a newly created datagram generated for the purposes of a link layer response for the passed interface. This call may be made in a number of situations, including for ARP or ND6 responses in the IPv4 and IPv6 stacks. +Set the label on the mbuf header of a newly created datagram generated for the purposes of a link layer response for the passed interface. +This call may be made in a number of situations, including for ARP or ND6 responses in the IPv4 and IPv6 stacks. [[mac-mpo-create-mbuf-from-bpfdesc]] ===== `mpo_create_mbuf_from_bpfdesc` [source,c] ---- -void mpo_create_mbuf_from_bpfdesc( bpf_d, - bpflabel, - mbuf, - mbuflabel); +void mpo_create_mbuf_from_bpfdesc( bpf_d, + bpflabel, + mbuf, + mbuflabel); struct bpf_d *bpf_d; struct label *bpflabel; struct mbuf *mbuf; @@ -2731,17 +2936,18 @@ | |=== -Set the label on the mbuf header of a newly created datagram generated using the passed BPF descriptor. This call is made when a write is performed to the BPF device associated with the passed BPF descriptor. +Set the label on the mbuf header of a newly created datagram generated using the passed BPF descriptor. +This call is made when a write is performed to the BPF device associated with the passed BPF descriptor. [[mac-mpo-create-mbuf-from-ifnet]] ===== `mpo_create_mbuf_from_ifnet` [source,c] ---- -void mpo_create_mbuf_from_ifnet( ifnet, - ifnetlabel, - mbuf, - mbuflabel); +void mpo_create_mbuf_from_ifnet( ifnet, + ifnetlabel, + mbuf, + mbuflabel); struct ifnet *ifnet; struct label *ifnetlabel; struct mbuf *mbuf; @@ -2779,12 +2985,12 @@ [source,c] ---- -void mpo_create_mbuf_multicast_encap( oldmbuf, - oldmbuflabel, - ifnet, - ifnetlabel, - newmbuf, - newmbuflabel); +void mpo_create_mbuf_multicast_encap( oldmbuf, + oldmbuflabel, + ifnet, + ifnetlabel, + newmbuf, + newmbuflabel); struct mbuf *oldmbuf; struct label *oldmbuflabel; struct ifnet *ifnet; @@ -2825,17 +3031,18 @@ | |=== -Set the label on the mbuf header of a newly created datagram generated from the existing passed datagram when it is processed by the passed multicast encapsulation interface. This call is made when an mbuf is to be delivered using the virtual interface. +Set the label on the mbuf header of a newly created datagram generated from the existing passed datagram when it is processed by the passed multicast encapsulation interface. +This call is made when an mbuf is to be delivered using the virtual interface. [[mac-mpo-create-mbuf-netlayer]] ===== `mpo_create_mbuf_netlayer` [source,c] ---- -void mpo_create_mbuf_netlayer( oldmbuf, - oldmbuflabel, - newmbuf, - newmbuflabel); +void mpo_create_mbuf_netlayer( oldmbuf, + oldmbuflabel, + newmbuf, + newmbuflabel); struct mbuf *oldmbuf; struct label *oldmbuflabel; struct mbuf *newmbuf; @@ -2866,17 +3073,18 @@ | |=== -Set the label on the mbuf header of a newly created datagram generated by the IP stack in response to an existing received datagram (`oldmbuf`). This call may be made in a number of situations, including when responding to ICMP request datagrams. +Set the label on the mbuf header of a newly created datagram generated by the IP stack in response to an existing received datagram (`oldmbuf`). +This call may be made in a number of situations, including when responding to ICMP request datagrams. [[mac-mpo-fragment-match]] ===== `mpo_fragment_match` [source,c] ---- -int mpo_fragment_match( fragment, - fragmentlabel, - ipq, - ipqlabel); +int mpo_fragment_match( fragment, + fragmentlabel, + ipq, + ipqlabel); struct mbuf *fragment; struct label *fragmentlabel; struct ipq *ipq; @@ -2907,17 +3115,20 @@ | |=== -Determine whether an mbuf header containing an IP datagram (`fragment`) fragment matches the label of the passed IP fragment reassembly queue (`ipq`). Return (1) for a successful match, or (0) for no match. This call is made when the IP stack attempts to find an existing fragment reassembly queue for a newly received fragment; if this fails, a new fragment reassembly queue may be instantiated for the fragment. Policies may use this entry point to prevent the reassembly of otherwise matching IP fragments if policy does not permit them to be reassembled based on the label or other information. +Determine whether an mbuf header containing an IP datagram (`fragment`) fragment matches the label of the passed IP fragment reassembly queue (`ipq`). +Return (1) for a successful match, or (0) for no match. +This call is made when the IP stack attempts to find an existing fragment reassembly queue for a newly received fragment; if this fails, a new fragment reassembly queue may be instantiated for the fragment. +Policies may use this entry point to prevent the reassembly of otherwise matching IP fragments if policy does not permit them to be reassembled based on the label or other information. [[mac-mpo-ifnet-relabel]] ===== `mpo_relabel_ifnet` [source,c] ---- -void mpo_relabel_ifnet( cred, - ifnet, - ifnetlabel, - newlabel); +void mpo_relabel_ifnet( cred, + ifnet, + ifnetlabel, + newlabel); struct ucred *cred; struct ifnet *ifnet; struct label *ifnetlabel; @@ -2955,10 +3166,10 @@ [source,c] ---- -void mpo_update_ipq( fragment, - fragmentlabel, - ipq, - ipqlabel); +void mpo_update_ipq( fragment, + fragmentlabel, + ipq, + ipqlabel); struct mbuf *fragment; struct label *fragmentlabel; struct ipq *ipq; @@ -2999,8 +3210,8 @@ [source,c] ---- -void mpo_create_cred( parent_cred, - child_cred); +void mpo_create_cred( parent_cred, + child_cred); struct ucred *parent_cred; struct ucred *child_cred; ---- @@ -3021,17 +3232,19 @@ | |=== -Set the label of a newly created subject credential from the passed subject credential. This call will be made when man:crcopy[9] is invoked on a newly created struct ucred. This call should not be confused with a process forking or creation event. +Set the label of a newly created subject credential from the passed subject credential. +This call will be made when man:crcopy[9] is invoked on a newly created `struct ucred`. +This call should not be confused with a process forking or creation event. [[mac-mpo-execve-transition]] ===== `mpo_execve_transition` [source,c] ---- -void mpo_execve_transition( old, - new, - vp, - vnodelabel); +void mpo_execve_transition( old, + new, + vp, + vnodelabel); struct ucred *old; struct ucred *new; struct vnode *vp; @@ -3063,16 +3276,19 @@ | |=== -Update the label of a newly created subject credential (`new`) from the passed existing subject credential (`old`) based on a label transition caused by executing the passed vnode (`vp`). This call occurs when a process executes the passed vnode and one of the policies returns a success from the `mpo_execve_will_transition` entry point. Policies may choose to implement this call simply by invoking `mpo_create_cred` and passing the two subject credentials so as not to implement a transitioning event. Policies should not leave this entry point unimplemented if they implement `mpo_create_cred`, even if they do not implement `mpo_execve_will_transition`. +Update the label of a newly created subject credential (`new`) from the passed existing subject credential (`old`) based on a label transition caused by executing the passed vnode (`vp`). +This call occurs when a process executes the passed vnode and one of the policies returns a success from the `mpo_execve_will_transition` entry point. +Policies may choose to implement this call simply by invoking `mpo_create_cred` and passing the two subject credentials so as not to implement a transitioning event. +Policies should not leave this entry point unimplemented if they implement `mpo_create_cred`, even if they do not implement `mpo_execve_will_transition`. [[mac-mpo-execve-will-transition]] ===== `mpo_execve_will_transition` [source,c] ---- -int mpo_execve_will_transition( old, - vp, - vnodelabel); +int mpo_execve_will_transition( old, + vp, + vnodelabel); struct ucred *old; struct vnode *vp; struct label *vnodelabel; @@ -3098,14 +3314,16 @@ | |=== -Determine whether the policy will want to perform a transition event as a result of the execution of the passed vnode by the passed subject credential. Return 1 if a transition is required, 0 if not. Even if a policy returns 0, it should behave correctly in the presence of an unexpected invocation of `mpo_execve_transition`, as that call may happen as a result of another policy requesting a transition. +Determine whether the policy will want to perform a transition event as a result of the execution of the passed vnode by the passed subject credential. +Return 1 if a transition is required, 0 if not. +Even if a policy returns 0, it should behave correctly in the presence of an unexpected invocation of `mpo_execve_transition`, as that call may happen as a result of another policy requesting a transition. [[mac-mpo-create-proc0]] ===== `mpo_create_proc0` [source,c] ---- -void mpo_create_proc0( cred); +void mpo_create_proc0( cred); struct ucred *cred; ---- @@ -3128,7 +3346,7 @@ [source,c] ---- -void mpo_create_proc1( cred); +void mpo_create_proc1( cred); struct ucred *cred; ---- @@ -3151,8 +3369,8 @@ [source,c] ---- -void mpo_relabel_cred( cred, - newlabel); +void mpo_relabel_cred( cred, + newlabel); struct ucred *cred; struct label *newlabel; ---- @@ -3178,7 +3396,12 @@ [[mac-access-control-checks]] === Access Control Checks -Access control entry points permit policy modules to influence access control decisions made by the kernel. Generally, although not always, arguments to an access control entry point will include one or more authorizing credentials, information (possibly including a label) for any other objects involved in the operation. An access control entry point may return 0 to permit the operation, or an man:errno[2] error value. The results of invoking the entry point across various registered policy modules will be composed as follows: if all modules permit the operation to succeed, success will be returned. If one or modules returns a failure, a failure will be returned. If more than one module returns a failure, the errno value to return to the user will be selected using the following precedence, implemented by the `error_select()` function in [.filename]#kern_mac.c#: +Access control entry points permit policy modules to influence access control decisions made by the kernel. +Generally, although not always, arguments to an access control entry point will include one or more authorizing credentials, information (possibly including a label) for any other objects involved in the operation. +An access control entry point may return 0 to permit the operation, or an man:errno[2] error value. +The results of invoking the entry point across various registered policy modules will be composed as follows: if all modules permit the operation to succeed, success will be returned. +If one or modules returns a failure, a failure will be returned. +If more than one module returns a failure, the errno value to return to the user will be selected using the following precedence, implemented by the `error_select()` function in [.filename]#kern_mac.c#: [.informaltable] [cols="1,1", frame="none"] @@ -3200,17 +3423,18 @@ |EPERM |=== -If none of the error values returned by all modules are listed in the precedence chart then an arbitrarily selected value from the set will be returned. In general, the rules provide precedence to errors in the following order: kernel failures, invalid arguments, object not present, access not permitted, other. +If none of the error values returned by all modules are listed in the precedence chart then an arbitrarily selected value from the set will be returned. +In general, the rules provide precedence to errors in the following order: kernel failures, invalid arguments, object not present, access not permitted, other. [[mac-mpo-bpfdesc-check-receive-from-ifnet]] ==== `mpo_check_bpfdesc_receive` [source,c] ---- -int mpo_check_bpfdesc_receive( bpf_d, - bpflabel, - ifnet, - ifnetlabel); +int mpo_check_bpfdesc_receive( bpf_d, + bpflabel, + ifnet, + ifnetlabel); struct bpf_d *bpf_d; struct label *bpflabel; struct ifnet *ifnet; @@ -3241,14 +3465,15 @@ | |=== -Determine whether the MAC framework should permit datagrams from the passed interface to be delivered to the buffers of the passed BPF descriptor. Return (0) for success, or an `errno` value for failure Suggested failure: EACCES for label mismatches, EPERM for lack of privilege. +Determine whether the MAC framework should permit datagrams from the passed interface to be delivered to the buffers of the passed BPF descriptor. +Return (0) for success, or an `errno` value for failure Suggested failure: EACCES for label mismatches, EPERM for lack of privilege. [[mac-mpo-check-kenv-dump]] ==== `mpo_check_kenv_dump` [source,c] ---- -int mpo_check_kenv_dump( cred); +int mpo_check_kenv_dump( cred); struct ucred *cred; ---- @@ -3271,8 +3496,8 @@ [source,c] ---- -int mpo_check_kenv_get( cred, - name); +int mpo_check_kenv_get( cred, + name); struct ucred *cred; char *name; ---- @@ -3300,8 +3525,8 @@ [source,c] ---- -int mpo_check_kenv_set( cred, - name); +int mpo_check_kenv_set( cred, + name); struct ucred *cred; char *name; ---- @@ -3329,8 +3554,8 @@ [source,c] ---- -int mpo_check_kenv_unset( cred, - name); +int mpo_check_kenv_unset( cred, + name); struct ucred *cred; char *name; ---- @@ -3358,9 +3583,9 @@ [source,c] ---- -int mpo_check_kld_load( cred, - vp, - vlabel); +int mpo_check_kld_load( cred, + vp, + vlabel); struct ucred *cred; struct vnode *vp; struct label *vlabel; @@ -3393,7 +3618,7 @@ [source,c] ---- -int mpo_check_kld_stat( cred); +int mpo_check_kld_stat( cred); struct ucred *cred; ---- @@ -3416,7 +3641,7 @@ [source,c] ---- -int mpo_check_kld_unload( cred); +int mpo_check_kld_unload( cred); struct ucred *cred; ---- @@ -3439,11 +3664,11 @@ [source,c] ---- -int mpo_check_pipe_ioctl( cred, - pipe, - pipelabel, - cmd, - data); +int mpo_check_pipe_ioctl( cred, + pipe, + pipelabel, + cmd, + data); struct ucred *cred; struct pipe *pipe; struct label *pipelabel; @@ -3486,9 +3711,9 @@ [source,c] ---- -int mpo_check_pipe_poll( cred, - pipe, - pipelabel); +int mpo_check_pipe_poll( cred, + pipe, + pipelabel); struct ucred *cred; struct pipe *pipe; struct label *pipelabel; @@ -3521,9 +3746,9 @@ [source,c] ---- -int mpo_check_pipe_read( cred, - pipe, - pipelabel); +int mpo_check_pipe_read( cred, + pipe, + pipelabel); struct ucred *cred; struct pipe *pipe; struct label *pipelabel; @@ -3556,10 +3781,10 @@ [source,c] ---- -int mpo_check_pipe_relabel( cred, - pipe, - pipelabel, - newlabel); +int mpo_check_pipe_relabel( cred, + pipe, + pipelabel, + newlabel); struct ucred *cred; struct pipe *pipe; struct label *pipelabel; @@ -3597,9 +3822,9 @@ [source,c] ---- -int mpo_check_pipe_stat( cred, - pipe, - pipelabel); +int mpo_check_pipe_stat( cred, + pipe, + pipelabel); struct ucred *cred; struct pipe *pipe; struct label *pipelabel; @@ -3632,9 +3857,9 @@ [source,c] ---- -int mpo_check_pipe_write( cred, - pipe, - pipelabel); +int mpo_check_pipe_write( cred, + pipe, + pipelabel); struct ucred *cred; struct pipe *pipe; struct label *pipelabel; @@ -3667,10 +3892,10 @@ [source,c] ---- -int mpo_check_socket_bind( cred, - socket, - socketlabel, - sockaddr); +int mpo_check_socket_bind( cred, + socket, + socketlabel, + sockaddr); struct ucred *cred; struct socket *socket; struct label *socketlabel; @@ -3706,10 +3931,10 @@ [source,c] ---- -int mpo_check_socket_connect( cred, - socket, - socketlabel, - sockaddr); +int mpo_check_socket_connect( cred, + socket, + socketlabel, + sockaddr); struct ucred *cred; struct socket *socket; struct label *socketlabel; @@ -3740,16 +3965,18 @@ | |=== -Determine whether the subject credential (`cred`) can connect the passed socket (`socket`) to the passed socket address (`sockaddr`). Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatches, EPERM for lack of privilege. +Determine whether the subject credential (`cred`) can connect the passed socket (`socket`) to the passed socket address (`sockaddr`). +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatches, EPERM for lack of privilege. [[mac-mpo-check-socket-receive]] ==== `mpo_check_socket_receive` [source,c] ---- -int mpo_check_socket_receive( cred, - so, - socketlabel); +int mpo_check_socket_receive( cred, + so, + socketlabel); struct ucred *cred; struct socket *so; struct label *socketlabel; @@ -3782,9 +4009,9 @@ [source,c] ---- -int mpo_check_socket_send( cred, - so, - socketlabel); +int mpo_check_socket_send( cred, + so, + socketlabel); struct ucred *cred; struct socket *so; struct label *socketlabel; @@ -3817,8 +4044,8 @@ [source,c] ---- -int mpo_check_cred_visible( u1, - u2); +int mpo_check_cred_visible( u1, + u2); struct ucred *u1; struct ucred *u2; ---- @@ -3839,16 +4066,19 @@ | |=== -Determine whether the subject credential `u1` can "see" other subjects with the passed subject credential `u2`. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatches, EPERM for lack of privilege, or ESRCH to hide visibility. This call may be made in a number of situations, including inter-process status sysctl's used by `ps`, and in procfs lookups. +Determine whether the subject credential `u1` can "see" other subjects with the passed subject credential `u2`. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatches, EPERM for lack of privilege, or ESRCH to hide visibility. +This call may be made in a number of situations, including inter-process status sysctl's used by `ps`, and in procfs lookups. [[mac-mpo-cred-check-socket-visible]] ==== `mpo_check_socket_visible` [source,c] ---- -int mpo_check_socket_visible( cred, - socket, - socketlabel); +int mpo_check_socket_visible( cred, + socket, + socketlabel); struct ucred *cred; struct socket *socket; struct label *socketlabel; @@ -3879,10 +4109,10 @@ [source,c] ---- -int mpo_check_ifnet_relabel( cred, - ifnet, - ifnetlabel, - newlabel); +int mpo_check_ifnet_relabel( cred, + ifnet, + ifnetlabel, + newlabel); struct ucred *cred; struct ifnet *ifnet; struct label *ifnetlabel; @@ -3920,10 +4150,10 @@ [source,c] ---- -int mpo_check_socket_relabel( cred, - socket, - socketlabel, - newlabel); +int mpo_check_socket_relabel( cred, + socket, + socketlabel, + newlabel); struct ucred *cred; struct socket *socket; struct label *socketlabel; @@ -3961,8 +4191,8 @@ [source,c] ---- -int mpo_check_cred_relabel( cred, - newlabel); +int mpo_check_cred_relabel( cred, + newlabel); struct ucred *cred; struct label *newlabel; ---- @@ -3990,10 +4220,10 @@ [source,c] ---- -int mpo_check_vnode_relabel( cred, - vp, - vnodelabel, - newlabel); +int mpo_check_vnode_relabel( cred, + vp, + vnodelabel, + newlabel); struct ucred *cred; struct vnode *vp; struct label *vnodelabel; @@ -4031,9 +4261,9 @@ [source,c] ---- -int mpo_check_mount_stat( cred, - mp, - mountlabel); +int mpo_check_mount_stat( cred, + mp, + mountlabel); struct ucred *cred; struct mount *mp; struct label *mountlabel; @@ -4059,15 +4289,18 @@ | |=== -Determine whether the subject credential can see the results of a statfs performed on the file system. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatches or EPERM for lack of privilege. This call may be made in a number of situations, including during invocations of man:statfs[2] and related calls, as well as to determine what file systems to exclude from listings of file systems, such as when man:getfsstat[2] is invoked. +Determine whether the subject credential can see the results of a statfs performed on the file system. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatches or EPERM for lack of privilege. +This call may be made in a number of situations, including during invocations of man:statfs[2] and related calls, as well as to determine what file systems to exclude from listings of file systems, such as when man:getfsstat[2] is invoked. [[mac-mpo-cred-check-proc-debug]] ==== `mpo_check_proc_debug` [source,c] ---- -int mpo_check_proc_debug( cred, - proc); +int mpo_check_proc_debug( cred, + proc); struct ucred *cred; struct proc *proc; ---- @@ -4088,17 +4321,20 @@ | |=== -Determine whether the subject credential can debug the passed process. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, EPERM for lack of privilege, or ESRCH to hide visibility of the target. This call may be made in a number of situations, including use of the man:ptrace[2] and man:ktrace[2] APIs, as well as for some types of procfs operations. +Determine whether the subject credential can debug the passed process. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, EPERM for lack of privilege, or ESRCH to hide visibility of the target. +This call may be made in a number of situations, including use of the man:ptrace[2] and man:ktrace[2] APIs, as well as for some types of procfs operations. [[mac-mpo-cred-check-vnode-access]] ==== `mpo_check_vnode_access` [source,c] ---- -int mpo_check_vnode_access( cred, - vp, - label, - flags); +int mpo_check_vnode_access( cred, + vp, + label, + flags); struct ucred *cred; struct vnode *vp; struct label *label; @@ -4129,16 +4365,19 @@ | |=== -Determine how invocations of man:access[2] and related calls by the subject credential should return when performed on the passed vnode using the passed access flags. This should generally be implemented using the same semantics used in `mpo_check_vnode_open`. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatches or EPERM for lack of privilege. +Determine how invocations of man:access[2] and related calls by the subject credential should return when performed on the passed vnode using the passed access flags. +This should generally be implemented using the same semantics used in `mpo_check_vnode_open`. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatches or EPERM for lack of privilege. [[mac-mpo-cred-check-vnode-chdir]] ==== `mpo_check_vnode_chdir` [source,c] ---- -int mpo_check_vnode_chdir( cred, - dvp, - dlabel); +int mpo_check_vnode_chdir( cred, + dvp, + dlabel); struct ucred *cred; struct vnode *dvp; struct label *dlabel; @@ -4164,16 +4403,18 @@ | |=== -Determine whether the subject credential can change the process working directory to the passed vnode. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can change the process working directory to the passed vnode. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-check-vnode-chroot]] ==== `mpo_check_vnode_chroot` [source,c] ---- -int mpo_check_vnode_chroot( cred, - dvp, - dlabel); +int mpo_check_vnode_chroot( cred, + dvp, + dlabel); struct ucred *cred; struct vnode *dvp; struct label *dlabel; @@ -4206,11 +4447,11 @@ [source,c] ---- -int mpo_check_vnode_create( cred, - dvp, - dlabel, - cnp, - vap); +int mpo_check_vnode_create( cred, + dvp, + dlabel, + cnp, + vap); struct ucred *cred; struct vnode *dvp; struct label *dlabel; @@ -4246,19 +4487,22 @@ | |=== -Determine whether the subject credential can create a vnode with the passed parent directory, passed name information, and passed attribute information. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. This call may be made in a number of situations, including as a result of calls to man:open[2] with O_CREAT, man:mkfifo[2], and others. +Determine whether the subject credential can create a vnode with the passed parent directory, passed name information, and passed attribute information. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +This call may be made in a number of situations, including as a result of calls to man:open[2] with O_CREAT, man:mkfifo[2], and others. [[mac-mpo-cred-check-vnode-delete]] ==== `mpo_check_vnode_delete` [source,c] ---- -int mpo_check_vnode_delete( cred, - dvp, - dlabel, - vp, - label, - cnp); +int mpo_check_vnode_delete( cred, + dvp, + dlabel, + vp, + label, + cnp); struct ucred *cred; struct vnode *dvp; struct label *dlabel; @@ -4299,17 +4543,21 @@ | |=== -Determine whether the subject credential can delete a vnode from the passed parent directory and passed name information. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. This call may be made in a number of situations, including as a result of calls to man:unlink[2] and man:rmdir[2]. Policies implementing this entry point should also implement `mpo_check_rename_to` to authorize deletion of objects as a result of being the target of a rename. +Determine whether the subject credential can delete a vnode from the passed parent directory and passed name information. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +This call may be made in a number of situations, including as a result of calls to man:unlink[2] and man:rmdir[2]. +Policies implementing this entry point should also implement `mpo_check_rename_to` to authorize deletion of objects as a result of being the target of a rename. [[mac-mpo-cred-check-vnode-deleteacl]] ==== `mpo_check_vnode_deleteacl` [source,c] ---- -int mpo_check_vnode_deleteacl( cred, - vp, - label, - type); +int mpo_check_vnode_deleteacl( cred, + vp, + label, + type); struct ucred *cred; struct vnode *vp; struct label *label; @@ -4340,16 +4588,18 @@ | |=== -Determine whether the subject credential can delete the ACL of passed type from the passed vnode. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can delete the ACL of passed type from the passed vnode. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-cred-check-vnode-exec]] ==== `mpo_check_vnode_exec` [source,c] ---- -int mpo_check_vnode_exec( cred, - vp, - label); +int mpo_check_vnode_exec( cred, + vp, + label); struct ucred *cred; struct vnode *vp; struct label *label; @@ -4375,17 +4625,20 @@ | |=== -Determine whether the subject credential can execute the passed vnode. Determination of execute privilege is made separately from decisions about any transitioning event. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can execute the passed vnode. +Determination of execute privilege is made separately from decisions about any transitioning event. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mpo-cred-check-vnode-getacl]] ==== `mpo_check_vnode_getacl` [source,c] ---- -int mpo_check_vnode_getacl( cred, - vp, - label, - type); +int mpo_check_vnode_getacl( cred, + vp, + label, + type); struct ucred *cred; struct vnode *vp; struct label *label; @@ -4416,19 +4669,21 @@ | |=== -Determine whether the subject credential can retrieve the ACL of passed type from the passed vnode. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can retrieve the ACL of passed type from the passed vnode. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-cred-check-vnode-getextattr]] ==== `mpo_check_vnode_getextattr` [source,c] ---- -int mpo_check_vnode_getextattr( cred, - vp, - label, - attrnamespace, - name, - uio); +int mpo_check_vnode_getextattr( cred, + vp, + label, + attrnamespace, + name, + uio); struct ucred *cred; struct vnode *vp; struct label *label; @@ -4469,19 +4724,22 @@ | |=== -Determine whether the subject credential can retrieve the extended attribute with the passed namespace and name from the passed vnode. Policies implementing labeling using extended attributes may be interested in special handling of operations on those extended attributes. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can retrieve the extended attribute with the passed namespace and name from the passed vnode. +Policies implementing labeling using extended attributes may be interested in special handling of operations on those extended attributes. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-check-vnode-link]] ==== `mpo_check_vnode_link` [source,c] ---- -int mpo_check_vnode_link( cred, - dvp, - dlabel, - vp, - label, - cnp); +int mpo_check_vnode_link( cred, + dvp, + dlabel, + vp, + label, + cnp); struct ucred *cred; struct vnode *dvp; struct label *dlabel; @@ -4529,10 +4787,10 @@ [source,c] ---- -int mpo_check_vnode_mmap( cred, - vp, - label, - prot); +int mpo_check_vnode_mmap( cred, + vp, + label, + prot); struct ucred *cred; struct vnode *vp; struct label *label; @@ -4570,10 +4828,10 @@ [source,c] ---- -void mpo_check_vnode_mmap_downgrade( cred, - vp, - label, - prot); +void mpo_check_vnode_mmap_downgrade( cred, + vp, + label, + prot); struct ucred *cred; struct vnode *vp; struct label *label; @@ -4611,10 +4869,10 @@ [source,c] ---- -int mpo_check_vnode_mprotect( cred, - vp, - label, - prot); +int mpo_check_vnode_mprotect( cred, + vp, + label, + prot); struct ucred *cred; struct vnode *vp; struct label *label; @@ -4648,10 +4906,10 @@ [source,c] ---- -int mpo_check_vnode_poll( active_cred, - file_cred, - vp, - label); +int mpo_check_vnode_poll( active_cred, + file_cred, + vp, + label); struct ucred *active_cred; struct ucred *file_cred; struct vnode *vp; @@ -4689,12 +4947,12 @@ [source,c] ---- -int mpo_vnode_rename_from( cred, - dvp, - dlabel, - vp, - label, - cnp); +int mpo_vnode_rename_from( cred, + dvp, + dlabel, + vp, + label, + cnp); struct ucred *cred; struct vnode *dvp; struct label *dlabel; @@ -4742,13 +5000,13 @@ [source,c] ---- -int mpo_check_vnode_rename_to( cred, - dvp, - dlabel, - vp, - label, - samedir, - cnp); +int mpo_check_vnode_rename_to( cred, + dvp, + dlabel, + vp, + label, + samedir, + cnp); struct ucred *cred; struct vnode *dvp; struct label *dlabel; @@ -4794,16 +5052,17 @@ | |=== -Determine whether the subject should be allowed to rename to the vnode `vp`, into the directory `dvp`, or to the name represented by `cnp`. If there is no existing file to overwrite, `vp` and `label` will be NULL. +Determine whether the subject should be allowed to rename to the vnode `vp`, into the directory `dvp`, or to the name represented by `cnp`. +If there is no existing file to overwrite, `vp` and `label` will be NULL. [[mac-mpo-cred-check-socket-listen]] ==== `mpo_check_socket_listen` [source,c] ---- -int mpo_check_socket_listen( cred, - socket, - socketlabel); +int mpo_check_socket_listen( cred, + socket, + socketlabel); struct ucred *cred; struct socket *socket; struct label *socketlabel; @@ -4829,17 +5088,19 @@ | |=== -Determine whether the subject credential can listen on the passed socket. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can listen on the passed socket. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-cred-check-vnode-lookup]] ==== `mpo_check_vnode_lookup` [source,c] ---- -int mpo_check_vnode_lookup( , - , - , - cnp); +int mpo_check_vnode_lookup( , + , + , + cnp); struct ucred *cred; struct vnode *dvp; struct label *dlabel; @@ -4870,17 +5131,19 @@ | |=== -Determine whether the subject credential can perform a lookup in the passed directory vnode for the passed name. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can perform a lookup in the passed directory vnode for the passed name. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-cred-check-vnode-open]] ==== `mpo_check_vnode_open` [source,c] ---- -int mpo_check_vnode_open( cred, - vp, - label, - acc_mode); +int mpo_check_vnode_open( cred, + vp, + label, + acc_mode); struct ucred *cred; struct vnode *vp; struct label *label; @@ -4911,16 +5174,18 @@ | |=== -Determine whether the subject credential can perform an open operation on the passed vnode with the passed access mode. Return 0 for success, or an errno value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can perform an open operation on the passed vnode with the passed access mode. +Return 0 for success, or an errno value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-cred-check-vnode-readdir]] ==== `mpo_check_vnode_readdir` [source,c] ---- -int mpo_check_vnode_readdir( , - , - ); +int mpo_check_vnode_readdir( , + , + ); struct ucred *cred; struct vnode *dvp; struct label *dlabel; @@ -4946,16 +5211,18 @@ | |=== -Determine whether the subject credential can perform a `readdir` operation on the passed directory vnode. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can perform a `readdir` operation on the passed directory vnode. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-cred-check-vnode-readlink]] ==== `mpo_check_vnode_readlink` [source,c] ---- -int mpo_check_vnode_readlink( cred, - vp, - label); +int mpo_check_vnode_readlink( cred, + vp, + label); struct ucred *cred; struct vnode *vp; struct label *label; @@ -4981,16 +5248,19 @@ | |=== -Determine whether the subject credential can perform a `readlink` operation on the passed symlink vnode. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. This call may be made in a number of situations, including an explicit `readlink` call by the user process, or as a result of an implicit `readlink` during a name lookup by the process. +Determine whether the subject credential can perform a `readlink` operation on the passed symlink vnode. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +This call may be made in a number of situations, including an explicit `readlink` call by the user process, or as a result of an implicit `readlink` during a name lookup by the process. [[mac-mpo-cred-check-vnode-revoke]] ==== `mpo_check_vnode_revoke` [source,c] ---- -int mpo_check_vnode_revoke( cred, - vp, - label); +int mpo_check_vnode_revoke( cred, + vp, + label); struct ucred *cred; struct vnode *vp; struct label *label; @@ -5016,18 +5286,20 @@ | |=== -Determine whether the subject credential can revoke access to the passed vnode. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can revoke access to the passed vnode. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-cred-check-vnode-setacl]] ==== `mpo_check_vnode_setacl` [source,c] ---- -int mpo_check_vnode_setacl( cred, - vp, - label, - type, - acl); +int mpo_check_vnode_setacl( cred, + vp, + label, + type, + acl); struct ucred *cred; struct vnode *vp; struct label *label; @@ -5063,19 +5335,21 @@ | |=== -Determine whether the subject credential can set the passed ACL of passed type on the passed vnode. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can set the passed ACL of passed type on the passed vnode. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-cred-check-vnode-setextattr]] ==== `mpo_check_vnode_setextattr` [source,c] ---- -int mpo_check_vnode_setextattr( cred, - vp, - label, - attrnamespace, - name, - uio); +int mpo_check_vnode_setextattr( cred, + vp, + label, + attrnamespace, + name, + uio); struct ucred *cred; struct vnode *vp; struct label *label; @@ -5116,17 +5390,22 @@ | |=== -Determine whether the subject credential can set the extended attribute of passed name and passed namespace on the passed vnode. Policies implementing security labels backed into extended attributes may want to provide additional protections for those attributes. Additionally, policies should avoid making decisions based on the data referenced from `uio`, as there is a potential race condition between this check and the actual operation. The `uio` may also be `NULL` if a delete operation is being performed. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can set the extended attribute of passed name and passed namespace on the passed vnode. +Policies implementing security labels backed into extended attributes may want to provide additional protections for those attributes. +Additionally, policies should avoid making decisions based on the data referenced from `uio`, as there is a potential race condition between this check and the actual operation. +The `uio` may also be `NULL` if a delete operation is being performed. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-cred-check-vnode-setflags]] ==== `mpo_check_vnode_setflags` [source,c] ---- -int mpo_check_vnode_setflags( cred, - vp, - label, - flags); +int mpo_check_vnode_setflags( cred, + vp, + label, + flags); struct ucred *cred; struct vnode *vp; struct label *label; @@ -5157,17 +5436,19 @@ | |=== -Determine whether the subject credential can set the passed flags on the passed vnode. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can set the passed flags on the passed vnode. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-cred-check-vnode-setmode]] ==== `mpo_check_vnode_setmode` [source,c] ---- -int mpo_check_vnode_setmode( cred, - vp, - label, - mode); +int mpo_check_vnode_setmode( cred, + vp, + label, + mode); struct ucred *cred; struct vnode *vp; struct label *label; @@ -5198,18 +5479,20 @@ | |=== -Determine whether the subject credential can set the passed mode on the passed vnode. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can set the passed mode on the passed vnode. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-cred-check-vnode-setowner]] ==== `mpo_check_vnode_setowner` [source,c] ---- -int mpo_check_vnode_setowner( cred, - vp, - label, - uid, - gid); +int mpo_check_vnode_setowner( cred, + vp, + label, + uid, + gid); struct ucred *cred; struct vnode *vp; struct label *label; @@ -5245,18 +5528,21 @@ | |=== -Determine whether the subject credential can set the passed uid and passed gid as file uid and file gid on the passed vnode. The IDs may be set to (`-1`) to request no update. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can set the passed uid and passed gid as file uid and file gid on the passed vnode. +The IDs may be set to (`-1`) to request no update. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-cred-check-vnode-setutimes]] ==== `mpo_check_vnode_setutimes` [source,c] ---- -int mpo_check_vnode_setutimes( , - , - , - , - ); +int mpo_check_vnode_setutimes( , + , + , + , + ); struct ucred *cred; struct vnode *vp; struct label *label; @@ -5292,15 +5578,17 @@ | |=== -Determine whether the subject credential can set the passed access timestamps on the passed vnode. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can set the passed access timestamps on the passed vnode. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-cred-check-proc-sched]] ==== `mpo_check_proc_sched` [source,c] ---- -int mpo_check_proc_sched( ucred, - proc); +int mpo_check_proc_sched( ucred, + proc); struct ucred *ucred; struct proc *proc; ---- @@ -5321,7 +5609,9 @@ | |=== -Determine whether the subject credential can change the scheduling parameters of the passed process. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, EPERM for lack of privilege, or ESRCH to limit visibility. +Determine whether the subject credential can change the scheduling parameters of the passed process. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, EPERM for lack of privilege, or ESRCH to limit visibility. See man:setpriority[2] for more information. @@ -5330,9 +5620,9 @@ [source,c] ---- -int mpo_check_proc_signal( cred, - proc, - signal); +int mpo_check_proc_signal( cred, + proc, + signal); struct ucred *cred; struct proc *proc; int signal; @@ -5358,16 +5648,18 @@ | |=== -Determine whether the subject credential can deliver the passed signal to the passed process. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, EPERM for lack of privilege, or ESRCH to limit visibility. +Determine whether the subject credential can deliver the passed signal to the passed process. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, EPERM for lack of privilege, or ESRCH to limit visibility. [[mac-mpo-cred-check-vnode-stat]] ==== `mpo_check_vnode_stat` [source,c] ---- -int mpo_check_vnode_stat( cred, - vp, - label); +int mpo_check_vnode_stat( cred, + vp, + label); struct ucred *cred; struct vnode *vp; struct label *label; @@ -5393,7 +5685,9 @@ | |=== -Determine whether the subject credential can `stat` the passed vnode. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the subject credential can `stat` the passed vnode. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. See man:stat[2] for more information. @@ -5402,11 +5696,11 @@ [source,c] ---- -int mpo_check_ifnet_transmit( cred, - ifnet, - ifnetlabel, - mbuf, - mbuflabel); +int mpo_check_ifnet_transmit( cred, + ifnet, + ifnetlabel, + mbuf, + mbuflabel); struct ucred *cred; struct ifnet *ifnet; struct label *ifnetlabel; @@ -5442,18 +5736,20 @@ | |=== -Determine whether the network interface can transmit the passed mbuf. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the network interface can transmit the passed mbuf. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-cred-check-socket-deliver]] ==== `mpo_check_socket_deliver` [source,c] ---- -int mpo_check_socket_deliver( cred, - ifnet, - ifnetlabel, - mbuf, - mbuflabel); +int mpo_check_socket_deliver( cred, + ifnet, + ifnetlabel, + mbuf, + mbuflabel); struct ucred *cred; struct ifnet *ifnet; struct label *ifnetlabel; @@ -5489,16 +5785,18 @@ | |=== -Determine whether the socket may receive the datagram stored in the passed mbuf header. Return 0 for success, or an `errno` value for failure. Suggested failures: EACCES for label mismatch, or EPERM for lack of privilege. +Determine whether the socket may receive the datagram stored in the passed mbuf header. +Return 0 for success, or an `errno` value for failure. +Suggested failures: EACCES for label mismatch, or EPERM for lack of privilege. [[mac-mpo-check-socket-visible]] ==== `mpo_check_socket_visible` [source,c] ---- -int mpo_check_socket_visible( cred, - so, - socketlabel); +int mpo_check_socket_visible( cred, + so, + socketlabel); struct ucred *cred; struct socket *so; struct label *socketlabel; @@ -5524,16 +5822,18 @@ | |=== -Determine whether the subject credential cred can "see" the passed socket (`socket`) using system monitoring functions, such as those employed by man:netstat[8] and man:sockstat[1]. Return 0 for success, or an `errno` value for failure. Suggested failure: EACCES for label mismatches, EPERM for lack of privilege, or ESRCH to hide visibility. +Determine whether the subject credential cred can "see" the passed socket (`socket`) using system monitoring functions, such as those employed by man:netstat[8] and man:sockstat[1]. +Return 0 for success, or an `errno` value for failure. +Suggested failure: EACCES for label mismatches, EPERM for lack of privilege, or ESRCH to hide visibility. [[mac-mpo-check-system-acct]] ==== `mpo_check_system_acct` [source,c] ---- -int mpo_check_system_acct( ucred, - vp, - vlabel); +int mpo_check_system_acct( ucred, + vp, + vlabel); struct ucred *ucred; struct vnode *vp; struct label *vlabel; @@ -5566,7 +5866,7 @@ [source,c] ---- -int mpo_check_system_nfsd( cred); +int mpo_check_system_nfsd( cred); struct ucred *cred; ---- @@ -5589,8 +5889,8 @@ [source,c] ---- -int mpo_check_system_reboot( cred, - howto); +int mpo_check_system_reboot( cred, + howto); struct ucred *cred; int howto; ---- @@ -5618,7 +5918,7 @@ [source,c] ---- -int mpo_check_system_settime( cred); +int mpo_check_system_settime( cred); struct ucred *cred; ---- @@ -5641,9 +5941,9 @@ [source,c] ---- -int mpo_check_system_swapon( cred, - vp, - vlabel); +int mpo_check_system_swapon( cred, + vp, + vlabel); struct ucred *cred; struct vnode *vp; struct label *vlabel; @@ -5676,14 +5976,14 @@ [source,c] ---- -int mpo_check_system_sysctl( cred, - name, - namelen, - old, - oldlenp, - inkernel, - new, - newlen); +int mpo_check_system_sysctl( cred, + name, + namelen, + old, + oldlenp, + inkernel, + new, + newlen); struct ucred *cred; int *name; u_int *namelen; @@ -5739,36 +6039,56 @@ [[mac-label-management]] === Label Management Calls -Relabel events occur when a user process has requested that the label on an object be modified. A two-phase update occurs: first, an access control check will be performed to determine if the update is both valid and permitted, and then the update itself is performed via a separate entry point. Relabel entry points typically accept the object, object label reference, and an update label submitted by the process. Memory allocation during relabel is discouraged, as relabel calls are not permitted to fail (failure should be reported earlier in the relabel check). +Relabel events occur when a user process has requested that the label on an object be modified. +A two-phase update occurs: first, an access control check will be performed to determine if the update is both valid and permitted, and then the update itself is performed via a separate entry point. +Relabel entry points typically accept the object, object label reference, and an update label submitted by the process. +Memory allocation during relabel is discouraged, as relabel calls are not permitted to fail (failure should be reported earlier in the relabel check). [[mac-userland-arch]] == Userland Architecture -The TrustedBSD MAC Framework includes a number of policy-agnostic elements, including MAC library interfaces for abstractly managing labels, modifications to the system credential management and login libraries to support the assignment of MAC labels to users, and a set of tools to monitor and modify labels on processes, files, and network interfaces. More details on the user architecture will be added to this section in the near future. +The TrustedBSD MAC Framework includes a number of policy-agnostic elements, including MAC library interfaces for abstractly managing labels, modifications to the system credential management and login libraries to support the assignment of MAC labels to users, and a set of tools to monitor and modify labels on processes, files, and network interfaces. +More details on the user architecture will be added to this section in the near future. [[mac-userland-labels]] === APIs for Policy-Agnostic Label Management -The TrustedBSD MAC Framework provides a number of library and system calls permitting applications to manage MAC labels on objects using a policy-agnostic interface. This permits applications to manipulate labels for a variety of policies without being written to support specific policies. These interfaces are used by general-purpose tools such as man:ifconfig[8], man:ls[1] and man:ps[1] to view labels on network interfaces, files, and processes. The APIs also support MAC management tools including man:getfmac[8], man:getpmac[8], man:setfmac[8], man:setfsmac[8], and man:setpmac[8]. The MAC APIs are documented in man:mac[3]. +The TrustedBSD MAC Framework provides a number of library and system calls permitting applications to manage MAC labels on objects using a policy-agnostic interface. +This permits applications to manipulate labels for a variety of policies without being written to support specific policies. +These interfaces are used by general-purpose tools such as man:ifconfig[8], man:ls[1] and man:ps[1] to view labels on network interfaces, files, and processes. +The APIs also support MAC management tools including man:getfmac[8], man:getpmac[8], man:setfmac[8], man:setfsmac[8], and man:setpmac[8]. +The MAC APIs are documented in man:mac[3]. -Applications handle MAC labels in two forms: an internalized form used to return and set labels on processes and objects (`mac_t`), and externalized form based on C strings appropriate for storage in configuration files, display to the user, or input from the user. Each MAC label contains a number of elements, each consisting of a name and value pair. Policy modules in the kernel bind to specific names and interpret the values in policy-specific ways. In the externalized string form, labels are represented by a comma-delimited list of name and value pairs separated by the `/` character. Labels may be directly converted to and from text using provided APIs; when retrieving labels from the kernel, internalized label storage must first be prepared for the desired label element set. Typically, this is done in one of two ways: using man:mac_prepare[3] and an arbitrary list of desired label elements, or one of the variants of the call that loads a default element set from the man:mac.conf[5] configuration file. Per-object defaults permit application writers to usefully display labels associated with objects without being aware of the policies present in the system. +Applications handle MAC labels in two forms: an internalized form used to return and set labels on processes and objects (`mac_t`), and externalized form based on C strings appropriate for storage in configuration files, display to the user, or input from the user. +Each MAC label contains a number of elements, each consisting of a name and value pair. +Policy modules in the kernel bind to specific names and interpret the values in policy-specific ways. +In the externalized string form, labels are represented by a comma-delimited list of name and value pairs separated by the `/` character. +Labels may be directly converted to and from text using provided APIs; when retrieving labels from the kernel, internalized label storage must first be prepared for the desired label element set. +Typically, this is done in one of two ways: using man:mac_prepare[3] and an arbitrary list of desired label elements, or one of the variants of the call that loads a default element set from the man:mac.conf[5] configuration file. +Per-object defaults permit application writers to usefully display labels associated with objects without being aware of the policies present in the system. [NOTE] ==== -Currently, direct manipulation of label elements other than by conversion to a text string, string editing, and conversion back to an internalized label is not supported by the MAC library. Such interfaces may be added in the future if they prove necessary for application writers. +Currently, direct manipulation of label elements other than by conversion to a text string, string editing, and conversion back to an internalized label is not supported by the MAC library. +Such interfaces may be added in the future if they prove necessary for application writers. ==== [[mac-userland-credentials]] === Binding of Labels to Users -The standard user context management interface, man:setusercontext[3], has been modified to retrieve MAC labels associated with a user's class from man:login.conf[5]. These labels are then set along with other user context when either `LOGIN_SETALL` is specified, or when `LOGIN_SETMAC` is explicitly specified. +The standard user context management interface, man:setusercontext[3], has been modified to retrieve MAC labels associated with a user's class from man:login.conf[5]. +These labels are then set along with other user context when either `LOGIN_SETALL` is specified, or when `LOGIN_SETMAC` is explicitly specified. [NOTE] ==== -It is expected that, in a future version of FreeBSD, the MAC label database will be separated from the [.filename]#login.conf# user class abstraction, and be maintained in a separate database. However, the man:setusercontext[3] API should remain the same following such a change. +It is expected that, in a future version of FreeBSD, the MAC label database will be separated from the [.filename]#login.conf# user class abstraction, and be maintained in a separate database. +However, the man:setusercontext[3] API should remain the same following such a change. ==== [[mac-conclusion]] == Conclusion -The TrustedBSD MAC framework permits kernel modules to augment the system security policy in a highly integrated manner. They may do this based on existing object properties, or based on label data that is maintained with the assistance of the MAC framework. The framework is sufficiently flexible to implement a variety of policy types, including information flow security policies such as MLS and Biba, as well as policies based on existing BSD credentials or file protections. Policy authors may wish to consult this documentation as well as existing security modules when implementing a new security service. +The TrustedBSD MAC framework permits kernel modules to augment the system security policy in a highly integrated manner. +They may do this based on existing object properties, or based on label data that is maintained with the assistance of the MAC framework. +The framework is sufficiently flexible to implement a variety of policy types, including information flow security policies such as MLS and Biba, as well as policies based on existing BSD credentials or file protections. +Policy authors may wish to consult this documentation as well as existing security modules when implementing a new security service.