Skip to contentSkip to conversation

Implement Trusted Security Event Modeling.

PATCH In review Greg Wettstein 3 participants 41 messages Aug 26, 2024 – Mar 3, 2025 Page 1 of 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover Implement Trusted Security Event Modeling.

Good morning, I hope this note finds the week starting well for everyone.

This is the fourth release of Trusted Security Event Modeling (TSEM) as a new Linux Security Module (LSM) architecture.

TSEM provides kernel infrastructure that allows the implementation of arbitrary model based mandatory access controls. TSEM is model agnostic and provides infrastructure for implementing deterministic, quasi-deterministic, probabilistic or machine learning (AI) based security models.

TSEM also provides a framework for generic security monitoring that can be used to implement Endpoint Detection and Response (EDR) systems without the need to write kernel code, implement kernel modules or attach BPF programs.

The only privileges needed for an EDR system based on TSEM is the ability to open the pseudo-file that exports security event descriptions for a security modeling namespace. This provides a framework for Linux to avoid the possibility of experiencing a 'CrowdStrike Calamity'.

TSEM operates under the premise, that operating system security, like all other physical phenomena in science and engineering, can be mathematically modeled. TSEM notionally treats the LSM security event handlers as a basis set of parameters that can be used to generate a functional value for the security state of a system or a confined workload.

TSEM uses generative functions, rather than static labels, to create the positive accession elements of a multi-dimensional access vector matrix. In doing so, it provides for the highly precise attestation of the trust status of a platform or workload. In the case of a security violation, it also provides very precise forensic characterizations of the security event.

TSEM's task identity model enables very precise detection and characterization of adversarial strategies such as Living Off The Land (LOTL).

TSEM is designed to support the concept of a Trust Orchestration System (TOS). Trust orchestration involves the process of modeling the security behavior of a workload, or a platform at large, and defining whether or not a process is to be trusted, based on whether or not the security events produced by it are consistent with a security behavior that the workload or platform has been unit tested to.

TSEM, in and of itself, does not implement a security policy or model. That capability is invested in an entity known as a Trusted Modeling Agent (TMA). A TMA can be implemented in the kernel itself or the security event descriptions can be exported to userspace for processing in a non-kernel based TMA.

To support this architecture, TSEM implements entirely within the context of the LSM architecture, the concept of security modeling namespaces that are similar in concept to other resource namespaces. A security modeling namespace is paired with a TMA that implements the root of trust for a namespace.

A TMA implementation uses the characteristics of the calling process and the descriptive parameters of a security event to drive generative functions that compute security state coefficients for each security event. The sum of these coefficients, represents the security 'state' of a model.

TSEM supports any number of security modeling namespaces that act independently of one another and of the root security modeling namespace. Each namespace can be configured with its own unique security model definition that can be modeled internally or externally. Alternately, the security modeling namespace can asynchronously export all of the security events for external review and analysis.

Security models to be enforced by a trust orchestrator in a security modeling namespace are developed by unit testing of a workload. This approach increases model precision and thus decreases the risk of the mandatory controls breaking applications or expected system behavior.

TSEM thus represents a security architecture that is designed to be paired with modern software development strategies that embrace resource containerization and Continuous Integration and Continuous Delivery principles. The objective of TSEM, along with the Quixote TOS implementation, is to bring to Linux security architectures what Docker brought to Linux resource namespaces.

TSEM implements support for modifying the processing of security events through the use of loadable modules on systems that have loadable module support enabled. Each security modeling namespace can select either the default event processing model or any of the event models that have been loaded at the time of namespace creation.

The userspace utilities include an example of a small loadable module that allows a security modeling namespace to implement functionality equivalent to the Linux Integrity Measurement Architecture (IMA).

Included with the implementation is an extensive documentation file that can be found in the following location in the kernel sources after application of the patch series.

Documentation/admin-guide/LSM/tsem.rst

TSEM formats security event descriptions into JSON encoded messages that can be consumed and analyzed by any JSON consuming data visualization, analysis, modeling or ingress system.

The following documentation file documents the control plane interface for TSEM including the JSON encoding format:

Documentation/ABI/testing/tsem

Reviewers, and others who are interested, are referred to these documents for a more extensive discussion into the rationale, design and implementation of the TSEM architecture.

Control of TSEM is surfaced entirely via the securityfs filesystem through the following directory hierarchy:

/sys/kernel/security/tsem

TSEM is designed to be self-contained and independent of the kernel at large and with other LSM's with which it stacks. Since the security guarantee resides in an externally created security model definition, it operates without the need for filesystem labeling or cryptographic integrity protection of filesystem metadata.

The Quixote userspace utilities that are needed to create, manage, interrogate and model security modeling namespaces are available at the following project site:

https://github.com/Quixote-Project

Included in the userspace tools are implementations of trust orchestrator's and TMA's for the following trust roots:

Kernel.

Userspace process.

SGX enclave.

Xen hypervisor stub-domain.

Hardware based security coprocessors.

An export only utility is also available that will read asynchronously exported security event descriptions. The export utility includes support for MQTT based broker connections that allow either on-premise or cloud based EDR systems to be implemented.

As always,
Dr. Greg

The Quixote Project - Flailing at the Travails of Cybersecurity

V1:
- Initial release.

V2:
- V1: https://lore.kernel.org/linux-security-module/[email protected]/T/#t
- Allow compile time configuration of the Platform Configuration
Register used to extend security coefficients in the root
security modeling namespace.
- Allow both internal and external modeling of security events
that are called in atomic context.
- Use JSON to encode security event characteristics.
- Use securityfs for TSEM control plane rooted at
/sys/kernel/security/tsem.
- Use framework of separate directories for internal TMA's to
protect ABI compatability.
- Use key=value arguments for control plane commands.
- Allow cryptographic hash function used for coefficient
generation to be configured on a namespace by namespace basis.
- Allow selection of initial or current user namespace as the
reference for UID/GID resolution to be configured on a namespace
by namespace basis.
- Allow the size of modeling and export structures to be configured
on a namespace by namespace basis.
- Extensively document all globally visible enumerations and structures.
- Use CAP_ML rather than CAP_TRUST for modeling capability bit.
- Implement orchestrator<->process mutual authentication.
- Implement occupancy counts for security state coefficients.
- Move TSEM to the first LSM in the LSM list.

V3:
- V2: https://lore.kernel.org/linux-security-module/[email protected]/T/#t
- Require CAP_MAC_ADMIN capability for namespace creation and management.
- Implement full modeling for all TSEM captured LSM events.
- Implement export only namespaces.
- Support export only root security modeling namespaces.
- Support invariant models for namespaces that create files.
- Model all filesystem types.
- Include device types in path descriptions.
- Use bprm_committed_creds for TASK_ID generation.
- Implemented modeling for capget, capset and capable LSM calls.
- Use static keys to optimize control paths.
- Standardize all event handlers to use common format.
- Level tmpfs based filesystems to a common UUID.
- Implement security event timestamps.
- Implement parent event tracking.
- Update TASK_ID generative function to use parent TASK_ID.
- Multiple style and bug fixes.
- Update TSEM documentation including per file functional descriptions.
- Document JSON security event encoding.

V4:
- V3: https://lore.kernel.org/linux-security-module/[email protected]/T/#m1cc4ad76677d07517220f1fadc2303c36a75bab0
- Convert tsem_mode command-line parameter to string arguments.
- Add namespace identity and event sequence numbers to event description.
- Implement selectable event bypass.
- Implement loadable security event processing modules.
- Bug fixes and code corrections and improvements.

Dr. Greg (14):
Update MAINTAINERS file.
Add TSEM specific documentation.
TSEM global declarations.
Add primary TSEM implementation file.
Add root domain trust implementation. Implement TSEM control plane.
Add namespace implementation.
Add security event description export facility. Add event processing implementation. Implement security event mapping.
Implement the internal Trusted Modeling Agent. Implement configuration and methods for default model. Implement infrastructure for loadable security models. Activate the configuration and build of the TSEM LSM.

 Documentation/ABI/testing/tsem                | 2420 ++++++++++++++++
 Documentation/admin-guide/LSM/index.rst       |    1 +
 Documentation/admin-guide/LSM/tsem.rst        | 1680 +++++++++++
 .../admin-guide/kernel-parameters.txt         |   29 +
 MAINTAINERS                                   |    8 +
 include/uapi/linux/lsm.h                      |    1 +
 security/Kconfig                              |   11 +-
 security/Makefile                             |    1 +
 security/security.c                           |    3 +-
 security/tsem/Kconfig                         |   36 +
 security/tsem/Makefile                        |    6 +
 security/tsem/event.c                         | 1846 +++++++++++++
 security/tsem/export.c                        |  429 +++
 security/tsem/fs.c                            | 2304 ++++++++++++++++
 security/tsem/map.c                           | 1536 +++++++++++
 security/tsem/model.c                         |  758 +++++
 security/tsem/model0.c                        |   21 +
 security/tsem/namespace.c                     |  530 ++++
 security/tsem/nsmgr.c                         |  255 ++
 security/tsem/nsmgr.h                         |   48 +
 security/tsem/trust.c                         |  261 ++
 security/tsem/tsem.c                          | 2446 +++++++++++++++++
 security/tsem/tsem.h                          | 2336 ++++++++++++++++
 23 files changed, 16960 insertions(+), 6 deletions(-)
 create mode 100644 Documentation/ABI/testing/tsem
 create mode 100644 Documentation/admin-guide/LSM/tsem.rst
 create mode 100644 security/tsem/Kconfig
 create mode 100644 security/tsem/Makefile
 create mode 100644 security/tsem/event.c
 create mode 100644 security/tsem/export.c
 create mode 100644 security/tsem/fs.c
 create mode 100644 security/tsem/map.c
 create mode 100644 security/tsem/model.c
 create mode 100644 security/tsem/model0.c
 create mode 100644 security/tsem/namespace.c
 create mode 100644 security/tsem/nsmgr.c
 create mode 100644 security/tsem/nsmgr.h
 create mode 100644 security/tsem/trust.c
 create mode 100644 security/tsem/tsem.c
 create mode 100644 security/tsem/tsem.h
Signature · 1 line
2.39.1
#1 lore raw

PATCH v4 1/14 Update MAINTAINERS file.

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 958e935449e5..f4a5772ea255 100644
@@ -22824,6 +22824,14 @@ S:	Maintained
 F:	Documentation/tee/ts-tee.rst
 F:	drivers/tee/tstee/
 
+TSEM SECURITY MODULE
+M:	Greg Wettstein <[email protected]>
+S:	Maintained
+L:	[email protected]
+F:	Documentation/admin-guide/LSM/tsem.rst
+F:	Documentation/ABI/testing/tsem
+F:	security/tsem/
+
 TTY LAYER AND SERIAL DRIVERS
 M:	Greg Kroah-Hartman <[email protected]>
 M:	Jiri Slaby <[email protected]>
Signature · 1 line
2.39.1
#2 lore raw

PATCH v4 2/14 Add TSEM specific documentation.

In reply to Greg Wettstein

An entry was added to the ABI testing documentation to document the API definitions for the TSEM ontrol plane.

The file documenting the kernel command-line parameters was updated to document the TSEM specific parameters that are implemented.

The primary TSEM documentation file was added to the LSM administration guide and the file was linked to the index of LSM documentation.

---
 Documentation/ABI/testing/tsem                | 2420 +++++++++++++++++
 Documentation/admin-guide/LSM/index.rst       |    1 +
 Documentation/admin-guide/LSM/tsem.rst        | 1680 ++++++++++++
 .../admin-guide/kernel-parameters.txt         |   29 +
 4 files changed, 4130 insertions(+)
 create mode 100644 Documentation/ABI/testing/tsem
 create mode 100644 Documentation/admin-guide/LSM/tsem.rst
Documentation/ABI/testing/tsem new file +2420 -0
new file mode 100644
index 000000000000..0e0e3201edf4
@@ -0,0 +1,2420 @@
+This file contains descriptions of output generated by the TSEM
+control plane files and the role of the only write-only file in the
+control plane.
+
+It is highly recommended that the following document be read in order
+to fully understand the rationale and functioning of these files:
+
+Documentation/admin-guide/LSM/tsem.rst
+
+What:		/sys/kernel/security/tsem
+Date:		March 2024
+Contact:	Greg Wettstein <[email protected]>
+Description:
+		The /sys/kernel/security/tsem directory contains files
+		and directories that implement the control plane for
+		the Trusted Security Event Modeling (TSEM) LSM.
+
+		The files in this directory hierarchy, with the
+		exception of the aggregate file, when read, reflect
+		the values for the security modeling namespace that
+		the process reading the files is operating in.
+
+What:		/sys/kernel/security/tsem/id
+Date:		March 2024
+Contact:	Greg Wettstein <[email protected]>
+Description:
+		The id file outputs the ASCII base 10 representation
+		of the security modeling namespace that the reading
+		process is operating in.
+
+		The root security modeling namespace has a value of
+		zero, a non-zero value indicates a modeling namespace
+		subordinate to the root model.
+
+		Each externally modeled security namespace will have a
+		file, with this id number, created in the
+		/sys/kernel/security/tsem/external_tma that is
+		documented below.
+
+What:		/sys/kernel/security/tsem/aggregate
+Date:		March 2024
+Contact:	Greg Wettstein <[email protected]>
+Description:	
+		The aggregate file contains the ASCII base 16
+		representation of the Trusted Platform Module (TPM)
+		based hardware aggregate measurement.  The hardware
+		aggregate measurement is the linear extension sum,
+		using the digest function chosen for the root modeling
+		namespace, of PCR registers 0 through 8
+
+		The hardware aggregate measurement is a common concept
+		in trusted systems and is used to verify the integrity
+		and known good state of the hardware environment
+		leading up to the boot of the operating system.
+
+		The size of the measurement is equal in length to the
+		ASCII Base16 representation of the cryptographic
+		digest function being used for the root security
+		modeling namespace.  For example, if the default
+		sha256 digest function is being used, the aggregate
+		measurement will be 64 ASCII hexadecimal characters.
+
+		On a platform without a TPM this value will be all
+		ASCII 0 values.
+
+What:		/sys/kernel/security/tsem/control
+Date:		March 2024
+Contact:	Greg Wettstein <[email protected]>
+Description:
+		The control file is the only writable file in the
+		filesystem and is used by trust orchestrator's to
+		configure and control the behavior of the TSEM
+		implementation.
+
+		The following keyword and arguments are recognized:
+
+		internal
+			The internal keyword causes an internally
+			modeled namespace to be created for the
+			calling process.
+
+		external
+			The external keyword causes an externally
+			modeled namespace to be created for the
+			calling process.
+
+		A modeling namespace created by either of these
+		directives accepts the following key=value pairs that
+		configure the namespace:
+
+
+		model=MODULE_NAME
+			The model key specifies the name of a security
+			model that is to be used to conduct the event
+			processing for a security modeling namespace.
+
+			If the standard build practice of using the
+			KBUILD_MODNAME CPP define to set the name of
+			the security model the model name will match
+			the name of the module, as displayed by the
+			lsmod command.  There is no requirement that
+			the security model name match the module name.
+
+		nsref=initial|current
+			The nsref key specifies the namespace that is
+			to be referenced when determining the UID/GID
+			values used to characterize a COE or CELL
+			mapping.
+
+			The initial keyword specifies that the initial
+			user namespace is to be used.  The current
+			keyword specifies that the user namespace of
+			the process that is invoking a security event
+			handler is used.
+
+			The default is to use the initial user
+			namespace.
+
+		digest=digestname
+			The digest key value is used to specify the
+			cryptographic hash function that is to be used
+			for the generation of the security state
+			coefficients for the LSM events being modeled.
+
+			The digestname value is the name used by the
+			Linux kernel cryptographic API to identify the
+			hash function.  Examples would include;
+			sha256, sha3-256, sm3 etc.  The source files
+			for the various cryptographic hash functions in
+			the crypto directory of the kernel source has
+			the names for hash functions implemented in
+			the kernel.
+
+			The sha256 hash function is the default
+			function for the root modeling namespace.
+			This can be modified by the tsem_digest
+			command-line parameter.
+
+			A hash function, used by the root modeling
+			namespace, must be built into the kernel.
+
+		cache=NN
+			The cache key specifies the size of the caches
+			to be used for holding pointers to structures
+			used for the modeling or export of security
+			events that are called while the invoking
+			process is in atomic context.
+
+			The value NN is the ASCII base 10
+			representation of the number of entries in the
+			cache.
+
+			By default, the root modeling namespace and an
+			externally modeled namespace will have 96
+			entries.  An internally modeled namespace will
+			have 16 entries.
+
+		key=HEXID
+			The key argument is used to specify the
+			authentication key that will be used by a
+			trust orchestrator to authenticate trust
+			control requests to a process running in the
+			security modeling namespace.
+
+			The HEXID value is the ASCII base16 encoded
+			representation of the key that is to be used.
+			The length of this key, in binary, must be
+			equal to the size of the digest produced by
+			the cryptographic hash function that is being
+			used in the security modeling namespace.
+
+		enforce
+			The enforce keyword causes the modeling
+			namespace of the process to enter enforcing
+			mode.  In this mode, a value of -EPERM will be
+			returned for a security event coefficient that
+			does not map into the current set of allowed
+			coefficients for the security model being
+			implemented in the namespace.
+
+		seal
+			The seal keyword causes the security model
+			being implemented for the namespace to be
+			placed in a sealed state.  In this state, the
+			current set of security coefficients is
+			considered to be the only set of valid
+			coefficients for the model.  Any subsequent
+			events that map to a coefficient not in the
+			current model will be considered a violation
+			of the model.
+
+		trusted pid=PID key=HEXID
+			The trusted keyword is used by a trust
+			orchestrator to specify that a process being
+			woken up after model evaluation of a security
+			event should be allowed to run in trusted
+			status.
+
+			The pid argument is used to locate the process
+			that is sleeping on the modeling event.
+
+			The HEXID argument is the authentication key
+			that was configured by a trust orchestrator
+			for the namespace at the time of its creation.
+
+		untrusted pid=PID key=HEXID
+			The untrusted keyword is used by a trust
+			orchestrator to specify that a process being
+			woken up after model evaluation should be
+			placed in untrusted status.
+
+			The pid argument is used to locate the process
+			that is sleeping on the modeling event.
+
+			The HEXID argument is the authentication key
+			that was configured by a trust orchestrator
+			for the namespace at the time of its creation.
+
+		state value=HEXID
+			The state keyword is used to indicate that the
+			security state coefficient, identified by the
+			ASCII base 16 encoded value specified by HEXID,
+			should be loaded into the current security
+			model as a valid security event coefficient.
+
+			The HEXID value will be the length of the
+			digest value of the cryptographic hash
+			function specified for the security modeling
+			namespace.
+
+		pseudonym value=HEXID
+			The pseudonym keyword is used to indicate that
+			the pathname, identified by the ASCII base 16
+			encoded value HEXID, should be designated to
+			return a constant digest value for the
+			contents of the file named by the pseudonym.
+
+			The HEXID value is computed with the following
+			function:
+
+			HEXID = HF(PATHNAME_LENGTH || PATHNAME)
+
+			Where HF is the cryptographic hash function
+			that has been designated for use by the
+			security modeling namespace and || implies
+			concatenation of the byte stream fed to the
+			hash function.
+
+		base value=HEXID
+			The base keyword is used to indicate that the
+			ASCII base 16 encoded value HEXID should be
+			registered as the value used to generate
+			security state coefficients for the model
+			implemented in the modeling namespace.
+
+			The binary length of the value specified by
+			HEXID must match the digest size of the
+			cryptographic hash function specified for use
+			in the security modeling namespace.
+
+			A model specific base value is designed to be
+			used as a 'freshness' nonce, similar to an
+			attestation nonce, to prove that a model state
+			value or measurement is current and not being
+			replayed.
+
+		lock
+			This command is only valid when loadable
+			module support is available in the kernel.
+
+			When executed this command blocks any further
+			TSEM models from being registered.  In
+			addition the reference count on all currently
+			registered modeling modules is increased so
+			that it is impossible to remove currently
+			loaded models.
+
+What:		/sys/kernel/security/tsem/internal_tma
+Date:		March 2024
+Contact:	Greg Wettstein <[email protected]>
+Description:
+		This directory will contain directories that will be
+		used to hold files that surface model parameters for
+		Trusted Modeling Agents (TMA's) for internally modeled
+		security namespaces.
+
+		There is currently only one internal TMA that is
+		surfaced through the following directory:
+
+		/sys/kernel/security/tsem/internal_tma/model0
+
+		The subsequent descriptions for the files implemented
+		in this directory will use ROOTDIR to represent the
+		above directory for space conservation purposes.
+
+What:		ROOTDIR/measurement
+Date:		March 2024
+Contact:	Greg Wettstein <[email protected]>
+Description:
+		The measurement file contains the ASCII base 16
+		representation of the time dependent linear extension
+		value of all the security state coefficients in the
+		model implemented by the namespace of the calling
+		process.
+
+		This value is similar in concept to measurement values
+		generated by TPM PCR's.  In the case of TSEM, it can
+		be used to validate the order integrity of the
+		security state coefficients output in the
+		trajectory_coefficients file documented below.
+		
+What:		ROOTDIR/state
+Date:		March 2024
+Contact:	Greg Wettstein <[email protected]>
+Description:
+		The state file contains the ASCII base 16
+		representation of the functional value of a security
+		modeling namespace.
+
+		The state value is a time independent representation
+		of the measurement of a security model.  This value is
+		designed to be a single value that represents whether
+		or not a workload has deviated from a defined set of
+		known good behaviors.
+
+What:		ROOTDIR/trajectory
+Date:		March 2024
+Contact:	Greg Wettstein <[email protected]>
+Description:
+		The trajectory file contains a description of the
+		security events that have occurred in a security
+		modeling namespace
+
+		Each entry in this file represents a single security
+		event and consists of a JSON encoded record with keys
+		and associated values or structures that define the
+		characteristics of the event.
+
+		Examples and descriptions of the JSON structures are
+		provided at the end of this document.
+		
+What:		ROOTDIR/trajectory_coefficients
+Date:		March 2024
+Contact:	Greg Wettstein <[email protected]>
+Description:
+		The trajectory_coefficients file will output the ASCII
+		base16 representation of each security state
+		coefficient that has been generated by the security
+		modeling namespace of the calling process.
+
+		The length of each point will be the ASCII
+		representation of the size of the cryptographic hash
+		function that has been specified for the model.
+
+What:		ROOTDIR/trajectory_counts
+Date:		March 2024
+Contact:	Greg Wettstein <[email protected]>
+Description:
+		The trajectory_coefficients file will output the ASCII
+		base10 representation of the number of times each
+		security state coefficient has been generated by the
+		security modeling namespace of the calling process.
+
+What:		ROOTDIR/forensics
+Date:		March 2024
+Contact:	Greg Wettstein <[email protected]>
+Description:
+		The forensics file contains the descriptions of
+		security events that are inconsistent with the
+		security model that the security namespace is
+		implementing.  Forensics events are generated after a
+		security model is 'sealed' and the events represent
+		security state coefficients that have not already been
+		generated by the model.
+
+		The format of lines in this file are identical to the
+		output generated by the ROOTDIR/trajectory file
+		that is documented above.
+
+What:		ROOTDIR/forensics_coefficients
+Date:		March 2024
+Contact:	Greg Wettstein <[email protected]>
+Description:
+		The forensics_coefficients file will output the ASCII
+		base16 representation of each security state
+		coefficient that have been generated by forensics
+		events in the security modeling namespace of the
+		calling process.
+
+		The length of each point will be the ASCII
+		representation of the size of the cryptographic hash
+		function that has been specified for the model.
+
+What:		ROOTDIR/forensics_counts
+Date:		March 2024
+Contact:	Greg Wettstein <[email protected]>
+Description:
+		The forensics_counts file will output the ASCII base10
+		representation of the number of times each security
+		state coefficient, generated by a forensics event, has
+		been generated by the security modeling namespace of
+		the calling process.
+
+What:		/sys/kernel/security/tsem/external_tma
+Date:		March 2024
+Contact:	Greg Wettstein <[email protected]>
+Description:
+		The external_tma is a container directory that holds
+		files that will be used to export JSON encoded security
+		event descriptions for externally modeled security
+		modeling namespaces.
+
+		The files created in this directory will be named by
+		the base 10 ASCII representation of the id value
+		assigned to the security modeling namespace.  See the
+		documentation for the /sys/kernel/security/tsem/id
+		file in this documentation for more details on this
+		value.
+
+		This file will is a read-only file that can be polled
+		by a userspace trust orchestrator implementation to
+		obtain security events that are to be modeled by a
+		Trusted Modeling Agent implementation associated with
+		the trust orchestrator.
+
+		Each exported event is a JSON encoded record
+		describing an event that is to be externally
+		processed.  The encoding for these events are included
+		below.
+
+		
+JSON Security Event Description Encoding:
+
+Methodology:
+------------
+
+The security event descriptions maintained by the internal TMA and
+that are exported to external trust orchestrator's are encoded in
+JavaScript Object Notation (JSON).  This section of the document will
+describe the encoding strategy that is used.
+
+An encoding strategy was used where each non-structure key value is
+encoded as a JSON string type.  In the case of numeric values it is
+the responsibility of the TMA to convert the string value into an
+appropriate numeric value for the generation of the mapping values
+that contribute to a security state coefficient.
+
+The JSON string encodings for numeric values follow the conventions
+used by the strtol() and/or strtoll() functions to interpret how to
+convert a string encoded numeric value into an appropriate numeric
+binary type when the conversion function is called with the 'special'
+value of 0 for the base argument.
+
+The following nomenclature will be define the value member for numeric
+types:
+
+	0MM:	A base 8 ASCII value.
+	NN:	A base 10 ASCII value.
+	0xHEX	A base 16 ASCII value.
+
+The MM, NN and HEX labels above do not imply a length of the numeric
+string but are used instead to imply that numeric digits of the
+specified type will follow.
+
+When the documentation below specifies a value name of DIGEST it is
+referring to a string value containing the base 16 hexadecimal
+encoding of a cryptographic digest value.  The length of the value
+will be equal to the ASCII hexadecimal encoding length of a digest
+value for the cryptographic compression function that is in effect for
+the security modeling namespace.  A DIGEST value will NOT be preceded
+by the 0x prefix for these values.
+
+A value name of ASCII implies an ASCII string.
+
+
+Event descriptions:
+-------------------
+
+Each TSEM supported LSM event handler (hook) encodes a description of
+the characteristics of an event in the following general form:
+
+{"event": {}, "COE": {}, "CELL": {}}
+
+Where the event key is used to label a structure that characterizes
+the event type.  The COE key labels a structure that characterizes the
+Context Of Execution that is executing the event and the CELL key
+labels a structure that defines the characteristics of the security
+event that an LSM handler/hook is invoked with.
+
+The CELL label used above is a generic label for documentation
+purposes.  The "CELL" label in an actual security event description
+will be replaced with one of the following currently supported event
+type descriptions:
+
+	task_kill
+	task_setpgid
+	task_getpgid
+	task_getsid
+	task_setnice
+	task_setioprio
+	task_getioprio
+	task_prlimit
+	task_setrlimit
+	task_setscheduler
+	task_getscheduler
+	task_prctl
+	file_open
+	mmap_file
+	file_ioctl
+	file_lock
+	file_fcntl
+	file_receive
+	unix_stream_connect
+	unix_may_send
+	socket_create
+	socket_connect
+	socket_bind
+	socket_accept
+	socket_listen
+	socket_socketpair
+	socket_sendmsg"
+	socket_recvmsg
+	socket_getsockname
+	socket_getpeername
+	socket_setsockopt
+	socket_shutdown
+	ptrace_traceme
+	kernel_module_request
+	kernel_load_data
+	kernel_read_file
+	sb_mount
+	sb_umount
+	sb_remount
+	sb_pivotroot
+	sb_statfs
+	move_mount
+	shm_associate
+	shm_shmctl
+	shm_shmat
+	sem_associate
+	sem_semctl
+	sem_semop
+	syslog
+	settime
+	quotactl
+	quota_on
+	msg_queue_associate
+	msg_queue_msgctl
+	msg_queue_msgsnd
+	msg_queue_msgrcv
+	ipc_permission
+	key_alloc
+	key_permission
+	netlink_send
+	inode_create
+	inode_link
+	inode_unlink
+	inode_symlink
+	inode_mkdir
+	inode_rmdir
+	inode_mknod
+	inode_rename
+	inode_setattr
+	inode_getattr
+	inode_setxattr
+	inode_getxattr
+	inode_listxattr
+	inode_removexattr
+	inode_killpriv
+	tun_dev_create
+	tun_dev_attach_queue
+	tun_dev_attach
+	tun_dev_open
+	bpf
+	bpf_map
+	bpf_prog
+	ptrace_access_check
+	capable
+	capget
+	capset
+
+
+Event encoding:
+---------------
+
+The 'event' label encodes a value structure of the following form:
+
+	"event": {
+		"context": "NN",
+		"number": "NN",
+	        "process": "ASCII",
+	        "type": "ASCII",
+	        "ttd": "NN",
+	        "p_ttd": "NN",
+	        "task_id": "DIGEST",
+	        "p_task_id": "DIGEST",
+	        "ts": "NN"
+	{
+
+Where the value type for the individual keys is as follows:
+
+	context:	A 64-bit numeric value representing the identity
+			number of the security modeling namespace that
+			generated the event.
+
+	number:		A 64-bit numeric value representing the sequence
+			number of the event in the security modeling
+			namespace that generated the event.
+
+	process:	The name of the process (current->comm) that
+			is invoking the security handler.
+
+	type:		One of the security event description names
+			noted above.
+
+	ttd:		A 64-bit numeric value incremented each time
+			a TASK_ID is generated by the bprm_committed_creds
+			handler.  This value is used to separate unique
+			invocations of an executable corpus of code.
+
+	p_ttd:		The ttd value of the parent process of the process
+			generating the event.  This value and the ttd
+			value can be used to reproduce the order of
+			execution of executable code on a platform or
+			in a security modeling namespace.
+
+	task_id:	The TASK_ID of the process executing the event.
+
+	p_task_id:	The TASK_ID of the parent process of the process
+			executing the event.
+
+	ts: 		The timestamp for when the security event occurred.
+			The timestamp value is in monotonic nanoseconds
+			since the hardware platform was booted.
+			
+
+Context Of Execution encoding:
+------------------------------
+
+The 'COE' label encodes a structure of the following form:
+
+	"COE": {
+		"uid": "NN",
+		"euid": "NN",
+		"suid": "NN",
+		"gid": "NN",
+		"egid": "NN",
+		"sgid": "NN",
+		"fsuid": "NN",
+		"fsgid": "NN",
+		"capeff": "0xHEX"
+	}
+
+	Which describes the credentials of the process that is
+	executing the event.  The reference for the numeric values of
+	the discretionary access control values is either the initial
+	user namespace or the user namespace that the security
+	modeling namespace is running in.
+
+	The namespace reference is a selectable feature when the
+	security modeling namespace is created.  The root security
+	modeling namespace always uses the initial user namespace.
+
+	It is assumed that anyone developing security models will be
+	familiar with the common definitions for the uid, gid
+	etc. labels.
+
+	The 'capeff' label is the effective capability set possessed
+	by a process when the security event is executed.
+
+	
+CELL (event description) encoding:
+----------------------------------
+	
+The 'CELL' label encodes multiple different structures depending on
+the security event that is being encoded.  An understanding of the
+various LSM security event hooks and their arguments is recommended
+prerequisite for anyone wishing to develop security models using these
+event descriptions.
+
+The CELL event descriptions frequently have subordinate JSON
+structures embedded in them.  In some cases only a single instance of
+a structure is used for that event type, in which case the definition
+of that structure will be included inline with the description of the
+event itself.
+
+The following general event subordinate parameter descriptions are
+used:
+
+The 'creds' structure is used to define the standard discretionary
+access based security credentials for a process:
+
+	creds {
+		"uid": "NN",
+		"euid": "NN",
+		"suid": "NN",
+		"gid": "NN",
+		"egid": "NN",
+		"sgid": "NN",
+		"fsuid": "NN",
+		"fsgid": "NN",
+		"capeff": "0xHEX",
+		"securebits:" "NN"
+	}
+
+	As in the case for the COE encoding standard knowledge of
+	discretionary access controls is assumed with the capeff label
+	being previously described.
+
+	securebits:	A numeric value containing bit specific fields
+			that a file capability enabled kernel will use
+			to invoke special handling of capabilities for
+			the root user id.
+
+
+The 'perm' structure is used to describe the IPC permissions for
+shared memory primitives such as shared memory regions, message
+queues, semaphores etc.:
+
+	"perm": {
+		"uid": "NN",
+		"gid": "NN",
+		"cuid": "NN",
+		"cgid": "NN",
+		"mode": "0MM",
+		"owner": "DIGEST"
+	}
+
+	uid:		The user id requesting permission for access to the
+			memory area.
+
+	gid:		The group id requesting permission for access to
+			the memory area.
+
+	cuid:		The alternate user id requesting permission for
+			access to the memory area.
+
+	cgid:		The alternate group id requesting permission for
+			access to the memory area.
+
+	mode:		The permissions being requested for access.
+
+	owner:		The TASK_ID of the process requesting access
+			to the memory area.
+
+
+The 'inode' structure is used to describe an inode structure used in
+a security event description:
+
+	"inode": {
+		"uid": "NN",
+		"gid": "NN",
+		"mode": "0MM,
+		"s_magic": "0xHEX",
+		"s_id": "ASCII",
+		"s_uuid": "HEX"
+	}
+
+	uid:		The user id that owns the inode.
+
+	gid:		The group id that owns the inode.
+
+	mode:		The discretionary access control permissions
+			for the inode.
+
+	s_magic:	The magic number of the filesystem that the
+			inode is in.
+
+	s_id:		The informational name from the superblock
+			of the filesystem the inode is in.
+
+	s_uuid:		The UUID of the filesystem the inode is in.
+
+
+The 'inode' structure is used to describe an inode structure used in
+a security event description:
+
+	"inode": {
+		"uid": "NN",
+		"gid": "NN",
+		"mode": "0MM,
+		"s_magic": "0xHEX",
+		"s_id": "ASCII",
+		"s_uuid": "HEX"
+	}
+		
+
+The 'path' structure is used to describe a path definition for an
+inode:
+
+	"path": {
+		"dev": {
+			"major": "NN",
+			"minor": "NN"
+		},
+		"instance": "NN",  	/* Optional. */
+		"owner": "DIGEST", 	/* Optional. */
+		"pathname": "ASCII"
+	}
+
+	dev:		A structure used to encapsulate the major and minor
+			numbers of the device that the filesystem is based
+			on.  This structure will not be included if the
+			path is not on a block device.
+
+	instance:	This key/value pair is only reported for an
+			inode that is created in the context of the
+			security modeling namespace that is reporting
+			the path description.
+
+			If reported, the instance value is the
+			instance count of an inode created under the
+			containing directory by the TASK_ID of the
+			process creating the inode.
+
+	owner:		As with the instance key, this key/value pair
+			is only reported for an inode created in the
+			context of the security modeling namespace
+			that is reporting the path description.
+
+			If reported, the DIGEST value is the TASK_ID
+			of the process that created the inode.
+
+	pathname:	The pathname of the file.
+	
+
+The 'dentry' structure is used to describe a dentry argument:
+
+	"dentry": {
+		"inode": {},
+		"path": {}
+	}
+
+	inode:		A JSON inode structure that describes the backing
+			inode for the dentry.  In some instances a
+			dentry does not have an inode defined, in which
+			case this key/value structure will be omitted
+			from the security event description.
+
+	path:		A JSON path structure describing the pathname
+			implemented by the dentry.
+			
+
+The 'file' structure is used to describe a file structure used in
+a security event description:
+
+	"file": {
+		"flags": "NN",
+		"inode": {},
+		"path": {}
+		"digest": "DIGEST"
+	}
+
+	flags:	The f_flags member of the file structure describing
+		how the file was opened.
+
+	inode:	A structure describing the inode that is backing
+		the file.  The definition of the inode structure will
+		be included after the descriptions of the inode based
+		security handlers.
+
+	path:	A structure describing the path to the file.
+
+	digest:	The cryptographic digest of the file.  For files
+		on a pseudo-filesystem or files that are created in
+		the context of a security modeling namespace this
+		value will be the 'zero-value' digest for the
+		hash function being used in the security modeling
+		namespace.
+
+
+The 'sb' structure is used to describe a filesystem superblock.
+
+	"sb": {
+		"dev_name", "ASCII",
+		"path", {},
+		"type", "ASCII",
+		"flags", "NN"
+	}
+
+	dev_name:	The device name that the filesystem is mounted
+			on.
+
+	path:		A JSON path description describing where the
+			the superblock is mounted.
+
+	type:		An ASCII string describing the mounted filesystem.
+
+	flags:		The mount flags for the mountpoint.
+
+
+The 'sock' structure is used to describe a socket that is used in
+a security event description:
+
+	sock {
+		"family": "NN",
+		"type": "NN",
+		"protocol": "NN",
+		"owner": "DIGEST"
+	}
+
+	family:		A numeric value describing the protocol family
+			that the socket is to be created for, ie. AF_UNIX,
+			AF_INET etc.
+
+	type:		The type of communications the socket is to
+			be used for, ie. SOCKET_STREAM, SOCKET_DGRAM.
+
+	protocol:	An optional protocol to be used with the socket.
+
+
+The 'addr' structure is used is an enclosing structure to hold
+subordinate structures that describe the address of a socket.  The
+addr field will contain a subordinate structure that is specific to
+the address type:
+
+	addr {
+		"af_inet": {}
+		"af_inet6": {}
+		"af_unix": {}
+		"af_other": {}
+	}
+
+The 'af_inet' structure defines an IPV4 network address:
+
+	"af_inet": {
+		"port": "NN",
+		"address": "NN
+	{
+
+	port:		The port number of the address.
+
+	address:	The 32-bit IPV4 address.
+
+The 'af_inet6' structure defines an IPV6 network address:
+
+	"af_inet6": {
+		"port": "NN",
+		"flow":	"NN",
+		"scope": "NN",
+		"address": "HEXID"
+	}
+
+	port:		The port number of the address.
+
+	flow:		The IPV6 flow specifier.
+
+	scope:		The IPV6 scope designator.
+
+	address:	The 128 bit IPV6 address in ASCII hexadecimal.
+
+The 'af_unix' structure a UNIX domain address:
+
+	"af_unix": {
+		"address": "ASCII"
+	}
+
+	address:	The path to the filesystem object representing
+			the socket.
+
+The 'af_other' structure is used to define a socket address other
+than one of the three above:
+
+	"af_other": {
+		"address": "DIGEST"
+	}
+
+	address:	The DIGEST value is the cryptographic digest
+			value over the sa_data member of the
+			sockaddr structure.
+
+
+Event Specific Encodings:
+-------------------------
+
+The 'task_kill' event models a request to send a signal to a target
+task:
+
+	"task_kill": {
+		"target": "DIGEST",
+		"sig": "NN",
+		"cross_ns": "NN"
+	}
+
+	target:		The TASK_ID of the process that the signal is
+			being sent to.
+
+	sig:		The number of the signal being sent.
+
+	cross_ns:	A boolean flag variable of 0 or 1 indicating
+			whether or not the signal will be crossing a
+			security modeling namespace boundary.
+
+
+The 'task_setpgid' event models a request to set the process group id
+of a task:
+
+	"task_setpgid": {
+		"task": "DIGEST",
+		"source": "DIGEST"
+	}
+
+	task:		The TASK_ID of the process whose process group
+			id is to be set.
+
+	source:		The TASK_ID of the process whose process group
+			id the target task is to be placed into.
+
+
+The 'task_getpgid' event describes a request to obtain the process
+group id of a task:
+
+	"task_getpgid": {
+		"task": "DIGEST",
+	}
+
+	task:		The TASK_ID of the process whose process group
+			id is to be obtained.
+
+
+The 'task_getsid' event describes a request to obtain the session id of
+a task.
+	
+	"task_getsid": {
+		"task": "DIGEST",
+	}
+
+	task:		The TASK_ID of the process whose session id is
+			to be obtained.
+
+
+The 'task_setnice' event describes a request to set the execution
+priority of a task.
+
+	"task_setnice": {
+		"task": "DIGEST",
+		"nice": "NN"
+	}
+
+	task:		The TASK_ID of the process whose priority is
+			to be set.
+
+	nice:		The numerical priority value to be set.
+
+
+The 'task_setioprio' event describes a request to set the io priority
+of a task.
+
+	"task_setioprio": {
+		"task": "DIGEST",
+		"ioprio": "NN"
+	}
+
+	task:		The TASK_ID of the process whose I/O priority is
+			to be set.
+
+	ioprio:		The numerical priority value to be set.
+
+
+
+The 'task_getioprio' event describes a request to get the io priority
+of a task.
+
+	"task_getioprio": {
+		"task": "DIGEST"
+	}
+
+	task:		The TASK_ID of the process whose I/O priority is
+			to be obtained.
+
+
+The 'task_prlimit' event describes a request to get or set resource
+limits for a task
+
+	"task_prlimit": {
+		"cred": {}
+		"tcred": {}
+	}
+
+	cred:		A credential structure, defined below, that
+			describes the credentials of the task that
+			is requesting the right to set resource limits
+			for a task.
+
+	tcred:		A credential structure that describes the
+			credentials of the task whose resource limits
+			are to queried.
+
+
+The 'task_setrlimit' event describes a request to set a new resource
+limit for a task.
+
+	"task_setrlimit": {
+		"task": "DIGEST"
+		"new_rlim": {
+			"resource": "NN",
+			"current": "NN",
+			"max": "NN"
+		}
+	}
+
+	task:		The TASK_ID of the process whose resource limit
+			is to be set.
+
+	new_rlim:	A structure with the following key values that
+		 	describes the resource limit being set:
+
+			resource:	The numeric identifier for the
+					resource being set.
+
+			current:	The current numeric value of
+					the resource.
+
+			max:		The new numeric value for the
+					resource.
+	
+
+The 'task_setscheduler' event describes a request to set a new scheduler
+type for a task.
+
+	"task_setscheduler": {
+		"task": "DIGEST"
+	}
+
+	task:		The TASK_ID of the process whose scheduler is
+			to be set.
+
+
+The 'task_getscheduler' event describes a request to obtain the type of
+process scheduler that is set for a task.
+
+	"task_getscheduler": {
+		"task": "DIGEST"
+	}
+
+	task:		The TASK_ID of the process whose scheduler
+			type is to be queried.
+
+
+The 'task_prctl' event describes a request to perform a process control
+operation on the task that is executing the event.
+
+	"task_prctl": {
+		"option": "NN",
+		"arg2": "NN",
+		"arg3": "NN",
+		"arg4": "NN",
+		"arg5": "NN
+	}
+
+	option:		The type of process control operation that is
+			to be performed.
+
+	arg2-5:		A total of four numeric values that describe
+			the process control operation.
+
+
+The 'file_open' event describes a request to open a file.
+
+	"file_open": {
+		"file": {}
+	}
+
+	file:	A structure describing the file that is to be opened.
+		This structure is used as a parameter in multiple
+		events and will be documented later.
+
+
+The 'file_ioctl' event describes a request to issue an ioctl call against
+a file.
+
+	"file_ioctl": {
+		"file": {},
+		"cmd": "NN
+	}
+
+	file:	The description of the file that the ioctl call is
+		to be issued against.
+
+	prot:	The numeric value of the argument specifying the memory
+		protections that are to be implemented.
+
+	flags:	The flags argument specifying the type of mapping to be
+		implemented.  See the mmap(2) manpage for information
+		about the protection and flags argument to the mmap
+		system call.
+
+
+The 'file_lock' event describes a request for permission to issue a
+lock operation against the specified file.
+
+	"file_lock": {
+		"file": {},
+		"cmd": "NN"
+	}
+
+	file:	The description of the file that the lock is to be
+		placed on.
+
+	cmd:	The numeric coding of the lock operation that is to
+		be performed.
+
+
+The 'file_fcntl' event describes a request for permission to issue a
+perform a file operation on the designated file.
+
+	"file_fcntl": {
+		"file": {},
+		"cmd": "NN"
+	}
+
+	file:	The description of the file that the file operation is
+		to be conducted on.
+
+	cmd:	The numeric coding of the type of file operation that
+		is to be performed.
+
+
+The 'file_receive' event describes a request for permission to receive
+an open file descriptor though an InterProcess Communications (IPC)
+call.
+
+	"file_receive": {
+		"file": {},
+	}
+
+	file:	The description of the file whose file descriptor is to
+		be received.
+
+
+The 'unix_stream_connect' event describes a request for permission to
+establish a UNIX domain stream connection.  This request for
+permission is for AF_UNIX sockets that are not enumerated using the
+traditional filename model.
+
+	"unix_stream_connect": {
+		"sock": {},
+		"other": "{}"
+	}
+
+	sock:	A JSON socket structure describing the socket that is
+		to be connected to a second socket.  A socket description
+		structure is used by other socket operations and its
+		characteristics will be documented later.
+
+	other:	A JSON socket structure describing the socket that is
+		to be connected to.
+
+
+The 'unix_may_send' event describes a request for permission to send
+a datagram from an originating socket to a destination socket.  This
+permission check is associated with the non-filename based sockets
+described above.
+
+	"unix_may_send": {
+		"sock": {},
+		"other": "{}"
+	}
+
+	sock:	A structure describing the socket that is originating
+		the datagram.
+
+	other:	A structure describing the socket that is to receive
+		the datagram.
+
+
+The 'socket_create' event describes a request for permission to create
+a networking socket.
+
+	"socket_create": {
+		"family": NN,
+		"type": "NN",
+		"protocol": "NN",
+		"kern": "NN"
+	}
+
+	family:		A numeric value describing the protocol family
+			that the socket is to be created for, ie. AF_UNIX,
+			AF_INET etc.
+
+	type:		The type of communications the socket is to
+			be used for, ie. SOCKET_STREAM, SOCKET_DGRAM.
+
+	protocol:	An optional protocol to be used with the socket.
+
+	kern:		A boolean value used to indicate whether or
+			not the socket is kernel based.
+
+
+The 'socket_connect' event describes a request for permission to
+create connect a socket to a remote endpoint address.
+
+	"socket_connect": {
+		"sock": {},
+		"addr": {}
+	}
+
+	sock:		A JSON socket description of the socket making
+			the connection request.
+
+	addr:		A JSON socket structure describing the connection
+			endpoint address.
+
+
+The 'socket_bind' event describes a request for permission to bind a
+socket to a network endpoint address.
+
+	"socket_bind": {
+		"sock": {},
+		"addr": {}
+	}
+
+	sock:		A JSON socket description of the socket making
+			the request.
+
+	addr:		A JSON address description describing the address
+			that is being bound to.
+
+
+The 'socket_accept' event describes a request for permission for a
+socket to accept a connection from a remote address.
+
+	"socket_accept": {
+		"sock": {},
+		"addr": {}
+	}
+
+	sock:		A JSON socket description of the socket making
+			the request.
+
+	addr:		A JSON address description of the address being
+			accepted by the socket.
+
+
+The 'socket_listen' event describes a request for permission for a
+socket to listen for a connection.
+
+	"socket_listen": {
+		"sock": {},
+		"backlog": "NN"
+	}
+
+	sock:		A JSON socket description of the socket making
+			the request to listen.
+
+	backlog:	The maximum number of entries that will be
+			allowed to be queued waiting for acceptance.
+
+
+The 'socket_socketpair' event describes a request for permission to
+create a pair of connected sockets.
+
+	"socket_socketpair": {
+		"socka": {},
+		"sockb": {}"
+	}
+
+	socka:		A JSON socket description of the first socket in
+			the pair.
+
+	sockb:		A JSON socket description of the second socket in
+			the pair.
+
+
+The 'socket_sendmsg' event describes a request for permission to
+send a message over a socket.
+
+	"socket_sendmsg": {
+		"sock": {},
+		"addr": {}"
+	}
+
+	sock:		A JSON socket description of the socket sending
+			the message.
+
+	addr:		A JSON address description defining the address
+			to which the message is being sent.
+
+
+The 'socket_recvmsg' event describes a request for permission to
+receive a message over a socket.
+
+	"socket_recvmsg": {
+		"sock": {},
+		"addr": {}"
+	}
+
+	sock:		A JSON socket description of the socket receiving
+			the message.
+
+	addr:		A JSON address description the address from which
+			the message is being received.
+
+
+The 'socket_getsockname' event describes a request for permission to
+read the address of a socket.
+
+	"socket_getsockname": {
+		"sock": {}
+	}
+
+	sock:		A JSON socket description of the socket whose
+			address is to be read.
+
+
+The 'socket_getpeername' event describes a request for permission to
+read the address of the socket's peer.
+
+	"socket_getpeername": {
+		"sock": {}
+	}
+
+	sock:		A JSON socket description of the socket the
+			peer address is to be obtained from.
+
+
+The 'socket_setsockopt' event describes a request for permission to
+set an option on a socket.
+
+	"socket_setsockopt": {
+		"sock": {},
+		"level": "NN",
+		"optname": "NN"
+	}
+
+	sock:		A JSON socket description of the socket whose
+			options are to be set.
+
+	level:		The protocol level at which the option will be
+			set.
+
+	optname:	The numeric coding of the option that will be set.
+
+
+The 'socket_shutdown' event describes a request for permission to shutdown
+a socket.
+
+	"socket_shutdown": {
+		"sock": {},
+		"how": "NN"
+	}
+
+	sock:		A JSON socket description of the socket that is
+			to be shutdown.
+
+	how:		A numeric code specifying how send and receives
+			on the socket are to be handled by the shutdown.
+
+
+The 'ptrace_traceme' event describes a request for permission for the
+parent process to trace the process that is executing the security
+handler.
+
+	"ptrace_traceme": {
+		"source": "DIGEST"
+	}
+
+	source:		The TASK_ID of the process requesting tracing
+			permissions.
+
+
+The 'kernel_module_request' event describes a request for permission
+to load a kernel module.
+
+	"kernel_module_request": {
+		"kmod_name": "ASCII"
+	}
+
+	kmod_name:	The name of the kernel module being requested.
+
+
+The 'kernel_load_data' event describes a request for permission to
+load data into the kernel
+
+	"kernel_load_data": {
+		"id": "NN",
+		"contents": "NN"
+	}
+
+	id:		A numeric identifier value representing the
+			type of data to be loaded.
+
+	contents:	A flag variable indicating if post data
+			loading will be used.
+		
+
+The 'kernel_read_file' event describes a request for permission for the
+kernel to load a file specified by userspace.
+
+	"kernel_read_file": {
+		"file": {},
+		"contents": "NN"
+	}
+
+	file:		A JSON description of the file to be read.
+
+	id:		A numeric identifier value representing the
+			type of data to be loaded.
+
+
+The 'sb_mount' event describes a request for permission to mount a
+filesystem.
+
+	sb_mount {
+		"dev_name": "ASCII",
+		"path": {}
+		"type": "ASCII",
+		"flags": "NN"
+	}
+
+	dev_name:	The name of the device that is to be mounted.
+
+	path:		A JSON path description describing where the
+			device is to be mounted.
+
+	type:		The type of filesystem to be mounted.
+
+	flags:		The mount flags to be implemented.
+	
+
+The 'sb_umount' event describes a request to unmount a filesystem.
+
+	"sb_umount": {
+		"mnt", {},
+		"flags", "NN"
+	}
+
+	mnt:		A JSON dentry structure defining the mount point
+			that is to be unmounted.
+
+	flags:		A numerical value specifying the flags passed
+			to the unmount command.
+
+
+The 'sb_remount' event describes a request for permission to remount a
+filesystem.
+
+	"sb_remount": {
+		"sb": {}
+		"dentry": {},
+		"fstype": "ASCII",
+		"s_flags": "NN"
+	}
+
+	sb:		A JSON superblock structure describing the
+			mountpoint that is to be remounted.
+
+	dentry:		A JSON dentry structure describing the mountpoint
+			that is to be remounted.
+
+	fstype:		The name of the filesystem being remounted.
+
+	s_flags:	The superblock flags describing the mount.
+
+
+The 'sb_pivotroot' event describes a request for permission to pivot
+the root filesystem to a new mount point.
+
+	"sb_pivotroot": {
+		"old_path": {},
+		"new_path": {}
+	}
+
+	old_path:	A JSON path structure specifying the location
+			from which the root filesystem is to be moved.
+
+	new_path:	A JSON path structure specifying the location
+			to which the root filesystem is to be moved.
+
+
+The 'sb_statfs' event describes a request for permission to access
+filesystem statistics.
+
+	"sb_statfs": {
+		"dentry": {},
+	}
+
+	dentry:		A JSON dentry structure describing the superblock
+			location for the request.
+
+
+The 'move_mount' event describes a request for permission to move a
+mount from one location to another.
+
+	"move_mount": {
+		"from_path": {},
+		"to_path": {}
+	}
+
+	from_path:	A JSON path structure describing the location from
+			where the mount is to be moved from.
+
+	to_path:	A JSON path structure describing the location to
+			where the mount is to be moved to.
+
+
+The 'shm_associate' event structure describes a request for permission
+to access an existing shared memory region.
+
+	"shm_associate": {
+		"perm": {},
+		"shmflg": "NN"
+	}
+
+	perm: 		A JSON IPC permissions structure describing the
+			permissions of the shared memory region.
+
+	shmflg:		A numeric flag describing the shared memory
+			operations being requested.
+
+
+The 'shm_shmctl' event structure describes a request for permission to
+execute a command on a SYSV shared memory region.
+
+	"shm_shmctl": {
+		"perm": {},
+		"cmd": "NN"
+	}
+
+	perm: 		A JSON IPC permissions structure describing the
+			permissions of the shared memory region.
+
+	cmd:		The command whose permission is to be checked.
+
+
+The 'shm_shmat' event structure describes a request for permission to
+attach to a shared memory region.
+
+	"shm_shmat": {
+		"perm": {},
+		"shmflg": "NN"
+	}
+
+	perm: 		A JSON IPC permissions structure describing the
+			permissions of the shared memory region.
+
+	shmflg:		The shared memory attachment command being
+			requested.
+
+
+The 'sem_associate' event structure describes a request for permission
+to attach to an existing shared memory semaphore.
+
+	"sem_associate": {
+		"perm": {},
+		"shmflg": "NN"
+	}
+
+	perm: 		A JSON IPC permissions structure describing the
+			permissions of the semaphores that the
+			association request is being requested for.
+
+	semflg:		The semaphore operations flag.
+
+
+The 'sem_semctl' event structure describes a request for permission
+to execute a control operation on a shared memory semaphore.
+
+	"sem_semctl": {
+		"perm": {},
+		"cmd": "NN"
+	}
+
+	perm: 		A JSON IPC permissions structure describing the
+			permissions of on the semaphore that the control
+			command is being requested on.
+
+	cmd:		The semaphore command that is being requested.
+
+
+The 'sem_semop' event structure describes a request for permission to
+request an operation on a semaphore set.
+
+	"sem_semctl": {
+		"perm": {},
+		"nsops": "NN",
+		"alter": "NN"
+	}
+
+	perm: 		A JSON IPC permissions structure describing the
+			permissions of the semaphore set that the
+			operation is being requested on.
+
+	nsops:		The number of operations to be performed.
+
+	alter:		The changes that are to be made.
+
+
+The 'syslog' event structure describes a request for permission to
+access the kernel message buffers or change console logging.
+
+	"syslog": {
+		"type": NN
+	}
+
+	type: 		The action that is being requested.
+
+
+The 'settime' event structure describes a request for permission to
+access the kernel message buffers or change console logging.
+
+	"settime": {
+		"ts": {
+			"seconds", "NN",
+			"nsecs", "NN"
+		},
+		"tz": {
+			"minuteswest", "NN",
+			"dsttime", "NN"
+		}
+	}
+
+	ts: 		If the call to the security_settime handler was
+			to set the time this structure will be present.
+
+	seconds:	The time in seconds to set.
+
+	nsecs:		The time in nano-seconds to be set.
+
+	tz:		If the call to the security_settime handler was
+			to set the timezone this structure will be present.
+
+	minuteswest:	The offset of the timezone.
+
+	dsttime:	A flag variable to indicate if daylight savings
+			time is to be set.
+
+
+The 'quotactl' event structure describes a request for permission to
+control manipulate filesystem quotas.
+
+	"quotactl": {
+		"cmds": "NN",
+		"type": "NN",
+		"id": "NN",
+		"sb", {}
+	}
+
+	cmds:		The quota commands to be enforced.
+
+	type:		The type of quota to be enforced.
+
+	id:		The quota version to be enforced.
+
+	sb:		A JSON superblock structure describing the
+			filesystem on which the quota command is to
+			operate on.
+
+
+The 'quota_on' event structure describes a request to enable quotas
+for a filesystem.
+
+	"quota_on": {
+		"dentry": {}
+	}
+
+	dentry:		A JSON dentry description describing the
+			mountpoint that quotas are to be enabled on.
+
+
+The 'msg_queue_associate' event structure describes a request to
+access a previously defined message queue.
+
+	"msg_queue_associate": {
+		"perm": {}
+		"msgflg": "NN"
+	}
+
+	perm: 		A JSON IPC permissions structure describing the
+			permissions of the message queue that association
+			is being requested for.
+
+	msgflg:		A numeric flag indicating the operation that is
+			being requested.
+
+
+The 'msg_queue_msgctl' event structure describes a request to execute
+a control operation on a shared memory message queue region.
+
+	"msg_queue_msgctl": {
+		"perm": {}
+		"cmd": "NN"
+	}
+
+	perm: 		A JSON IPC permissions structure describing the
+			permissions of the shared memory message queue
+			region that the control command is being
+			requested on.
+
+	cmd:		A numeric flag indicating the control operation
+			that is to be executed.
+
+
+The 'msg_queue_msgsnd' event structure describes a request to send a
+message over a shared memory message queue.
+
+	"msg_queue_msgsnd": {
+		"perm": {}
+		"msqflg": "NN"
+	}
+
+	perm: 		A JSON IPC permissions structure describing the
+			permissions of the shared memory message queue
+			region that the message is being sent on.
+
+	msqflg:		A numeric coding of the operation that is to
+			be performed.
+
+
+The 'msg_queue_msgrcv' event structure describes a request to receive
+a message over a shared memory message queue.
+
+	"msg_queue_msgrcv": {
+		"perm": {}
+		"target": "DIGEST"
+		"type": "NN",
+		"mode": 
+	}
+
+	perm: 		A JSON IPC permissions structure describing the
+			permissions of the shared memory message queue
+			region that the message is being received on.
+
+	target:		The TASK_ID of the process that is to receive
+			the message.
+
+	type:		The type of message that is to be received.
+
+	mode:		The operations flag for the message.
+
+
+The 'ipc_permission' event structure describes a request to check if
+SYSV IPC access is to be allowed.
+
+	"ipc_permission": {
+		"perm": {}
+		"target": "DIGEST"
+		"type": "NN",
+		"mode": "NN"
+	}
+
+	ipcp: 		A JSON IPC permissions structure describing the
+			permissions on the SYSV shared memory region that
+			is to be checked.
+
+	flag:		The access permissions being requested.
+
+
+The 'key_alloc' event structure describes a request for permission to
+allocate and initialize a kernel key structure.
+
+	"key_alloc": {
+		"creds": {},
+		"flags": "NN"
+	}
+
+	creds: 		A JSON credentials structure describing the
+			the access controls for the key structure
+
+	flags:		A numeric control constant describing how the
+			key is to be created.
+
+
+The 'key_permission' event structure describes a request for
+permission to execute a control operation on a kernel key structure.
+
+	"key_permission": {
+		"key_refs": {
+			"possessed": "NN",
+			"uid": "NN",
+			"gid": "NN",
+			"flags": "NN"
+		}
+		"creds": {},
+		"perm", "NN"
+	}
+
+	key_refs:	A JSON structure describing the key to be
+			accessed.
+
+		possessed:	A flag indicating whether or not the key is
+				possessed by a process.
+
+		uid:		The user id that owns the key.
+
+		gid:		The group id that owns the key.
+
+		flags:		Flags describing the state of the key.
+
+	creds		A credentials structure describing the task that
+			is requesting access to the key.
+
+	perm:		The permissions that are being requested on the
+			key.
+
+
+The 'netlink_send' event structure describes the permissions that are
+to be set on a netlink socket.
+
+	"netlink_send": {
+		"sock": {},
+		"uid": "NN",
+		"gid": "NN"
+		"portid": "NN",
+		"dst_group": "NN",
+		"nsid_set": "NN",
+		"nsid": "NN"
+	}
+
+	sock:		A JSON socket description structure describing
+			the socket over which the message is to be sent.
+
+	uid:		The user id that the message is to be sent to.
+
+	gid:		The group id that the message is to be sent to.
+
+	portid:		The port identifier of the 	
+
+	dst_group:	The destination group for the message.
+
+	nsid_set:	A flag variable indicating that the nsid value
+			is valid.
+
+	nsid:		The namespace identifier.
+
+
+The 'inode_create' event structure describes a request to create an
+inode.
+
+	"inode_create": {
+		"dir":	{},
+		"dentry": {},
+		"mode": "0MM"
+	}
+
+	dir:		A JSON inode description describing the directory
+			the inode is to be created under.
+
+	dentry:		A JSON dentry description describing the location
+			where the inode is to be created.
+
+	mode:		The permissions to be assigned to the inode.
+
+
+The 'inode_link' event structure describes a request to link an inode
+to a new location.
+
+	"inode_link": {
+		"old_dentry": {},
+		"dir": {},
+		"new_dentry": {}
+	}
+
+	old_dentry:	A JSON dentry description describing the current
+			location of the inode.
+
+	dir		A JSON inode description describing the parent
+			directory under which the inode link will be
+			created.
+
+	new_dentry:	A JSON dentry description describing the location
+			of the new link.
+
+
+The 'inode_unlink' event structure describes a request to delete an
+inode.
+
+	"inode_unlink": {
+		"dir": {},
+		"dentry": {}
+	}
+
+	dir:		A JSON inode structure describing the parent
+			directory from which the inode is to be removed.
+
+	dentry:		A JSON dentry description describing the inode
+			to be removed.
+
+
+The inode_symlink event structure describes a request to delete an inode.
+
+	"inode_symlink": {
+		"dir": {},
+		"dentry": {},
+		"old_name": "ASCII"
+	}
+
+	dir:		A JSON inode structure describing the parent
+			directory in which the link is to be created.
+
+	dentry:		A JSON dentry description describing the inode
+			that is to be created as the link.
+
+	old_name:	The name of the existing filename to be linked.
+
+
+The 'inode_mkdir' event structure describes a request to create an
+directory.
+
+	"inode_mkdir": {
+		"dir": {},
+		"dentry": {},
+		"mode": "0MM"
+	}
+
+	dir:		A JSON inode structure describing the parent
+			directory in which the directory is to be created.
+
+	dentry:		A JSON dentry description describing the directory
+			inode that is to be created.
+
+	mode:		The permissions to be assigned to the new directory.
+
+
+The 'inode_rmdir' event structure describes a request to remove a
+directory inode.
+
+	"inode_rmdir": {
+		"dir": {},
+		"dentry": {},
+	}
+
+	dir:		A JSON inode structure describing the parent
+			directory of the directory being removed.
+
+	dentry:		A JSON dentry description describing the directory
+			inode that is to be removed.
+
+	mode:		The permissions to be assigned to the new directory.
+
+
+The 'inode_mknod' event structure describes a request to remove a directory
+inode.
+
+	"inode_mknod": {
+		"dir": {},
+		"dentry": {},
+		"mode": "0MM",
+		"dev": {
+			"major": "NN",
+			"minor": "NN"
+		}
+	}
+
+	dir:		A JSON inode structure describing the directory
+			under which the device node is being created.
+
+	dentry:		A JSON dentry description describing the location
+			of the device node inode.
+
+	mode:		The permissions to be assigned to the device node.
+
+	dev:		A JSON structure describing the device node
+			characteristics:
+
+		major:		The major number of the device to be
+				created.
+
+		minor:		The minor number of the device to be
+				created.
+
+
+The 'inode_rename' event structure describes a request to rename an
+inode.
+
+	"inode_rename": {
+		"old_dir": {},
+		"old_dentry": {},
+		"new_dir": {},
+		"new_dentry": {}
+	}
+
+	old_dir:	A JSON inode structure describing the parent
+			directory of the inode to be renamed.
+
+	old_dentry:	A JSON dentry description describing the location
+			of the inode to be renamed.
+
+	new_dir:	A JSON inode structure describing the parent
+			directory of the new location of the inode.
+
+	new_dentry:	A JSON dentry description describing the new
+			inode location.
+
+
+The 'inode_setattr' event structure describes a request to set the
+attributes of an inode.
+
+	"inode_setattr": {
+		"dentry": {},
+		"attr": {
+			"valid": "NN",
+			"mode": "0MM",
+			"uid": "NN",
+			"gid": "NN",
+			"size": "NN
+		}
+	}
+
+	dentry:		A JSON dentry structure describing the inode
+			whose characteristics are to be set.
+
+	attr:		A JSON structure describing the characteristics
+			that will be set:
+
+		valid:		A numeric encoding of what characteristics
+				of the inode should be set.
+
+		mode:		If requested, the permissions that are to
+				be set.
+
+		uid:		If requested, the new user id to be set.
+
+		gid:		If requested, the new group id to be set.
+
+		size:		If requested, the new size of the file.
+
+
+
+The 'inode_getattr' event structure describes a request to obtain the
+attributes of an inode.
+
+	"inode_getattr": {
+		"path": {}
+	}
+
+	path:		A JSON path structure describing the path to
+			the inode whose attributes are to be retrieved.
+
+
+The 'inode_setxattr' event structure describes a request to set the
+extended attributes of an inode.
+
+	"inode_setxattr": {
+		"dentry": {},
+		"name": "ASCII",
+		"value": "BASE64",
+		"flags": "NN"
+	}
+
+	dentry:		A JSON dentry structure describing the inode
+			whose extended attributes are to be set.
+
+	name:		The name of the attribute to be set.
+
+	value:		The value of the attribute to be set encoded
+			as a Base64 ASCII string.
+
+	flags:		The operations flag for how to set the attribute.
+
+
+The 'inode_getxattr' event structure describes a request to get the
+extended attributes of an inode.
+
+	"inode_getxattr": {
+		"dentry": {},
+		"name": "ASCII",
+	}
+
+	dentry:		A JSON dentry structure describing the inode
+			whose extended attributes are to be requested.
+
+	name:		The name of the attribute whose value is to
+			be requested.
+
+
+The 'inode_listxattr' event structure describes a request to list the
+extended attributes attached to an inode.
+
+	"inode_listxattr": {
+		"dentry": {}
+	}
+
+	dentry:		A JSON dentry structure describing the inode
+			whose extended attributes are to be listed.
+
+
+The 'inode_removexattr' event structure describes a request to remove
+an extended attributes attached to an inode.
+
+	"inode_removexattr": {
+		"dentry": {},
+		"name": "ASCII"
+	}
+
+	dentry:		A JSON dentry structure describing the inode
+			whose extended attribute are to be removed.
+
+	name:		The name of the extended attribute that is to
+			be removed.
+
+
+The 'inode_killpriv' event structure describes a request to remove
+privileges from an inode.
+
+	"inode_killpriv": {
+		"dentry": {}
+	}
+
+	dentry:		A JSON dentry structure describing the inode
+			whose privileges are to be removed.
+
+
+The 'tun_dev_create' event structure describes a request to create a
+TUN network device.
+
+	"tun_dev_create": {
+	}
+
+	No parameters are processed for this request.
+
+
+The 'tun_dev_attach_queue' event structure describes a request to
+attach a TUN device queue.
+
+	"tun_dev_attach_queue": {
+	}
+
+	No parameters are processed for this request.
+
+
+The 'tun_dev_attach' event structure describes a request to attach to
+a TUN device.
+
+	"tun_dev_attach": {
+		"sock": {}
+	}
+
+	sock:		A JSON socket description structure describing
+			the socket requesting access to the TUN device.
+
+
+The 'tun_dev_open' event structure describes a request to open a
+network TUN device.
+
+	"tun_dev_open": {
+	}
+
+	No parameters are processed for this request.
+
+
+The 'bpf' event structure describes a request to use the BPS system
+call.
+
+	"bpf": {
+		"cmd": "NN",
+		"attr": {
+			"size": "NN"
+		}
+	}
+
+	cmd:		The BPF command that is being requested.
+
+	attr:		A JSON structure describing the attributes for
+			the command:
+
+		size:		The size of the BPF attribute description
+				that will be passed to the BPF call.
+
+
+The 'bpf_map' event structure describes a request for permission to
+access a BPF map.
+
+	"bpf_map": {
+		"map": {
+			"map_type": "NN",
+			"fmode": "NN"
+		}
+	}
+
+	map:		A JSON description structure used to describe the
+			map that will be accessed.
+
+	fmode:		The permissions to be used for accessing the
+			map.
+
+
+The 'bpf_prog' event structure describes a request for permission to
+access a BPF program.
+
+	"bpf_prog": {
+		"prog": {
+			"type": "NN",
+			"attach_type": "NN"
+		}
+	}
+
+	prog:		A JSON description structure used to describe the
+			program that access is being requested to.
+
+		type:		The type of program being described.
+
+		attach_type:	The type of attachment to be used for the
+				program.
+
+
+The 'capable' event structure describes a request to check if a
+process has a specific capability.
+
+	"capable": {
+		"cap": "NN",
+		"opts": "NN"
+	}
+
+	cap:		The capability being requested.
+
+	opts:		The options directing how the check is to be
+			performed.
+
+
+The 'capget' event structure describes a request to return the
+capability sets that a process has.
+
+	"capget": {
+		"target": "DIGEST",
+		"effective": "0xHEX",
+		"inheritable": "0xHEX",
+		"permitted": "0xHEX"
+	}
+
+	target:		The TASK_ID of the process whose capability masks
+			are to be checked.
+
+	effective:	The effective capabilities of the process.
+
+	inheritable:	The inheritable capabilities of the process.
+
+	permitted:	The permitted capabilities of the process.
+
+
+The 'capset' event structure describes a request to set the
+capabilities of a target process.
+
+	"capset": {
+		"effective": "0xHEX",
+		"inheritable": "0xHEX",
+		"permitted": "0xHEX"
+	}
+
+	effective:	The effective capabilities to be set.
+
+	inheritable:	The inheritable capabilities to be set.
+
+	permitted:	The permitted capabilities to be set.
+
+
+Security event export encodings:
+--------------------------------
+
+External trust orchestrator's read security events from the control
+plane file created for an externally modeled security namespace.
+
+The encoding of the event is in the following form:
+
+{"export": {}, "event": {}}
+
+Where the event structure is the previously described event structure
+with the following additional key:
+
+	pid:		The process identifier (PID) of the task that
+			generated the event.
+
+			The primary TSEM documentation file documents why
+			this value can be safely used in this context.
+
+
+The 'export' structure encodes the characteristics type of the
+exported event.
+
+	"export:" {
+		"type": "ASCII",
+		"TYPE": {}
+	}
+
+The 'export' structure is a self-describing structure where the ASCII
+string that serves as the value of the 'type' key will serve as the
+key value that describes the payload structure of the event, ie. the
+TYPE key will be substituted with the ASCII string.
+
+The following payload labels are defined:
+
+	event
+	async_event
+	aggregate
+	log
+
+The event and async_event payload labels both resolve to the
+previously documented 'event' payload.  The use of different labels
+for the event is to provide a means for a trust orchestrator to know
+the context that the process was running in when the event was
+generated.
+
+The 'aggregate' structure defines the hardware boot measurement
+described previously in this documentation.
+
+	"aggregate": {
+		"value": "DIGEST"
+	}
+
+	value:		The hardware aggregate measurement.
+
+
+The 'log' structure is used to describe a security event that was
+requested while the task was running in untrusted status after a
+security model violating event:
+
+	"log": {
+		"process": "ASCII",
+		"event": "ASCII",
+		"action": "ASCII"
+	}
+
+	process:	The process name (current->comm) that invoked
+			the event.
+
+	event:		The CELL description name of the event that
+			was requested.
+
+	action:		A string value indicating how the event was
+			enforced, either DENY or LOG.
Documentation/admin-guide/LSM/index.rst +1 -0
index a6ba95fbaa9f..cebd3b02598d 100644
@@ -47,3 +47,4 @@ subdirectories.
    tomoyo
    Yama
    SafeSetID
+   tsem
Documentation/admin-guide/LSM/tsem.rst new file +1680 -0

576 lines not on this page · raw message

Documentation/admin-guide/kernel-parameters.txt +29 -0
index 27ec49af1bf2..36460e179793 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.39.1

Part of the diff is not shown here. View the raw message.

maintainer
#3 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

Quoted 27 lines · On Aug 26, 2024 Greg Wettstein <[email protected]> wrote:

An entry was added to the ABI testing documentation to document the API definitions for the TSEM ontrol plane.

The file documenting the kernel command-line parameters was updated to document the TSEM specific parameters that are implemented.

The primary TSEM documentation file was added to the LSM administration guide and the file was linked to the index of LSM documentation.

---
 Documentation/ABI/testing/tsem                | 2420 +++++++++++++++++
 Documentation/admin-guide/LSM/index.rst       |    1 +
 Documentation/admin-guide/LSM/tsem.rst        | 1680 ++++++++++++
 .../admin-guide/kernel-parameters.txt         |   29 +
 4 files changed, 4130 insertions(+)
 create mode 100644 Documentation/ABI/testing/tsem
 create mode 100644 Documentation/admin-guide/LSM/tsem.rst
Documentation/ABI/testing/tsem new file +0 -0
new file mode 100644
index 000000000000..0e0e3201edf4

Documentation/ABI/testing/tsem line 8

Quoted 8 lines
Documentation/ABI/testing/tsem new file +8 -0
@@ -0,0 +1,2420 @@
+This file contains descriptions of output generated by the TSEM
+control plane files and the role of the only write-only file in the
+control plane.
+
+It is highly recommended that the following document be read in order
+to fully understand the rationale and functioning of these files:
+
+Documentation/admin-guide/LSM/tsem.rst

Will do ...

Quoted 22 lines
Documentation/admin-guide/LSM/tsem.rst new file +16 -0
new file mode 100644
index 000000000000..1c69a5cb7517
@@ -0,0 +1,1680 @@
+====
+TSEM
+====
+
+	"This is the story of the wine of Brule, and it shows what
+	 men love is never money itself but their own way, and
+	 that human beings love sympathy and pageant above all
+	 things."
+				- Hilaire Belloc
+				  The Path to Rome
+
+TSEM is the Trusted Security Event Modeling system.  TSEM is the
+kernel LSM based infrastructure that provides a platform for
+implementing model based mandatory access controls.  TSEM is model
+agnostic and is designed to support deterministic, quasi-deterministic
+and machine learning models.

...

Quoted 48 lines
Documentation/admin-guide/LSM/tsem.rst new file +48 -0
+Security Event Modeling
+=======================
+
+	"We can no longer speak of the behavior of the particle
+	 independently of the process of observation. As a final
+	 consequence, the natural laws formulated mathematically in
+	 quantum theory no longer deal with the elementary particles
+	 themselves but with our knowledge of them. Nor is it any
+	 longer possible to ask whether or not these particles exist in
+	 space and time objectively ... When we speak of the picture of
+	 nature in the exact science of our age, we do not mean a
+	 picture of nature so much as a picture of our relationships
+	 with nature.  ...Science no longer confronts nature as an
+	 objective observer, but sees itself as an actor in this
+	 interplay between man and nature. The scientific method of
+	 analysing, explaining and classifying has become conscious of
+	 its limitations, which arise out of the fact that by its
+	 intervention science alters and refashions the object of
+	 investigation. In other words, method and object can no longer
+	 be separated."
+				- Werner Karl Heisenberg
+
+Security Event Modeling (SEM), is an alternative strategy to implement
+the security guarantees of mandatory access and integrity controls, in
+a manner that is consistent with emerging application development
+strategies such as namespaces and CI/CD workflows.
+
+As was noted at the start of this document, the premise for SEM is
+that the security behavior of a platform, or alternatively a workload,
+can be modeled like any other physical phenomenon in science and
+engineering.
+
+Inspiration for this came from the primary TSEM author/architect
+having trained as a quantum chemist, conducting very early research in
+the development of multi-scale modeling strategies for molecules of
+size to be of interest to pharmaceutical intents.
+
+SEM is premised on the theory that kernel security architects have
+instrumented the LSM security event hooks to be called in locations
+before security sensitive operations are conducted, with appropriate
+descriptive parameters, that are considered relevant to the security
+posture of the kernel.  With respect to modeling, the security event
+hooks are conceptualized as representing the independent variables of
+a basis set that yields a functional definition for the security state
+of an execution trajectory.
+
+SEM can be framed in the context of classic subject/object mandatory
+access controls, by the notion that a unique identity can be generated

Documentation/admin-guide/LSM/tsem.rst line 272

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+for each element of an access vector matrix, rather than a boolean
+value.  In SEM, a security execution trajectory is defined by the set
+of security state coefficients that a process hierarchy (workload)
+generates.  This execution trajectory produces a vector of identities,
+whose sum in an appropriate form, yields a functional definition of
+the security state of the system.
+
+Two subordinate identities are combined to yield a security event
+state coefficient.  These subordinate identities are referred to as
+the Context Of Execution (COE) and the CELL, which are conceptually

Please define the CELL acronym here as I believe it is the first use of "CELL" in this document.

Quoted 26 lines
Documentation/admin-guide/LSM/tsem.rst new file +26 -0
+similar to the subject and object in mandatory access control.  The
+COE identity is derived from the parameters that describe the security
+relevant characteristics (ie. credentials) of a process, while the
+CELL value is derived from the parameters used by a security event
+hook to describe the characteristics of the event.
+
+A security policy is implemented by a modeling algorithm that
+translates COE and CELL event parameters into their respective
+identities.  The COE and CELL are combined to yield a security state
+coefficient that uniquely describes the security event in the security
+model.  Different security policies and criteria can be developed by
+modifying how the modeling algorithm utilizes the COE and CELL
+characteristics.
+
+Since the security policy is implemented with a modeling algorithm, a
+single platform can support multiple and arbitrary security policies.
+The equivalent of a resource namespace in SEM is referred to as a
+security modeling namespace.
+
+The formation of the security state coefficients from existing kernel
+parameters eliminates the need for the use of extended attributes to
+hold security label definitions.  In SEM, a cryptographically signed
+security model definition, designed to be interpreted by a modeling
+algorithm, becomes the bearer's token for the security of the modeled
+workload, rather than information encoded in filesystem security
+attributes.

...

Quoted 31 lines
Documentation/admin-guide/LSM/tsem.rst new file +31 -0
+Process and Platform Trust Status
+=================================
+
+A fundamental concept in TSEM is the notion of providing a precise
+definition for what it means for a platform or workload to be trusted.
+A trusted platform or workload is one where there has not been an
+attempt by a process to execute a security relevant event that does
+not map into a known security state coefficient.
+
+The process trust status is a characteristic of the process that is
+passed to any subordinate processes that are descendants of that
+process.  Once a process is tagged as untrusted, that characteristic
+cannot be removed from the process.  In a 'fruit from the poisoned
+vine' paradigm, all subordinate processes created by an untrusted
+process are untrusted as well.
+
+On entry into each TSEM security event handler, the trust status of a
+process is checked before an attempt to model the event is made.  An
+attempt to execute a security event by an untrusted process will cause
+the event, and its characteristics, to be logged.  The return status
+of the hook will be determined by the enforcement state of the model.
+A permission denial is only returned if the TMA is running in
+enforcing mode.
+
+If the platform running the TSEM LSM has a TPM, the hardware aggregate
+value is computed at the time that TSEM is initialized.  This hardware
+aggregate value is the linear extension sum over Platform
+Configuration Registers (PCR's) 0 through 7.  This is the same
+aggregate value that is computed by the Integrity Measurement
+Architecture (IMA) and is the industry standard method of providing an
+evaluation measurement of the hardware platform state.

Documentation/admin-guide/LSM/tsem.rst

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+
+Internally modeled namespaces have the hardware aggregate measurement
+included as the first event in the security model.  Externally modeled
+namespaces export the hardware aggregate value to the TMA for
+inclusion as the first event of the model maintained by the external
+TMA.
+
+The root security model extends each security state coefficient into a
+PCR.  The default PCR is 11 but is configurable through the kernel
+compilation configuration process.

Presented here simply as a FYI:

https://uapi-group.org/specifications/specs/linux_tpm_pcr_registry

I'm not going to recommend any one particular PCR, but I thought the "registry" info above might be useful when trying to avoid PCR collisions.

Quoted 35 lines
Documentation/admin-guide/LSM/tsem.rst new file +35 -0
+The use of a separate PCR from IMA
+allows hardware based TSEM measurements to coexist with IMA
+measurement values.  This hardware measurement value is designed to
+allow attestation to the hardware state that the root model is running
+in.
+
+TSEM is designed to support a philosophy where the root security
+modeling namespace will be a minimum Trusted Computing Base
+implementation that will only be running trust orchestrators and any
+other infrastructure needed to support running workloads in
+subordinate security namespaces.
+
+The subordinate security modeling namespaces are designed to decrease
+model complexity in order to support a single functional value
+describing the 'known good' security state of a subordinate security
+workload.  Subordinate security modeling namespaces are
+non-hierarchical, ie. a security modeling namespace cannot itself
+parent an additional security modeling namespace.
+
+The Linux TSEM Implementation
+=============================
+
+	"Sometimes the questions are complicated and the answers are
+	 simple."
+				- Dr. Seuss
+
+The Linux TSEM implementation is deliberately simplistic and consists
+of the following two generic components:
+
+- Security modeling namespace and security event export functionality.
+
+- Internal trusted modeling agent implementation.
+
+The security modeling namespace and export functionality is designed
+to be generic infrastructure that allows security namespaces to be

Documentation/admin-guide/LSM/tsem.rst line 512

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+created that are either internally or externally modeled.  The TSEM
+implementation does not pose any constraints on what type of modeling
+can or should be implemented in these namespaces.
+
+On the theory that security event handlers represent all of the
+security relevant action points in the kernel, any security or
+integrity model can be implemented using the TSEM infrastructure.  For
+example, basic IMA functionality could be implemented by a TMA that
+maps the digests of files accessed, or mapped executable, by the root
+user as the security state coefficients.

In order to keep the peace among different LSMs, we try very hard to avoid language along the lines of "LSM A could be implemented by LSM B". Please refrain from such language, especially in documentation that lives within the kernel.

Documentation/admin-guide/LSM/tsem.rst line 519

Quoted 6 lines
Documentation/admin-guide/LSM/tsem.rst new file +6 -0
+A primary intent of the Linux TSEM implementation is to provide a
+generic method for implementing security policy in userspace rather
+than the kernel.  This is consistent with what has been the historic
+understanding in Linux architecture, that policy decisions should be
+delegated, when possible, to userspace rather than to kernel based
+implementations.

[NOTE: Feel free to ignore the paragraph below, you addressed the issue
of non-blocking access control hooks in externally modeled namespaces later in this document.]

If I recall correctly, previous reviews that looked briefly at the TSEM implementation brought up an issue where several LSM/TSEM decision points in the kernel were non-blocking, which presents a problem for TSEM, or any LSM that wishes to call out to userspace for an access control decision. At the time of the review, I believe the TSEM answer was, in broad terms, "TODO". Has this been resolved yet through some change to TSEM, or am I simply remembering things incorrectly and TSEM has always handled this case properly?

Quoted 29 lines
Documentation/admin-guide/LSM/tsem.rst new file +29 -0
+The model is extremely simplistic; a TMA interprets a security event
+and its characteristics and advises whether or not the kernel should
+designate the process as trusted or untrusted after event processing
+is complete.
+
+The following sections discuss various aspects of the infrastructure
+used to implement this architecture.
+
+Internal vs external modeling
+-----------------------------
+
+When a TSEM security modeling namespace is created, a designation is
+made as to whether the namespace is to be internally or externally
+modeled.
+
+In an internally modeled namespace, the security event handlers pass the
+event type and its characteristics to the designated internal trusted
+modeling agent.  The agent provides the permission value for the
+security event handler to return as the result of the event and sets
+the trust status of the process executing the event.
+
+In an externally modeled namespace, the event type and parameters are
+exported to userspace for processing by a trust orchestrator with an
+associated TMA.  The trust orchestrator communicates the result of the
+modeling back to the kernel to support the setting of the process
+trust status.
+
+The exception to this model are for security event handlers that are
+called in atomic, ie. non-sleeping context.  The export of these

Documentation/admin-guide/LSM/tsem.rst line 559

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+security event descriptions are done asynchronously in order to avoid
+having the TSEM implementation attempt to sleep in atomic context
+while the userspace trust orchestrator is scheduled for execution.
+
+It is up to the trust orchestrator and its security policy to
+determine how it handles events that violate the security model being
+enforced in this model.  The Quixote trust orchestrators shut down the
+entire workload running in the security namespace if an asynchronously
+modeled event violates the security model being enforced and the model
+is running in enforcing mode.

I understand your desire to simply pass off the non-blocking/async access control hole as a security policy issue, but it seems to me that this is a fundamental flaw with an externally modeled TSEM namespace. If an externally modeled namespace was configured with an enforcing policy, it doesn't appear that there is a mechanism for TSEM to properly enforce that policy as there is an unbounded delay between the undesired access and a denial verdict being processed by the kernel.

Unless you can resolve this somehow, and I'm not sure how, I would suggest dropping external/userspace trust orchestrators. They simply don't seem able to reliably implement their security policies.

Documentation/admin-guide/LSM/tsem.rst line 572

Quoted 12 lines
Documentation/admin-guide/LSM/tsem.rst new file +12 -0
+Internally modeled domains are able to provide immediate interception
+and modification of the trust status of a process that is violating
+the security model.  This has implications for the root security
+namespace that is running on a system with a TPM, since the security
+event coefficients are logged to the Platform Configuration Register
+that is being used by TSEM.
+
+Issuing the TPM transaction would cause the process to attempt to
+sleep while it waits for the TPM command to complete.  In order to
+address this issue, the TPM transactions are deferred to an ordered
+workqueue for execution.  The use of an ordered workqueue maintains
+the time dependency of the security coefficients being registered.

I would suggest removing the "time dependency" phrase and focus on the workqueue preserving the ordering of the TPM transactions.

Documentation/admin-guide/LSM/tsem.rst line 584

Quoted 11 lines
Documentation/admin-guide/LSM/tsem.rst new file +11 -0
+In order to handle modeling of security events in atomic context, the
+TSEM implementation maintains caches (magazines) of structures that
+are needed to implement the modeling and export of events.  The size
+of this cache can be configured independently for each individual
+security modeling namespace that is created.  The default
+implementation is for a cache size of 32 for internally modeled
+namespaces and 128 for externally modeled namespaces.
+
+By default the root security namespace uses a cache size of 128.  This
+value can be configured by the 'tsem_cache' kernel command-line
+parameter to an alternate value.

I haven't looked at the implementation yet, but I don't understand both why a kmem_cache couldn't be used here as well as why this implementation detail is deemed significant enough to be mentioned in this high level design document.

Quoted 4 lines
Documentation/admin-guide/LSM/tsem.rst new file +4 -0
+Trust Orchestrator/Process authentication
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The process identifier values (PID's) that are exported in the

Documentation/admin-guide/LSM/tsem.rst line 599

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+security event descriptions are the unique global PID values, not the
+value as seen through the lens of a PID namespace.
+
+PID values are, by default, not considered to be a stable identifier
+between the kernel and userspace.  In the case of TSEM external
+modeling, the threat model for a namespace is whether or not an
+adversarial process, running in either the root security modeling
+namespace or another subordinate security modeling namespace, can kill
+a process that is being orchestrated and substitute an alternate
+process with an identical PID value.

We've talked about this previously, but given my current understanding of TSEM, one of my concerns is the presence of user controlled data in a TSEM security event. This could include PIDs, task->comm values, and potentially others (I haven't gone through the full CELL list yet).

Documentation/admin-guide/LSM/tsem.rst

Quoted 8 lines
Documentation/admin-guide/LSM/tsem.rst new file +8 -0
+The suggested threat model would be that the orchestrator would set
+the trust status of the adversarial process rather than the one that
+had emitted the security event characteristics.  The threat interval
+is the latency time required for the processing of the security event
+description by the trust orchestrator and its associated TMA.
+
+Exploiting this theoretical race is extremely complex and requires an
+in depth understanding of the TSEM architecture.

I don't believe we want to accept a LSM with race conditions, even theoretical ones. One can argue how likely such a race condition would be in practice, but the audeience here is too samll, the future too unpredictable, and the adversaries too clever for such a debate to be very meaningful.

At this point in the development process, there is an opportunity to design away all race conditions, even the theoretical ones, let's do that while we can.

Quoted 35 lines
Documentation/admin-guide/LSM/tsem.rst new file +35 -0
+Rather than discuss
+the conditions that must be met and their implications, this
+discussion will first focus on the generic threat model and its
+generic utility to an adversary followed by a treatment of the
+mechanisms that TSEM implements in order to mitigate this threat.
+
+In short, a process in an adversarial security modeling namespace
+would want to execute security events that are barred from its
+security model with the hope of having them approved by an alternate
+namespace.
+
+A process waiting for the external modeling of a security event
+description can only be placed back into run state by two methods:
+reception of a fatal signal or the TRUST_PENDING status bit being
+cleared from its TSEM specific task control structure by a trust
+orchestrator.
+
+If a process being evaluated receives a fatal signal, its trust status
+will be set to untrusted and an error will be returned to the trust
+orchestrator.  The error would cause a trust violation to be
+registered for the workload.  In addition, the evaluation of the event
+would be terminated, so a replacement process would not receive an
+incorrect trust assessment for an event that was initiated by its
+predecessor.
+
+The second issue that limits the utility of a PID substitution attack
+is that from the point of substitution forward it would place the
+replacement process in the context of the security model that the
+trust orchestrator is enforcing.  As a result, a substituted process
+would not be allowed to exhibit any security behaviors inconsistent
+with the model being enforced.
+
+If an attempt to exploit this race would be considered, an adversarial
+process would have to force the termination of a process in the target
+namespace and then fork and exit a process a sufficient number of

Documentation/admin-guide/LSM/tsem.rst line 652

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+times in order to have a process under its control match the PID value
+of the process that was waiting for an orchestration response.
+
+Measured modeling latency times for a trust orchestrator running the
+deterministic Quixote TMA in userspace, on current generation x86_64
+hardware, averages 170 micro-seconds.  In a worst case scenario from
+the perspective of an adversary, there would be a need to force the
+termination of the target process and then fork and execute a
+sufficient number of times to force the PID collision during this time
+interval.

It is best not to rely on hardware performance to mitigate security concerns, at some point or with some configuration, you will be wrong.

Quoted 147 lines
Documentation/admin-guide/LSM/tsem.rst new file +147 -0
+As a generic protection, TSEM in the tsem_task_kill() handler, blocks
+the notion of 'cross-model' signals, ie. a signal originating from an
+external security modeling namespace.  This would require the
+adversary to reliably force a process termination through a mechanism
+other than signaling, for example, through the OOM killer whose signal
+transmission would not be blocked by this policy control.
+
+When a subordinate security modeling namespace is created, the id
+number of the namespace is registered in the tsem_task structure of
+the trust orchestrator that is creating the namespace.  The TSEM
+driver will refuse to honor control plane requests affecting the trust
+status of a process whose trust orchestrator security namespace id
+does not match the namespace identifier of the process that it is
+being asked to act on.
+
+As an additional protection, TSEM uses an authentication strategy that
+allows a process running in a security modeling namespace to verify
+that a control request is coming from the trust orchestrator that
+initiated the namespace the process is running in.  As part of the
+setup of a security modeling namespace, a trust orchestrator is
+required to provide an ASCII hexadecimally encoded authentication key
+that matches the length of a digest value of cryptographic hash
+function being used to generate security state coefficient in the
+security modeling namespace.  This authentication key must be provided
+by the trust orchestrator for every subsequent control plane request.
+
+The process that is being transferred to a subordinate security
+modeling namespace generates a second random key that is hashed with
+the authentication key provided by the trust orchestrator, using the
+hash function that has been defined for the security namespace.  The
+resultant digest value is compared to a list of authentication keys
+for all currently executing namespaces.  The selection of the second
+random key is repeated until a globally unique key is generated.
+
+This randomly generated authentication key is stored in the tsem_task
+structure of the process and propagated to any subsequent processes
+that are created in the namespace.  The hash product of this key and
+the orchestration authentication key, ie. the globally unique key, is
+placed in the tsem_task control structure of the orchestration
+process.
+
+When a control plane request is received, the authentication key
+provided by the trust orchestrator is used to re-generate an
+authentication key based on the randomly generated namespace key held
+by the process whose trust status is being updated.  The generated
+authentication key is compared to the key in the tsem_task structure
+of the process issuing the orchestration call.  The control plane will
+refuse to honor a control plane request if the call specific key that
+is generated does not match the key generated at the time the security
+namespace was created.
+
+Event modeling
+--------------
+
+The generation of security state coefficients is a functional process
+that uses a cryptographic hash function for the creation of the
+individual identity mappings that contribute to the generation of the
+security state coefficient.
+
+TSEM can use any cryptographic hash function available to the Linux
+kernel for this purpose.  The hash function to be used for a security
+modeling namespace is specified as a parameter to the namespace
+creation process.
+
+By default, the root security namespace uses sha256.  This value can
+be modified through the tsem_digest kernel command-line parameter.
+
+Since TSEM is active before the kernel has the ability to load
+modules, the root modeling domain must be a cryptographic hash
+function that is statically compiled into the kernel.  By default the
+TSEM configuration selects for the presence of the sha256 hash
+function.
+
+TSEM security event modeling is based on the following functional
+definition for a security event coefficient:
+
+Coeff = HF(HF(EVENT_ID) || PTASK_ID || TASK_ID || HF(COE) || HF(CELL))
+
+	Where:
+		Coeff	 = A security state coefficient that is equal
+			   in length to the digest value of the
+			   cryptographic hash function in use for the
+			   security modeling namespace.
+
+		HF	 = Security namespace specific hash function.
+
+		||       = Concatenation operator.
+
+		EVENT_ID = The ASCII name of event.
+
+		PTASK_ID = The TASK_ID of the parent process of the
+			   process represented by TASK_ID.
+
+		TASK_ID  = The process specific identity of the
+			   executable code that is calling the security
+			   event handler.
+
+		COE      = Characteristics of the context of execution
+			   of the event.
+
+		CELL	 = Characteristics of the LSM event that is being
+			   modeled.
+
+Workload or platform specific security state coefficient definitions
+are generated by a TMA, using the COE or CELL characteristics that are
+considered relevant for the model being implemented.  These
+coefficients are used to determine whether or not an event should lead
+to the process being considered trusted or untrusted.
+
+The TASK_ID component of the function above is important with respect
+to the generation of the security state coefficients.  The notion of a
+task identity serves to link the concepts of system integrity and
+security access control.
+
+The TASK_ID is defined by the following function:
+
+TASK_ID = HF(HF(EVENT) || PTASK_ID || NULL_ID || HF(COE) || HF(CELL))
+
+	Where:
+		TASK_ID	  = The executable identity of the process
+			    expressed as a digest value of length
+			    equal to the cryptographic hash function
+			    the security modeling namespace is using.
+
+		HF	  = Security namespace specific hash function.
+
+		||        = Concatenation operator.
+
+		EVENT	  = The string "bprm_committed_creds".
+
+		PTASK_ID  = The TASK_ID of the parent process of the
+			    process whose TASK_ID is being generated.
+
+		NULL_ID	  = A buffer of null bytes equal to the digest
+			    size of the hash function being used for
+			    the namespace.
+
+		COE	  = Characteristics of the context of execution
+			    calling the bprm_committed_creds LSM hook.
+
+		CELL	  = The characteristics of the file provided
+			    by the linux_binprm structure passed to
+			    the security_bprm_committed_creds handler.
+
+An attentive reader will quickly conclude, correctly, that the TASK_ID
+function generates an executable specific security coefficient for the
+bprm_committed_creds security hook.  The generative function for the

Documentation/admin-guide/LSM/tsem.rst line 810

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+TASK_ID is the same as the standard security state coefficient; with
+the exception that the task identity is replaced with a 'null id',
+consisting of the number of null bytes in the digest size of the
+namespace specific hash function.
+
+One of the CELL characteristics used in the computation of the task
+identity is the digest of the executable file.  Modifying an
+executable, or attempting to execute a binary not considered in the
+security model, will result in an alteration of the task identity that
+propagates to the generation of invalid state coefficients.

Presumably an attacker could craft a malicious executable (or influence the CELL value if it incorporates user controlled values) that collides with the digest of a known and trusted application.

Quoted 153 lines
Documentation/admin-guide/LSM/tsem.rst new file +153 -0
+The task identity is saved in the TSEM specific task structure and is
+used to compute the state coefficients for any security events that
+the task subsequently executes.  As noted in the previous paragraph,
+incorporating the TASK_ID into the computation of security state
+coefficients results in the security state coefficient values becoming
+specific to the corpus of executable code that initiated a process.
+This affords a very high degree of specificity with respect to the
+security models that can be implemented.
+
+As was demonstrated in the TBDHTTRAD section, in contrast to standard
+digest based controls, TSEM will discriminate the following commands
+as different events/coefficients in a security model:
+
+cat /etc/shadow
+
+grep something /etc/shadow
+
+while read input
+do
+	echo $input;
+done < /etc/shadow
+
+An important, and perhaps subtle issue to note, is how these events
+result in the change of process trust status.  In the first two cases,
+if access to the /etc/shadow file is not permitted by the operative
+security model, the cat and grep process will become untrusted.
+
+In the third example, the shell process itself would become untrusted.
+This would cause any subsequent attempts to execute a binary to be
+considered untrusted events, even if access to the binary is a
+permitted coefficient in the model.
+
+The integration of the PTASK_ID in the generation of the security
+state coefficients causes the coefficients to be dependent on the
+chain of execution of executable code.  This concept generates
+extremely specific security coefficients that yield the high
+sensitivity of TSEM based security models.
+
+For example, consider the following chain of execution:
+
+init/systemd -> sshd -> bash
+
+init/systemd -> getty -> bash
+
+Even if the COE characteristics (credentials) of the two bash
+processes are identical, the security coefficients generated by the
+two bash shells will be different.  This is secondary to the fact that
+the TASK_ID of the two bash processes will be different by virtue of
+the fact that the first bash process will have a PTASK_ID that
+represents the TASK_ID of the ssh process, while the second process
+will have a PTASK_ID that represents the TASK_ID of the getty process.
+
+This generative functions provides a framework for modeling that
+yields very precise tracking of security relevant events.  This is
+significant with respect to detecting and addressing adversarial
+techniques such as Living Off The Land (LOTL).
+
+Since the modeling operates at the level of a mandatory security
+control, these permission denials would occur even if the process is
+running with classic root privilege levels.  This is secondary to the
+notion that security and trust status are invested in the trust
+orchestrator and ultimately the TMA.
+
+From a hardware perspective, this is important with respect to the
+notion of a TMA being a model for a successor to the TPM.  From a
+system trust or integrity perspective, a TPM is designed to provide a
+retrospective assessment of the actions that have occurred on a
+platform.  A verifying party uses the TPM event log and a PCR based
+summary measurement, to verify what actions have occurred on the host,
+in order to allow a determination of whether or not the platform
+should be 'trusted'.
+
+In contrast, a TSEM/TMA based system enforces, on a real time basis,
+that a platform or workload remains in a trusted state.  Security
+relevant actions cannot be conducted unless the TMA authorizes the
+actions as being trusted.
+
+This is particularly important with respect to embedded systems.  A
+TPM based architecture would not prevent a system from having its
+trust status altered.  Maintaining the system in a trusted state would
+require attestation polling of the system, and presumably, executing
+actions if the platform has engaged in untrusted behavior.
+
+Conversely, a trust orchestrated software implementation enforces that
+a system or workload remain in a security/trust state that it's
+security model was unit tested to.
+
+Security model functional definitions
+-------------------------------------
+
+Previously, classic trusted system implementations supported the
+notion of the 'measurement' of the system.  The measurement is the
+value of a linear extension function of all the security relevant
+actions recorded by a trust measurement system such as IMA.
+
+In TPM based trust architectures, this measurement is maintained in a
+PCR.  A measurement value is submitted to the TPM that extends the
+current measurement using the following formula:
+
+MEASUREMENT = HF(CURRENT || NEW)
+
+	Where:
+		MEASUREMENT = The new measurement value to be maintained
+			      in the register for the system.
+
+		HF	    = A cryptographic hash function supported
+			      by the TPM device.
+
+		||	    = Concatenation operator.
+
+		CURRENT     = The current measurement value.
+
+		NEW	    = A new measurement value to be added to
+			      the current measurement.
+
+The use of a cryptographic function produces a non-commutative sum
+that can be used to verify the integrity of a series of measurements.
+With respect to security modeling theory, this can be thought of as a
+'time-dependent' measurement of the system.  Stated more simply, the
+measurement value is sensitive to the order in which the measurements
+were made.
+
+In systems such as IMA, the measurement value reflects the sum of
+digest values of what are considered to be security critical entities,
+most principally, files that are accessed or memory that is mapped
+executable, based on various policies.
+
+In TSEM based TMA's, the measurement of a security modeling namespace
+is the sum of the unique security state coefficients generated by the
+security model being enforced.  As previously noted, on systems with a
+TPM, the root security modeling namespace measurement is maintained by
+default in PCR 11 or the PCR that was selected at kernel configuration
+time.
+
+The challenge associated with classic integrity measurements is the
+time dependent nature of using a non-commutative summing function.
+The almost universal embrace of SMP based hardware architectures, in
+addition to standard kernel task scheduling issues, makes the
+measurement values non-deterministic.  This requires a verifying party
+to evaluate an event log, verified by a measurement value, to
+determine whether or not the system is in a security appropriate or
+trusted state.
+
+TSEM addresses this issue by implementing a strategy designed to
+produce a single functional value that represents the functional
+security state of a model.  This allows a TMA to attest to the
+trust/security status of a platform or workload by signing this
+singular value and presenting it to a verifying party.
+
+In TSEM nomenclature, this functional value is referred to as the
+'state' of the model.  The attestation model is to use trust
+orchestrators to generate the state value of a workload by unit
+testing.  This state value can be packaged with a utility or container

Documentation/admin-guide/LSM/tsem.rst line 974

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+to represent a summary trust characteristic that can be attested by a
+TMA, eliminating the need for a verifying partner to review and verify
+an event log.
+
+TMA's implement this architecture by maintaining a single instance
+vector of the set of unique security state coefficients that have been
+experienced in a security modeling namespace.  The state measurement
+is generated by sorting the security state coefficient vector in
+big-endian hash format and then generating a standard linear extension
+measurement over this new vector.

There are cases where ordering of events is important when assessing the security state of the system, e.g. disabling/enabling security features. In these cases where ordering is necessary to attest the security state of the system, is there some middle ground, or does an admin need to revert to a "classic" orderered measurement?

Documentation/admin-guide/LSM/tsem.rst line 985

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+Any security event that generates an associated state coefficient that
+is not in the model will resulted in a perturbed state function value.
+That perturbed value would be interpreted by a verifying party as an
+indication of an untrusted system.
+
+Since the TMA maintains the security event descriptions in time
+ordered form, the option to provide a classic event log and
+measurement are preserved and available.  Extensive experience in the
+development of TSEM modeled systems has demonstrated the superiority
+of state value interpretation over classic measurement schemes.

I don't disagree that working with the pre-sorted measurement is far easier, I just wonder how many systems would be able to give up on the event ordering to have the simplified modeling. Surely we will all have different experiences here, but I'm not sure the pre-sorted measurement approach would have been acceptable in many of the projects I've worked on over the years.

Quoted 34 lines
Documentation/admin-guide/LSM/tsem.rst new file +34 -0
+A TMA may choose to incorporate a 'base nonce' into a security model
+that it is implementing, this base nonce is designed to serve in a
+manner similar to an attestation nonce.  If used, the trust
+orchestrator is responsible for negotiating a random base nonce with a
+verifying party at the time of initialization of a security modeling
+namespace and providing it to the TMA.
+
+The TMA uses the base nonce to extend each security event coefficient
+that is generated by the model.  This causes the state and measurement
+values of the model to become dependent on this base nonce, a process
+that can be used to defeat a replay attack against the security model.
+
+Control plane
+-------------
+
+Both primary functions of TSEM: security modeling namespace management
+and the internal TMA modeling implementation, are controlled by
+pseudo-files in the securityfs filesystem.  The following directory
+is the top level implementation directory for the TSEM control plane:
+
+/sys/kernel/security/tsem
+
+The following file in the kernel source tree documents, in detail,
+the interfaces provided by the filesystem:
+
+Documentation/ABI/testing/tsem
+
+This filesystem is primarily intended for use by trust orchestrators
+to create and manage security modeling namespaces.
+
+The files are process context sensitive.  Writing to the control file,
+or reading from the informational files, will act on or reference the
+security modeling namespace that the accessing process is assigned to.
+

Documentation/admin-guide/LSM/tsem.rst

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+The following files are provided in the root directory of the TSEM
+control plane and implement global controls for the TSEM LSM:
+
+	aggregate
+	id
+	control
+
+The 'aggregate' file is used by trust orchestrators for internally
+modeled namespaces to obtain the hardware measurement value for
+inclusion in a security model.

So I'm clear on this, internally modeled namespaces still access the hardware measurement directly from inside the kernel, yes? In the interally modeled case this is simply available as a reference, and the in-kernel TMA doesn't call out to userspace to access this value, yes?

Quoted 23 lines
Documentation/admin-guide/LSM/tsem.rst new file +23 -0
+A trust orchestrator for an externally
+modeled namespace capture this value as the first event generated by a
+security modeling namespace.
+
+The 'id' file is used to determine the security modeling namespace
+that the process is running in.  The namespace id value of 0 is
+reserved for the root security modeling namespace, a non-zero value
+indicates that the process is running in a subordinate security
+modeling namespace.
+
+The TSEM implementation is controlled by the only writable file, which
+is the 'control' file.
+
+The following keywords are used by trust orchestrators to place the
+process writing to the file in an internally or externally modeled
+security namespace:
+
+	internal
+	external
+
+Each argument accepts key=value pairs that configure the namespace.
+The following key values are currently accepted:
+

Documentation/admin-guide/LSM/tsem.rst

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+	model
+	nsref
+	digest
+	cache
+	key
+
+The 'model' keyword takes as an argument the name of a loadable module
+that will be used to implement the event processing for a security
+modeling namespace.  If the module has not already been loaded, TSEM
+will attempt to dynamically load the module.

I'm still sorting out the stuff in the docs and haven't gotten to the implementation yet, but just so we're clear on the details about TSEM modules, TSEM shouldn't attempt to sidestep the LSM framework as TOMOYO did recently and we later had to revert.

Considering that TSEM is likely to want to be active before enough of a userspace exists to load a module (see the previous sections on hash functions), it seems like the best option is to simply include all of the desired internal TMAs in the kernel at build time.

Quoted 43 lines
Documentation/admin-guide/LSM/tsem.rst new file +43 -0
+If the standard practice
+is followed of using the KBUILD_MODNAME CPP define to set the name of
+the security model, the argument to the model keyword will be that
+name, a value that will match the name that is displayed by the lsmod
+command.  It should be noted that there is no requirement that the
+security model name match the name of the module generated by the
+build process.
+
+The 'nsref' keyword takes one of the following two values:
+
+	initial
+	current
+
+The initial argument indicates that the UID/GID values for the COE and
+CELL characteristics are derived from the initial user namespace.
+This is the default characteristic if the nsref key is not specified.
+
+The current argument indicates that the UID/GID values are derived
+from the user namespace that the process is running in, when the
+request is made to model an event.
+
+The 'digest' keyword is used to specify the cryptographic hash
+function that is to be used to create the functional values for the
+security state coefficients for the namespace.  The value to this
+keyword is the name by which the hash function is defined by the
+cryptographic API in the kernel.
+
+Examples of suitable strings are as follows:
+
+	sha256
+	sha3-256
+	sm3
+
+Definitions for the names of the cryptographic hashes can be found in
+the source files for the various cryptographic hash functions in the
+'crypto' directory of the Linux source tree.
+
+The 'cache' keyword is used to specify the size of the caches used to
+hold pointers to data structures used for the internal modeling of
+security events or the export of the security event to external trust
+orchestrators.  These pre-allocated structures are used to service
+security event hooks that are called while the process is running in
+atomic context and thus cannot sleep in order to allocate memory.

Documentation/admin-guide/LSM/tsem.rst line 1114

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+
+The argument to this keyword is a numeric value specifying the number
+of structures that are to be held in reserve for the namespace.
+
+By default the root security modeling namespace and externally modeled
+namespaces have a default value of 128 entries.  An internally modeled
+namespace has a default value of 32 entries.  The size requirements of
+these caches can be highly dependent on the characteristics of the
+modeled workload and may require tuning to the needs of the platform
+or workload.

Presumably TSEM provides usage statistics somewhere so admins can monitor and tune as desired? If so, it seems like it would be a good idea to add a reference here.

Documentation/admin-guide/LSM/tsem.rst line 1119

Quoted 4 lines
Documentation/admin-guide/LSM/tsem.rst new file +4 -0
+The structures that are used by security events generated in atomic
+context are replenished by work requests submitted to the high
+priority system workqueue.  The refill latency will also affect the
+magazine sizes that are needed.

Once again, it seems like a kmem_cache could be useful.

Quoted 11 lines
Documentation/admin-guide/LSM/tsem.rst new file +11 -0
+The 'key' keyword is used to specify the authentication key that is to
+be used to support the authentication of trust control requests from a
+trust orchestrator to processes running in a security modeling
+namespace.  The argument to this keyword is the ASCII base16
+representation of the key that is to be used.  The length of the key
+must be equal to the length of the ASCII base16 representation of the
+digest value of the cryptographic digest function defined for the
+security modeling namespace.
+
+The following keywords and arguments are used by trust orchestrators
+to set the trust status of a process after the processing of a

Documentation/admin-guide/LSM/tsem.rst

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+security event by an external TMA:
+
+	trusted pid=PID key=HEXID
+	untrusted pid=PID key=HEXID
+
+	PID is the process identifier that is provided to the TMA in
+	the security event description.  HEXID is the base16 ASCII
+	representation of the authentication key that the security
+	modeling namespace was configured with when the namespace was
+	created.

This is something that will likely have to wait until the review progresses further down into the implementation as it raises a fair number of red flags. To be fair, it is possible they are false warnings, but judgement on this will have to wait until the other major concerns from the doc review have been addressed in some way.

Quoted 168 lines
Documentation/admin-guide/LSM/tsem.rst new file +168 -0
+     The length of the ASCII representation of HEXID must
+	equal the size of the base16 ASCII representation of a digest
+	value for the cryptographic hash function selected for the
+	security modeling namespace.
+
+By default a security modeling namespace runs in free modeling mode.
+The modeling mode is changed by writing the following keywords to the
+control file:
+
+	seal
+	enforce
+
+The seal value is used to specify that any further security state
+coefficients are to be considered outside the bounds of a desired
+security model.  The security event descriptions that generate these
+coefficients will be considered forensics events for the model.
+
+The enforce key is used to specify that invalid security events
+generate permission denials as the return value for the LSM security
+event handler that generates the invalid events.
+
+The following keyword and argument are used to load a security model
+into an internal TMA modeling implementation:
+
+	state value=HEXID
+
+	Where HEXID is the ASCII base 16 representation of a security
+	state coefficient that represents a valid security event in
+	the model.  The length of the HEXID string must be equal to
+	the size of the ASCII base 16 representation of the digest
+	value of the cryptographic hash function defined for the
+	security modeling namespace.
+
+	After writing a series of state values the trust orchestrator
+	writes the 'seal' keyword to the control file to complete
+	creation of a security model.
+
+	Writing the 'enforce' keyword to the control file will place
+	the defined model in enforcing mode.
+
+	Defining a security model to be enforced will affect the
+	output of the 'trajectory' file.  The 'trajectory' file will
+	have no event descriptions for a sealed model, since the event
+	description list is only populated when a new state
+	coefficient is added to the model.
+
+	In a sealed model the security event descriptions will be
+	surfaced in the 'forensics' file instead to indicate they are
+	violations against the security model being enforced.
+
+	Since the state state coefficients are generated with a
+	cryptographic hash function, the first pre-image resistance
+	characteristics of the function prevents a security model
+	description from disclosing information, a-priori, about the
+	desired characteristics of the workload.
+
+The following keyword and argument is used to set a base nonce for the
+internal TMA:
+
+	base value=HEXID
+
+	Where HEXID is the ASCII base 16 representation of a value
+	that each security state event mapping is to be extended with
+	before being committed as a security state coefficient value
+	for the model.  The size of the HEXID string must equal the
+	size of the ASCII base 16 representation of a digest value of
+	the cryptographic hash function defined for the security
+	modeling namespace.
+
+The following keyword and argument is used to create a file digest
+pseudonym for the internal TMA:
+
+	pseudonym value=HEXID
+
+	Where HEXID is the ASCII base 16 representation of a file
+	digest pseudonym that is to be maintained by the model.  See
+	the ABI documentation for how the argument to this verb is
+	generated.
+	
+	The size of the HEXID string must equal the size of the ASCII
+	base 16 representation of a digest value of the cryptographic
+	hash function defined for the security modeling namespace.
+
+The following keyword is used to lock the current TSEM modeling
+configuration:
+
+	lock
+
+This command is only valid when loadable module support is available
+in the kernel.  When executed this command blocks any further TSEM
+models from being registered.  In addition the reference count on all
+currently registgered modeling modules is increased so that it is not
+possible to remove currently loaded modules.
+
+The following two directories are implemented in the top level TSEM
+control directory in order to support interfaces to internally and
+externally modeled namespaces:
+
+	external_tma
+	internal_tma
+
+The external_tma directory holds a file, that is created when the
+request to create an externally modeled namespace is made.  The filename
+is the ASCII base 10 representation of the id number of the security
+modeling namespace.  The descriptions for security events that occur
+in the context of the namespace are exported in JSON format through
+this file to the external trust orchestrator that is controlling the
+security modeling namespace.
+
+The internal_tma directory is a container directory that holds
+directories for the control of each internal TMA that is implemented
+in the kernel.
+
+There is currently only a single kernel based TMA that is managed
+through the following directory:
+
+/sys/kernel/security/tsem/internal_tma/model0
+
+The following files are implemented for this model:
+
+	measurement
+	state
+
+	trajectory
+	trajectory_coefficients
+	trajectory_counts
+
+	forensics
+	forensics_coefficient
+	forensics_counts
+
+The 'measurement' file outputs the classic linear extension value of
+the security state coefficients that are generated in the context of
+the security modeling namespace.  This value is time dependent and can
+be used to verify the order of the security events that occurred in
+the model.
+
+The 'state' file outputs the time independent functional value of
+security state of the security modeling namespace.  This value and its
+generation and motivation are discussed in the 'Security model
+functional definitions' section of this document.
+
+The 'trajectory' file outputs the description of each security event
+recorded by the model in time dependent form.  The ABI documentation
+file contains a complete description of the output that is generated
+by this file and the 'forensics' file described below.
+
+The 'trajectory_coefficients' file outputs the set of security state
+coefficients in the model.  These coefficients match the entries of
+the event descriptions that are output in the 'trajectory' file.
+
+The security state coefficients can be paired with the security state
+descriptions with the following shell command, where DIR is the path
+to the individual files:
+
+paste DIR/trajectory_coefficients DIR/trajectory
+
+The 'trajectory_counts" file outputs the number of times that each
+security state coefficient, output by the 'trajectory_coefficients'
+file, has been experienced in the security modeling namespace.  This
+value can be used to verify that a security sensitive event has
+occurred or for statistical inference as to the anomaly status of an
+event.
+
+The 'forensics' file outputs the description of security events that
+have occurred when the namespace security model is running in a sealed
+state.  These events are useful for characterizing a security
+intrusion that has occurred or for refinement of a security model.

Documentation/admin-guide/LSM/tsem.rst line 1318

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+
+The 'forensics_coefficients' file outputs the security state
+coefficients that are generated by the forensics events that have
+been captured by the model and available through the 'forensics' file.
+
+The 'forensics_counts" file outputs the number of times that each
+security state coefficient output by the 'forensics_coefficients' file
+has been experienced in the security namespace.  This value can can be
+used for statistical inference as to the anomaly status of the
+namespace.

--
paul-moore.com

author
#4 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

On Mon, Jan 13, 2025 at 08:29:47PM -0500, Paul Moore wrote:

Good morning Paul, I hope your week is ending well.

We appreciate the time you committed to looking at our documentation.

Quoted 117 lines · On Aug 26, 2024 Greg Wettstein <[email protected]> wrote:
Quoted 27 lines

An entry was added to the ABI testing documentation to document the API definitions for the TSEM ontrol plane.

The file documenting the kernel command-line parameters was updated to document the TSEM specific parameters that are implemented.

The primary TSEM documentation file was added to the LSM administration guide and the file was linked to the index of LSM documentation.

---
 Documentation/ABI/testing/tsem                | 2420 +++++++++++++++++
 Documentation/admin-guide/LSM/index.rst       |    1 +
 Documentation/admin-guide/LSM/tsem.rst        | 1680 ++++++++++++
 .../admin-guide/kernel-parameters.txt         |   29 +
 4 files changed, 4130 insertions(+)
 create mode 100644 Documentation/ABI/testing/tsem
 create mode 100644 Documentation/admin-guide/LSM/tsem.rst
Documentation/ABI/testing/tsem new file +0 -0
new file mode 100644
index 000000000000..0e0e3201edf4

Documentation/ABI/testing/tsem line 8

Quoted 8 lines
Documentation/ABI/testing/tsem new file +8 -0
@@ -0,0 +1,2420 @@
+This file contains descriptions of output generated by the TSEM
+control plane files and the role of the only write-only file in the
+control plane.
+
+It is highly recommended that the following document be read in order
+to fully understand the rationale and functioning of these files:
+
+Documentation/admin-guide/LSM/tsem.rst

Will do ...

Quoted 22 lines
Documentation/admin-guide/LSM/tsem.rst new file +16 -0
new file mode 100644
index 000000000000..1c69a5cb7517
@@ -0,0 +1,1680 @@
+====
+TSEM
+====
+
+	"This is the story of the wine of Brule, and it shows what
+	 men love is never money itself but their own way, and
+	 that human beings love sympathy and pageant above all
+	 things."
+				- Hilaire Belloc
+				  The Path to Rome
+
+TSEM is the Trusted Security Event Modeling system.  TSEM is the
+kernel LSM based infrastructure that provides a platform for
+implementing model based mandatory access controls.  TSEM is model
+agnostic and is designed to support deterministic, quasi-deterministic
+and machine learning models.

...

Quoted 53 lines
Documentation/admin-guide/LSM/tsem.rst new file +53 -0
+Security Event Modeling
+=======================
+
+	"We can no longer speak of the behavior of the particle
+	 independently of the process of observation. As a final
+	 consequence, the natural laws formulated mathematically in
+	 quantum theory no longer deal with the elementary particles
+	 themselves but with our knowledge of them. Nor is it any
+	 longer possible to ask whether or not these particles exist in
+	 space and time objectively ... When we speak of the picture of
+	 nature in the exact science of our age, we do not mean a
+	 picture of nature so much as a picture of our relationships
+	 with nature.  ...Science no longer confronts nature as an
+	 objective observer, but sees itself as an actor in this
+	 interplay between man and nature. The scientific method of
+	 analysing, explaining and classifying has become conscious of
+	 its limitations, which arise out of the fact that by its
+	 intervention science alters and refashions the object of
+	 investigation. In other words, method and object can no longer
+	 be separated."
+				- Werner Karl Heisenberg
+
+Security Event Modeling (SEM), is an alternative strategy to implement
+the security guarantees of mandatory access and integrity controls, in
+a manner that is consistent with emerging application development
+strategies such as namespaces and CI/CD workflows.
+
+As was noted at the start of this document, the premise for SEM is
+that the security behavior of a platform, or alternatively a workload,
+can be modeled like any other physical phenomenon in science and
+engineering.
+
+Inspiration for this came from the primary TSEM author/architect
+having trained as a quantum chemist, conducting very early research in
+the development of multi-scale modeling strategies for molecules of
+size to be of interest to pharmaceutical intents.
+
+SEM is premised on the theory that kernel security architects have
+instrumented the LSM security event hooks to be called in locations
+before security sensitive operations are conducted, with appropriate
+descriptive parameters, that are considered relevant to the security
+posture of the kernel.  With respect to modeling, the security event
+hooks are conceptualized as representing the independent variables of
+a basis set that yields a functional definition for the security state
+of an execution trajectory.
+
+SEM can be framed in the context of classic subject/object mandatory
+access controls, by the notion that a unique identity can be generated
+for each element of an access vector matrix, rather than a boolean
+value.  In SEM, a security execution trajectory is defined by the set
+of security state coefficients that a process hierarchy (workload)
+generates.  This execution trajectory produces a vector of identities,
+whose sum in an appropriate form, yields a functional definition of
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 272

Quoted 5 lines
Documentation/admin-guide/LSM/tsem.rst new file +5 -0
+the security state of the system.
+
+Two subordinate identities are combined to yield a security event
+state coefficient.  These subordinate identities are referred to as
+the Context Of Execution (COE) and the CELL, which are conceptually

Please define the CELL acronym here as I believe it is the first use of "CELL" in this document.

FWIW, CELL isn't an acronym, it is a metaphor.

TSEM was conceptually inspired by and derived from the Turing Abstract Machine Model (TAMM), as applied to the problem of modeling the security state of an execution domain.

As everyone reading this knows, a TAMM, in practice, consists of a head traversing an infinite paper tape divided into cells that direct the next state of the machine.

In TSEM, the model consists of a Context Of Execution (COE) with security definining characteristics, traversing a finite set of measurement points of infinite length, with defining characteristics at each point.

We refer to a measurement point and its characteristics as a CELL in deference to the inspiration for all of this.

We will add this explanation to the documentation.

Quoted 73 lines
Quoted 26 lines
Documentation/admin-guide/LSM/tsem.rst new file +26 -0
+similar to the subject and object in mandatory access control.  The
+COE identity is derived from the parameters that describe the security
+relevant characteristics (ie. credentials) of a process, while the
+CELL value is derived from the parameters used by a security event
+hook to describe the characteristics of the event.
+
+A security policy is implemented by a modeling algorithm that
+translates COE and CELL event parameters into their respective
+identities.  The COE and CELL are combined to yield a security state
+coefficient that uniquely describes the security event in the security
+model.  Different security policies and criteria can be developed by
+modifying how the modeling algorithm utilizes the COE and CELL
+characteristics.
+
+Since the security policy is implemented with a modeling algorithm, a
+single platform can support multiple and arbitrary security policies.
+The equivalent of a resource namespace in SEM is referred to as a
+security modeling namespace.
+
+The formation of the security state coefficients from existing kernel
+parameters eliminates the need for the use of extended attributes to
+hold security label definitions.  In SEM, a cryptographically signed
+security model definition, designed to be interpreted by a modeling
+algorithm, becomes the bearer's token for the security of the modeled
+workload, rather than information encoded in filesystem security
+attributes.

...

Quoted 31 lines
Documentation/admin-guide/LSM/tsem.rst new file +31 -0
+Process and Platform Trust Status
+=================================
+
+A fundamental concept in TSEM is the notion of providing a precise
+definition for what it means for a platform or workload to be trusted.
+A trusted platform or workload is one where there has not been an
+attempt by a process to execute a security relevant event that does
+not map into a known security state coefficient.
+
+The process trust status is a characteristic of the process that is
+passed to any subordinate processes that are descendants of that
+process.  Once a process is tagged as untrusted, that characteristic
+cannot be removed from the process.  In a 'fruit from the poisoned
+vine' paradigm, all subordinate processes created by an untrusted
+process are untrusted as well.
+
+On entry into each TSEM security event handler, the trust status of a
+process is checked before an attempt to model the event is made.  An
+attempt to execute a security event by an untrusted process will cause
+the event, and its characteristics, to be logged.  The return status
+of the hook will be determined by the enforcement state of the model.
+A permission denial is only returned if the TMA is running in
+enforcing mode.
+
+If the platform running the TSEM LSM has a TPM, the hardware aggregate
+value is computed at the time that TSEM is initialized.  This hardware
+aggregate value is the linear extension sum over Platform
+Configuration Registers (PCR's) 0 through 7.  This is the same
+aggregate value that is computed by the Integrity Measurement
+Architecture (IMA) and is the industry standard method of providing an
+evaluation measurement of the hardware platform state.

Documentation/admin-guide/LSM/tsem.rst

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+
+Internally modeled namespaces have the hardware aggregate measurement
+included as the first event in the security model.  Externally modeled
+namespaces export the hardware aggregate value to the TMA for
+inclusion as the first event of the model maintained by the external
+TMA.
+
+The root security model extends each security state coefficient into a
+PCR.  The default PCR is 11 but is configurable through the kernel
+compilation configuration process.

Presented here simply as a FYI:

Quoted 5 lines

https://uapi-group.org/specifications/specs/linux_tpm_pcr_registry

I'm not going to recommend any one particular PCR, but I thought the "registry" info above might be useful when trying to avoid PCR collisions.

Thank you for forwarding reference along, we received a pointer to this from James Bottomely as well.

The PCR register for the root modeling namespace is a Kconfig option so it can be tuned appropriately. Given the limited supply of PCR's, the register selection should probably also be a a command-line option down the road.

Quoted 42 lines
Quoted 42 lines
Documentation/admin-guide/LSM/tsem.rst new file +42 -0
+The use of a separate PCR from IMA
+allows hardware based TSEM measurements to coexist with IMA
+measurement values.  This hardware measurement value is designed to
+allow attestation to the hardware state that the root model is running
+in.
+
+TSEM is designed to support a philosophy where the root security
+modeling namespace will be a minimum Trusted Computing Base
+implementation that will only be running trust orchestrators and any
+other infrastructure needed to support running workloads in
+subordinate security namespaces.
+
+The subordinate security modeling namespaces are designed to decrease
+model complexity in order to support a single functional value
+describing the 'known good' security state of a subordinate security
+workload.  Subordinate security modeling namespaces are
+non-hierarchical, ie. a security modeling namespace cannot itself
+parent an additional security modeling namespace.
+
+The Linux TSEM Implementation
+=============================
+
+	"Sometimes the questions are complicated and the answers are
+	 simple."
+				- Dr. Seuss
+
+The Linux TSEM implementation is deliberately simplistic and consists
+of the following two generic components:
+
+- Security modeling namespace and security event export functionality.
+
+- Internal trusted modeling agent implementation.
+
+The security modeling namespace and export functionality is designed
+to be generic infrastructure that allows security namespaces to be
+created that are either internally or externally modeled.  The TSEM
+implementation does not pose any constraints on what type of modeling
+can or should be implemented in these namespaces.
+
+On the theory that security event handlers represent all of the
+security relevant action points in the kernel, any security or
+integrity model can be implemented using the TSEM infrastructure.  For
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 512

Quoted 3 lines
Documentation/admin-guide/LSM/tsem.rst new file +3 -0
+example, basic IMA functionality could be implemented by a TMA that
+maps the digests of files accessed, or mapped executable, by the root
+user as the security state coefficients.

In order to keep the peace among different LSMs, we try very hard to avoid language along the lines of "LSM A could be implemented by LSM B". Please refrain from such language, especially in documentation that lives within the kernel.

We were not suggesting superiority or replacement, our apologies to the community if the above would be perceived as such.

We have previously fielded significant review criticism regarding the fact that we cannot claim that TSEM implements a 'security model'. The goal of the documentation was to suggest that arbitrary security models can be implemented by TSEM, not that TSEM would provide a better implementation.

In fact, the upcoming V5 release and its associated userspace tools, have a proof of concept implementation of TOMOYO as a TSEM loadable module, as a further indication of its ability to lowering the barriers to the development of alternative or customized security architectures.

Quoted 11 lines

Documentation/admin-guide/LSM/tsem.rst line 519

Quoted 6 lines
Documentation/admin-guide/LSM/tsem.rst new file +6 -0
+A primary intent of the Linux TSEM implementation is to provide a
+generic method for implementing security policy in userspace rather
+than the kernel.  This is consistent with what has been the historic
+understanding in Linux architecture, that policy decisions should be
+delegated, when possible, to userspace rather than to kernel based
+implementations.

[NOTE: Feel free to ignore the paragraph below, you addressed the issue of non-blocking access control hooks in externally modeled namespaces later in this document.]

Quoted 8 lines

If I recall correctly, previous reviews that looked briefly at the TSEM implementation brought up an issue where several LSM/TSEM decision points in the kernel were non-blocking, which presents a problem for TSEM, or any LSM that wishes to call out to userspace for an access control decision. At the time of the review, I believe the TSEM answer was, in broad terms, "TODO". Has this been resolved yet through some change to TSEM, or am I simply remembering things incorrectly and TSEM has always handled this case properly?

Will defer comments to below.

Quoted 49 lines
Quoted 29 lines
Documentation/admin-guide/LSM/tsem.rst new file +29 -0
+The model is extremely simplistic; a TMA interprets a security event
+and its characteristics and advises whether or not the kernel should
+designate the process as trusted or untrusted after event processing
+is complete.
+
+The following sections discuss various aspects of the infrastructure
+used to implement this architecture.
+
+Internal vs external modeling
+-----------------------------
+
+When a TSEM security modeling namespace is created, a designation is
+made as to whether the namespace is to be internally or externally
+modeled.
+
+In an internally modeled namespace, the security event handlers pass the
+event type and its characteristics to the designated internal trusted
+modeling agent.  The agent provides the permission value for the
+security event handler to return as the result of the event and sets
+the trust status of the process executing the event.
+
+In an externally modeled namespace, the event type and parameters are
+exported to userspace for processing by a trust orchestrator with an
+associated TMA.  The trust orchestrator communicates the result of the
+modeling back to the kernel to support the setting of the process
+trust status.
+
+The exception to this model are for security event handlers that are
+called in atomic, ie. non-sleeping context.  The export of these

Documentation/admin-guide/LSM/tsem.rst line 559

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+security event descriptions are done asynchronously in order to avoid
+having the TSEM implementation attempt to sleep in atomic context
+while the userspace trust orchestrator is scheduled for execution.
+
+It is up to the trust orchestrator and its security policy to
+determine how it handles events that violate the security model being
+enforced in this model.  The Quixote trust orchestrators shut down the
+entire workload running in the security namespace if an asynchronously
+modeled event violates the security model being enforced and the model
+is running in enforcing mode.

I understand your desire to simply pass off the non-blocking/async access control hole as a security policy issue, but it seems to me that this is a fundamental flaw with an externally modeled TSEM namespace. If an externally modeled namespace was configured with an enforcing policy, it doesn't appear that there is a mechanism for TSEM to properly enforce that policy as there is an unbounded delay between the undesired access and a denial verdict being processed by the kernel.

Quoted 4 lines

Unless you can resolve this somehow, and I'm not sure how, I would suggest dropping external/userspace trust orchestrators. They simply don't seem able to reliably implement their security policies.

An important issue.

Some reflections on why we would, respectfully, disagree.

A business assessment of the current security market suggests that the mindset in security has changed from prevention to detection. TSEM is about providing kernel infrastructure to enable better solutions for the detection model.

Current Endpoint Detection and Response Systems (EDRS) largely do not provide bounded enforcement actions in response to the detection of a security anomaly. This will increasingly be the case as the industry turns to machine learning rather than deterministic security models.

I think we can agree that models by current EDRS vendors, that are said to detect security anomalies based on the real time machine learning analysis of models built from trillions of data points, are not going to run inside the kernel.

We have team members who measure bounded response time for major EDRS products and a common measurement is four seconds under optimal conditions. Since userspace is involved, it could also be technically unbounded.

In spite of this, these are multi-billion dollar enterprises, that have not only market demand but corporate insistence on their use. Without going into further detail, as this particular response is already too long, we believe that TSEM opens the door to even better solutions in this space.

We can provide further discussion if there is interest.

We believe there is a technical solution to this problem as well but our work on that front, at this point, is too technically immature to go into.

Quoted 7 lines
Quoted 7 lines
Documentation/admin-guide/LSM/tsem.rst new file +7 -0
+Internally modeled domains are able to provide immediate interception
+and modification of the trust status of a process that is violating
+the security model.  This has implications for the root security
+namespace that is running on a system with a TPM, since the security
+event coefficients are logged to the Platform Configuration Register
+that is being used by TSEM.
+
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 572

Quoted 5 lines
Documentation/admin-guide/LSM/tsem.rst new file +5 -0
+Issuing the TPM transaction would cause the process to attempt to
+sleep while it waits for the TPM command to complete.  In order to
+address this issue, the TPM transactions are deferred to an ordered
+workqueue for execution.  The use of an ordered workqueue maintains
+the time dependency of the security coefficients being registered.

I would suggest removing the "time dependency" phrase and focus on the workqueue preserving the ordering of the TPM transactions.

We will follow this suggestion.

Quoted 8 lines
Quoted 8 lines
Documentation/admin-guide/LSM/tsem.rst new file +8 -0
+In order to handle modeling of security events in atomic context, the
+TSEM implementation maintains caches (magazines) of structures that
+are needed to implement the modeling and export of events.  The size
+of this cache can be configured independently for each individual
+security modeling namespace that is created.  The default
+implementation is for a cache size of 32 for internally modeled
+namespaces and 128 for externally modeled namespaces.
+
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 584

Quoted 3 lines
Documentation/admin-guide/LSM/tsem.rst new file +3 -0
+By default the root security namespace uses a cache size of 128.  This
+value can be configured by the 'tsem_cache' kernel command-line
+parameter to an alternate value.

I haven't looked at the implementation yet, but I don't understand both why a kmem_cache couldn't be used here as well as why this implementation detail is deemed significant enough to be mentioned in this high level design document.

TSEM does use kmem_cache allocations for all of its relevant data structures.

The use of a kmem_cache, however, does not solve the problem for security event handlers that are required to run in atomic context. To address the needs of those handlers you need to serve the structures out of a pre-allocated magazine that is guaranteed to not require any memory allocation or sleeping locks.

When TSEM is requested to handle a security event handler that runs in atomic context, it allocates the event structure from the magazine of structures that was populated at boot time from kmem_cache allocations. An asynchronous work request is queued to re-populate the slots as they are used, again from kmem_cache allocations.

Quoted 12 lines
Quoted 12 lines
Documentation/admin-guide/LSM/tsem.rst new file +12 -0
+Trust Orchestrator/Process authentication
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The process identifier values (PID's) that are exported in the
+security event descriptions are the unique global PID values, not the
+value as seen through the lens of a PID namespace.
+
+PID values are, by default, not considered to be a stable identifier
+between the kernel and userspace.  In the case of TSEM external
+modeling, the threat model for a namespace is whether or not an
+adversarial process, running in either the root security modeling
+namespace or another subordinate security modeling namespace, can kill
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 599

Quoted 2 lines
Documentation/admin-guide/LSM/tsem.rst new file +2 -0
+a process that is being orchestrated and substitute an alternate
+process with an identical PID value.

We've talked about this previously, but given my current understanding of TSEM, one of my concerns is the presence of user controlled data in a TSEM security event. This could include PIDs, task->comm values, and potentially others (I haven't gone through the full CELL list yet).

Point one: we don't use task->comm values, or PID's, in the generative models.

Point two: TSEM is based on a model of deriving the allowed security states from unit testing of an application, platform or workload under controlled conditions, not unlike the need to conduct filesystem labeling or metadata signing in a known and protected environment for label based subject/object mandatory access control models and integrity architectures.

Adversaries can certainly attempt to manipulate the runtime environment to change the input to the generative functions, that however, results in detectable model violations.

Quoted 15 lines

Documentation/admin-guide/LSM/tsem.rst

Quoted 8 lines
Documentation/admin-guide/LSM/tsem.rst new file +8 -0
+The suggested threat model would be that the orchestrator would set
+the trust status of the adversarial process rather than the one that
+had emitted the security event characteristics.  The threat interval
+is the latency time required for the processing of the security event
+description by the trust orchestrator and its associated TMA.
+
+Exploiting this theoretical race is extremely complex and requires an
+in depth understanding of the TSEM architecture.

I don't believe we want to accept a LSM with race conditions, even theoretical ones. One can argue how likely such a race condition would be in practice, but the audeience here is too samll, the future too unpredictable, and the adversaries too clever for such a debate to be very meaningful.

Quoted 3 lines

At this point in the development process, there is an opportunity to design away all race conditions, even the theoretical ones, let's do that while we can.

We've deliberated a lot about this since our earlier discussions. We would offer one primary response that may simplify further discussions on this issue.

A PID race or similar attack is not a relevant attack, given the Task Identity Model that TSEM is based on.

By definition, based on the generative model that is used for task identities, a substituted task will have a different task identity and thus unable to generate security state coefficients consistent with the model being enforced.

Quoted 41 lines
Quoted 41 lines
Documentation/admin-guide/LSM/tsem.rst new file +41 -0
+Rather than discuss
+the conditions that must be met and their implications, this
+discussion will first focus on the generic threat model and its
+generic utility to an adversary followed by a treatment of the
+mechanisms that TSEM implements in order to mitigate this threat.
+
+In short, a process in an adversarial security modeling namespace
+would want to execute security events that are barred from its
+security model with the hope of having them approved by an alternate
+namespace.
+
+A process waiting for the external modeling of a security event
+description can only be placed back into run state by two methods:
+reception of a fatal signal or the TRUST_PENDING status bit being
+cleared from its TSEM specific task control structure by a trust
+orchestrator.
+
+If a process being evaluated receives a fatal signal, its trust status
+will be set to untrusted and an error will be returned to the trust
+orchestrator.  The error would cause a trust violation to be
+registered for the workload.  In addition, the evaluation of the event
+would be terminated, so a replacement process would not receive an
+incorrect trust assessment for an event that was initiated by its
+predecessor.
+
+The second issue that limits the utility of a PID substitution attack
+is that from the point of substitution forward it would place the
+replacement process in the context of the security model that the
+trust orchestrator is enforcing.  As a result, a substituted process
+would not be allowed to exhibit any security behaviors inconsistent
+with the model being enforced.
+
+If an attempt to exploit this race would be considered, an adversarial
+process would have to force the termination of a process in the target
+namespace and then fork and exit a process a sufficient number of
+times in order to have a process under its control match the PID value
+of the process that was waiting for an orchestration response.
+
+Measured modeling latency times for a trust orchestrator running the
+deterministic Quixote TMA in userspace, on current generation x86_64
+hardware, averages 170 micro-seconds.  In a worst case scenario from
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 652

Quoted 4 lines
Documentation/admin-guide/LSM/tsem.rst new file +4 -0
+the perspective of an adversary, there would be a need to force the
+termination of the target process and then fork and execute a
+sufficient number of times to force the PID collision during this time
+interval.

It is best not to rely on hardware performance to mitigate security concerns, at some point or with some configuration, you will be wrong.

See our comments above as to why most of this discussion is irrelevant at this point.

Quoted 153 lines
Quoted 153 lines
Documentation/admin-guide/LSM/tsem.rst new file +153 -0
+As a generic protection, TSEM in the tsem_task_kill() handler, blocks
+the notion of 'cross-model' signals, ie. a signal originating from an
+external security modeling namespace.  This would require the
+adversary to reliably force a process termination through a mechanism
+other than signaling, for example, through the OOM killer whose signal
+transmission would not be blocked by this policy control.
+
+When a subordinate security modeling namespace is created, the id
+number of the namespace is registered in the tsem_task structure of
+the trust orchestrator that is creating the namespace.  The TSEM
+driver will refuse to honor control plane requests affecting the trust
+status of a process whose trust orchestrator security namespace id
+does not match the namespace identifier of the process that it is
+being asked to act on.
+
+As an additional protection, TSEM uses an authentication strategy that
+allows a process running in a security modeling namespace to verify
+that a control request is coming from the trust orchestrator that
+initiated the namespace the process is running in.  As part of the
+setup of a security modeling namespace, a trust orchestrator is
+required to provide an ASCII hexadecimally encoded authentication key
+that matches the length of a digest value of cryptographic hash
+function being used to generate security state coefficient in the
+security modeling namespace.  This authentication key must be provided
+by the trust orchestrator for every subsequent control plane request.
+
+The process that is being transferred to a subordinate security
+modeling namespace generates a second random key that is hashed with
+the authentication key provided by the trust orchestrator, using the
+hash function that has been defined for the security namespace.  The
+resultant digest value is compared to a list of authentication keys
+for all currently executing namespaces.  The selection of the second
+random key is repeated until a globally unique key is generated.
+
+This randomly generated authentication key is stored in the tsem_task
+structure of the process and propagated to any subsequent processes
+that are created in the namespace.  The hash product of this key and
+the orchestration authentication key, ie. the globally unique key, is
+placed in the tsem_task control structure of the orchestration
+process.
+
+When a control plane request is received, the authentication key
+provided by the trust orchestrator is used to re-generate an
+authentication key based on the randomly generated namespace key held
+by the process whose trust status is being updated.  The generated
+authentication key is compared to the key in the tsem_task structure
+of the process issuing the orchestration call.  The control plane will
+refuse to honor a control plane request if the call specific key that
+is generated does not match the key generated at the time the security
+namespace was created.
+
+Event modeling
+--------------
+
+The generation of security state coefficients is a functional process
+that uses a cryptographic hash function for the creation of the
+individual identity mappings that contribute to the generation of the
+security state coefficient.
+
+TSEM can use any cryptographic hash function available to the Linux
+kernel for this purpose.  The hash function to be used for a security
+modeling namespace is specified as a parameter to the namespace
+creation process.
+
+By default, the root security namespace uses sha256.  This value can
+be modified through the tsem_digest kernel command-line parameter.
+
+Since TSEM is active before the kernel has the ability to load
+modules, the root modeling domain must be a cryptographic hash
+function that is statically compiled into the kernel.  By default the
+TSEM configuration selects for the presence of the sha256 hash
+function.
+
+TSEM security event modeling is based on the following functional
+definition for a security event coefficient:
+
+Coeff = HF(HF(EVENT_ID) || PTASK_ID || TASK_ID || HF(COE) || HF(CELL))
+
+	Where:
+		Coeff	 = A security state coefficient that is equal
+			   in length to the digest value of the
+			   cryptographic hash function in use for the
+			   security modeling namespace.
+
+		HF	 = Security namespace specific hash function.
+
+		||       = Concatenation operator.
+
+		EVENT_ID = The ASCII name of event.
+
+		PTASK_ID = The TASK_ID of the parent process of the
+			   process represented by TASK_ID.
+
+		TASK_ID  = The process specific identity of the
+			   executable code that is calling the security
+			   event handler.
+
+		COE      = Characteristics of the context of execution
+			   of the event.
+
+		CELL	 = Characteristics of the LSM event that is being
+			   modeled.
+
+Workload or platform specific security state coefficient definitions
+are generated by a TMA, using the COE or CELL characteristics that are
+considered relevant for the model being implemented.  These
+coefficients are used to determine whether or not an event should lead
+to the process being considered trusted or untrusted.
+
+The TASK_ID component of the function above is important with respect
+to the generation of the security state coefficients.  The notion of a
+task identity serves to link the concepts of system integrity and
+security access control.
+
+The TASK_ID is defined by the following function:
+
+TASK_ID = HF(HF(EVENT) || PTASK_ID || NULL_ID || HF(COE) || HF(CELL))
+
+	Where:
+		TASK_ID	  = The executable identity of the process
+			    expressed as a digest value of length
+			    equal to the cryptographic hash function
+			    the security modeling namespace is using.
+
+		HF	  = Security namespace specific hash function.
+
+		||        = Concatenation operator.
+
+		EVENT	  = The string "bprm_committed_creds".
+
+		PTASK_ID  = The TASK_ID of the parent process of the
+			    process whose TASK_ID is being generated.
+
+		NULL_ID	  = A buffer of null bytes equal to the digest
+			    size of the hash function being used for
+			    the namespace.
+
+		COE	  = Characteristics of the context of execution
+			    calling the bprm_committed_creds LSM hook.
+
+		CELL	  = The characteristics of the file provided
+			    by the linux_binprm structure passed to
+			    the security_bprm_committed_creds handler.
+
+An attentive reader will quickly conclude, correctly, that the TASK_ID
+function generates an executable specific security coefficient for the
+bprm_committed_creds security hook.  The generative function for the
+TASK_ID is the same as the standard security state coefficient; with
+the exception that the task identity is replaced with a 'null id',
+consisting of the number of null bytes in the digest size of the
+namespace specific hash function.
+
+One of the CELL characteristics used in the computation of the task
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 810

Quoted 4 lines
Documentation/admin-guide/LSM/tsem.rst new file +4 -0
+identity is the digest of the executable file.  Modifying an
+executable, or attempting to execute a binary not considered in the
+security model, will result in an alteration of the task identity that
+propagates to the generation of invalid state coefficients.

Presumably an attacker could craft a malicious executable (or influence the CELL value if it incorporates user controlled values) that collides with the digest of a known and trusted application.

An incredibly important issue, so apologies for a more lengthy reply on this issue.

More precisely, the objective for an adversary would be to generate the same security coefficient for a specific security event type using an alternative ensemble of operating system relevant characteristics for the event.

The generative functions for the COE, CELL, task identities and ultimately the security state coefficients, are based on industry standard cryptographic hash functions. The attack scenario suggested above would represent a major failure in the second pre-image resistance characteristics of these industry standard security primitives.

The ability to decept these security primitives, in such a manner, would represent a crisis for the entire technology industry.

At a minimum, a demonstrated exploit of this type would render the following technologies subject to easily exploitable security failures:

- TPM's.
- TDX/SGX.
- Digital signatures.
- VPN's.
- OpenSSH.
- SSL/HTTPS.
- Any type of code signing.
- GIT... :-)

Based on one of your earlier review suggestions, we implemented algorithmic agility in TSEM for the generative functions. TSEM can use any cryptographic hash function in the kernel the generative functions.

If this failure mode were to be demonstrated, we would switch to whatever replacement function that the rest of the world would also be rushing to, in order to address such a fundamental failure in the security infrastructure that civilization now largely depends on.

Quoted 161 lines
Quoted 161 lines
Documentation/admin-guide/LSM/tsem.rst new file +161 -0
+The task identity is saved in the TSEM specific task structure and is
+used to compute the state coefficients for any security events that
+the task subsequently executes.  As noted in the previous paragraph,
+incorporating the TASK_ID into the computation of security state
+coefficients results in the security state coefficient values becoming
+specific to the corpus of executable code that initiated a process.
+This affords a very high degree of specificity with respect to the
+security models that can be implemented.
+
+As was demonstrated in the TBDHTTRAD section, in contrast to standard
+digest based controls, TSEM will discriminate the following commands
+as different events/coefficients in a security model:
+
+cat /etc/shadow
+
+grep something /etc/shadow
+
+while read input
+do
+	echo $input;
+done < /etc/shadow
+
+An important, and perhaps subtle issue to note, is how these events
+result in the change of process trust status.  In the first two cases,
+if access to the /etc/shadow file is not permitted by the operative
+security model, the cat and grep process will become untrusted.
+
+In the third example, the shell process itself would become untrusted.
+This would cause any subsequent attempts to execute a binary to be
+considered untrusted events, even if access to the binary is a
+permitted coefficient in the model.
+
+The integration of the PTASK_ID in the generation of the security
+state coefficients causes the coefficients to be dependent on the
+chain of execution of executable code.  This concept generates
+extremely specific security coefficients that yield the high
+sensitivity of TSEM based security models.
+
+For example, consider the following chain of execution:
+
+init/systemd -> sshd -> bash
+
+init/systemd -> getty -> bash
+
+Even if the COE characteristics (credentials) of the two bash
+processes are identical, the security coefficients generated by the
+two bash shells will be different.  This is secondary to the fact that
+the TASK_ID of the two bash processes will be different by virtue of
+the fact that the first bash process will have a PTASK_ID that
+represents the TASK_ID of the ssh process, while the second process
+will have a PTASK_ID that represents the TASK_ID of the getty process.
+
+This generative functions provides a framework for modeling that
+yields very precise tracking of security relevant events.  This is
+significant with respect to detecting and addressing adversarial
+techniques such as Living Off The Land (LOTL).
+
+Since the modeling operates at the level of a mandatory security
+control, these permission denials would occur even if the process is
+running with classic root privilege levels.  This is secondary to the
+notion that security and trust status are invested in the trust
+orchestrator and ultimately the TMA.
+
+From a hardware perspective, this is important with respect to the
+notion of a TMA being a model for a successor to the TPM.  From a
+system trust or integrity perspective, a TPM is designed to provide a
+retrospective assessment of the actions that have occurred on a
+platform.  A verifying party uses the TPM event log and a PCR based
+summary measurement, to verify what actions have occurred on the host,
+in order to allow a determination of whether or not the platform
+should be 'trusted'.
+
+In contrast, a TSEM/TMA based system enforces, on a real time basis,
+that a platform or workload remains in a trusted state.  Security
+relevant actions cannot be conducted unless the TMA authorizes the
+actions as being trusted.
+
+This is particularly important with respect to embedded systems.  A
+TPM based architecture would not prevent a system from having its
+trust status altered.  Maintaining the system in a trusted state would
+require attestation polling of the system, and presumably, executing
+actions if the platform has engaged in untrusted behavior.
+
+Conversely, a trust orchestrated software implementation enforces that
+a system or workload remain in a security/trust state that it's
+security model was unit tested to.
+
+Security model functional definitions
+-------------------------------------
+
+Previously, classic trusted system implementations supported the
+notion of the 'measurement' of the system.  The measurement is the
+value of a linear extension function of all the security relevant
+actions recorded by a trust measurement system such as IMA.
+
+In TPM based trust architectures, this measurement is maintained in a
+PCR.  A measurement value is submitted to the TPM that extends the
+current measurement using the following formula:
+
+MEASUREMENT = HF(CURRENT || NEW)
+
+	Where:
+		MEASUREMENT = The new measurement value to be maintained
+			      in the register for the system.
+
+		HF	    = A cryptographic hash function supported
+			      by the TPM device.
+
+		||	    = Concatenation operator.
+
+		CURRENT     = The current measurement value.
+
+		NEW	    = A new measurement value to be added to
+			      the current measurement.
+
+The use of a cryptographic function produces a non-commutative sum
+that can be used to verify the integrity of a series of measurements.
+With respect to security modeling theory, this can be thought of as a
+'time-dependent' measurement of the system.  Stated more simply, the
+measurement value is sensitive to the order in which the measurements
+were made.
+
+In systems such as IMA, the measurement value reflects the sum of
+digest values of what are considered to be security critical entities,
+most principally, files that are accessed or memory that is mapped
+executable, based on various policies.
+
+In TSEM based TMA's, the measurement of a security modeling namespace
+is the sum of the unique security state coefficients generated by the
+security model being enforced.  As previously noted, on systems with a
+TPM, the root security modeling namespace measurement is maintained by
+default in PCR 11 or the PCR that was selected at kernel configuration
+time.
+
+The challenge associated with classic integrity measurements is the
+time dependent nature of using a non-commutative summing function.
+The almost universal embrace of SMP based hardware architectures, in
+addition to standard kernel task scheduling issues, makes the
+measurement values non-deterministic.  This requires a verifying party
+to evaluate an event log, verified by a measurement value, to
+determine whether or not the system is in a security appropriate or
+trusted state.
+
+TSEM addresses this issue by implementing a strategy designed to
+produce a single functional value that represents the functional
+security state of a model.  This allows a TMA to attest to the
+trust/security status of a platform or workload by signing this
+singular value and presenting it to a verifying party.
+
+In TSEM nomenclature, this functional value is referred to as the
+'state' of the model.  The attestation model is to use trust
+orchestrators to generate the state value of a workload by unit
+testing.  This state value can be packaged with a utility or container
+to represent a summary trust characteristic that can be attested by a
+TMA, eliminating the need for a verifying partner to review and verify
+an event log.
+
+TMA's implement this architecture by maintaining a single instance
+vector of the set of unique security state coefficients that have been
+experienced in a security modeling namespace.  The state measurement
+is generated by sorting the security state coefficient vector in
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 974

Quoted 2 lines
Documentation/admin-guide/LSM/tsem.rst new file +2 -0
+big-endian hash format and then generating a standard linear extension
+measurement over this new vector.

There are cases where ordering of events is important when assessing the security state of the system, e.g. disabling/enabling security features. In these cases where ordering is necessary to attest the security state of the system, is there some middle ground, or does an admin need to revert to a "classic" orderered measurement?

If the time order of two security critical events is important, the only thing that can be done is to evalute which event occurred first.

TSEM now facilitates this by including nanosecond timestamp measurements of when each event occurred, see the 'ts' key value in the JSON 'event' description structure.

Someone wishing to appraise the security status of a time dependent TSEM model would verify that the timestamps on the two event descriptions are ordered properly.

Quoted 9 lines
Quoted 9 lines
Documentation/admin-guide/LSM/tsem.rst new file +9 -0
+Any security event that generates an associated state coefficient that
+is not in the model will resulted in a perturbed state function value.
+That perturbed value would be interpreted by a verifying party as an
+indication of an untrusted system.
+
+Since the TMA maintains the security event descriptions in time
+ordered form, the option to provide a classic event log and
+measurement are preserved and available.  Extensive experience in the
+development of TSEM modeled systems has demonstrated the superiority
Quoted 8 lines
Quoted 1 line

+of state value interpretation over classic measurement schemes.

I don't disagree that working with the pre-sorted measurement is far easier, I just wonder how many systems would be able to give up on the event ordering to have the simplified modeling. Surely we will all have different experiences here, but I'm not sure the pre-sorted measurement approach would have been acceptable in many of the projects I've worked on over the years.

Three general observations.

Roberto's work on Integrity Digest Caches would suggest that other groups feel that non-temporal assessments are of value.

The 'real' world consists of shades of grey. In earlier reviews you questioned why TSEM was delivering ordered as well as unordered measurement trajectories. The reason we provide both is to support the grey world we must function in.

Partitioning workloads into security modeling namespaces is a central requirement to increasing the precision of security assessment. Invariant state assessments are of significant value in a world which has increasingly turned to containerized workloads, even on edge devices where our team is very active. One of the objectives of TSEM is to allow development teams to easily deploy the ability to determine if their workloads have ever exhibited an undesired security behavior.

Quoted 42 lines
Quoted 42 lines
Documentation/admin-guide/LSM/tsem.rst new file +42 -0
+A TMA may choose to incorporate a 'base nonce' into a security model
+that it is implementing, this base nonce is designed to serve in a
+manner similar to an attestation nonce.  If used, the trust
+orchestrator is responsible for negotiating a random base nonce with a
+verifying party at the time of initialization of a security modeling
+namespace and providing it to the TMA.
+
+The TMA uses the base nonce to extend each security event coefficient
+that is generated by the model.  This causes the state and measurement
+values of the model to become dependent on this base nonce, a process
+that can be used to defeat a replay attack against the security model.
+
+Control plane
+-------------
+
+Both primary functions of TSEM: security modeling namespace management
+and the internal TMA modeling implementation, are controlled by
+pseudo-files in the securityfs filesystem.  The following directory
+is the top level implementation directory for the TSEM control plane:
+
+/sys/kernel/security/tsem
+
+The following file in the kernel source tree documents, in detail,
+the interfaces provided by the filesystem:
+
+Documentation/ABI/testing/tsem
+
+This filesystem is primarily intended for use by trust orchestrators
+to create and manage security modeling namespaces.
+
+The files are process context sensitive.  Writing to the control file,
+or reading from the informational files, will act on or reference the
+security modeling namespace that the accessing process is assigned to.
+
+The following files are provided in the root directory of the TSEM
+control plane and implement global controls for the TSEM LSM:
+
+	aggregate
+	id
+	control
+
+The 'aggregate' file is used by trust orchestrators for internally
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst

Quoted 2 lines
Documentation/admin-guide/LSM/tsem.rst new file +2 -0
+modeled namespaces to obtain the hardware measurement value for
+inclusion in a security model.

So I'm clear on this, internally modeled namespaces still access the hardware measurement directly from inside the kernel, yes? In the interally modeled case this is simply available as a reference, and the in-kernel TMA doesn't call out to userspace to access this value, yes?

Correct.

Quoted 30 lines
Quoted 30 lines
Documentation/admin-guide/LSM/tsem.rst new file +30 -0
+A trust orchestrator for an externally
+modeled namespace capture this value as the first event generated by a
+security modeling namespace.
+
+The 'id' file is used to determine the security modeling namespace
+that the process is running in.  The namespace id value of 0 is
+reserved for the root security modeling namespace, a non-zero value
+indicates that the process is running in a subordinate security
+modeling namespace.
+
+The TSEM implementation is controlled by the only writable file, which
+is the 'control' file.
+
+The following keywords are used by trust orchestrators to place the
+process writing to the file in an internally or externally modeled
+security namespace:
+
+	internal
+	external
+
+Each argument accepts key=value pairs that configure the namespace.
+The following key values are currently accepted:
+
+	model
+	nsref
+	digest
+	cache
+	key
+
+The 'model' keyword takes as an argument the name of a loadable module
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst

Quoted 3 lines
Documentation/admin-guide/LSM/tsem.rst new file +3 -0
+that will be used to implement the event processing for a security
+modeling namespace.  If the module has not already been loaded, TSEM
+will attempt to dynamically load the module.

I'm still sorting out the stuff in the docs and haven't gotten to the implementation yet, but just so we're clear on the details about TSEM modules, TSEM shouldn't attempt to sidestep the LSM framework as TOMOYO did recently and we later had to revert.

We were active in those discussions and are on record with respect to supporting the notion that LSM's should not attempt to sidestep the LSM infrastructure.

TSEM operates entirely within the LSM framework. TSEM loadable modules were implemented in order to allow shaping of the event mapping to allow multiple types of models to be implemented.

Quoted 4 lines

Considering that TSEM is likely to want to be active before enough of a userspace exists to load a module (see the previous sections on hash functions), it seems like the best option is to simply include all of the desired internal TMAs in the kernel at build time.

Our experience in building solutions in this space is to have a very minimal orchestration environment running in the root modeling namespace that sets up the host and is modeled by the default deterministic TMA.

The orchestration environment then runs containerized workloads in independent modeling namespaces that benefit from the availability of multiple models, including the simple export of security events for external EDRS evaluation.

Quoted 49 lines
Quoted 49 lines
Documentation/admin-guide/LSM/tsem.rst new file +49 -0
+If the standard practice
+is followed of using the KBUILD_MODNAME CPP define to set the name of
+the security model, the argument to the model keyword will be that
+name, a value that will match the name that is displayed by the lsmod
+command.  It should be noted that there is no requirement that the
+security model name match the name of the module generated by the
+build process.
+
+The 'nsref' keyword takes one of the following two values:
+
+	initial
+	current
+
+The initial argument indicates that the UID/GID values for the COE and
+CELL characteristics are derived from the initial user namespace.
+This is the default characteristic if the nsref key is not specified.
+
+The current argument indicates that the UID/GID values are derived
+from the user namespace that the process is running in, when the
+request is made to model an event.
+
+The 'digest' keyword is used to specify the cryptographic hash
+function that is to be used to create the functional values for the
+security state coefficients for the namespace.  The value to this
+keyword is the name by which the hash function is defined by the
+cryptographic API in the kernel.
+
+Examples of suitable strings are as follows:
+
+	sha256
+	sha3-256
+	sm3
+
+Definitions for the names of the cryptographic hashes can be found in
+the source files for the various cryptographic hash functions in the
+'crypto' directory of the Linux source tree.
+
+The 'cache' keyword is used to specify the size of the caches used to
+hold pointers to data structures used for the internal modeling of
+security events or the export of the security event to external trust
+orchestrators.  These pre-allocated structures are used to service
+security event hooks that are called while the process is running in
+atomic context and thus cannot sleep in order to allocate memory.
+
+The argument to this keyword is a numeric value specifying the number
+of structures that are to be held in reserve for the namespace.
+
+By default the root security modeling namespace and externally modeled
+namespaces have a default value of 128 entries.  An internally modeled
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 1114

Quoted 4 lines
Documentation/admin-guide/LSM/tsem.rst new file +4 -0
+namespace has a default value of 32 entries.  The size requirements of
+these caches can be highly dependent on the characteristics of the
+modeled workload and may require tuning to the needs of the platform
+or workload.

Presumably TSEM provides usage statistics somewhere so admins can monitor and tune as desired? If so, it seems like it would be a good idea to add a reference here.

We have trended toward the Linus philosophy of reducing the need to worry about properly tuning knobs.

So, significant testing with standard Linux distributions running a TSEM kernel have caused us to raise the cache sizes to levels that support the boot of a standard Linux distribution. These levels are more than sufficient for containerized workloads.

To your point more specifically, we haven't had the bandwidth for this yet but the ability to report the low water marks for a namespace would probably be of benefit.

Quoted 6 lines

Documentation/admin-guide/LSM/tsem.rst line 1119

Quoted 4 lines
Documentation/admin-guide/LSM/tsem.rst new file +4 -0
+The structures that are used by security events generated in atomic
+context are replenished by work requests submitted to the high
+priority system workqueue.  The refill latency will also affect the
+magazine sizes that are needed.

Once again, it seems like a kmem_cache could be useful.

As noted above, all of the primary TSEM event structure are filled from structure specific kmem_cache implementations.

As we also noted previously, that doesn't eliminate the need for atomic context structure magazines. We develop exclusively with full lock debugging enabled, lockdep splats show up pretty quickly with a simple kmem_cache implementation.

Quoted 19 lines
Quoted 19 lines
Documentation/admin-guide/LSM/tsem.rst new file +19 -0
+The 'key' keyword is used to specify the authentication key that is to
+be used to support the authentication of trust control requests from a
+trust orchestrator to processes running in a security modeling
+namespace.  The argument to this keyword is the ASCII base16
+representation of the key that is to be used.  The length of the key
+must be equal to the length of the ASCII base16 representation of the
+digest value of the cryptographic digest function defined for the
+security modeling namespace.
+
+The following keywords and arguments are used by trust orchestrators
+to set the trust status of a process after the processing of a
+security event by an external TMA:
+
+	trusted pid=PID key=HEXID
+	untrusted pid=PID key=HEXID
+
+	PID is the process identifier that is provided to the TMA in
+	the security event description.  HEXID is the base16 ASCII
+	representation of the authentication key that the security
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst

Quoted 2 lines
Documentation/admin-guide/LSM/tsem.rst new file +2 -0
+	modeling namespace was configured with when the namespace was
+	created.

This is something that will likely have to wait until the review progresses further down into the implementation as it raises a fair number of red flags. To be fair, it is possible they are false warnings, but judgement on this will have to wait until the other major concerns from the doc review have been addressed in some way.

Hopefully we have reached a point where the generic major review concerns have been addressed, please let us know of specific concerns and we will address them directly.

Quoted 172 lines
Quoted 172 lines
Documentation/admin-guide/LSM/tsem.rst new file +172 -0
+     The length of the ASCII representation of HEXID must
+	equal the size of the base16 ASCII representation of a digest
+	value for the cryptographic hash function selected for the
+	security modeling namespace.
+
+By default a security modeling namespace runs in free modeling mode.
+The modeling mode is changed by writing the following keywords to the
+control file:
+
+	seal
+	enforce
+
+The seal value is used to specify that any further security state
+coefficients are to be considered outside the bounds of a desired
+security model.  The security event descriptions that generate these
+coefficients will be considered forensics events for the model.
+
+The enforce key is used to specify that invalid security events
+generate permission denials as the return value for the LSM security
+event handler that generates the invalid events.
+
+The following keyword and argument are used to load a security model
+into an internal TMA modeling implementation:
+
+	state value=HEXID
+
+	Where HEXID is the ASCII base 16 representation of a security
+	state coefficient that represents a valid security event in
+	the model.  The length of the HEXID string must be equal to
+	the size of the ASCII base 16 representation of the digest
+	value of the cryptographic hash function defined for the
+	security modeling namespace.
+
+	After writing a series of state values the trust orchestrator
+	writes the 'seal' keyword to the control file to complete
+	creation of a security model.
+
+	Writing the 'enforce' keyword to the control file will place
+	the defined model in enforcing mode.
+
+	Defining a security model to be enforced will affect the
+	output of the 'trajectory' file.  The 'trajectory' file will
+	have no event descriptions for a sealed model, since the event
+	description list is only populated when a new state
+	coefficient is added to the model.
+
+	In a sealed model the security event descriptions will be
+	surfaced in the 'forensics' file instead to indicate they are
+	violations against the security model being enforced.
+
+	Since the state state coefficients are generated with a
+	cryptographic hash function, the first pre-image resistance
+	characteristics of the function prevents a security model
+	description from disclosing information, a-priori, about the
+	desired characteristics of the workload.
+
+The following keyword and argument is used to set a base nonce for the
+internal TMA:
+
+	base value=HEXID
+
+	Where HEXID is the ASCII base 16 representation of a value
+	that each security state event mapping is to be extended with
+	before being committed as a security state coefficient value
+	for the model.  The size of the HEXID string must equal the
+	size of the ASCII base 16 representation of a digest value of
+	the cryptographic hash function defined for the security
+	modeling namespace.
+
+The following keyword and argument is used to create a file digest
+pseudonym for the internal TMA:
+
+	pseudonym value=HEXID
+
+	Where HEXID is the ASCII base 16 representation of a file
+	digest pseudonym that is to be maintained by the model.  See
+	the ABI documentation for how the argument to this verb is
+	generated.
+	
+	The size of the HEXID string must equal the size of the ASCII
+	base 16 representation of a digest value of the cryptographic
+	hash function defined for the security modeling namespace.
+
+The following keyword is used to lock the current TSEM modeling
+configuration:
+
+	lock
+
+This command is only valid when loadable module support is available
+in the kernel.  When executed this command blocks any further TSEM
+models from being registered.  In addition the reference count on all
+currently registgered modeling modules is increased so that it is not
+possible to remove currently loaded modules.
+
+The following two directories are implemented in the top level TSEM
+control directory in order to support interfaces to internally and
+externally modeled namespaces:
+
+	external_tma
+	internal_tma
+
+The external_tma directory holds a file, that is created when the
+request to create an externally modeled namespace is made.  The filename
+is the ASCII base 10 representation of the id number of the security
+modeling namespace.  The descriptions for security events that occur
+in the context of the namespace are exported in JSON format through
+this file to the external trust orchestrator that is controlling the
+security modeling namespace.
+
+The internal_tma directory is a container directory that holds
+directories for the control of each internal TMA that is implemented
+in the kernel.
+
+There is currently only a single kernel based TMA that is managed
+through the following directory:
+
+/sys/kernel/security/tsem/internal_tma/model0
+
+The following files are implemented for this model:
+
+	measurement
+	state
+
+	trajectory
+	trajectory_coefficients
+	trajectory_counts
+
+	forensics
+	forensics_coefficient
+	forensics_counts
+
+The 'measurement' file outputs the classic linear extension value of
+the security state coefficients that are generated in the context of
+the security modeling namespace.  This value is time dependent and can
+be used to verify the order of the security events that occurred in
+the model.
+
+The 'state' file outputs the time independent functional value of
+security state of the security modeling namespace.  This value and its
+generation and motivation are discussed in the 'Security model
+functional definitions' section of this document.
+
+The 'trajectory' file outputs the description of each security event
+recorded by the model in time dependent form.  The ABI documentation
+file contains a complete description of the output that is generated
+by this file and the 'forensics' file described below.
+
+The 'trajectory_coefficients' file outputs the set of security state
+coefficients in the model.  These coefficients match the entries of
+the event descriptions that are output in the 'trajectory' file.
+
+The security state coefficients can be paired with the security state
+descriptions with the following shell command, where DIR is the path
+to the individual files:
+
+paste DIR/trajectory_coefficients DIR/trajectory
+
+The 'trajectory_counts" file outputs the number of times that each
+security state coefficient, output by the 'trajectory_coefficients'
+file, has been experienced in the security modeling namespace.  This
+value can be used to verify that a security sensitive event has
+occurred or for statistical inference as to the anomaly status of an
+event.
+
+The 'forensics' file outputs the description of security events that
+have occurred when the namespace security model is running in a sealed
+state.  These events are useful for characterizing a security
+intrusion that has occurred or for refinement of a security model.
+
+The 'forensics_coefficients' file outputs the security state
+coefficients that are generated by the forensics events that have
+been captured by the model and available through the 'forensics' file.
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 1318

Quoted 6 lines
Documentation/admin-guide/LSM/tsem.rst new file +6 -0
+
+The 'forensics_counts" file outputs the number of times that each
+security state coefficient output by the 'forensics_coefficients' file
+has been experienced in the security namespace.  This value can can be
+used for statistical inference as to the anomaly status of the
+namespace.

paul-moore.com

Thank you for taking the time to review our documentatioin, we look forward to further engagement on the code.

Best wishes for an enjoyable weekend.

As always,
Dr. Greg

The Quixote Project - Flailing at the Travails of Cybersecurity
https://github.com/Quixote-Project

#5 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

Quoted 2 lines · Dr. Greg

On Mon, Jan 13, 2025 at 08:29:47PM -0500, Paul Moore wrote:

...

Quoted 17 lines
Quoted 2 lines

Please define the CELL acronym here as I believe it is the first use of "CELL" in this document.

FWIW, CELL isn't an acronym, it is a metaphor.

TSEM was conceptually inspired by and derived from the Turing Abstract Machine Model (TAMM), as applied to the problem of modeling the security state of an execution domain.

As everyone reading this knows, a TAMM, in practice, consists of a head traversing an infinite paper tape divided into cells that direct the next state of the machine.

In TSEM, the model consists of a Context Of Execution (COE) with security definining characteristics, traversing a finite set of measurement points of infinite length, with defining characteristics at each point.

Quoted 4 lines

We refer to a measurement point and its characteristics as a CELL in deference to the inspiration for all of this.

We will add this explanation to the documentation.

Communication within a community as culturally diverse as the Linux kernel developers* requires that you do not assume that "everyone reading this" knows much of anything beyond how to type "make". Let's face it, there are kernel developers today who would look at the Turing test and say "is that even a thing?" There are others who don't have an education that includes mid-twentieth century technological history.

[* Yes, an awful lot of Linux kernel developers are western males. ]

...

Quoted 3 lines

We believe there is a technical solution to this problem as well but our work on that front, at this point, is too technically immature to go into.

Didn't Pierre de Fermat say something like that about some theorem or another?

...

... Sorry, all I have time for today.

author
#6 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

On Fri, Jan 17, 2025 at 10:10:30AM -0800, Casey Schaufler wrote:

Good morning Casey, I hope your weekend is going well, thanks for taking the time to forward along your thoughts on our work.

Quoted 35 lines · Dr. Greg
Quoted 2 lines · Paul Moore

...

Quoted 18 lines
Quoted 2 lines

Please define the CELL acronym here as I believe it is the first use of "CELL" in this document.

FWIW, CELL isn't an acronym, it is a metaphor.

TSEM was conceptually inspired by and derived from the Turing Abstract Machine Model (TAMM), as applied to the problem of modeling the security state of an execution domain.

As everyone reading this knows, a TAMM, in practice, consists of a head traversing an infinite paper tape divided into cells that direct the next state of the machine.

In TSEM, the model consists of a Context Of Execution (COE) with security definining characteristics, traversing a finite set of measurement points of infinite length, with defining characteristics at each point.

Quoted 4 lines

We refer to a measurement point and its characteristics as a CELL in deference to the inspiration for all of this.

We will add this explanation to the documentation.

Communication within a community as culturally diverse as the Linux kernel developers* requires that you do not assume that "everyone reading this" knows much of anything beyond how to type "make". Let's face it, there are kernel developers today who would look at the Turing test and say "is that even a thing?" There are others who don't have an education that includes mid-twentieth century technological history.

Quoted 3 lines

[* Yes, an awful lot of Linux kernel developers are western males. ]

...

Sigh....

It would thus appear that effective dialogue in the Linux kernel community is now about as perilous as attempting to square dance in a minefield with snowshoes on.

When we penned the reflections above, we very specifically did not want to be so pejorative as to suggest that anyone involved in this endeavor wouldn't have at least a basic understanding of the computability theory that all of our work is based. They even have a movie about it, presumably in multiple languages.

In any event, we apologize for being mistaken.

We will add a Wikipedia link in the documentation pointing to an article on Turing machines, for the benefit of the unwashed masses now involved in kernel development.

Quoted 6 lines
Quoted 3 lines

We believe there is a technical solution to this problem as well but our work on that front, at this point, is too technically immature to go into.

Didn't Pierre de Fermat say something like that about some theorem or another?

I believe you are referring to Fermat's Last Theorem, formerly known as Fermat's Conjecture.

For all the bystanders whose level of understanding is limited to 'make bzImage':

Fermat's Conjecture, now a proven and foundational theorem in algebraic number theory, states that there exist no three positive
integers: a, b or c; that satisfies the following algebraic relationship for any value of n greater than two:

a^n + b^n = c^n

Fermat penned the theorem into the margin of his copy of Diophantus's Arithmetica, and in a note below it, indicated there was insufficient room in the margin to write the formal proof.

It was called Fermat's Conjecture, since many doubted its validity or that Fermat ever had any proof for what he was proposing.

As a Quixote team we take some solace to your reference of Fermat's Theorem with respect to our work. It took 358 years to formally prove his theorem, in the face of many nay-sayers. It turns out he was absolutely right and his vision is now universally accepted as a foundational premise of mathematics.

And so it goes with respect to the perils of innovation.

Quoted 1 line

... Sorry, all I have time for today.

Yes, and I need to get outside and get my fishhouse off the lake. It is going to be -20 tonight and the 4-wheeler isn't going to start in the morning.

We always appreciate the insight that you bring forward with respect to our work.

Best wishes for a pleasant weekend.

As always,
Dr. Greg

The Quixote Project - Flailing at the Travails of Cybersecurity
https://github.com/Quixote-Project

#7 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

Quoted 38 lines · Dr. Greg

On Fri, Jan 17, 2025 at 10:10:30AM -0800, Casey Schaufler wrote:

Good morning Casey, I hope your weekend is going well, thanks for taking the time to forward along your thoughts on our work.

Quoted 33 lines · Dr. Greg
Quoted 2 lines · Paul Moore

...

Quoted 17 lines
Quoted 2 lines

Please define the CELL acronym here as I believe it is the first use of "CELL" in this document.

FWIW, CELL isn't an acronym, it is a metaphor.

TSEM was conceptually inspired by and derived from the Turing Abstract Machine Model (TAMM), as applied to the problem of modeling the security state of an execution domain.

As everyone reading this knows, a TAMM, in practice, consists of a head traversing an infinite paper tape divided into cells that direct the next state of the machine.

In TSEM, the model consists of a Context Of Execution (COE) with security definining characteristics, traversing a finite set of measurement points of infinite length, with defining characteristics at each point.

Quoted 4 lines

We refer to a measurement point and its characteristics as a CELL in deference to the inspiration for all of this.

We will add this explanation to the documentation.

Communication within a community as culturally diverse as the Linux kernel developers* requires that you do not assume that "everyone reading this" knows much of anything beyond how to type "make". Let's face it, there are kernel developers today who would look at the Turing test and say "is that even a thing?" There are others who don't have an education that includes mid-twentieth century technological history.

Quoted 8 lines
Quoted 3 lines

[* Yes, an awful lot of Linux kernel developers are western males. ]

...

Sigh....

It would thus appear that effective dialogue in the Linux kernel community is now about as perilous as attempting to square dance in a minefield with snowshoes on.

This isn't about Political Correctness. It's about communication. Your documentation appears to target PHD level computer scientists. Most Linux kernel developers are much more the BS engineer sort. I'm not saying you need to dumb it down, I'm suggesting that you could make it easier to review by targeting your audience better.

Quoted 11 lines

When we penned the reflections above, we very specifically didot want to be so pejorative as to suggest that anyone involved in this endeavor wouldn't have at least a basic understanding of the computability theory that all of our work is based. They even have a movie about it, presumably in multiple languages.

In any event, we apologize for being mistaken.

We will add a Wikipedia link in the documentation pointing to an article on Turing machines, for the benefit of the unwashed masses now involved in kernel development.

The link is a good idea.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

We believe there is a technical solution to this problem as well but our work on that front, at this point, is too technically immature to go into.

Didn't Pierre de Fermat say something like that about some theorem or another?

Quoted 7 lines

...

As a Quixote team we take some solace to your reference of Fermat's Theorem with respect to our work. It took 358 years to formally prove his theorem, in the face of many nay-sayers. It turns out he was absolutely right and his vision is now universally accepted as a foundational premise of mathematics.

If it takes the Quixote team 358 years to develop a technical solution I expect you will miss your market window. :(

author
#8 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

On Tue, Jan 21, 2025 at 10:09:59AM -0800, Casey Schaufler wrote:

Hi Casey, I hope your weekend has gone well, greetings to other on the list as well.

Quoted 42 lines · Dr. Greg
Quoted 41 lines · Casey Schaufler

Good morning Casey, I hope your weekend is going well, thanks for taking the time to forward along your thoughts on our work.

Quoted 36 lines · Dr. Greg
Quoted 2 lines · Paul Moore

...

Quoted 17 lines
Quoted 2 lines

Please define the CELL acronym here as I believe it is the first use of "CELL" in this document.

FWIW, CELL isn't an acronym, it is a metaphor.

TSEM was conceptually inspired by and derived from the Turing Abstract Machine Model (TAMM), as applied to the problem of modeling the security state of an execution domain.

As everyone reading this knows, a TAMM, in practice, consists of a head traversing an infinite paper tape divided into cells that direct the next state of the machine.

In TSEM, the model consists of a Context Of Execution (COE) with security definining characteristics, traversing a finite set of measurement points of infinite length, with defining characteristics at each point.

Quoted 4 lines

We refer to a measurement point and its characteristics as a CELL in deference to the inspiration for all of this.

We will add this explanation to the documentation.

Communication within a community as culturally diverse as the Linux kernel developers* requires that you do not assume that "everyone reading this" knows much of anything beyond how to type "make". Let's face it, there are kernel developers today who would look at the Turing test and say "is that even a thing?" There are others who don't have an education that includes mid-twentieth century technological history.

[* Yes, an awful lot of Linux kernel developers are western males. ]

...

Quoted 8 lines
Quoted 5 lines

Sigh....

It would thus appear that effective dialogue in the Linux kernel community is now about as perilous as attempting to square dance in a minefield with snowshoes on.

This isn't about Political Correctness. It's about communication. Your documentation appears to target PHD level computer scientists.

Probably not surprising, given that Quixote has been architected and stewarded by three Ph.D.'s, one soon to be Ph.D. and a rather remarkable individual that has four Ph.D.'s worth of experience, if I can choose my phrasing carefully, in global cyber-operations of various types.

Quoted 3 lines

Most Linux kernel developers are much more the BS engineer sort. I'm not saying you need to dumb it down, I'm suggesting that you could make it easier to review by targeting your audience better.

In the theory portion of the documentation we attempted to draw correlations between classic mandatory access control and integrity architectures and what we are implementing with Quixote/TSEM.

Quoted 6 lines
Quoted 6 lines

When we penned the reflections above, we very specifically didot want to be so pejorative as to suggest that anyone involved in this endeavor wouldn't have at least a basic understanding of the computability theory that all of our work is based. They even have a movie about it, presumably in multiple languages.

Quoted 7 lines
Quoted 5 lines

In any event, we apologize for being mistaken.

We will add a Wikipedia link in the documentation pointing to an article on Turing machines, for the benefit of the unwashed masses now involved in kernel development.

The link is a good idea.

Clarifications to the theory section and a Wikipedia link have been added and will appear in V5.

Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

We believe there is a technical solution to this problem as well but our work on that front, at this point, is too technically immature to go into.

Didn't Pierre de Fermat say something like that about some theorem or another?

Quoted 8 lines
Quoted 5 lines

As a Quixote team we take some solace to your reference of Fermat's Theorem with respect to our work. It took 358 years to formally prove his theorem, in the face of many nay-sayers. It turns out he was absolutely right and his vision is now universally accepted as a foundational premise of mathematics.

If it takes the Quixote team 358 years to develop a technical solution I expect you will miss your market window. :(

If we didn't believe that we have a solid technical solution in hand within the context of this century, and groups that have asked for it to be in the kernel, we wouldn't be expending cycles on getting it upstreamed.

We are hoping for considerably better than 358 years, but that would seem to be dependent on Linux review bandwidth, which everyone agrees is strained.

More to the point, we were making an allusion with our comments that throughout history, disruptive innovation has been consistently missed by the technical status quo.

Once again, thank you for your comments and review.

Have a good remainder of the weekend.

As always,
Dr. Greg

The Quixote Project - Flailing at the Travails of Cybersecurity
https://github.com/Quixote-Project

maintainer
#9 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

In reply to Dr. Greg
Quoted 22 lines · Dr. Greg
Quoted 21 lines · Paul Moore
Quoted 20 lines · On Aug 26, 2024 Greg Wettstein <[email protected]> wrote:

An entry was added to the ABI testing documentation to document the API definitions for the TSEM ontrol plane.

The file documenting the kernel command-line parameters was updated to document the TSEM specific parameters that are implemented.

The primary TSEM documentation file was added to the LSM administration guide and the file was linked to the index of LSM documentation.

---
 Documentation/ABI/testing/tsem                | 2420 +++++++++++++++++
 Documentation/admin-guide/LSM/index.rst       |    1 +
 Documentation/admin-guide/LSM/tsem.rst        | 1680 ++++++++++++
 .../admin-guide/kernel-parameters.txt         |   29 +
 4 files changed, 4130 insertions(+)
 create mode 100644 Documentation/ABI/testing/tsem
 create mode 100644 Documentation/admin-guide/LSM/tsem.rst

...

Quoted 62 lines
Quoted 53 lines
Quoted 53 lines
Documentation/admin-guide/LSM/tsem.rst new file +53 -0
+Security Event Modeling
+=======================
+
+   "We can no longer speak of the behavior of the particle
+    independently of the process of observation. As a final
+    consequence, the natural laws formulated mathematically in
+    quantum theory no longer deal with the elementary particles
+    themselves but with our knowledge of them. Nor is it any
+    longer possible to ask whether or not these particles exist in
+    space and time objectively ... When we speak of the picture of
+    nature in the exact science of our age, we do not mean a
+    picture of nature so much as a picture of our relationships
+    with nature.  ...Science no longer confronts nature as an
+    objective observer, but sees itself as an actor in this
+    interplay between man and nature. The scientific method of
+    analysing, explaining and classifying has become conscious of
+    its limitations, which arise out of the fact that by its
+    intervention science alters and refashions the object of
+    investigation. In other words, method and object can no longer
+    be separated."
+                           - Werner Karl Heisenberg
+
+Security Event Modeling (SEM), is an alternative strategy to implement
+the security guarantees of mandatory access and integrity controls, in
+a manner that is consistent with emerging application development
+strategies such as namespaces and CI/CD workflows.
+
+As was noted at the start of this document, the premise for SEM is
+that the security behavior of a platform, or alternatively a workload,
+can be modeled like any other physical phenomenon in science and
+engineering.
+
+Inspiration for this came from the primary TSEM author/architect
+having trained as a quantum chemist, conducting very early research in
+the development of multi-scale modeling strategies for molecules of
+size to be of interest to pharmaceutical intents.
+
+SEM is premised on the theory that kernel security architects have
+instrumented the LSM security event hooks to be called in locations
+before security sensitive operations are conducted, with appropriate
+descriptive parameters, that are considered relevant to the security
+posture of the kernel.  With respect to modeling, the security event
+hooks are conceptualized as representing the independent variables of
+a basis set that yields a functional definition for the security state
+of an execution trajectory.
+
+SEM can be framed in the context of classic subject/object mandatory
+access controls, by the notion that a unique identity can be generated
+for each element of an access vector matrix, rather than a boolean
+value.  In SEM, a security execution trajectory is defined by the set
+of security state coefficients that a process hierarchy (workload)
+generates.  This execution trajectory produces a vector of identities,
+whose sum in an appropriate form, yields a functional definition of
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 272

Quoted 5 lines
Documentation/admin-guide/LSM/tsem.rst new file +5 -0
+the security state of the system.
+
+Two subordinate identities are combined to yield a security event
+state coefficient.  These subordinate identities are referred to as
+the Context Of Execution (COE) and the CELL, which are conceptually

Please define the CELL acronym here as I believe it is the first use of "CELL" in this document.

Quoted 1 line

FWIW, CELL isn't an acronym, it is a metaphor.

My mistake. I know how hard naming can be, so if you feel like "CELL" is the best choice here I'm not going to object, however, I think it is worth a mention that in our acronym heavy industry any term that is presented in all caps is often seen as an acronym and not a metaphor.

Quoted 32 lines
Quoted 23 lines
Quoted 23 lines
Documentation/admin-guide/LSM/tsem.rst new file +23 -0
+The Linux TSEM Implementation
+=============================
+
+   "Sometimes the questions are complicated and the answers are
+    simple."
+                           - Dr. Seuss
+
+The Linux TSEM implementation is deliberately simplistic and consists
+of the following two generic components:
+
+- Security modeling namespace and security event export functionality.
+
+- Internal trusted modeling agent implementation.
+
+The security modeling namespace and export functionality is designed
+to be generic infrastructure that allows security namespaces to be
+created that are either internally or externally modeled.  The TSEM
+implementation does not pose any constraints on what type of modeling
+can or should be implemented in these namespaces.
+
+On the theory that security event handlers represent all of the
+security relevant action points in the kernel, any security or
+integrity model can be implemented using the TSEM infrastructure.  For
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 512

Quoted 3 lines
Documentation/admin-guide/LSM/tsem.rst new file +3 -0
+example, basic IMA functionality could be implemented by a TMA that
+maps the digests of files accessed, or mapped executable, by the root
+user as the security state coefficients.

In order to keep the peace among different LSMs, we try very hard to avoid language along the lines of "LSM A could be implemented by LSM B". Please refrain from such language, especially in documentation that lives within the kernel.

Quoted 2 lines

We were not suggesting superiority or replacement, our apologies to the community if the above would be perceived as such.

My recommendation is to simply avoid any mention of other LSMs. Not only does it avoid any unforeseen negative comparisons, it also encourages the documentation to fully explain the LSM without having to rely on an understanding of another, which could result in its own set of problems.

Quoted 5 lines

In fact, the upcoming V5 release and its associated userspace tools, have a proof of concept implementation of TOMOYO as a TSEM loadable module, as a further indication of its ability to lowering the barriers to the development of alternative or customized security architectures.

Ignoring any technical issues for a moment, I would strongly suggest against that approach for the reasons given above. I can appreciate that your intent is likely to demonstrate the capabilities of TSEM, but doing so by emulating an existing LSM sets a bad precedent and I will not view it positively.

Quoted 46 lines
Quoted 41 lines
Quoted 21 lines
Documentation/admin-guide/LSM/tsem.rst new file +21 -0
+Internal vs external modeling
+-----------------------------
+
+When a TSEM security modeling namespace is created, a designation is
+made as to whether the namespace is to be internally or externally
+modeled.
+
+In an internally modeled namespace, the security event handlers pass the
+event type and its characteristics to the designated internal trusted
+modeling agent.  The agent provides the permission value for the
+security event handler to return as the result of the event and sets
+the trust status of the process executing the event.
+
+In an externally modeled namespace, the event type and parameters are
+exported to userspace for processing by a trust orchestrator with an
+associated TMA.  The trust orchestrator communicates the result of the
+modeling back to the kernel to support the setting of the process
+trust status.
+
+The exception to this model are for security event handlers that are
+called in atomic, ie. non-sleeping context.  The export of these

Documentation/admin-guide/LSM/tsem.rst line 559

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+security event descriptions are done asynchronously in order to avoid
+having the TSEM implementation attempt to sleep in atomic context
+while the userspace trust orchestrator is scheduled for execution.
+
+It is up to the trust orchestrator and its security policy to
+determine how it handles events that violate the security model being
+enforced in this model.  The Quixote trust orchestrators shut down the
+entire workload running in the security namespace if an asynchronously
+modeled event violates the security model being enforced and the model
+is running in enforcing mode.

I understand your desire to simply pass off the non-blocking/async access control hole as a security policy issue, but it seems to me that this is a fundamental flaw with an externally modeled TSEM namespace. If an externally modeled namespace was configured with an enforcing policy, it doesn't appear that there is a mechanism for TSEM to properly enforce that policy as there is an unbounded delay between the undesired access and a denial verdict being processed by the kernel.

Quoted 4 lines

Unless you can resolve this somehow, and I'm not sure how, I would suggest dropping external/userspace trust orchestrators. They simply don't seem able to reliably implement their security policies.

Quoted 8 lines

An important issue.

Some reflections on why we would, respectfully, disagree.

A business assessment of the current security market suggests that the mindset in security has changed from prevention to detection. TSEM is about providing kernel infrastructure to enable better solutions for the detection model.

I believe the LSM can support both the enforcement of security policy and the observation of security relevant events on a system. In fact most of the existing LSMs do both, at least to some extent.

However, while logging of security events likely needs to be asynchronous for performance reasons, enforcement of security policy likely needs to be synchronous to have any reasonable level of assurance. You are welcome to propose LSMs which provide observability functionality that is either sync, async, or some combination of both (? it would need to make sense to do both ?), but I'm not currently interested in accepting LSMs that provide asynchronous enforcement as I don't view that as a "reasonable" enforcement mechanism.

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
Documentation/admin-guide/LSM/tsem.rst new file +8 -0
+In order to handle modeling of security events in atomic context, the
+TSEM implementation maintains caches (magazines) of structures that
+are needed to implement the modeling and export of events.  The size
+of this cache can be configured independently for each individual
+security modeling namespace that is created.  The default
+implementation is for a cache size of 32 for internally modeled
+namespaces and 128 for externally modeled namespaces.
+
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 584

Quoted 3 lines
Documentation/admin-guide/LSM/tsem.rst new file +3 -0
+By default the root security namespace uses a cache size of 128.  This
+value can be configured by the 'tsem_cache' kernel command-line
+parameter to an alternate value.

I haven't looked at the implementation yet, but I don't understand both why a kmem_cache couldn't be used here as well as why this implementation detail is deemed significant enough to be mentioned in this high level design document.

Quoted 8 lines

TSEM does use kmem_cache allocations for all of its relevant data structures.

The use of a kmem_cache, however, does not solve the problem for security event handlers that are required to run in atomic context. To address the needs of those handlers you need to serve the structures out of a pre-allocated magazine that is guaranteed to not require any memory allocation or sleeping locks.

This still seems somewhat suspicious as there are a couple of GFP flags that allow for non-blocking allocations in all but a few cases, but I'll defer further discussion of that until I get to the code. In my opinion, there are still enough red flags in these documentation reviews to keep me from investing the time in reviewing the TSEM code.

Regardless, I stand by my previous comment that discussion of these caches may be a bit more detail that is needed in this document, but of course that is your choice. It's a balancing act between providing enough high level detail to satisfy users and reviewers, and producing a document that is so verbose that the time required to properly review it is prohibitive.

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
Documentation/admin-guide/LSM/tsem.rst new file +12 -0
+Trust Orchestrator/Process authentication
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The process identifier values (PID's) that are exported in the
+security event descriptions are the unique global PID values, not the
+value as seen through the lens of a PID namespace.
+
+PID values are, by default, not considered to be a stable identifier
+between the kernel and userspace.  In the case of TSEM external
+modeling, the threat model for a namespace is whether or not an
+adversarial process, running in either the root security modeling
+namespace or another subordinate security modeling namespace, can kill
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 599

Quoted 2 lines
Documentation/admin-guide/LSM/tsem.rst new file +2 -0
+a process that is being orchestrated and substitute an alternate
+process with an identical PID value.

We've talked about this previously, but given my current understanding of TSEM, one of my concerns is the presence of user controlled data in a TSEM security event. This could include PIDs, task->comm values, and potentially others (I haven't gone through the full CELL list yet).

Quoted 2 lines

Point one: we don't use task->comm values, or PID's, in the generative models.

Yet a PID is still exported to an external orchestrator.

Quoted 126 lines
Quoted 102 lines
Quoted 102 lines
Documentation/admin-guide/LSM/tsem.rst new file +102 -0
+Event modeling
+--------------
+
+The generation of security state coefficients is a functional process
+that uses a cryptographic hash function for the creation of the
+individual identity mappings that contribute to the generation of the
+security state coefficient.
+
+TSEM can use any cryptographic hash function available to the Linux
+kernel for this purpose.  The hash function to be used for a security
+modeling namespace is specified as a parameter to the namespace
+creation process.
+
+By default, the root security namespace uses sha256.  This value can
+be modified through the tsem_digest kernel command-line parameter.
+
+Since TSEM is active before the kernel has the ability to load
+modules, the root modeling domain must be a cryptographic hash
+function that is statically compiled into the kernel.  By default the
+TSEM configuration selects for the presence of the sha256 hash
+function.
+
+TSEM security event modeling is based on the following functional
+definition for a security event coefficient:
+
+Coeff = HF(HF(EVENT_ID) || PTASK_ID || TASK_ID || HF(COE) || HF(CELL))
+
+   Where:
+           Coeff    = A security state coefficient that is equal
+                      in length to the digest value of the
+                      cryptographic hash function in use for the
+                      security modeling namespace.
+
+           HF       = Security namespace specific hash function.
+
+           ||       = Concatenation operator.
+
+           EVENT_ID = The ASCII name of event.
+
+           PTASK_ID = The TASK_ID of the parent process of the
+                      process represented by TASK_ID.
+
+           TASK_ID  = The process specific identity of the
+                      executable code that is calling the security
+                      event handler.
+
+           COE      = Characteristics of the context of execution
+                      of the event.
+
+           CELL     = Characteristics of the LSM event that is being
+                      modeled.
+
+Workload or platform specific security state coefficient definitions
+are generated by a TMA, using the COE or CELL characteristics that are
+considered relevant for the model being implemented.  These
+coefficients are used to determine whether or not an event should lead
+to the process being considered trusted or untrusted.
+
+The TASK_ID component of the function above is important with respect
+to the generation of the security state coefficients.  The notion of a
+task identity serves to link the concepts of system integrity and
+security access control.
+
+The TASK_ID is defined by the following function:
+
+TASK_ID = HF(HF(EVENT) || PTASK_ID || NULL_ID || HF(COE) || HF(CELL))
+
+   Where:
+           TASK_ID   = The executable identity of the process
+                       expressed as a digest value of length
+                       equal to the cryptographic hash function
+                       the security modeling namespace is using.
+
+           HF        = Security namespace specific hash function.
+
+           ||        = Concatenation operator.
+
+           EVENT     = The string "bprm_committed_creds".
+
+           PTASK_ID  = The TASK_ID of the parent process of the
+                       process whose TASK_ID is being generated.
+
+           NULL_ID   = A buffer of null bytes equal to the digest
+                       size of the hash function being used for
+                       the namespace.
+
+           COE       = Characteristics of the context of execution
+                       calling the bprm_committed_creds LSM hook.
+
+           CELL      = The characteristics of the file provided
+                       by the linux_binprm structure passed to
+                       the security_bprm_committed_creds handler.
+
+An attentive reader will quickly conclude, correctly, that the TASK_ID
+function generates an executable specific security coefficient for the
+bprm_committed_creds security hook.  The generative function for the
+TASK_ID is the same as the standard security state coefficient; with
+the exception that the task identity is replaced with a 'null id',
+consisting of the number of null bytes in the digest size of the
+namespace specific hash function.
+
+One of the CELL characteristics used in the computation of the task
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 810

Quoted 4 lines
Documentation/admin-guide/LSM/tsem.rst new file +4 -0
+identity is the digest of the executable file.  Modifying an
+executable, or attempting to execute a binary not considered in the
+security model, will result in an alteration of the task identity that
+propagates to the generation of invalid state coefficients.

Presumably an attacker could craft a malicious executable (or influence the CELL value if it incorporates user controlled values) that collides with the digest of a known and trusted application.

An incredibly important issue, so apologies for a more lengthy reply on this issue.

More precisely, the objective for an adversary would be to generate the same security coefficient for a specific security event type using an alternative ensemble of operating system relevant characteristics for the event.

The generative functions for the COE, CELL, task identities and ultimately the security state coefficients, are based on industry standard cryptographic hash functions. The attack scenario suggested above would represent a major failure in the second pre-image resistance characteristics of these industry standard security primitives.

Quoted 2 lines

The ability to decept these security primitives, in such a manner, would represent a crisis for the entire technology industry.

Look around, it is happening now. Of course the level of risk varies tremendously based on the application and yes, the chosen hash function. However, given the composition of TSEM's CELL value in some events, and the importance of a hashed event value in TSEM's policy/model enforcement, it seems like this is something that one would want to address.

Quoted 86 lines
Quoted 74 lines
Quoted 74 lines
Documentation/admin-guide/LSM/tsem.rst new file +74 -0
+Security model functional definitions
+-------------------------------------
+
+Previously, classic trusted system implementations supported the
+notion of the 'measurement' of the system.  The measurement is the
+value of a linear extension function of all the security relevant
+actions recorded by a trust measurement system such as IMA.
+
+In TPM based trust architectures, this measurement is maintained in a
+PCR.  A measurement value is submitted to the TPM that extends the
+current measurement using the following formula:
+
+MEASUREMENT = HF(CURRENT || NEW)
+
+   Where:
+           MEASUREMENT = The new measurement value to be maintained
+                         in the register for the system.
+
+           HF          = A cryptographic hash function supported
+                         by the TPM device.
+
+           ||          = Concatenation operator.
+
+           CURRENT     = The current measurement value.
+
+           NEW         = A new measurement value to be added to
+                         the current measurement.
+
+The use of a cryptographic function produces a non-commutative sum
+that can be used to verify the integrity of a series of measurements.
+With respect to security modeling theory, this can be thought of as a
+'time-dependent' measurement of the system.  Stated more simply, the
+measurement value is sensitive to the order in which the measurements
+were made.
+
+In systems such as IMA, the measurement value reflects the sum of
+digest values of what are considered to be security critical entities,
+most principally, files that are accessed or memory that is mapped
+executable, based on various policies.
+
+In TSEM based TMA's, the measurement of a security modeling namespace
+is the sum of the unique security state coefficients generated by the
+security model being enforced.  As previously noted, on systems with a
+TPM, the root security modeling namespace measurement is maintained by
+default in PCR 11 or the PCR that was selected at kernel configuration
+time.
+
+The challenge associated with classic integrity measurements is the
+time dependent nature of using a non-commutative summing function.
+The almost universal embrace of SMP based hardware architectures, in
+addition to standard kernel task scheduling issues, makes the
+measurement values non-deterministic.  This requires a verifying party
+to evaluate an event log, verified by a measurement value, to
+determine whether or not the system is in a security appropriate or
+trusted state.
+
+TSEM addresses this issue by implementing a strategy designed to
+produce a single functional value that represents the functional
+security state of a model.  This allows a TMA to attest to the
+trust/security status of a platform or workload by signing this
+singular value and presenting it to a verifying party.
+
+In TSEM nomenclature, this functional value is referred to as the
+'state' of the model.  The attestation model is to use trust
+orchestrators to generate the state value of a workload by unit
+testing.  This state value can be packaged with a utility or container
+to represent a summary trust characteristic that can be attested by a
+TMA, eliminating the need for a verifying partner to review and verify
+an event log.
+
+TMA's implement this architecture by maintaining a single instance
+vector of the set of unique security state coefficients that have been
+experienced in a security modeling namespace.  The state measurement
+is generated by sorting the security state coefficient vector in
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 974

Quoted 2 lines
Documentation/admin-guide/LSM/tsem.rst new file +2 -0
+big-endian hash format and then generating a standard linear extension
+measurement over this new vector.

There are cases where ordering of events is important when assessing the security state of the system, e.g. disabling/enabling security features. In these cases where ordering is necessary to attest the security state of the system, is there some middle ground, or does an admin need to revert to a "classic" orderered measurement?

If the time order of two security critical events is important, the only thing that can be done is to evalute which event occurred first.

Quoted 7 lines

TSEM now facilitates this by including nanosecond timestamp measurements of when each event occurred, see the 'ts' key value in the JSON 'event' description structure.

Someone wishing to appraise the security status of a time dependent TSEM model would verify that the timestamps on the two event descriptions are ordered properly.

In those cases I do have to wonder if most of TSEM's advantages are now lost.

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
Documentation/admin-guide/LSM/tsem.rst new file +9 -0
+Any security event that generates an associated state coefficient that
+is not in the model will resulted in a perturbed state function value.
+That perturbed value would be interpreted by a verifying party as an
+indication of an untrusted system.
+
+Since the TMA maintains the security event descriptions in time
+ordered form, the option to provide a classic event log and
+measurement are preserved and available.  Extensive experience in the
+development of TSEM modeled systems has demonstrated the superiority
Quoted 8 lines
Quoted 1 line

+of state value interpretation over classic measurement schemes.

I don't disagree that working with the pre-sorted measurement is far easier, I just wonder how many systems would be able to give up on the event ordering to have the simplified modeling. Surely we will all have different experiences here, but I'm not sure the pre-sorted measurement approach would have been acceptable in many of the projects I've worked on over the years.

Quoted 4 lines

Three general observations.

Roberto's work on Integrity Digest Caches would suggest that other groups feel that non-temporal assessments are of value.

The integrity digest caching functionality isn't a security policy, it's a cache that improves integrity measurements/verifications in some use cases. It's an implementation improvement, not a security model.

Quoted 4 lines

The 'real' world consists of shades of grey. In earlier reviews you questioned why TSEM was delivering ordered as well as unordered measurement trajectories. The reason we provide both is to support the grey world we must function in.

My argument was that TSEM was putting forth unordered measurements as a solution to all that ails existing ordered measurement solutions, so it made little sense to include ordered measurements if the TSEM solution was superior. I think the reality is that unordered measurements look appealing on paper, and perhaps even have a few use cases that can leverage these benefits without having to worry about the downsides, but they aren't going to be a reasonable solution for a large number of use cases. This raises a question of why include both? The unordered approach may be novel, but is it applicable enough to warrant the added complexity?

Quoted 80 lines
Quoted 30 lines
Quoted 30 lines
Documentation/admin-guide/LSM/tsem.rst new file +30 -0
+Control plane
+-------------
+
+Both primary functions of TSEM: security modeling namespace management
+and the internal TMA modeling implementation, are controlled by
+pseudo-files in the securityfs filesystem.  The following directory
+is the top level implementation directory for the TSEM control plane:
+
+/sys/kernel/security/tsem
+
+The following file in the kernel source tree documents, in detail,
+the interfaces provided by the filesystem:
+
+Documentation/ABI/testing/tsem
+
+This filesystem is primarily intended for use by trust orchestrators
+to create and manage security modeling namespaces.
+
+The files are process context sensitive.  Writing to the control file,
+or reading from the informational files, will act on or reference the
+security modeling namespace that the accessing process is assigned to.
+
+The following files are provided in the root directory of the TSEM
+control plane and implement global controls for the TSEM LSM:
+
+   aggregate
+   id
+   control
+
+The 'aggregate' file is used by trust orchestrators for internally
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+modeled namespaces to obtain the hardware measurement value for
+inclusion in a security model.

So I'm clear on this, internally modeled namespaces still access the hardware measurement directly from inside the kernel, yes? In the interally modeled case this is simply available as a reference, and the in-kernel TMA doesn't call out to userspace to access this value, yes?

Correct.

Quoted 30 lines
Quoted 30 lines
Documentation/admin-guide/LSM/tsem.rst new file +30 -0
+A trust orchestrator for an externally
+modeled namespace capture this value as the first event generated by a
+security modeling namespace.
+
+The 'id' file is used to determine the security modeling namespace
+that the process is running in.  The namespace id value of 0 is
+reserved for the root security modeling namespace, a non-zero value
+indicates that the process is running in a subordinate security
+modeling namespace.
+
+The TSEM implementation is controlled by the only writable file, which
+is the 'control' file.
+
+The following keywords are used by trust orchestrators to place the
+process writing to the file in an internally or externally modeled
+security namespace:
+
+   internal
+   external
+
+Each argument accepts key=value pairs that configure the namespace.
+The following key values are currently accepted:
+
+   model
+   nsref
+   digest
+   cache
+   key
+
+The 'model' keyword takes as an argument the name of a loadable module
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst

Quoted 3 lines
Documentation/admin-guide/LSM/tsem.rst new file +3 -0
+that will be used to implement the event processing for a security
+modeling namespace.  If the module has not already been loaded, TSEM
+will attempt to dynamically load the module.

I'm still sorting out the stuff in the docs and haven't gotten to the implementation yet, but just so we're clear on the details about TSEM modules, TSEM shouldn't attempt to sidestep the LSM framework as TOMOYO did recently and we later had to revert.

Quoted 7 lines

We were active in those discussions and are on record with respect to supporting the notion that LSM's should not attempt to sidestep the LSM infrastructure.

TSEM operates entirely within the LSM framework. TSEM loadable modules were implemented in order to allow shaping of the event mapping to allow multiple types of models to be implemented.

Another area where one might question the tradeoff between complexity and capability.

Quoted 73 lines
Quoted 4 lines

Considering that TSEM is likely to want to be active before enough of a userspace exists to load a module (see the previous sections on hash functions), it seems like the best option is to simply include all of the desired internal TMAs in the kernel at build time.

Our experience in building solutions in this space is to have a very minimal orchestration environment running in the root modeling namespace that sets up the host and is modeled by the default deterministic TMA.

The orchestration environment then runs containerized workloads in independent modeling namespaces that benefit from the availability of multiple models, including the simple export of security events for external EDRS evaluation.

Quoted 49 lines
Quoted 49 lines
Documentation/admin-guide/LSM/tsem.rst new file +49 -0
+If the standard practice
+is followed of using the KBUILD_MODNAME CPP define to set the name of
+the security model, the argument to the model keyword will be that
+name, a value that will match the name that is displayed by the lsmod
+command.  It should be noted that there is no requirement that the
+security model name match the name of the module generated by the
+build process.
+
+The 'nsref' keyword takes one of the following two values:
+
+   initial
+   current
+
+The initial argument indicates that the UID/GID values for the COE and
+CELL characteristics are derived from the initial user namespace.
+This is the default characteristic if the nsref key is not specified.
+
+The current argument indicates that the UID/GID values are derived
+from the user namespace that the process is running in, when the
+request is made to model an event.
+
+The 'digest' keyword is used to specify the cryptographic hash
+function that is to be used to create the functional values for the
+security state coefficients for the namespace.  The value to this
+keyword is the name by which the hash function is defined by the
+cryptographic API in the kernel.
+
+Examples of suitable strings are as follows:
+
+   sha256
+   sha3-256
+   sm3
+
+Definitions for the names of the cryptographic hashes can be found in
+the source files for the various cryptographic hash functions in the
+'crypto' directory of the Linux source tree.
+
+The 'cache' keyword is used to specify the size of the caches used to
+hold pointers to data structures used for the internal modeling of
+security events or the export of the security event to external trust
+orchestrators.  These pre-allocated structures are used to service
+security event hooks that are called while the process is running in
+atomic context and thus cannot sleep in order to allocate memory.
+
+The argument to this keyword is a numeric value specifying the number
+of structures that are to be held in reserve for the namespace.
+
+By default the root security modeling namespace and externally modeled
+namespaces have a default value of 128 entries.  An internally modeled
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 1114

Quoted 4 lines
Documentation/admin-guide/LSM/tsem.rst new file +4 -0
+namespace has a default value of 32 entries.  The size requirements of
+these caches can be highly dependent on the characteristics of the
+modeled workload and may require tuning to the needs of the platform
+or workload.

Presumably TSEM provides usage statistics somewhere so admins can monitor and tune as desired? If so, it seems like it would be a good idea to add a reference here.

Quoted 2 lines

We have trended toward the Linus philosophy of reducing the need to worry about properly tuning knobs.

I agree that generally speaking the less tuning knobs to get wrong, the better. However, that assumes a system that can adjust itself as necessary to ensure a reasonable level of operation. If TSEM can not dynamically adjust itself you should consider exposing those tunables.

Signature · 1 line
paul-moore.com
author
#10 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

On Tue, Jan 28, 2025 at 05:23:52PM -0500, Paul Moore wrote:

Good morning, I hope the week is going well for everyone.

We will deal with the issues you raised in separate e-mails, particularly the one below, since we have been advised that no one likes to read very much.

Quoted 19 lines
Quoted 19 lines
Quoted 3 lines

Presumably an attacker could craft a malicious executable (or influence the CELL value if it incorporates user controlled values) that collides with the digest of a known and trusted application.

An incredibly important issue, so apologies for a more lengthy reply on this issue.

More precisely, the objective for an adversary would be to generate the same security coefficient for a specific security event type using an alternative ensemble of operating system relevant characteristics for the event.

The generative functions for the COE, CELL, task identities and ultimately the security state coefficients, are based on industry standard cryptographic hash functions. The attack scenario suggested above would represent a major failure in the second pre-image resistance characteristics of these industry standard security primitives.

Quoted 4 lines
Quoted 2 lines

The ability to decept these security primitives, in such a manner, would represent a crisis for the entire technology industry.

Look around, it is happening now.

No it isn't, at least not for primitives that are currently security relevant, here is why we know it isn't happening.

For simplicity, let's take SHA256, the hash function that TSEM uses by default.

SHA256 is one member of the family of hash functions that is currently codified for use in the Federal Information Processing Standards (FIPS) document 180-4. FIPS specifically validates this hash function on the basis of its demonstrated first and second pre-image resistance strength for non-classified and non-military security applications.

FIPS compliance is a requirement for federal contracting and compliance, particularly for anything to do with money; banks, credit cards (PCI) etc., security issues that people take very, very seriously.

If an active exploit in a FIPS validated primitive was understood to exist, the US Commerce Department would be required to publish a revision to the acceptability clause of 180-4. Since the National Institute of Standards holds the responsibility for the performance of federally mandated algorithms, they would in turn, be required to issue a deprecation notice along with a mitigation and transition strategy.

The Federal Register currently does not document the publication of any such notices.

If you doubt that this isn't a well understood process and one that is taken very seriously, review the December 13, 2024 deprecation and transition announcement for RSA-2048 and ECDSA-256.

All that being said, we could have missed something, if what you propose is currently happening, please cite the CVE number that documents an operational exploit of the second pre-image resistance strength of this hash function or a reference to the Federal Register publication of one of these notices.

FWIW, one of our team members did the first FIPS compliance and validation work for a technology company that is a major employer of Linux kernel developers.

Quoted 5 lines

Of course the level of risk varies tremendously based on the application and yes, the chosen hash function. However, given the composition of TSEM's CELL value in some events, and the importance of a hashed event value in TSEM's policy/model enforcement, it seems like this is something that one would want to address.

We do address it, two primary points:

One, by default, TSEM uses SHA256 and it is currently accepted that it would be computationally infeasible for an attacker to find a second pre-image for a security coefficient generated with this function.

Two, TSEM supports algorithmic agility, so if a functional second pre-image attack emerged, there is an expectation that there would be a migration to a non-vulnerable primitive. This is considered standard and acceptable practice in the security industry.

An even deeper and more fundamental reason why this type of attack wouldn't be relevant in a TSEM protected workload.

The independent variables in the TSEM generative model are the security events being modeled. OS level actions that would express the efforts of an adversary consist of multiple security events, each with their own security state coefficient that would have be mapped into a known good coefficient by manipulation of the characteristics of each independent variable.

Lets look at the Apache Struts vulnerability that was the basis for the Equifax breach [1], arguably the start of the modern day era of major persistent exploits.

The vulnerability in the attack was taking advantage of a serialization regression in the Apache Struts code. This regression was used to implant a .war file that was executed by the Tomcat application server, that in turn fetched a webshell that was used to access the host and establish persistence.

There are two sentinel events in the compromise:

1.) Implantation of the .war file.
2.) The use of wget to enable access and persistence.

In event 1 there will be a series of security states that are occupied, if you will pardon my background in quantum, that represent the events necessary to write the .war file. The only degree of freedom that the attacker can control is what would be the cryptographic hash of the contents of the .war file. Manipulation of that file would have to yield a file (pre-image) that would still be interpreted as a valid .war file.

The attacker must do so without any knowledge of the Tomcat execution environment and the known good states that it will occupy. In a classic compromise an attacker only needs to know they are attacking a Tomcat/Struts execution environment.

With respect to the second sentinel event, the execution of the wget binary for installation of the persistence infrastructure. In a TSEM model of the compromise on a 6.12 kernel, the wget invocation is modeled by a total of 81 security state coefficients. This would require an adversary to develop 81 separate and colliding second pre-images in order to avoid detection.

As we've noted previously, it is currently considered computationally infeasible to create just one of these.

The following is probably not going to survive mail munging but here is a jq formatted expression of one of these events, the wget binary memory mapping its executable .text sections:

{

  "event": {
    "context": "6",
    "number": "978",
    "process": "wget",
    "type": "mmap_file",
    "ttd": "381",
    "p_ttd": "380",
    "task_id": "3e005861133608e71044ee178dbb891989dea6747ce8c0bc5928530a6902c48b",
    "p_task_id": "41274f59bfa217305cf2c529a70154e83e1a936798fa5ad5eb4ad9b7307cf1ab",
    "ts": "17463238151"
  },
  "COE": {
    "uid": "0",
    "euid": "0",
    "suid": "0",
    "gid": "0",
    "egid": "0",
    "sgid": "0",
    "fsuid": "0",
    "fsgid": "0",
    "capeff": "0x20000420"
  },
  "mmap_file": {
    "file": {
      "flags": "32800",
      "inode": {
        "uid": "2",
        "gid": "2",
        "mode": "0100755",
        "s_magic": "0xef53",
        "s_id": "xvdb",
        "s_uuid": "a953e99a39e54e478c9edf24815ddc49"
      },
      "path": {
        "dev": {
          "major": "202",
          "minor": "16"
        },
        "type": "namespace",
        "pathname": "/usr/bin/wget"
      },
      "digest": "55ceecbb3177e24872da8945660821943ab8fa17214637b5211d0dff5286e6b8"
    },
    "prot": "5",
    "flags": "5"

}
}

If one reviews the COE and CELL characteristics in this expression you will come to the conclusion that the attacker has no ability to modify any of the event characteristics, in pursuit of masking this event as an alternative good event. So this single security event, among a number of others of the 81, would generate a detectable model violation and intrusion alert event.

In addition, any of the actions undertaken by the persistence shell would have to be masked as known good events. By definition the persistence shell, and any of its subordinate processes, will have a task identity different than any other process that Tomcat would run.

So every security event generated by these processes would need to be masked as a known good event. Once again with limited degrees of freedom in the input domain.

Paul, we appreciate the significant demands on your time and the fact that you have not been able to look at any of the code or implementation details and no doubt by extension, to compile and test a kernel and the userspace utilities to see what TSEM is actually doing.

TSEM is a little bit like the Keccak/SHA3 hashing functions. If you follow the academic work of individuals attempting to study and defeat the pre-image resistance of this family of functions, you will note that they all comment that you have to work with the 'sponge construction' that SHA3 is based on, to understand how difficult it is to defeat.

Quoted 1 line

paul-moore.com

Apologies for the length of this note, but as you noted, this issue is rather central to the security deliverables of TSEM.

I need to get on my cross-country skis.

Best wishes for a pleasant weekend.

As always,
Dr. Greg

The Quixote Project - Flailing at the Travails of Cybersecurity
https://github.com/Quixote-Project

[1]: Not that it means much, but I led a demonstration of the ability to detect the Equifax exploit, with an earlier and more primitive implementation of what has become TSEM. In a Faraday shielded room at what was to become DHS/CISA headquarters in the Glebe Building in Arlington, Virginia, shortly before whatever it was then became CISA. It was a successful demonstration, despite the fact that we were depending on wireless networking that we brought with us to connect back to our servers in the heartland... :-)

author
#11 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

In reply to Paul Moore

On Tue, Jan 28, 2025 at 05:23:52PM -0500, Paul Moore wrote:

For the record, further documentation of our replies to TSEM technical issues.

Quoted 27 lines · On Thu, Jan 16, 2025 at 11:47???PM Dr. Greg <[email protected]> wrote:
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
Documentation/admin-guide/LSM/tsem.rst new file +8 -0
+In order to handle modeling of security events in atomic context, the
+TSEM implementation maintains caches (magazines) of structures that
+are needed to implement the modeling and export of events.  The size
+of this cache can be configured independently for each individual
+security modeling namespace that is created.  The default
+implementation is for a cache size of 32 for internally modeled
+namespaces and 128 for externally modeled namespaces.
+
Quoted 8 lines

Documentation/admin-guide/LSM/tsem.rst line 584

Quoted 3 lines
Documentation/admin-guide/LSM/tsem.rst new file +3 -0
+By default the root security namespace uses a cache size of 128.  This
+value can be configured by the 'tsem_cache' kernel command-line
+parameter to an alternate value.

I haven't looked at the implementation yet, but I don't understand both why a kmem_cache couldn't be used here as well as why this implementation detail is deemed significant enough to be mentioned in this high level design document.

Quoted 8 lines

TSEM does use kmem_cache allocations for all of its relevant data structures.

The use of a kmem_cache, however, does not solve the problem for security event handlers that are required to run in atomic context. To address the needs of those handlers you need to serve the structures out of a pre-allocated magazine that is guaranteed to not require any memory allocation or sleeping locks.

Quoted 5 lines

This still seems somewhat suspicious as there are a couple of GFP flags that allow for non-blocking allocations in all but a few cases, but I'll defer further discussion of that until I get to the code. In my opinion, there are still enough red flags in these documentation reviews to keep me from investing the time in reviewing the TSEM code.

As a group, we can state quite affirmatively to the fact that we have experience and understanding in use of memory allocation instruction flags. Our use of namespace specific event processing structure caches is not driven by unfamiliarity with the use and implications of GFP_ATOMIC.

The use of independent structure magazines, for security events running in atomic context in a security modeling namespace, is driven by the need to prevent security adversaries from placing pressure on the global kernel atomic page reserves.

These namespace specific event magazines prevent an adversary from waging a memory denial of service attack against the kernel at large. Adversaries can only impair their own functionality in a security modeling namespace through the use of a synthetic attack workload that stresses the availability of atomic context memory.

Further, TSEM is formulated on the premise that software teams, as a by product of CI/CD automation and testing, can develop precise descriptions of the security behavior of their workloads. One component of that description is the cache depth needed to support security event handlers running in atomic context.

Exceeding that cache depth would be a sentinel forensic event for a workload. For anyone unfamiliar with modern IT security architectures, a very specific alert on your security dashboard that one of the tens of thousands of workloads that are running is doing something it shouldn't.

Adversaries really hate to be noticed.

Quoted 6 lines

Regardless, I stand by my previous comment that discussion of these caches may be a bit more detail that is needed in this document, but of course that is your choice. It's a balancing act between providing enough high level detail to satisfy users and reviewers, and producing a document that is so verbose that the time required to properly review it is prohibitive.

It was our understanding that the administrative guides to a security architecture are intended to provide comprehensive information on the use and management of the implementation.

We were attempting to be thorough in the description and rationale for all the technical aspects of TSEM. The discourse in Documentation/memory-barriers.txt would seem to provide justification for intimate detail on important operational issues in the kernel.

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 6 lines
Documentation/admin-guide/LSM/tsem.rst new file +6 -0
+The 'cache' keyword is used to specify the size of the caches used to
+hold pointers to data structures used for the internal modeling of
+security events or the export of the security event to external trust
+orchestrators.  These pre-allocated structures are used to service
+security event hooks that are called while the process is running in
+atomic context and thus cannot sleep in order to allocate memory.

Documentation/admin-guide/LSM/tsem.rst line 1114

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+
+The argument to this keyword is a numeric value specifying the number
+of structures that are to be held in reserve for the namespace.
+
+By default the root security modeling namespace and externally modeled
+namespaces have a default value of 128 entries.  An internally modeled
+namespace has a default value of 32 entries.  The size requirements of
+these caches can be highly dependent on the characteristics of the
+modeled workload and may require tuning to the needs of the platform
+or workload.

Presumably TSEM provides usage statistics somewhere so admins can monitor and tune as desired? If so, it seems like it would be a good idea to add a reference here.

Quoted 8 lines
Quoted 2 lines

We have trended toward the Linus philosophy of reducing the need to worry about properly tuning knobs.

I agree that generally speaking the less tuning knobs to get wrong, the better. However, that assumes a system that can adjust itself as necessary to ensure a reasonable level of operation. If TSEM can not dynamically adjust itself you should consider exposing those tunables.

The atomic structure magazine sizes (cache depth) can be set on a per namespace basis, including the root modeling namespace.

Our current development tree, on our GitHub site if anyone is interested, has simplified the cache sizing by using a single default value that is of sufficient size to boot a standard Linux (Debian) implementation.

For subordinate modeling namespaces, experience has shown that to be more than what is needed, but it greatly simplifies the ability to use TSEM 'out of the box'.

We still need to update the documentation to call out this fact and note that development teams can adjust this value downward for subordinate workloads that require lower levels of atomic event reserves, if there is a desire to save memory. Or upward if a workload generates a pathologically large corpus of security events that run in atomic context.

One could arguably make this self-tuning by setting a low water mark that would trigger the expansion of the depth of the event structure caches. Which would invariably lead to a request to have a tunable to set that low water mark....

Not to mention an argument about the performance impacts of locking the namespace context to prevent atomic context events from running while the event magazines are expanded.

Quoted 1 line

paul-moore.com

Have a good day.

As always,
Dr. Greg

The Quixote Project - Flailing at the Travails of Cybersecurity
https://github.com/Quixote-Project

#12 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

Quoted 10 lines · Dr. Greg

On Tue, Jan 28, 2025 at 05:23:52PM -0500, Paul Moore wrote:

For the record, further documentation of our replies to TSEM technical issues.

...

Further, TSEM is formulated on the premise that software teams, as a by product of CI/CD automation and testing, can develop precise descriptions of the security behavior of their workloads.

I've said it before, and I'll say it again. This premise is hopelessly naive. If it was workable you'd be able to use SELinux and audit2allow to create perfect security, and it would have been done 15 years ago. The whole idea that you can glean what a software system is *supposed* to do from what it *does* flies completely in the face of basic security principles.

author
#13 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

On Tue, Feb 25, 2025 at 07:48:31AM -0800, Casey Schaufler wrote:

Good morning, I hope this note finds the week going well for everyone.

Quoted 12 lines · Dr. Greg
Quoted 10 lines · Paul Moore

For the record, further documentation of our replies to TSEM technical issues.

...

Further, TSEM is formulated on the premise that software teams, as a by product of CI/CD automation and testing, can develop precise descriptions of the security behavior of their workloads.

Quoted 6 lines

I've said it before, and I'll say it again. This premise is hopelessly naive. If it was workable you'd be able to use SELinux and audit2allow to create perfect security, and it would have been done 15 years ago. The whole idea that you can glean what a software system is *supposed* to do from what it *does* flies completely in the face of basic security principles.

You view our work as hopelessly naive because you, and perhaps others, view it through a 45+ year old lens of classic subject/object mandatory controls that possess only limited dimensionality.

We view it through a lens of 10+ years of developing new multi-scale methods for modeling alpha2-adrenergic receptor antagonists... :-)

We don't offer this observation just in jest. If people don't understand what we mean by this, they should consider the impact that Singular Value Decomposition methods had when they were brought over from engineering and applied to machine learning and classification.

A quote from John von Neumann, circa 1949, would seem appropriate:

"It would appear that we have reached the limits of what is
possible to achieve with computer technology, although one should be careful with such statements, as they tend to sound pretty silly in 5 years."

If anyone spends time understanding the generative functions that we are using, particularly the task identity model, they will find that the coefficients that define the permitted behaviors have far more specificity, with respect to classifying what a system is *supposed* to do, than the two, possibly three dimensions of classic subject/object controls.

More specifically to the issues you raise.

Your SeLinux/audit2allow analogy is flawed and isn't a relevant comparison to what we are implementing. audit2allow is incapable of defining a closed set of allowed security behaviors that are *supposed* to be exhibited by a workload.

The use of audit2allow only generates what can be considered as possible permitted exceptions to a security model, after the model has failed and hopefully before people have simply turned off the infrastructure in frustration because they needed a working system.

Unit testing of a workload under TSEM produces a closed set of high resolution permitted behaviors generated by the normal functioning of that workload, in other words all of the security behaviors that are exibited when the workload is doing what it is *supposed* to do. TSEM operates under default deny criteria, so if workload testing is insufficient in coverage, any unexpressed behaviors will be denied, thus blocking or alerting on any undesired security behaviors.

I believe our team is unique in these conversations in being the only group that has ever compiled a kernel with TSEM enabled and actually spent time running and testing its performance with the trust orchestrators and modeling tools we provide. That includes unit testing of workloads and then running the models developed from those tests against kernels and application stacks with documented vulnerabilities. To determine whether the models can detect deviations generated by an exploit of those vulnerabilities, from what the workload is *supposed* to be doing.

If anyone is interested in building and testing TSEM and can demonstrate that security behaviors, undesired from its training set, can escape detection we would certainly embrace an example so we can review why it is occurring and integrate it into our testing and development framework.

FWIW, a final thought for those reading along at home.

TSEM is not as much an LSM as it is a generic framework for driving mathematical models over the basis set of information provided by the LSM hooks.

All of the above starts the conversation on deterministic models, we can begin argueing about the relevancy of probabilistic and inferential models at everyone's convenience. The latter two of which will probably drive how the industry does security for the next 45 years.

Have a good day.

As always,
Dr. Greg

The Quixote Project - Flailing at the Travails of Cybersecurity
https://github.com/Quixote-Project

#14 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

Quoted 21 lines · Dr. Greg

On Tue, Feb 25, 2025 at 07:48:31AM -0800, Casey Schaufler wrote:

Good morning, I hope this note finds the week going well for everyone.

Quoted 11 lines · Dr. Greg
Quoted 10 lines · Paul Moore

For the record, further documentation of our replies to TSEM technical issues.

...

Further, TSEM is formulated on the premise that software teams, as a by product of CI/CD automation and testing, can develop precise descriptions of the security behavior of their workloads.

Quoted 6 lines

I've said it before, and I'll say it again. This premise is hopelessly naive. If it was workable you'd be able to use SELinux and audit2allow to create perfect security, and it would have been done 15 years ago. The whole idea that you can glean what a software system is *supposed* to do from what it *does* flies completely in the face of basic security principles.

Quoted 3 lines

You view our work as hopelessly naive because you, and perhaps others, view it through a 45+ year old lens of classic subject/object mandatory controls that possess only limited dimensionality.

I view your work as hopelessly naive because I've seen the basic idea fail spectacularly so many times. That includes things I have written, such as the Datastate LSM.

... and don't play the stodgy old fart card on me. I've been working on making the LSM more available to new security models for years.

Quoted 2 lines

We view it through a lens of 10+ years of developing new multi-scale methods for modeling alpha2-adrenergic receptor antagonists... :-)

Which is relevant how?

Quoted 11 lines

We don't offer this observation just in jest. If people don't understand what we mean by this, they should consider the impact that Singular Value Decomposition methods had when they were brought over from engineering and applied to machine learning and classification.

A quote from John von Neumann, circa 1949, would seem appropriate:

"It would appear that we have reached the limits of what is
possible to achieve with computer technology, although one should be careful with such statements, as they tend to sound pretty silly in 5 years."

New good ideas can shatter old conceptions. Old bad ideas with a fresh coat of paint and impressive new terminology fail to impress.

Quoted 6 lines

If anyone spends time understanding the generative functions that we are using, particularly the task identity model, they will find that the coefficients that define the permitted behaviors have far more specificity, with respect to classifying what a system is *supposed* to do, than the two, possibly three dimensions of classic subject/object controls.

Squirrels are funny rodents. If you model their behavior you will declare that they are herbivores. In California (where many strange and wonderful things happen) squirrels have begun to eat voles, a very carnivorous behavior. If you believe in modeling as a way to identify correct behavior, you have to say that these furry creatures that eat voles are not squirrels. If, on the other hand, you look at the environment they live in you can see that the loss of native habitat has reduced the available fat calories to the point where survival requires changed behavior. They're still squirrels, and no amount of modeling is going to change that.

Quoted 11 lines

More specifically to the issues you raise.

Your SeLinux/audit2allow analogy is flawed and isn't a relevant comparison to what we are implementing. audit2allow is incapable of defining a closed set of allowed security behaviors that are *supposed* to be exhibited by a workload.

The use of audit2allow only generates what can be considered as possible permitted exceptions to a security model, after the model has failed and hopefully before people have simply turned off the infrastructure in frustration because they needed a working system.

It's a poor workman who blames his tools. Why haven't audit and audit2allow been enhanced to provide the information necessary to create your analysis? I suggest that it's because the value has been recognized as unimportant.

Quoted 7 lines

Unit testing of a workload under TSEM produces a closed set of high resolution permitted behaviors generated by the normal functioning of that workload, in other words all of the security behaviors that are exibited when the workload is doing what it is *supposed* to do. TSEM operates under default deny criteria, so if workload testing is insufficient in coverage, any unexpressed behaviors will be denied, thus blocking or alerting on any undesired security behaviors.

And how is that different from running SELinux in permissive mode?

Quoted 10 lines

I believe our team is unique in these conversations in being the only group that has ever compiled a kernel with TSEM enabled and actually spent time running and testing its performance with the trust orchestrators and modeling tools we provide. That includes unit testing of workloads and then running the models developed from those tests against kernels and application stacks with documented vulnerabilities. To determine whether the models can detect deviations generated by an exploit of those vulnerabilities, from what the workload is *supposed* to be doing.

Quoted 5 lines

If anyone is interested in building and testing TSEM and can demonstrate that security behaviors, undesired from its training set, can escape detection we would certainly embrace an example so we can review why it is occurring and integrate it into our testing and development framework.

Sigh. You keep coming back to a train of logic that is based on a flawed assumption. If you accept that observed behavior describes intended behavior the arguments that follow may be convincing. I, for one, do not accept that assumption.

Quoted 19 lines

FWIW, a final thought for those reading along at home.

TSEM is not as much an LSM as it is a generic framework for driving mathematical models over the basis set of information provided by the LSM hooks.

All of the above starts the conversation on deterministic models, we can begin argueing about the relevancy of probabilistic and inferential models at everyone's convenience. The latter two of which will probably drive how the industry does security for the next 45 years.

Have a good day.

As always,
Dr. Greg

The Quixote Project - Flailing at the Travails of Cybersecurity
https://github.com/Quixote-Project

author
#15 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

On Thu, Feb 27, 2025 at 08:47:43AM -0800, Casey Schaufler wrote:

Good morning, I hope the week is starting well for everyone.

Quoted 29 lines · Dr. Greg
Quoted 23 lines · Casey Schaufler

Good morning, I hope this note finds the week going well for everyone.

Quoted 12 lines · Dr. Greg
Quoted 10 lines · Paul Moore

For the record, further documentation of our replies to TSEM technical issues.

...

Further, TSEM is formulated on the premise that software teams, as a by product of CI/CD automation and testing, can develop precise descriptions of the security behavior of their workloads.

Quoted 6 lines

I've said it before, and I'll say it again. This premise is hopelessly naive. If it was workable you'd be able to use SELinux and audit2allow to create perfect security, and it would have been done 15 years ago. The whole idea that you can glean what a software system is *supposed* to do from what it *does* flies completely in the face of basic security principles.

Quoted 4 lines

You view our work as hopelessly naive because you, and perhaps others, view it through a 45+ year old lens of classic subject/object mandatory controls that possess only limited dimensionality.

Quoted 6 lines

I view your work as hopelessly naive because I've seen the basic idea fail spectacularly so many times. That includes things I have written, such as the Datastate LSM.

... and don't play the stodgy old fart card on me. I've been working on making the LSM more available to new security models for years.

I'm not playing any cards, I am simply advocating that TSEM needs to be viewed through the lens of multi-dimensional numerical modeling, a framework that you are uncomfortable with.

To that end.

One of our project advisors, who manages a large containerized microservices shop, has been following all of this. He phoned me and questioned if the problem could be that you were viewing TSEM as a whole system solution rather than a modeling solution based on limited scope modeling.

Just for the record, is it clear that we are working on limited scope modeling environments?

With respect to this failing before, could you give us a literature citation that we could review that discusses the failure of previous systems that were using generative functions to uniquely label each security event based on the cryptographic identity of the executable code that is generating the event?

To support further discussion, it would be helpful if you could document the spectacular failure mode you would anticipate in the framework of classical security discussion.

TSEM, like other security architectures, has basically two failure modes:

1.) False positives.

2.) False negatives.

3.) Implementation complexity failures.

False negatives are arguably the most dangerous. Something was allowed to occur that should not have been allowed to occur.

When a workload is trained, either a security coefficient for a security behavior is generated or it is not. Thus, when the model is enforced, generated coefficients either exist or do not exist in the outcome set.

If the coefficient does not exist, there is a chance that this is a false positive due to insufficient training coverage. The correction is the same as in other architectures, fold the false positive back into the training set. Until that happens the behavior is constrained from occurring.

By definition there are no false negatives, ie. an event that did occur but should not have occured, since the only coefficients in the training sets are those that are consistent with the training behavior.

Implementation complexity focuses on the ability of the technology to either be deployed at all, or more importantly, deployed properly due to lack of industry skills or infrastructure support.

We would look forward to elaborations on the specific failure modes that would occur.

Quoted 4 lines
Quoted 2 lines

We view it through a lens of 10+ years of developing new multi-scale methods for modeling alpha2-adrenergic receptor antagonists... :-)

Which is relevant how?

In industry it is referred to as the application of tanslational technologies. The notion that advances beyond current practice in a field can achieved by the novel application of methods from other technology disciplines.

See my 2017 invited presentation at the NSA's High Confidence Software Systems conference.

Also, see the impact of the application of Singular Value Decomposition on machine learning and classification.

Quoted 7 lines
Quoted 7 lines

We don't offer this observation just in jest. If people don't understand what we mean by this, they should consider the impact that Singular Value Decomposition methods had when they were brought over from engineering and applied to machine learning and classification.

A quote from John von Neumann, circa 1949, would seem appropriate:

Quoted 7 lines
Quoted 4 lines

"It would appear that we have reached the limits of what is
possible to achieve with computer technology, although one should be careful with such statements, as they tend to sound pretty silly in 5 years."

New good ideas can shatter old conceptions. Old bad ideas with a fresh coat of paint and impressive new terminology fail to impress.

Once again, as we noted above, if you could, please forward to the list citations that specifically reference failure modes of numerical modeling of security events to assist further discussion.

Quoted 7 lines
Quoted 6 lines

If anyone spends time understanding the generative functions that we are using, particularly the task identity model, they will find that the coefficients that define the permitted behaviors have far more specificity, with respect to classifying what a system is *supposed* to do, than the two, possibly three dimensions of classic subject/object controls.

Quoted 10 lines

Squirrels are funny rodents. If you model their behavior you will declare that they are herbivores. In California (where many strange and wonderful things happen) squirrels have begun to eat voles, a very carnivorous behavior. If you believe in modeling as a way to identify correct behavior, you have to say that these furry creatures that eat voles are not squirrels. If, on the other hand, you look at the environment they live in you can see that the loss of native habitat has reduced the available fat calories to the point where survival requires changed behavior. They're still squirrels, and no amount of modeling is going to change that.

Personally, I never thought it would come down to this but here you go:

I have a pet squirrel named Rocky that I have owned since it was a pup and its mother was killed crossing Douglas County Road 7 in front of our house. He lives in a small kennel in our house.

Every day I take Rocky outside and open the door to his kennel. Rocky runs around the yard twice and then up an oak tree and loads his cheeks with acorns. He comes back to his kennel, eats his acorns and falls asleep until the next day.

One night Jay Evil sneaks into the house, abducts Rocky and replaces him with his evil squirrel Rabid, who looks exactly like Rocky but fell out of a tree on his head when he missed a jump from one branch to another and hasn't been right since.

As usual, the next day I take what I think is Rocky out into the front yard and open the kennel door. The faux Rocky runs out into the yard, chases down, attacks, kills and begins to eat our German Shepherd Max.

Conclusion, this squirrel's behavior is suspicious and should be remediated.

TSEM, as a high granularity modeling architecture, would interrupt the process when the squirrel began to chase Max.

Quoted 12 lines
Quoted 11 lines

More specifically to the issues you raise.

Your SeLinux/audit2allow analogy is flawed and isn't a relevant comparison to what we are implementing. audit2allow is incapable of defining a closed set of allowed security behaviors that are *supposed* to be exhibited by a workload.

The use of audit2allow only generates what can be considered as possible permitted exceptions to a security model, after the model has failed and hopefully before people have simply turned off the infrastructure in frustration because they needed a working system.

Quoted 4 lines

It's a poor workman who blames his tools. Why haven't audit and audit2allow been enhanced to provide the information necessary to create your analysis? I suggest that it's because the value has been recognized as unimportant.

You suggest or you have proof?

Once again, audit2allow is a tool for folding false positives back into a security model. Mathematically, it is designed to provide the row and column definition of a false positive security violation in an access vector matrix.

TSEM creates a high precision bounded training set of known good security behaviors from a high dimensionality basis set. This training set is used to constrain subsequent executions of the workload on which it was trained.

audit2allow was a tool that was implemented to compensate for complexity induced limitations of SeLinux.

TSEM is designed to eliminate the need for such a tool.

Quoted 10 lines
Quoted 8 lines

Unit testing of a workload under TSEM produces a closed set of high resolution permitted behaviors generated by the normal functioning of that workload, in other words all of the security behaviors that are exibited when the workload is doing what it is *supposed* to do. TSEM operates under default deny criteria, so if workload testing is insufficient in coverage, any unexpressed behaviors will be denied, thus blocking or alerting on any undesired security behaviors.

And how is that different from running SELinux in permissive mode?

SeLinux in permissive mode operates after the fact to correct a model that was incorrect in its design.

TSEM is designed to produce a high precision definition of what a workload should do. High precision definitions are less prone to false positives that have historically proven to be the reason that security controls are disabled and thus rendered ineffective, despite their technical superiority.

Quoted 16 lines
Quoted 10 lines

I believe our team is unique in these conversations in being the only group that has ever compiled a kernel with TSEM enabled and actually spent time running and testing its performance with the trust orchestrators and modeling tools we provide. That includes unit testing of workloads and then running the models developed from those tests against kernels and application stacks with documented vulnerabilities. To determine whether the models can detect deviations generated by an exploit of those vulnerabilities, from what the workload is *supposed* to be doing.

Quoted 5 lines

If anyone is interested in building and testing TSEM and can demonstrate that security behaviors, undesired from its training set, can escape detection we would certainly embrace an example so we can review why it is occurring and integrate it into our testing and development framework.

Quoted 4 lines

Sigh. You keep coming back to a train of logic that is based on a flawed assumption. If you accept that observed behavior describes intended behavior the arguments that follow may be convincing. I, for one, do not accept that assumption.

As I noted above, you operate from a mindset of classic subject/object mandatory access controls rather than from the notion of numerically modeled security behavior.

Future students of technology will note that Linux moved through three phases of security architecture development:

Subject/object based mandatory access controls.

Pathname based controls.

Model based controls.

TSEM is the the first major implementation of the latter type of control for the Linux kernel. We accept resistance to the appearance of these types of controls, the same thing happened with pathname based controls. The resistance doesn't mean the technology is invalid.

The technology industry is moving towards model based security controls, for a variety of reasons, too numerous to be litigated in this context, so lets consider just one.

Without question, SeLinux is world class security technology. However, by virtue statements of individuals like Kyle Moffett, it is designed, by experts, to be implemented, by experts. That model is inconsistent with the world we find ourselves in, both from a personnel and a technology context.

Companies that can run well tuned SeLinux implementations, for free, turn it off and instead install security solutions, based on behavior observation and modeling, that they have to pay significant amounts of money for.

TSEM is designed to provide better and more trouble free access to the data needed to drive model based workload controls. Nothing we do constrains the ability of anyone to implement an alternate security model of their choosing.

Have a good week.

As always,
Dr. Greg

The Quixote Project - Flailing at the Travails of Cybersecurity
https://github.com/Quixote-Project

author
#17 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

In reply to Paul Moore

On Tue, Jan 28, 2025 at 05:23:52PM -0500, Paul Moore wrote:

Good morning, I hope mid-week is going well for everyone.

After the issue of the functionality of modern cryptographic primitives, a discussion of the second most important issue Paul raises.

Quoted 46 lines
Quoted 33 lines
Quoted 28 lines
Quoted 8 lines
Documentation/admin-guide/LSM/tsem.rst new file +8 -0
+In an externally modeled namespace, the event type and parameters are
+exported to userspace for processing by a trust orchestrator with an
+associated TMA.  The trust orchestrator communicates the result of the
+modeling back to the kernel to support the setting of the process
+trust status.
+
+The exception to this model are for security event handlers that are
+called in atomic, ie. non-sleeping context.  The export of these

Documentation/admin-guide/LSM/tsem.rst line 559

Quoted 10 lines
Documentation/admin-guide/LSM/tsem.rst new file +10 -0
+security event descriptions are done asynchronously in order to avoid
+having the TSEM implementation attempt to sleep in atomic context
+while the userspace trust orchestrator is scheduled for execution.
+
+It is up to the trust orchestrator and its security policy to
+determine how it handles events that violate the security model being
+enforced in this model.  The Quixote trust orchestrators shut down the
+entire workload running in the security namespace if an asynchronously
+modeled event violates the security model being enforced and the model
+is running in enforcing mode.

I understand your desire to simply pass off the non-blocking/async access control hole as a security policy issue, but it seems to me that this is a fundamental flaw with an externally modeled TSEM namespace. If an externally modeled namespace was configured with an enforcing policy, it doesn't appear that there is a mechanism for TSEM to properly enforce that policy as there is an unbounded delay between the undesired access and a denial verdict being processed by the kernel.

Quoted 4 lines

Unless you can resolve this somehow, and I'm not sure how, I would suggest dropping external/userspace trust orchestrators. They simply don't seem able to reliably implement their security policies.

Quoted 8 lines

An important issue.

Some reflections on why we would, respectfully, disagree.

A business assessment of the current security market suggests that the mindset in security has changed from prevention to detection. TSEM is about providing kernel infrastructure to enable better solutions for the detection model.

I believe the LSM can support both the enforcement of security policy and the observation of security relevant events on a system. In fact most of the existing LSMs do both, at least to some extent.

Quoted 9 lines

However, while logging of security events likely needs to be asynchronous for performance reasons, enforcement of security policy likely needs to be synchronous to have any reasonable level of assurance. You are welcome to propose LSMs which provide observability functionality that is either sync, async, or some combination of both (? it would need to make sense to do both ?), but I'm not currently interested in accepting LSMs that provide asynchronous enforcement as I don't view that as a "reasonable" enforcement mechanism.

This is an artificial distinction that will prove limiting to the security that Linux will be able to deliver in the future.

Based on your response, is it your stated position as Linux security maintainer, that you consider modern Endpoint Detection and Response Systems (EDRS) lacking with respect to their ability to implement a "reasonable" enforcement and assurance mechanism?

If this is the case, your philosophy leaves Linux in a position that is inconsistent with how the industry is choosing to implement security.

Let me cite an example from one of our project advisors.

This individual is a senior principal at a reasonably large technology products company that depends on Linux almost exclusively to support its operations. At any given instant he participates in supervising a fleet of around 6,000 virtual machines running about 50,000-60,000 containerized workloads.

All of the Linux deployments are Ansible orchestrated. The security deployment consists of disabling SeLinux and installing an EDRS solution. Doing the latter checks all the boxes they need for their corporate security compliance policies.

He, and others, have watched this discussion closely over the last two years that we have tried to get TSEM reviewed and just recently phoned me with the following comment:

"I think the problem is that these guys don't understand how security is being done and the reasons why".

There is probably not a modern EDRS solution that does not involve going to the cloud for its decision making enforcement, in most cases based on Indicators Of Compromise (IOC) trained machine learning models. Asynchronous detection, enforcement and remediation is now standard practice. In the security industry, a 1 minute response to a security event is considered the 'gold' standard.

For the sake of discussion, lets take a Quixote userspace Trusted Modeling Agent (TMA) running TSEM based deterministic modeling of a containerized workload. As we've discussed previously, demonstrated average response times are on the order of 170 micro-seconds.

For an event that needs asynchronous enforcement, ie. running in atomic context, that represents a 3.5 order of magnitude advantage in response over the industry standard, without the attendant challenges of going off machine or installing kernel based infrastructure.

What would be the rationale or advantage of denying those that desire this type of security option, a 3,500 fold increase in security response times?

Let's take another need for running in userspace, trusted execution environments. Support is available in our userspace package for running a TMA model in either an SGX enclave or in an independent hypervisor protected execution context, both of which significantly harden the enforcement implementation against attack by adversaries.

As Linux security maintainer, we assume that you have read Executive Order 14144 signed on January 16th 2025. That document specifically calls out the requirement for the increased use of trusted execution environments in combination with advancements in endpoint detection.

It shouldn't be a leap in imagination as to the regulatory compliance advantages associated with hardware attestation that the security implementation is operational and in a known good enforcement state.

Finally, at this point in time, it would seem unwise in the technology industry, to discount the importance of 'AI', or more correctly machine learning. As we've noted before in our discussions, it is unlikely that we are going to see synchronous LSM enforcement using a machine learning model trained on potentially trillions of data observations and indicators.

The LSM is designed to provide security services to the users of Linux, not to be a kingdom.

Linux is/was about 'choice' as to how users want to use their hardware.

Artifically limiting the types of security that can be implemented by the LSM works to the detriment of the security innovation that Linux can deliver and the Linux user community writ large.

Quoted 1 line

paul-moore.com

Best wishes for a productive remainder of the week.

As always,
Dr. Greg

The Quixote Project - Flailing at the Travails of Cybersecurity
https://github.com/Quixote-Project

#18 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

Quoted 21 lines · Dr. Greg

On Tue, Jan 28, 2025 at 05:23:52PM -0500, Paul Moore wrote:

Good morning, I hope mid-week is going well for everyone.

After the issue of the functionality of modern cryptographic primitives, a discussion of the second most important issue Paul raises.

Quoted 4 lines

I believe the LSM can support both the enforcement of security policy and the observation of security relevant events on a system. In fact most of the existing LSMs do both, at least to some extent.

Quoted 9 lines

However, while logging of security events likely needs to be asynchronous for performance reasons, enforcement of security policy likely needs to be synchronous to have any reasonable level of assurance. You are welcome to propose LSMs which provide observability functionality that is either sync, async, or some combination of both (? it would need to make sense to do both ?), but I'm not currently interested in accepting LSMs that provide asynchronous enforcement as I don't view that as a "reasonable" enforcement mechanism.

Quoted 2 lines

This is an artificial distinction that will prove limiting to the security that Linux will be able to deliver in the future.

I'll apologize up front to everyone else for this response, but I hope it is something you might understand.

A security guard scans a person's access pass. As the computer system that processes the data is slow, the guard lets the person go through the gate. An access denial finally comes through. The guard turns and shoots the intruder. What other choice is available? The intruder may have seen what should not have been seen. Now the guard has to file a fatal incident report and slow down everything else while cleaning up the remains.

tl;dr - async access control is just messy.

Quoted 4 lines

Based on your response, is it your stated position as Linux security maintainer, that you consider modern Endpoint Detection and Response Systems (EDRS) lacking with respect to their ability to implement a "reasonable" enforcement and assurance mechanism?

You are conflating issues. It isn't the purpose of the system, it is the mechanism by which it is implemented that is the problem.

Quoted 11 lines

If this is the case, your philosophy leaves Linux in a position that is inconsistent with how the industry is choosing to implement security.

Let me cite an example from one of our project advisors.

This individual is a senior principal at a reasonably large technology products company that depends on Linux almost exclusively to support its operations. At any given instant he participates in supervising a fleet of around 6,000 virtual machines running about 50,000-60,000 containerized workloads.

How can this possibly be a kernel problem?

Quoted 4 lines

All of the Linux deployments are Ansible orchestrated. The security deployment consists of disabling SeLinux and installing an EDRS solution. Doing the latter checks all the boxes they need for their corporate security compliance policies.

Without insight regarding what these policies might be it is impossible to say for sure, but I'll bet a refreshing beverage that they involve all sorts of application level protocols, and other things the kernel has no business moderating.

Quoted 6 lines

He, and others, have watched this discussion closely over the last two years that we have tried to get TSEM reviewed and just recently phoned me with the following comment:

"I think the problem is that these guys don't understand how security is being done and the reasons why".

Oh, make no mistake, I (at least) understand how security is being done these days and find it terrifying. We do in the kernel what can and should be done in the kernel, but adding general supply chain controls as an LSM isn't gonna happen in my (admittedly limited) lifetime.

Quoted 2 lines

There is probably not a modern EDRS solution that does not involve going to the cloud for its decision making enforcement,

Wow. The number and density of application and network protocols necessary for that to work puts an Austrian pastry to shame. And you want to put that in the kernel?

Quoted 5 lines

in most cases
based on Indicators Of Compromise (IOC) trained machine learning models. Asynchronous detection, enforcement and remediation is now standard practice. In the security industry, a 1 minute response to a security event is considered the 'gold' standard.

A one minute delay in an openat() call ain't gonna happen.

Quoted 14 lines

For the sake of discussion, lets take a Quixote userspace Trusted Modeling Agent (TMA) running TSEM based deterministic modeling of a containerized workload. As we've discussed previously, demonstrated average response times are on the order of 170 micro-seconds.

For an event that needs asynchronous enforcement, ie. running in atomic context, that represents a 3.5 order of magnitude advantage in response over the industry standard, without the attendant challenges of going off machine or installing kernel based infrastructure.

What would be the rationale or advantage of denying those that desire this type of security option, a 3,500 fold increase in security response times?

Quoted 8 lines

Let's take another need for running in userspace, trusted execution environments. Support is available in our userspace package for running a TMA model in either an SGX enclave or in an independent hypervisor protected execution context, both of which significantly harden the enforcement implementation against attack by adversaries.

As Linux security maintainer, we assume that you have read Executive Order 14144 signed on January 16th 2025.

Remember "C2 in '92"? Executive order. Industry invested ~$25 Million in 1990's dollars in evaluation costs alone. Never enforced. I am not shaking in my boots.

Quoted 7 lines

That document specifically
calls out the requirement for the increased use of trusted execution environments in combination with advancements in endpoint detection.

It shouldn't be a leap in imagination as to the regulatory compliance advantages associated with hardware attestation that the security implementation is operational and in a known good enforcement state.

When those technologies have developed some level of maturity and acceptance they'll be worth considering more seriously.

Quoted 6 lines

Finally, at this point in time, it would seem unwise in the technology industry, to discount the importance of 'AI', or more correctly machine learning. As we've noted before in our discussions, it is unlikely that we are going to see synchronous LSM enforcement using a machine learning model trained on potentially trillions of data observations and indicators.

I'm not discounting AI. I'm questioning it's use in kernel access control implementations. You cannot ignore the impact of access control on system performance. Ever.

Quoted 2 lines

The LSM is designed to provide security services to the users of Linux, not to be a kingdom.

It's never been more than a principality. ;)

Quoted 2 lines

Linux is/was about 'choice' as to how users want to use their hardware.

Nah, it's about a Finish grad student's side project.

Quoted 3 lines

Artifically limiting the types of security that can be implemented by the LSM works to the detriment of the security innovation that Linux can deliver and the Linux user community writ large.

If you can demonstrate a sane implementation of your mechanism we're all ears. User space policy adjudication isn't sane. It wasn't in the 1980's, it isn't now.

author
#19 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

On Wed, Feb 05, 2025 at 11:58:00AM -0800, Casey Schaufler wrote:

Good morning, I hope the week is progressing well.

I need to climb on an airplane in less than 24 hours to fly to Aspen to spend some time skiing with the 'beautiful people', so only two comments.

Quoted 28 lines · Dr. Greg
Quoted 21 lines · Paul Moore

Good morning, I hope mid-week is going well for everyone.

After the issue of the functionality of modern cryptographic primitives, a discussion of the second most important issue Paul raises.

Quoted 4 lines

I believe the LSM can support both the enforcement of security policy and the observation of security relevant events on a system. In fact most of the existing LSMs do both, at least to some extent.

Quoted 9 lines

However, while logging of security events likely needs to be asynchronous for performance reasons, enforcement of security policy likely needs to be synchronous to have any reasonable level of assurance. You are welcome to propose LSMs which provide observability functionality that is either sync, async, or some combination of both (? it would need to make sense to do both ?), but I'm not currently interested in accepting LSMs that provide asynchronous enforcement as I don't view that as a "reasonable" enforcement mechanism.

Quoted 2 lines

This is an artificial distinction that will prove limiting to the security that Linux will be able to deliver in the future.

I'll apologize up front to everyone else for this response, but I hope it is something you might understand.

Quoted 8 lines

A security guard scans a person's access pass. As the computer system that processes the data is slow, the guard lets the person go through the gate. An access denial finally comes through. The guard turns and shoots the intruder. What other choice is available? The intruder may have seen what should not have been seen. Now the guard has to file a fatal incident report and slow down everything else while cleaning up the remains.

tl;dr - async access control is just messy.

Stated more precisely, the model is asynchronous behavioral controls and model response.

It is currently what 100+ billion dollar security companies and their products are based on. Which, in an increasingly wide swath of corporate IT, you are required to implement.

Kernel security maintainers can choose to ignore the issue, doesn't mean it isn't reality.

We have a very diverse team, members of which have been involved in international cybersecurity issues that have been in the news. I've personally written white papers for the consumption of individuals that are in the news, as to the socio-technical issues that are behind why we can't have nice things in cybersecurity.

We believe Linux can improve on this situation. We at least look on it as fortunate to have a public record as to why that may not be possible, if that turns out to be the case.

Quoted 118 lines
Quoted 4 lines

Based on your response, is it your stated position as Linux security maintainer, that you consider modern Endpoint Detection and Response Systems (EDRS) lacking with respect to their ability to implement a "reasonable" enforcement and assurance mechanism?

You are conflating issues. It isn't the purpose of the system, it is the mechanism by which it is implemented that is the problem.

Quoted 11 lines

If this is the case, your philosophy leaves Linux in a position that is inconsistent with how the industry is choosing to implement security.

Let me cite an example from one of our project advisors.

This individual is a senior principal at a reasonably large technology products company that depends on Linux almost exclusively to support its operations. At any given instant he participates in supervising a fleet of around 6,000 virtual machines running about 50,000-60,000 containerized workloads.

How can this possibly be a kernel problem?

Quoted 4 lines

All of the Linux deployments are Ansible orchestrated. The security deployment consists of disabling SeLinux and installing an EDRS solution. Doing the latter checks all the boxes they need for their corporate security compliance policies.

Without insight regarding what these policies might be it is impossible to say for sure, but I'll bet a refreshing beverage that they involve all sorts of application level protocols, and other things the kernel has no business moderating.

Quoted 6 lines

He, and others, have watched this discussion closely over the last two years that we have tried to get TSEM reviewed and just recently phoned me with the following comment:

"I think the problem is that these guys don't understand how security is being done and the reasons why".

Oh, make no mistake, I (at least) understand how security is being done these days and find it terrifying. We do in the kernel what can and should be done in the kernel, but adding general supply chain controls as an LSM isn't gonna happen in my (admittedly limited) lifetime.

Quoted 2 lines

There is probably not a modern EDRS solution that does not involve going to the cloud for its decision making enforcement,

Wow. The number and density of application and network protocols necessary for that to work puts an Austrian pastry to shame. And you want to put that in the kernel?

Quoted 5 lines

in most cases
based on Indicators Of Compromise (IOC) trained machine learning models. Asynchronous detection, enforcement and remediation is now standard practice. In the security industry, a 1 minute response to a security event is considered the 'gold' standard.

A one minute delay in an openat() call ain't gonna happen.

Quoted 14 lines

For the sake of discussion, lets take a Quixote userspace Trusted Modeling Agent (TMA) running TSEM based deterministic modeling of a containerized workload. As we've discussed previously, demonstrated average response times are on the order of 170 micro-seconds.

For an event that needs asynchronous enforcement, ie. running in atomic context, that represents a 3.5 order of magnitude advantage in response over the industry standard, without the attendant challenges of going off machine or installing kernel based infrastructure.

What would be the rationale or advantage of denying those that desire this type of security option, a 3,500 fold increase in security response times?

Quoted 8 lines

Let's take another need for running in userspace, trusted execution environments. Support is available in our userspace package for running a TMA model in either an SGX enclave or in an independent hypervisor protected execution context, both of which significantly harden the enforcement implementation against attack by adversaries.

As Linux security maintainer, we assume that you have read Executive Order 14144 signed on January 16th 2025.

Remember "C2 in '92"? Executive order. Industry invested ~$25 Million in 1990's dollars in evaluation costs alone. Never enforced. I am not shaking in my boots.

Quoted 7 lines

That document specifically
calls out the requirement for the increased use of trusted execution environments in combination with advancements in endpoint detection.

It shouldn't be a leap in imagination as to the regulatory compliance advantages associated with hardware attestation that the security implementation is operational and in a known good enforcement state.

When those technologies have developed some level of maturity and acceptance they'll be worth considering more seriously.

Quoted 6 lines

Finally, at this point in time, it would seem unwise in the technology industry, to discount the importance of 'AI', or more correctly machine learning. As we've noted before in our discussions, it is unlikely that we are going to see synchronous LSM enforcement using a machine learning model trained on potentially trillions of data observations and indicators.

I'm not discounting AI. I'm questioning it's use in kernel access control implementations. You cannot ignore the impact of access control on system performance. Ever.

Quoted 2 lines

The LSM is designed to provide security services to the users of Linux, not to be a kingdom.

It's never been more than a principality. ;)

Quoted 2 lines

Linux is/was about 'choice' as to how users want to use their hardware.

Nah, it's about a Finish grad student's side project.

Quoted 7 lines
Quoted 3 lines

Artifically limiting the types of security that can be implemented by the LSM works to the detriment of the security innovation that Linux can deliver and the Linux user community writ large.

If you can demonstrate a sane implementation of your mechanism we're all ears. User space policy adjudication isn't sane. It wasn't in the 1980's, it isn't now.

For the official record, a number of your assessments above are incorrect and do not reflect our implementation or intentions.

It doesn't seem to be a worthwhile expenditure of anyone's time to discuss technical specifics.

We will remain content to be 'The Ghost of Christmas Yet To Come'.

Best wishes for a productive remainder of the week to everyone.

As always,
Dr. Greg

The Quixote Project - Flailing at the Travails of Cybersecurity
https://github.com/Quixote-Project

maintainer
#20 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

In reply to Dr. Greg
Quoted 16 lines · Dr. Greg
Quoted 4 lines · Paul Moore

I believe the LSM can support both the enforcement of security policy and the observation of security relevant events on a system. In fact most of the existing LSMs do both, at least to some extent.

Quoted 9 lines

However, while logging of security events likely needs to be asynchronous for performance reasons, enforcement of security policy likely needs to be synchronous to have any reasonable level of assurance. You are welcome to propose LSMs which provide observability functionality that is either sync, async, or some combination of both (? it would need to make sense to do both ?), but I'm not currently interested in accepting LSMs that provide asynchronous enforcement as I don't view that as a "reasonable" enforcement mechanism.

Quoted 7 lines

This is an artificial distinction that will prove limiting to the security that Linux will be able to deliver in the future.

Based on your response, is it your stated position as Linux security maintainer, that you consider modern Endpoint Detection and Response Systems (EDRS) lacking with respect to their ability to implement a "reasonable" enforcement and assurance mechanism?

As stated previously: "I'm not currently interested in accepting LSMs that provide asynchronous enforcement as I don't view that as a reasonable enforcement mechanism."

Quoted 3 lines

If this is the case, your philosophy leaves Linux in a position that is inconsistent with how the industry is choosing to implement security.

In this case perhaps TSEM is not well suited for the upstream Linux kernel and your efforts are better spent downstream, much like the industry you appear to respect.

Signature · 1 line
paul-moore.com
author
#21 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

On Thu, Feb 06, 2025 at 10:48:57AM -0500, Paul Moore wrote:

Good morning to everyone.

Quoted 20 lines · On Wed, Feb 5, 2025 at 7:01???AM Dr. Greg <[email protected]> wrote:
Quoted 19 lines · Paul Moore
Quoted 5 lines

I believe the LSM can support both the enforcement of security policy and the observation of security relevant events on a system. In fact most of the existing LSMs do both, at least to some extent.

Quoted 9 lines

However, while logging of security events likely needs to be asynchronous for performance reasons, enforcement of security policy likely needs to be synchronous to have any reasonable level of assurance. You are welcome to propose LSMs which provide observability functionality that is either sync, async, or some combination of both (? it would need to make sense to do both ?), but I'm not currently interested in accepting LSMs that provide asynchronous enforcement as I don't view that as a "reasonable" enforcement mechanism.

This is an artificial distinction that will prove limiting to the security that Linux will be able to deliver in the future.

Quoted 8 lines
Quoted 4 lines

Based on your response, is it your stated position as Linux security maintainer, that you consider modern Endpoint Detection and Response Systems (EDRS) lacking with respect to their ability to implement a "reasonable" enforcement and assurance mechanism?

As stated previously: "I'm not currently interested in accepting LSMs that provide asynchronous enforcement as I don't view that as a reasonable enforcement mechanism."

You personally don't, the IT and security compliance industry does, it seems to leave Linux security infrastructure in an interesting conundrum.

For the record, just to be very clear as to what an LSM is allowed to do under your administration, for our benefit and the benefit of others:

An LSM asynchronously streams an encoding of every security event that occurs into something in userspace, somewhere, that interprets those events. Is userspace allowed to directly signal the operating system if it detects an anomaly in one of those events or a pattern of events and at what resolution level can the signalling occur?

Quoted 7 lines
Quoted 3 lines

If this is the case, your philosophy leaves Linux in a position that is inconsistent with how the industry is choosing to implement security.

In this case perhaps TSEM is not well suited for the upstream Linux kernel and your efforts are better spent downstream, much like the industry you appear to respect.

Fascinating response from someone given the privilege of maintainership status of a sub-system in a project whose leadership preaches the need to always work with and submit to upstream.

Even more fascinating when that individual publically states that he is employed by the largest technology company in the world because of that companies desire to promote the health and well being of the Linux eco-system and community.

For the record, we don't respect any industry, we respect the need to address the challenges associated with how we are currently doing and thinking about things.

Quoted 1 line

paul-moore.com

Our apologies to everyone for being a voice crying out in the wilderness.

As always,
Dr. Greg

The Quixote Project - Flailing at the Travails of Cybersecurity
https://github.com/Quixote-Project

#22 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

Quoted 38 lines · Dr. Greg

On Thu, Feb 06, 2025 at 10:48:57AM -0500, Paul Moore wrote:

Good morning to everyone.

Quoted 19 lines · On Wed, Feb 5, 2025 at 7:01???AM Dr. Greg <[email protected]> wrote:
Quoted 18 lines · Paul Moore
Quoted 5 lines

I believe the LSM can support both the enforcement of security policy and the observation of security relevant events on a system. In fact most of the existing LSMs do both, at least to some extent.

Quoted 9 lines

However, while logging of security events likely needs to be asynchronous for performance reasons, enforcement of security policy likely needs to be synchronous to have any reasonable level of assurance. You are welcome to propose LSMs which provide observability functionality that is either sync, async, or some combination of both (? it would need to make sense to do both ?), but I'm not currently interested in accepting LSMs that provide asynchronous enforcement as I don't view that as a "reasonable" enforcement mechanism.

This is an artificial distinction that will prove limiting to the security that Linux will be able to deliver in the future.

Quoted 7 lines
Quoted 4 lines

Based on your response, is it your stated position as Linux security maintainer, that you consider modern Endpoint Detection and Response Systems (EDRS) lacking with respect to their ability to implement a "reasonable" enforcement and assurance mechanism?

As stated previously: "I'm not currently interested in accepting LSMs that provide asynchronous enforcement as I don't view that as a reasonable enforcement mechanism."

You personally don't, the IT and security compliance industry does, it seems to leave Linux security infrastructure in an interesting conundrum.

For the record, just to be very clear as to what an LSM is allowed to do under your administration, for our benefit and the benefit of others:

Quoted 5 lines

An LSM asynchronously streams an encoding of every security event that occurs into something in userspace, somewhere, that interprets those events. Is userspace allowed to directly signal the operating system if it detects an anomaly in one of those events or a pattern of events and at what resolution level can the signalling occur?

Not to throw a wet blanket on your argument, but you can do just that with a combination of the audit trail and Smack. Well, mostly. You can't retroactively deny an access, but you can change the Smack label on a file or change the access rules as desired. What you can't do is detain an event while user space is queried about the decision. That is, I believe, the fundamental problem with your approach.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

If this is the case, your philosophy leaves Linux in a position that is inconsistent with how the industry is choosing to implement security.

In this case perhaps TSEM is not well suited for the upstream Linux kernel and your efforts are better spent downstream, much like the industry you appear to respect.

Fascinating response from someone given the privilege of maintainership status of a sub-system in a project whose leadership preaches the need to always work with and submit to upstream.

"Work with" sometimes means you don't get everything you thought you wanted in the way you wanted it. Refer to the work on LSM stacking, which looks very different now than it did when I started on it in 2010.

Quoted 5 lines

Even more fascinating when that individual publically states that he is employed by the largest technology company in the world because of that companies desire to promote the health and well being of the Linux eco-system and community.

Quoted 7 lines

For the record, we don't respect any industry, we respect the need to address the challenges associated with how we are currently doing and thinking about things.

Quoted 1 line

paul-moore.com

Our apologies to everyone for being a voice crying out in the wilderness.

You aren't crying anything new. It's not easy to address all of the issues necessary to make a chunk of code acceptable to the Linux kernel. I doesn't help that you're crying in a language in which much of your audience is not fluent.

Quoted 7 lines

As always,
Dr. Greg

The Quixote Project - Flailing at the Travails of Cybersecurity
https://github.com/Quixote-Project

maintainer
#23 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

In reply to Dr. Greg
Quoted 26 lines · Dr. Greg
Quoted 24 lines · Paul Moore
Quoted 23 lines · On Wed, Feb 5, 2025 at 7:01???AM Dr. Greg <[email protected]> wrote:
Quoted 4 lines · Paul Moore

I believe the LSM can support both the enforcement of security policy and the observation of security relevant events on a system. In fact most of the existing LSMs do both, at least to some extent.

Quoted 9 lines

However, while logging of security events likely needs to be asynchronous for performance reasons, enforcement of security policy likely needs to be synchronous to have any reasonable level of assurance. You are welcome to propose LSMs which provide observability functionality that is either sync, async, or some combination of both (? it would need to make sense to do both ?), but I'm not currently interested in accepting LSMs that provide asynchronous enforcement as I don't view that as a "reasonable" enforcement mechanism.

This is an artificial distinction that will prove limiting to the security that Linux will be able to deliver in the future.

Based on your response, is it your stated position as Linux security maintainer, that you consider modern Endpoint Detection and Response Systems (EDRS) lacking with respect to their ability to implement a "reasonable" enforcement and assurance mechanism?

Quoted 7 lines
Quoted 3 lines

As stated previously: "I'm not currently interested in accepting LSMs that provide asynchronous enforcement as I don't view that as a reasonable enforcement mechanism."

You personally don't, the IT and security compliance industry does, it seems to leave Linux security infrastructure in an interesting conundrum.

Your concern over the state of the LSM has been previously noted, and I assure you I've rolled my eyes at each reference since.

Quoted 3 lines

For the record, just to be very clear as to what an LSM is allowed to do under your administration, for our benefit and the benefit of others ...

I've repeated my position once already, if any current or aspiring LSM developers are unsure about some aspect of this, they are welcome to bring their specific concerns to the list and we can discuss them.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

If this is the case, your philosophy leaves Linux in a position that is inconsistent with how the industry is choosing to implement security.

In this case perhaps TSEM is not well suited for the upstream Linux kernel and your efforts are better spent downstream, much like the industry you appear to respect.

Quoted 8 lines

Fascinating response from someone given the privilege of maintainership status of a sub-system in a project whose leadership preaches the need to always work with and submit to upstream.

Even more fascinating when that individual publically states that he is employed by the largest technology company in the world because of that companies desire to promote the health and well being of the Linux eco-system and community.

I would suggest that your interpretation of my previous comments are a bit "off" in my opinion, but who am I to argue with a view that sees my comments as this fascinating!

Jokes aside, to be clear I didn't tell you not to continue to post newer revisions of TSEM, I simply suggested that based on the choices you've made in designing and developing TSEM, it may be better suited to a downstream solution and not the upstream Linux kernel. However, perhaps continuing to post a LSM that has not been accepted upstream due to inherent design decisions is perfectly in keeping with a LSM that relishes references to Don Quixote.

Quoted 3 lines

For the record, we don't respect any industry, we respect the need to address the challenges associated with how we are currently doing and thinking about things.

Noted.

Signature · 1 line
paul-moore.com
author
#24 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

On Fri, Feb 07, 2025 at 07:29:58PM -0500, Paul Moore wrote:

Good morning to everyone.

Quoted 31 lines · On Fri, Feb 7, 2025 at 5:20???AM Dr. Greg <[email protected]> wrote:
Quoted 30 lines · Paul Moore
Quoted 28 lines · On Wed, Feb 5, 2025 at 7:01???AM Dr. Greg <[email protected]> wrote:
Quoted 16 lines · Paul Moore
Quoted 5 lines

I believe the LSM can support both the enforcement of security policy and the observation of security relevant events on a system. In fact most of the existing LSMs do both, at least to some extent.

Quoted 9 lines

However, while logging of security events likely needs to be asynchronous for performance reasons, enforcement of security policy likely needs to be synchronous to have any reasonable level of assurance. You are welcome to propose LSMs which provide observability functionality that is either sync, async, or some combination of both (? it would need to make sense to do both ?), but I'm not currently interested in accepting LSMs that provide asynchronous enforcement as I don't view that as a "reasonable" enforcement mechanism.

Quoted 7 lines

This is an artificial distinction that will prove limiting to the security that Linux will be able to deliver in the future.

Based on your response, is it your stated position as Linux security maintainer, that you consider modern Endpoint Detection and Response Systems (EDRS) lacking with respect to their ability to implement a "reasonable" enforcement and assurance mechanism?

As stated previously: "I'm not currently interested in accepting LSMs that provide asynchronous enforcement as I don't view that as a reasonable enforcement mechanism."

Quoted 6 lines
Quoted 3 lines

You personally don't, the IT and security compliance industry does, it seems to leave Linux security infrastructure in an interesting conundrum.

Your concern over the state of the LSM has been previously noted, and I assure you I've rolled my eyes at each reference since.

Addressed at the end of this e-mail.

You can also see our reply to James Morris and the announcement of the Linux Security Summit in Denver this summer.

Quoted 7 lines
Quoted 3 lines

For the record, just to be very clear as to what an LSM is allowed to do under your administration, for our benefit and the benefit of others ...

I've repeated my position once already, if any current or aspiring LSM developers are unsure about some aspect of this, they are welcome to bring their specific concerns to the list and we can discuss them.

For the record, we did bring a specific concern to the list for discussion, you removed the question and example we raised from your reply.

Let me re-state the example and question for the benefit of everyone reading along at home.

An LSM encodes a description of each security event it handles that is designed to be consumed by an application running in userspace or on a dedicated device that analyzes the events. If the application or device detects an anomalous event or pattern of events it takes action to protect the system.

Would such an LSM be permitted to exist?

If the answer to the previous question is yes, at what level of event resolution can the remediative action be taken?

We will look forward to the ensueing discussion.

Quoted 21 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

If this is the case, your philosophy leaves Linux in a position that is inconsistent with how the industry is choosing to implement security.

In this case perhaps TSEM is not well suited for the upstream Linux kernel and your efforts are better spent downstream, much like the industry you appear to respect.

Quoted 8 lines

Fascinating response from someone given the privilege of maintainership status of a sub-system in a project whose leadership preaches the need to always work with and submit to upstream.

Even more fascinating when that individual publically states that he is employed by the largest technology company in the world because of that companies desire to promote the health and well being of the Linux eco-system and community.

I would suggest that your interpretation of my previous comments are a bit "off" in my opinion, but who am I to argue with a view that sees my comments as this fascinating!

Quoted 7 lines

Jokes aside, to be clear I didn't tell you not to continue to post newer revisions of TSEM, I simply suggested that based on the choices you've made in designing and developing TSEM, it may be better suited to a downstream solution and not the upstream Linux kernel. However, perhaps continuing to post a LSM that has not been accepted upstream due to inherent design decisions is perfectly in keeping with a LSM that relishes references to Don Quixote.

Since we seem to be on the precipice of closing down the discussion on the relevancy of LSM development moving forward, a final comment for the record.

We were not tilting at windmills when we started this effort two years ago, we fully understood that we would be involved in a long game.

Our objectives were to either:

1.) Provide Linux security development with infrastructure for a more generic and safer security modeling architecture that is consistent with the current and emerging threat environment and counter-offensive technologies.

or

2.) Document that upstream Linux security development is not a suitable venue for analyzing and solving these and upcoming security challenges.

Two outcomes were possible, either outcome was acceptable, the second seems to be the one that is eventuating.

Quoted 1 line

paul-moore.com

Have a good week.

As always,
Dr. Greg

The Quixote Project - Flailing at the Travails of Cybersecurity
https://github.com/Quixote-Project

maintainer
#25 lore raw

Re: [PATCH v4 2/14] Add TSEM specific documentation.

Quoted 36 lines · Dr. Greg
Quoted 34 lines · Paul Moore
Quoted 33 lines · On Fri, Feb 7, 2025 at 5:20???AM Dr. Greg <[email protected]> wrote:
Quoted 20 lines · Paul Moore
Quoted 19 lines · On Wed, Feb 5, 2025 at 7:01???AM Dr. Greg <[email protected]> wrote:
Quoted 4 lines · Paul Moore

I believe the LSM can support both the enforcement of security policy and the observation of security relevant events on a system. In fact most of the existing LSMs do both, at least to some extent.

Quoted 9 lines

However, while logging of security events likely needs to be asynchronous for performance reasons, enforcement of security policy likely needs to be synchronous to have any reasonable level of assurance. You are welcome to propose LSMs which provide observability functionality that is either sync, async, or some combination of both (? it would need to make sense to do both ?), but I'm not currently interested in accepting LSMs that provide asynchronous enforcement as I don't view that as a "reasonable" enforcement mechanism.

This is an artificial distinction that will prove limiting to the security that Linux will be able to deliver in the future.

Quoted 8 lines
Quoted 4 lines

Based on your response, is it your stated position as Linux security maintainer, that you consider modern Endpoint Detection and Response Systems (EDRS) lacking with respect to their ability to implement a "reasonable" enforcement and assurance mechanism?

As stated previously: "I'm not currently interested in accepting LSMs that provide asynchronous enforcement as I don't view that as a reasonable enforcement mechanism."

You personally don't, the IT and security compliance industry does, it seems to leave Linux security infrastructure in an interesting conundrum.

Quoted 7 lines
Quoted 2 lines

Your concern over the state of the LSM has been previously noted, and I assure you I've rolled my eyes at each reference since.

Addressed at the end of this e-mail.

You can also see our reply to James Morris and the announcement of the Linux Security Summit in Denver this summer.

I did. As Casey already mentioned, you are free to submit a proposal. I believe most of the program committee will remember you from your previous presentation.

Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

For the record, just to be very clear as to what an LSM is allowed to do under your administration, for our benefit and the benefit of others ...

I've repeated my position once already, if any current or aspiring LSM developers are unsure about some aspect of this, they are welcome to bring their specific concerns to the list and we can discuss them.

For the record, we did bring a specific concern to the list for discussion, you removed the question and example we raised from your reply.

I routinely trim replies to improve readability, especially in the case of large emails, and since mailing lists are archived no data is lost. As far as answering questions regarding hypothetical LSMs, I see no reason to do so given the nature of your on-list comments of late. I've provided feedback on the specifics of the TSEM approach as well as general feedback on async enforcement and that will have to be sufficient for now.

Signature · 1 line
paul-moore.com
#26 lore raw

PATCH v4 3/14 TSEM global declarations.

In reply to Greg Wettstein

TSEM is designed, from a functional perspective, to be entirely contained in its own directory.

TSEM uses a single global header file, tsem.h, to define the enumeration types, structure definitions and functions that are referenced across all of the compilation units that implement the LSM.

---
 security/tsem/tsem.h | 2336 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 2336 insertions(+)
 create mode 100644 security/tsem/tsem.h
security/tsem/tsem.h new file +2336 -0
new file mode 100644
index 000000000000..24f52824089e
@@ -0,0 +1,2336 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+/*
+ * Copyright (C) 2024 Enjellic Systems Development, LLC
+ * Author: Dr. Greg Wettstein <[email protected]>
+ *
+ * This is the single include file that documents all of the externally
+ * visible types and functions that are used by TSEM.  This file is
+ * currently organized into four major sections in the following order;
+ *
+ * includes used by all compilation units
+ * CPP definitions
+ * enumeration types
+ * structure definitions
+ * function declarations
+ * inline encapsulation functions.
+ *
+ * Include files that are referenced by more than a single compilation
+ * should be included in this file.  Includes that are needed to
+ * satisfy compilation requirements for only a single file should be
+ * included in the file needing that include.
+ *
+ * Understanding the overall implementation and architecture of TSEM
+ * will be facilitated by reviewing the documentation in this file.
+ */
+
+#include <linux/wait.h>
+#include <linux/kref.h>
+#include <linux/lsm_hooks.h>
+#include <linux/capability.h>
+#include <crypto/hash.h>
+#include <crypto/hash_info.h>
+#include <net/af_unix.h>
+
+/*
+ * The number of 'slots' in the structure magazines that are used to
+ * satisfy modeling of security events that are called in atomic context.
+ */
+#define TSEM_ROOT_MAGAZINE_SIZE	128
+#define TSEM_MAGAZINE_SIZE_INTERNAL 32
+#define TSEM_MAGAZINE_SIZE_EXTERNAL 128
+
+/**
+ * enum tsem_event_type - Ordinal value for a security event.
+ * @TSEM_BPRM_COMMITTED_CREDS: Ordinal value for bprm_committed_creds.
+ * @TSEM_TASK_KILL: Ordinal value for task kill.
+ * @....: Remainder follows with a similar naming format that has
+ *        TSEM_ prep ended to the raw LSM security hook name.
+ * @TSEM_EVENT_CNT: The final ordinal value is used to define the
+ *		    length of the following arrays that are indexed
+ *		    by the ordinal value of the hook:
+ *
+ * This enumeration is used to designate an ordinal value for each
+ * security event, ie. LSM hook/event handler, that TSEM is
+ * implementing modeling for.  This value is used to identify the
+ * handler that is either having its event description being exported
+ * to an external trust orchestrator or modeled by the internal TMA
+ * implementation.
+ *
+ * The primary use of this enumeration is to conditionalize code paths
+ * based on the security hook being processed and to index the
+ * tsem_names array and the array that defines the action that is to
+ * be taken in response to an event that generates a permissions
+ * violation.
+ *
+ * NOTE:
+ * If additions or deletions are made to these enumerated constants
+ * there needs to be coordinated changes made to the tsem_names array
+ * in the tsem.c file.
+ */
+enum tsem_event_type {
+	TSEM_BPRM_COMMITTED_CREDS = 1,
+	TSEM_TASK_KILL,
+	TSEM_TASK_SETPGID,
+	TSEM_TASK_GETPGID,
+	TSEM_TASK_GETSID,
+	TSEM_TASK_SETNICE,
+	TSEM_TASK_SETIOPRIO,
+	TSEM_TASK_GETIOPRIO,
+	TSEM_TASK_PRLIMIT,
+	TSEM_TASK_SETRLIMIT,
+	TSEM_TASK_SETSCHEDULER,
+	TSEM_TASK_GETSCHEDULER,
+	TSEM_TASK_PRCTL,
+	TSEM_FILE_OPEN,
+	TSEM_MMAP_FILE,
+	TSEM_FILE_IOCTL,
+	TSEM_FILE_LOCK,
+	TSEM_FILE_FCNTL,
+	TSEM_FILE_RECEIVE,
+	TSEM_UNIX_STREAM_CONNECT,
+	TSEM_UNIX_MAY_SEND,
+	TSEM_SOCKET_CREATE,
+	TSEM_SOCKET_CONNECT,
+	TSEM_SOCKET_BIND,
+	TSEM_SOCKET_ACCEPT,
+	TSEM_SOCKET_LISTEN,
+	TSEM_SOCKET_SOCKETPAIR,
+	TSEM_SOCKET_SENDMSG,
+	TSEM_SOCKET_RECVMSG,
+	TSEM_SOCKET_GETSOCKNAME,
+	TSEM_SOCKET_GETPEERNAME,
+	TSEM_SOCKET_SETSOCKOPT,
+	TSEM_SOCKET_SHUTDOWN,
+	TSEM_PTRACE_TRACEME,
+	TSEM_KERNEL_MODULE_REQUEST,
+	TSEM_KERNEL_LOAD_DATA,
+	TSEM_KERNEL_READ_FILE,
+	TSEM_SB_MOUNT,
+	TSEM_SB_UMOUNT,
+	TSEM_SB_REMOUNT,
+	TSEM_SB_PIVOTROOT,
+	TSEM_SB_STATFS,
+	TSEM_MOVE_MOUNT,
+	TSEM_SHM_ASSOCIATE,
+	TSEM_SHM_SHMCTL,
+	TSEM_SHM_SHMAT,
+	TSEM_SEM_ASSOCIATE,
+	TSEM_SEM_SEMCTL,
+	TSEM_SEM_SEMOP,
+	TSEM_SYSLOG,
+	TSEM_SETTIME,
+	TSEM_QUOTACTL,
+	TSEM_QUOTA_ON,
+	TSEM_MSG_QUEUE_ASSOCIATE,
+	TSEM_MSG_QUEUE_MSGCTL,
+	TSEM_MSG_QUEUE_MSGSND,
+	TSEM_MSG_QUEUE_MSGRCV,
+	TSEM_IPC_PERMISSION,
+	TSEM_KEY_ALLOC,
+	TSEM_KEY_PERMISSION,
+	TSEM_NETLINK_SEND,
+	TSEM_INODE_CREATE,
+	TSEM_INODE_LINK,
+	TSEM_INODE_UNLINK,
+	TSEM_INODE_SYMLINK,
+	TSEM_INODE_MKDIR,
+	TSEM_INODE_RMDIR,
+	TSEM_INODE_MKNOD,
+	TSEM_INODE_RENAME,
+	TSEM_INODE_SETATTR,
+	TSEM_INODE_GETATTR,
+	TSEM_INODE_SETXATTR,
+	TSEM_INODE_GETXATTR,
+	TSEM_INODE_LISTXATTR,
+	TSEM_INODE_REMOVEXATTR,
+	TSEM_INODE_KILLPRIV,
+	TSEM_TUN_DEV_CREATE,
+	TSEM_TUN_DEV_ATTACH_QUEUE,
+	TSEM_TUN_DEV_ATTACH,
+	TSEM_TUN_DEV_OPEN,
+	TSEM_BPF,
+	TSEM_BPF_MAP,
+	TSEM_BPF_PROG,
+	TSEM_PTRACE_ACCESS_CHECK,
+	TSEM_CAPABLE,
+	TSEM_CAPGET,
+	TSEM_CAPSET,
+	TSEM_EVENT_CNT
+};
+
+/**
+ * enum tsem_action_type - Ordinal value for security responses.
+ * @TSEM_ACTION_LOG: Ordinal value to indicate that a security event
+ *		     that results in a model permissions violation
+ *		     should be logged.
+ * @TSEM_ACTION_EPERM: Ordinal value to indicate that a security event
+ *		       generating a model permissions violation should
+ *		       return -EPERM to the caller.
+ *
+ * This enumeration type is used to designate what type of action is
+ * to be taken when the processing of a security event hook results in
+ * a model violation.  The TSEM_ACTION_LOG and TSEM_ACTION_EPERM
+ * translate into the classical concepts of logging or enforcing
+ * actions used by other mandatory access control architectures.
+ */
+enum tsem_action_type {
+	TSEM_ACTION_LOG = 0,
+	TSEM_ACTION_EPERM,
+	TSEM_ACTION_CNT
+};
+
+/**
+ * enum tsem_control_type - Ordinal values for TSEM control actions.
+ * @TSEM_CONTROL_INTERNAL: This ordinal value is set when the first
+ *			   word of an argument string written to the
+ *			   control file is the word 'internal'.  This
+ *			   designates that the security namespace will
+ *			   be modeled by the internal TMA.
+ * @TSEM_CONTROL_EXTERNAL: This ordinal value is set when the first
+ *			   word of an argument string written to the
+ *			   control file is the word 'external'.  This
+ *			   designates that the security namespace will
+ *			   be model by an external TMA.
+ * @TSEM_CONTROL_ENFORCE: This ordinal value is set when the word
+ *			  'enforce' is written to the control file.
+ *			  This indicates that model is to be placed
+ *			  in 'enforcing' mode and security events that
+ *			  result in model violations will return EPERM.
+ * @TSEM_CONTROL_SEAL: This ordinal value is set when the word 'seal'
+ *		       is written to the control file.  This indicates
+ *		       that the model for security domain will treat
+ *		       all security events that do not conform to the
+ *		       model as 'forensics' events.
+ * @TSEM_CONTROL_TRUSTED: This ordinal value is used when the first
+ *			  word of an argument string written to the
+ *			  control file is the word 'trusted'.  This
+ *			  is interpreted as a directive to set the
+ *			  trust status of the task that executed the
+ *			  security event to be trusted.
+ * @TSEM_CONTROL_UNTRUSTED: This ordinal value is used when the first
+ *			    word of an argument string written to the
+ *			    control file is the word 'untrusted'.
+ *			    This is interpreted as a directive to set
+ *			    the trust status of the task that executed
+ *			    the security event to be untrusted.
+ * @TSEM_CONTROL_MAP_STATE: This ordinal value is used when the first
+ *			    word of an argument string written to the
+ *			    control file is the word 'state'.  The
+ *			    argument to this directive will be an
+ *			    ASCII hexadecimally encoded string of the
+ *			    current model's digest size that will be
+ *			    treated as a security state point for
+ *			    inclusion in the security model for the
+ *			    security domain/namespace.
+ * @TSEM_CONTROL_MAP_PSEUDONYM: This ordinal value is used when the
+ *				first word of an argument string
+ *				written to the control file is the
+ *				word 'pseudonym'.  The argument to
+ *				this directive will be an ASCII
+ *				hexadecimally encoded string of the
+ *				current model's digest size that will
+ *				be treated as a pseudonym directive
+ *				for the security domain/namespace.
+ * TSEM_CONTROL_MAP_BASE: This ordinal value is used when the first
+ *			  word of an argument string written to the
+ *			  control file is the word 'base'.  The
+ *			  argument to this directive will be an ASCII
+ *			  hexadecimally encoded string of the current
+ *			  model's digest size that will be treated as
+ *			  the base value for the computation of the
+ *			  functional values (measurement and state) of
+ *			  the security domain/namespace.
+ * TSEM_CONTROL_LOCK: This ordinal value is used to indicate that a
+ *		      request is being made to lock the model configuration
+ *		      of the host from further modification.  Invoking
+ *		      this command causes any additional requests to
+ *		      register security models to be denied.  In addition
+ *		      the reference count of all currently loaded models
+ *		      is increased in order to prevent the models from
+ *		      being unloaded.
+ *
+ * This enumeration type is used to designate what type of control
+ * action is to be implemented when arguments are written to the TSEM
+ * control file (/sys/kernel/security/tsem/control).  The ordinal
+ * values govern the processing of the command and the interpretation
+ * of the rest of the command argument string.
+ */
+enum tsem_control_type {
+	TSEM_CONTROL_INTERNAL = 0,
+	TSEM_CONTROL_EXTERNAL,
+	TSEM_CONTROL_EXPORT,
+	TSEM_CONTROL_ENFORCE,
+	TSEM_CONTROL_SEAL,
+	TSEM_CONTROL_TRUSTED,
+	TSEM_CONTROL_UNTRUSTED,
+	TSEM_CONTROL_MAP_STATE,
+	TSEM_CONTROL_MAP_PSEUDONYM,
+	TSEM_CONTROL_MAP_BASE,
+	TSEM_CONTROL_LOCK
+};
+
+/**
+ * enum tsem_ns_reference - Ordinal value for DAC namespace reference.
+ * @TSEM_NS_INITIAL: This ordinal value indicates that the uid/gid
+ *		     values should be interpreted against the initial
+ *		     user namespace.
+ * @TSEM_NS_CURRENT: This ordinal value indicates that the uid/gid
+ *		     values should be interpreted against the user
+ *		     namespace that is in effect for the process being
+ *		     modeled.
+ *
+ * This enumeration type is used to indicate what user namespace
+ * should be referenced when the uid/gid values are interpreted for
+ * the creation of either the COE or CELL identities.  The enumeration
+ * ordinal passed to the tsem_ns_create() function, to configure the
+ * security domain/namespace, is set by the nsref argument to either
+ * the 'internal' or 'external' control commands.
+ */
+enum tsem_ns_reference {
+	TSEM_NS_INITIAL = 1,
+	TSEM_NS_CURRENT
+};
+
+/**
+ * enum tsem_task_trust - Ordinal value describing task trust status.
+ * @TSEM_TASK_TRUSTED: This ordinal value indicates that the task has
+ *		       not executed a security event that has resulted
+ *		       in a security behavior not described by the
+ *		       security model the task is being governed by.
+ * @TSEM_TASK_UNTRUSTED: This ordinal value indicates that the task
+ *		          has requested the execution of a security event
+ *		          that resulted in a security behavior not
+ *		          permitted by the security model the task is
+ *		          being governed by.
+ * @TSEM_TASK_TRUST_PENDING: This ordinal value indicates that the setting
+ *			     of the task trust status is pending a response
+ *		             from an external TMA.
+ *
+ * This enumeration type is used to specify the three different trust
+ * states that a task can be in.  The trust status of a task is
+ * regulated by the trust_status member of struct tsem_task.  A task
+ * carrying the status of TSEM_TASK_TRUSTED means that it has
+ * not requested the execution of any security events that are
+ * inconsistent with the security model that the task is running in.
+ *
+ * If a task requests execution of a security event that is
+ * inconsistent with the security model it is operating in, and the
+ * domain is running in 'sealed' mode, the task trust status is set to
+ * TSEM_TASK_UNTRUSTED.  This value is 'sticky' in that it will be
+ * propagated to any child tasks that are spawned from an untrusted
+ * task.
+ *
+ * In the case of an externally modeled security domain/namespace, the
+ * task trust status cannot be determined until the modeling of the
+ * security event has been completed.  The tsem_export_event()
+ * function sets the trust status TSEM_TASK_TRUST_PENDING and then
+ * places the task into an interruptible sleep state.
+ *
+ * Only two events will cause the task to be removed from sleep state.
+ * Either the task is killed or a control message is written to the
+ * TSEM control file that specifies the trust status of the task.  See
+ * the description of the TSEM_CONTROL_TRUSTED and
+ * TSEM_CONTROL_UNTRUSTED enumeration types.
+ */
+enum tsem_task_trust {
+	TSEM_TASK_TRUSTED = 1,
+	TSEM_TASK_UNTRUSTED = 2,
+	TSEM_TASK_TRUST_PENDING = 4
+};
+
+/**
+ * enum tsem_inode_state - Ordinal value for inode reference state.
+ * @TSEM_INODE_COLLECTING: This ordinal value indicates that the inode
+ *			   is being opened in order to compute the
+ *			   digest of the file.
+ * @TSEM_INODE_COLLECTED: This ordinal value indicates that the digest
+ *			  file for the contents of the file referenced
+ *			  by the inode has been collected and is
+ *			  available in the digest cache attached to
+ *			  the inode.
+ * @TSEM_INODE_CONTROL_PLANE: The associated inode represents a TSEM
+ *			       control plane file that should be
+ *			      bypassed for security tests such as
+ *			      the TSEM_FILE_OPEN event.
+ *
+ * This enumeration type is used to specify the status of the inode.
+ * The primary purpose of this enumeration is so that the recursive
+ * call to the TSEM_FILE_OPEN hook, caused by the kernel opening the
+ * file to compute the checksum, can be bypassed when the digest
+ * value of the file is being computed for inclusion in an event
+ * description.
+ *
+ * The state value of the inode is carried in struct tsem_inode and is
+ * set and interrogated by the event.c:add_file_digest() function.  If
+ * the status of the inode is TSEM_INODE_COLLECTED and the iversion of
+ * the inode is the same as it was at collection time, the cached
+ * value for the currently active namespace digest function is
+ * returned.
+ *
+ * If the test for the relevancy of the cached digest value fails the
+ * status of the inode is set to TSEM_INODE_COLLECTING.  The
+ * tsem_file_open() function will check the inode status when it is
+ * invoked by the integrity_kernel_read() function and if it is
+ * set to 'COLLECTING', a successful permissions check is returned so
+ * that the kernel can open the file and compute its digest.
+ *
+ * The TSEM_INODE_CONTROL_PLANE value is used to indicate that the
+ * attached inode is part of the TSEM control plane.  This allows
+ * security events referencing this inode to bypass event processing
+ * in order to avoid a 'Heisenberg deadlock' situation.
+ */
+enum tsem_inode_state {
+	TSEM_INODE_COLLECTING = 1,
+	TSEM_INODE_COLLECTED,
+	TSEM_INODE_CONTROL_PLANE
+};
+
+/**
+ * struct tsem_task - TSEM task control structure.
+ * @tma_for_ns: The context identity number of the namespace that
+ *		the task has control over if any.
+ * @instance: The instance number of the task.  The global task
+ *	      instance number is incremented each time the
+ *	      bprm_committed_creds handler is invoked to compute the
+ *	      TASK_ID of a process.   This instance number represents
+ *	      the total number of unique instances of a specific body
+ *	      of executable code has been requested.
+ * @p_instance: The instance number of the parent process to the
+ *		process represented by an instance of this structure.
+ *		This value allows an execution heirarchy of executable
+ *		code to be established.
+ * @trust_status: The enumeration type that specifies the trust state of
+ *		  the process.
+ * @task_id: The TSEM task identity (TASK_ID) of the process.
+ * @p_task_id: The TASK_ID of the parent process to the process
+ *	       represented by an instance of this structure.
+ * @task_key: A security model specific digest value that is used to
+ *	      authenticate a task that is running as a trust
+ *	      orchestrator to a task that is under the control of the
+ *	      orchestrator.
+ * @context: A pointer to the tsem_context structure that defines the
+ *	     modeling context that the task is running under.
+
+ * This structure is represents the TSEM security state of a task.  It
+ * is automatically created when the task control structure is
+ * allocated for the creation of a new task.
+ *
+ * The trust_status member of structure determines whether or not the
+ * task is in a condition to be trusted.  It represents whether or not
+ * the task has requested execution of a security event that is
+ * inconsistent with the security model that the task is running
+ * under.  Reference the tsem_trust_status enumeration type for more
+ * information on this member.  The trust status value is propagated
+ * to any child tasks that are spawned from a task.
+ *
+ * The value of task_id member is generated by the
+ * tsem_bprm_committed_creds() function that computes the task
+ * identity based TSEM TASK_ID generative function.  This task_id
+ * value is used in the computation of the security state point values
+ * in combination with the COE and CELL mappings for this event.
+ * The task_id digest creates security state points that are specific
+ * to the executable code that was used to initiate the task.
+ *
+ * The instance member of the structure is used to temporally
+ * disambiguate instances of the same task_id.  A single 64-bit
+ * counter is used to generate the instance.  This counter is
+ * incremented and assigned to the instance member of the structure
+ * at the same tame the TASK_ID value is computed.
+ *
+ * The task_key member holds the authentication key that will be used
+ * to authenticate a process that is requesting the ability to set the
+ * trust status of a process.  This value is generated for the task
+ * structure of the trust orchestrator when a security modeling
+ * namespace is created by the orchestrator.
+ *
+ * The context member of the structure contains a pointer to the
+ * tsem_context structure allocated when a security modeling namespace
+ * is created by the tsem_ns_create() function.  This structure will
+ * contain all of the information needed to define how the task is to
+ * have its security behavior modeled.
+ */
+struct tsem_task {
+	u64 tma_for_ns;
+	u64 instance;
+	u64 p_instance;
+	enum tsem_task_trust trust_status;
+	u8 task_id[HASH_MAX_DIGESTSIZE];
+	u8 p_task_id[HASH_MAX_DIGESTSIZE];
+	u8 task_key[HASH_MAX_DIGESTSIZE];
+	struct tsem_context *context;
+};
+
+/**
+ * struct tsem_context - TSEM modeling context description.
+ * @kref: Reference count for the context.
+ * @work: Work structure for asynchronous release of the context.
+ * @id: The index number of the context.
+ * @event_number: The current sequence number of events that have occurred
+ *		  in the security modeling namespace represented by
+ *		  the structure.
+ * @sealed: A status variable indicating whether or not the
+ *	    modeling context can be modified.
+ * @use_current_ns: Status variable indicating which user namespace
+ *		    should be used for resolution of uid/gid values.
+ *		    A true value indicates that the user namespace
+ *		    the process is running under should be used.
+ * @actions: An array of enum tsem_action_type variables indicating
+ *	     the type of response that should be returned in
+ *	     response to the modeling of a security event that
+ *	     is inconsistent with the model being used for the
+ *	     security context.
+ * @digestname: A pointer to a null-terminated buffer containing the
+ *		name of the digest function that is to be used for
+ *		this security context.
+ * @zero_digest: The digest value for a 'zero-length' digest value.
+ * @tfm: A pointer to the digest transformation structure that is to
+ *	 generate cryptographic checksums for the modeling context.
+ * @inode_mutex: The lock that protects the inode_list that tracks
+ *		 inodes created in the context of a security modeling
+ *		 namespace.
+ * @inode_list: The list of inodes created in a security modeling
+ *		namespace protected by the inode_mutex member of
+ *		this structure.
+ * @magazine_size: The number of struct tsem_event structures that
+ *		   are held in reserve for security event handlers that
+ *		   are called in atomic context.
+ * @magazine_lock: The spinlock that protects access to the event
+ *		   magazine.
+ * @magazine_index: The bitmap that is used to track the magazine slots
+ *		    that have been allocated.
+ * @ws: An array of work structures that are used to refill the event
+ *	magazine slots.
+ * @magazine: An array of pointers to tsem_event structures that are
+ *	      pre-allocated for security handlers that are called in
+ *	      atomic context.
+ * @ops: A pointer to the tsem_context_ops that implements the
+ *	 models for the security model using in a security modeling
+ *	 namespace.
+ * @model: If the modeling context is implemented with a kernel based
+ *	   trusted model agent this pointer will point to the struct
+ *	   tsem_model structure that maintains the state of the
+ *	   security model.
+ * @external: If the modeling context is implemented with an external
+ *	      modeling agent this pointer will point to the
+ *	      tsem_external structure that implements the interface to
+ *            the trust orchestrator that is managing the security
+ *	      modeling namespace represented by this structure.
+ *
+ * This structure is used to represent the state of a TSEM security
+ * modeling namespace.  A pointer to this structure is stored in the
+ * struct tsem_task structure.
+ *
+ * This structure is allocated by the tsem_ns_create() function in
+ * response to a TSEM control request.  This structure maintains all
+ * of the information that describes the security modeling namespace
+ * that is not specific to the type of namespace, ie. external or
+ * internal that is being implemented.
+ *
+ * The id member is a 64-bit counter that cannot feasibly be
+ * overflowed and that is incremented for each namespace that is
+ * created.  The root modeling namespace has a value of zero so the
+ * TSEM code uses a pattern of testing this value for non-zero status
+ * as an indication of whether or not the task is running in a
+ * subordinate modeling namespace.
+ *
+ * Each security modeling namespace can have an independent
+ * cryptographic digest function that is used as the compression
+ * function for generating the security coefficients, and other
+ * entities, that are used to model security events that occur in a
+ * namespace.  A single struct tfm is allocated for this digest
+ * function at the time that the tsem_context structure is created and
+ * is maintained in this structure for subsequent use during event
+ * processing.
+ *
+ * Each cryptographic digest function has a 'zero message' value that
+ * is the result of the initialization and closure of a hash function
+ * that has no other input.  This zero digest value is computed at the
+ * time of the creation of the array.  This digest value is returned
+ * for files with zero sizes, have pseudonyms declared for them or
+ * that reside on pseudo-filesystems.
+
+ * The actions array contains a specification of how each security
+ * event should be handled in the event that a TMA detects a
+ * security event inconsistent with the model designated for the
+ * security modeling namespace.  This array allows the specification
+ * of whether the events should be enforcing or logging.
+ *
+ * Each security event that is processed requires a struct tsem_event
+ * structure that drives either the internal modeling of an event or
+ * its export to an external modeling agent.  Some security event
+ * hooks are called while a task is running in atomic context. Since
+ * memory cannot be allocated while a process is in atomic context, a
+ * magazine of these structures is maintained by this structure for
+ * security events that run in atomic context.  The size of this
+ * magazine is dynamic and is configurable for each security modeling
+ *
+ * When a tsem_event structure is allocated for an atomic event a
+ * request for the refill of the slot that is vacated is dispatched to
+ * an asynchronous workqueue.  The ws member of this structure points
+ * to an array of work structures for this refill capability, one for
+ * each slot in the magazine.
+ *
+ * All of this infrastructure is generic for each security modeling
+ * namespace.  How the security modeling is done is governed by the
+ * model and externally defined members of this structure.  These
+ * members point to data structures that either maintain the security
+ * model state for an in kernel trusted modeling agent or handle the
+ * export of the event to an external trust orchestrator.
+ *
+ * Each task that is created in a non-root security modeling namespace
+ * increments the reference count maintained in the kref member of
+ * this structure in the tsem_task_alloc() function.  The
+ * tsem_task_free() function decrements this reference count.  When
+ * the reference count expires, ie. when the last task using the
+ * modeling namespace exits, an asynchronous workqueue request is
+ * dispatched to dispose of the context.  The work member of this
+ * structure is used to reference that workqueue.
+ */
+struct tsem_context {
+	struct kref kref;
+	struct work_struct work;
+
+	u64 id;
+	u64 event_number;
+	u64 timestamp;
+	bool sealed;
+	bool use_current_ns;
+
+	enum tsem_action_type actions[TSEM_EVENT_CNT];
+
+	char *digestname;
+	u8 zero_digest[HASH_MAX_DIGESTSIZE];
+	struct crypto_shash *tfm;
+
+	struct mutex inode_mutex;
+	struct list_head inode_list;
+
+	unsigned int magazine_size;
+	spinlock_t magazine_lock;
+	unsigned long *magazine_index;
+	struct tsem_work *ws;
+	struct tsem_event **magazine;
+
+	const struct tsem_context_ops *ops;
+	struct tsem_model *model;
+	struct tsem_external *external;
+};
+
+/**
+ * struct tsem_context_ops - Security modeling namespace operations.
+ * @char: A pointer to a null-terminated array containing the name
+ *	  of the security model being implemented.
+ * @bypass: A pointer to an array of booleans of size TSEM_EVENT_CNT
+ *	    that specify whether or not a security event handler should
+ *	    be bypassed.
+ * @event_init: A pointer to the function that implements initialization
+ *		of the characteristics of the security event.
+ * @map: A pointer to the function that implements the mapping
+ *	 of security event characteristics into a security
+ *	 coefficient.
+ *
+ * This structure is used to define the operations that are available
+ * for a security modeling namespace.  It provides the mechanism for
+ * customizing the CELL descriptions that are implemented for a security
+ * model.
+ */
+struct tsem_context_ops {
+	const char *name;
+	const bool *bypasses;
+	int (*init)(struct tsem_event *ep);
+	int (*map)(struct tsem_event *ep);
+};
+
+/**
+ * struct tsem_model - TSEM internal TMA description.
+ * @have_aggregate: Flag variable to indicate whether or not the
+ *		    hardware aggregate value has been injected into
+ *		    the model.
+ * @base: The base value that is to be used in computing the
+ *	  security state coefficients for the model.
+ * @measurement: The time dependent linear extension state of the
+ *		 security state coefficients that have been
+ *		 experienced in the model.
+ * @state: The time independent functional description of the security
+ *	   model.
+ * @point_lock: The spinlock that protects access to the list of
+ *		security state coefficients in the model.
+ * @point_list: A pointer to the list of security state coefficients
+ *		in the model protected by the point_lock.
+ * @point_end_mutex: The mutex that is used to protect the end of the
+ *		     list of security state coefficients that will
+ *		     be exported.
+ * @point_end: A pointer to the end of the list of security state
+ *	       coefficients that will be traversed by a call to the
+ *	       control plane.
+ * @trajectory_lock: The spinlock used to protect the list of security
+ *		     event descriptions in the model.
+ * @trajectory_list: A pointer to the list of descriptions of the
+ *		     security events that have been recorded in this
+ *		     model.
+ * @trajectory_end_mutex: The mutex that protects the end of the list
+ *			  of security event descriptions.
+ * @trajectory_end: A pointer to the end of the list of security event
+ *		    descriptions that will be traversed by a call to
+ *		    the control plane.
+ * @forensics_lock: The spinlock used to protect the list of security
+ *		    event descriptions that are considered invalid by
+ *		    the model being enforced.
+ * @forensics_list: A pointer to the list of descriptions of security
+ *		    events that are considered invalid by the security
+ *		    model being enforced.
+ * @forensics_end_mutex: The mutex that protects the end of the list
+ *			 of security event descriptions that are
+ *			 considered invalid by the current model.
+ * @forensics_end: A pointer to the end of the list of security event
+ *		   descriptions, that are considered invalid, that are
+ *		   to be traversed by a call to the control plane.
+ * @pseudonym_mutex: The mutex lock that protects the list of file
+ *		     digest pseudonyms for the current model.
+ * @pseudonum_list: A pointer to the list of file digest pseudonyms
+ *		    that have been declared for the current model.
+ * @magazine_size: The number of struct tsem_event_point structures that
+ *		   are held in reserve for security event hooks that
+ *		   are called in atomic context.
+ * @magazine_lock: The spinlock that protects access to the event
+ *		   magazine for the security context.
+ * @magazine_index: The bitmap that is used to track the magazine slots
+ *		    that have been allocated.
+ * @ws: An array of work structures that are used to refill the magazine
+ *	slots.
+ * @magazine: An array of pointers to struct tsem_event_point structures that
+ *	      are pre-allocated for security hooks called in atomic
+ *	      context.
+ *
+ * If a call to the tsem_ns_create() function specifies that a kernel
+ * based trusted modeling agent is to be used to implement the
+ * security namespace model, a pointer to this structure is placed in
+ * the struct tsem_context structure.  This structure is used to
+ * maintain the state of the kernel based model.
+ *
+ * There are two primary functional values that are maintained by the
+ * model.  The measurement member of this structure represents the
+ * time dependent linear extension sum of the security state
+ * coefficients that have been assigned to security events that have
+ * occurred in the context of the model.  This is a measurement
+ * that has been classically maintained by a Trusted Platform Module.
+ *
+ * This classic integrity measurement is subject to scheduling
+ * dependencies and may be invariant from run to run of the model.  It
+ * is of primary use in verifying the order of security events that
+ * have occurred in the model.
+ *
+ * The state member of this structure represents a time independent
+ * linear extension sum of the security state coefficients that have
+ * been generated in the model.  It represents a functional value
+ * for the security state of the model being enforced.
+ *
+ * Both of these measurements are dependent on the platform hardware
+ * aggregate value and the base point that has been defined for the
+ * define.
+ *
+ * A non-NULL representation of the hardware aggregate value is only
+ * available if the platform has a TPM.  The have_aggregate member of
+ * this structure is a flag variable that indicates whether or not the
+ * aggregate value has been injected into the model.
+ *
+ * The base member of this structure contains a model specific
+ * coefficient that is used to perturb each security state coefficient
+ * generated in the model.  This value is designed to serve as a
+ * 'freshness' value for a verifying party to the model.
+ *
+ * There are three primary model lists maintain by this structure:
+ *
+ * * security state points
+ * * security trajectory events
+ * * security forensics events
+ *
+ * Similar members are maintained in this structure to support each of
+ * these lists.
+ *
+ * All three lists are extension only and are protected by a spinlock
+ * that can be held in atomic context.  This spinlock is only held for
+ * the period of time required to extend the list.
+ *
+ * Calls by the control plane to interrogate the lists require the
+ * traversal of the list that is ill-suited for a spinlock.  As a
+ * result each list type has a mutex associated with it that protects
+ * a pointer to the end of the list, an endpoint that is determined at
+ * the start of a call to the control plane.
+ *
+ * The list spinlock is used at the start of the control plane call to
+ * capture the end of the list that is then protected by the mutex.
+ * In essence this is used to transition protection of the list from
+ * the spinlock to the mutex.
+ *
+ * The kernel based modeling agent has support for maintaining a
+ * constant digest value for files, that by function, do not have a
+ * fixed digest value, such as log files or files residing on a
+ * pseudo-filesystem.  The pseudonym_list member of this structure
+ * points to the list of these designations.  The pseudonym_mutex
+ * structure protects this list.
+ *
+ * Like the struct tsem_context structure the tsem_model structure
+ * maintains a magazine of structures that are used to service
+ * security events that are called in atomic context.  The magazine
+ * maintained by this structure is a list of struct tsem_event_point
+ * structures that are used to describe the security state
+ * coefficients held by the model.
+ *
+ * The description of struct tsem_context details the implementation
+ * of the magazine which is identical to the implementation for this
+ * structure, with the exception of the type of structures that are
+ * held in reserve.
+ */
+struct tsem_model {
+	bool have_aggregate;
+
+	u8 base[HASH_MAX_DIGESTSIZE];
+	u8 measurement[HASH_MAX_DIGESTSIZE];
+	u8 state[HASH_MAX_DIGESTSIZE];
+
+	spinlock_t point_lock;
+	struct list_head point_list;
+	struct mutex point_end_mutex;
+	struct list_head *point_end;
+	unsigned int point_count;
+
+	spinlock_t trajectory_lock;
+	struct list_head trajectory_list;
+	struct mutex trajectory_end_mutex;
+	struct list_head *trajectory_end;
+
+	spinlock_t forensics_lock;
+	struct list_head forensics_list;
+	struct mutex forensics_end_mutex;
+	struct list_head *forensics_end;
+
+	struct mutex pseudonym_mutex;
+	struct list_head pseudonym_list;
+
+	struct mutex mount_mutex;
+	struct list_head mount_list;
+
+	unsigned int magazine_size;
+	spinlock_t magazine_lock;
+	unsigned long *magazine_index;
+	struct tsem_work *ws;
+	struct tsem_event_point **magazine;
+};
+
+/**
+ * struct tsem_external - TSEM external TMA description.
+ * @export_only: A flag variable used to indicate that the security
+ *		 namespace is running in export only mode that
+ *		 simply presents the events to the external trust
+ *		 orchestrator.
+ * @export_lock: The spinlock that protects access to the export_list
+ *		 member of this structure.
+ * @export_list: A pointer to the list of events waiting to be
+ *		 exported to the trust orchestrator for the security
+ *		 modeling namespace.  The structure type that is
+ *		 linked by this list is the struct export_event
+ *		 structure that is private to the export.c compilation
+ *		 unit.
+ * @dentry: A pointer to the dentry describing the pseudo-file in the
+ *	    /sys/kernel/security/tsem/external_tma directory that is
+ *	    being used to export security event descriptions to the
+ *	    external trust orchestrator for the security modeling
+ *	    namespace.
+ * @have_event: A flag variable to indicate that is work queued
+ *		on the export pseudo-file for the security modeling
+ *		namespace.
+ * @wq: The work queue used to implement polling for the security
+ *	event export file.
+ * @magazine_size: The number of struct export_event structures that
+ *		   are held in reserve for security event hooks that
+ *		   are called in atomic context.
+ * @magazine_lock: The spinlock that protects access to the event
+ *		   magazine for the security modeling domain.
+ * @magazine_index: The bitmap that is used to track the magazine slots
+ *		    that have been allocated.
+ * @ws: An array of work structures that are used to refill the magazine
+ *	slots.
+ * @magazine: An array of pointers to struct export_event structures that
+ *	      are pre-allocated for security hooks called in atomic
+ *	      context.
+ *
+ * If an externally modeled security modeling namespace is created
+ * a structure of this type is allocated for the namespace and placed
+ * in the struct tsem_context structure.
+ *
+ * The primary purpose of this structure is to manage event
+ * descriptions that are being transmitted to the trust orchestrator
+ * associated with the security modeling namespace.  The pseudo-file
+ * will be as follows:
+ *
+ * /sys/kernel/security/tsem/external_tma/N
+ *
+ * Where N is the context id number of the modeling namespace.
+ *
+ * The dentry member of this structure is used to represent the
+ * pseudo-file that is created when the external modeled namespace is
+ * created.
+ *
+ * This list of events waiting to be received by the trust
+ * orchestrator is maintained in the export_list member of this
+ * structure.  Additions or removals from the list hold the spinlock
+ * described by the export_lock member of this structure.
+ *
+ * The wq member of this structure is used to implement a workqueue
+ * to support polling for events on the export control file.  The
+ * have_event flag is set to indicate to the polling call that
+ * security events are available for export.
+ *
+ * When a security event description is exported the calling task is
+ * scheduled away to allow the trust orchestrator to process the
+ * event.  This obviously creates issues for security events that are
+ * called in atomic context.
+ *
+ * Security events in atomic context are exported as an async_event
+ * rather than a simple event.  The trust orchestrator has the option
+ * of killing the workload that deviated from the security model or
+ * signaling a violation of the model.
+ *
+ * To support the export of asynchronous events, magazine
+ * infrastructure, similar to the event and model structure magazines,
+ * is maintained by this structure for the external modeling
+ * namespace.
+ */
+struct tsem_external {
+	bool export_only;
+
+	spinlock_t export_lock;
+	struct list_head export_list;
+	struct dentry *dentry;
+	bool have_event;
+	wait_queue_head_t wq;
+
+	unsigned int magazine_size;
+	spinlock_t magazine_lock;
+	unsigned long *magazine_index;
+	struct tsem_work *ws;
+	struct export_event **magazine;
+};
+
+/**
+ * struct tsem_work - TSEM magazine refill work structure.
+ * @index: The index number of the slot in the structure magazine that
+ *	   is being refilled.
+ * @u: A union that holds pointers to the structure whose magazine is
+ *     being refilled.
+ * @work: The work structure that manages the workqueue being used to
+ *	  refill the magazine entry.
+ *
+ * As has been previously documented for the struct tsem_context,
+ * struct tsem_model and struct tsem_external structures, there is a
+ * need to maintain a magazine of these structures in order to allow
+ * the processing of security events that are called in atomic
+ * context.  An array of this structure type is embedded in each of
+ * those structures to manage the asynchronous refill of the slot in
+ * the magazine that was used to handle an atomic security event.
+ *
+ * The index member of this structure points to the slot in the
+ * magazine that this work item is referencing.
+ *
+ * The structure that the refill work is being done for is maintained
+ * in the respective structure pointer in the u member of this
+ * structure.
+ *
+ * The work member of this structure is used to reference the
+ * asynchronous work request that is being submitted for the refill.
+ */
+struct tsem_work {
+	unsigned int index;
+	union {
+		struct tsem_context *ctx;
+		struct tsem_model *model;
+		struct tsem_external *ext;
+	} u;
+	struct work_struct work;
+};
+
+/**
+ * struct tsem_COE - TSEM context of execution definition structure.
+ * @uid: The numeric user identity that the COE is running with.
+ * @euid: The effective user identity that the COE is running with.
+ * @suid: The saved user identity possessed by the COE.
+ * @gid: The group identity that the COE is running with.
+ * @egid: The effective group identity that the COE possesses.
+ * @sgid: The saved group identity of the COE.
+ * @fsuid: The filesystem user identity that the COE is running with.
+ * @fsgid: The filesystem group identity that the COE is running with.
+ * @capeff: This union is used to implement access to the effective
+ *	    capability set the COE is running with.  The mask value
+ *	    is used to assign to the structure with the value member
+ *	    used to extract the 64 bit value for export and
+ *	    computation.
+ * @securebits: In a file capabilities implementation this value
+ *		specifies potential handling for process running with
+ *		a UID value of 0.
+ *
+ * A security state coefficient is computed from two primary entities:
+ * the COE and the CELL identities.  This structure is used to carry
+ * and encapsulate the characteristics of the context of execution
+ * (COE) that will be used to generate the COE identity.
+ *
+ * The numeric values for discretionary access controls, ie. uid, gid,
+ * are determined by which user namespace the security modeling
+ * namespace is configured to reference.  The reference will be either
+ * the initial user namespace or the user namespace that the context
+ * of execution is running in.  This reference can be set on a per
+ * security model namespace basis.
+ */
+struct tsem_COE {
+	uid_t uid;
+	uid_t euid;
+	uid_t suid;
+
+	gid_t gid;
+	gid_t egid;
+	gid_t sgid;
+
+	uid_t fsuid;
+	gid_t fsgid;
+
+	union {
+		kernel_cap_t mask;
+		u64 value;
+	} capeff;
+
+	unsigned int securebits;
+};
+
+/**
+ * struct tsem_inode_cell - TSEM inode information.
+ * @uid: The numeric user identity assigned to the inode.
+ * @gid: The numeric group identity assigned to the inode.
+ * @mode: The discretionary access mode for the file.
+ * @s_magic: The magic number of the filesystem that the file resides
+ *	     in.
+ * @s_id: The name of the block device supporting the filesystem the
+ *	  inode is on.
+ * @s_uuid: The uuid of the filesystem that contains the inode.
+ *
+ * This structure defines the characteristics of an inode that is
+ * referenced by a security event.
+ */
+struct tsem_inode_cell {
+	uid_t uid;
+	gid_t gid;
+	umode_t mode;
+	u32 s_magic;
+	u8 s_id[32];
+	u8 s_uuid[16];
+};
+
+/**
+ * struct tsem_inode_entry - Reference to a directory inode with temp files.
+ * @list: List of directory inodes for a security modeling namespace
+ *	  that have had an inode created under the directory.
+ * @tsip: A pointer to the TSEM security description of a temporary
+ *	  file that was createdunder a directory entry.
+ *
+ * This structure is used to implement a list of directory inodes that
+ * have had temporary files created under them in a security modeling
+ * namespace.  This list is used to allow the instance identifiers
+ * for inodes to be removed when the security modeling namespace
+ * terminates or when the directory in which temporary files had been
+ * created is removed.
+ */
+
+struct tsem_inode_entry {
+	struct list_head list;
+	struct tsem_inode *tsip;
+};
+
+/**
+ * struct tsem_inode_instance - Instance information for a created inode.
+ * @list: List of inode owners.
+ * @creator: The id number of the security modeling namespace that is
+ *	     creating an inode.
+ * @instance: The instance number of an inode being created under a
+ *	      given directory.
+ * @owner: The TASK_ID of the process creating the inode.
+ * @pathname: A pointer to allocated memory holding the null-terminated
+ *	      pathname for the inode.
+ *
+ * This structure is used to convey information about the owner and
+ * instance number of an inode created in a security modeling namespace.
+ *
+ * This structure serves three distinct purposes.
+ *
+ * A linked list of these structures is used to convey ownership and
+ * instance information about a created inode from the
+ * tsem_inode_create() function to the tsem_inode_init_security()
+ * function, so that this information can be attached to the inode via
+ * the tsem_inode structure.
+ *
+ * Secondly, a linked list of inode ownership information is
+ * maintained for inodes that are created in a security modeling
+ * namespace and used as mountpoints.  This list is maintained in the
+ * security model description for the namespace.  Since the inode that
+ * is 'covering' the mountpoint is different than the inode describing
+ * the directory created for the mountpoint, the ownership information
+ * for the inode needs to carried as a characteristic of the model.
+ *
+ * The final use of this structure is to track the instance numbers of
+ * an inode created by a TASK_ID.  This list is carried by the
+ * directory in which temporary files and directories are created.
+ *
+ */
+struct tsem_inode_instance {
+	struct list_head list;
+
+	u64 creator;
+	u64 instance;
+	u8 owner[HASH_MAX_DIGESTSIZE];
+	char *pathname;
+};
+
+/**
+ * struct tsem_path - TSEM path information.
+ * @created: A flag to indicate that the path was created in the
+ *	     context of the current security modeling namespace.
+ * @creator: The id of the security modeling namespace that created
+ *	     the path.
+ * @instance: The instance number of an inode that was created.
+ * @owner: The TASK_ID of the process that created the path.
+ * @dev: The device number that the filesystem is mounted on.
+ * @pathname: An allocated and null-terminated buffer containing the
+ *	      path from the root directory to the file.
+ *
+ * The tsem_path structure is used to carry information about the
+ * pathname and ownership of a filesystem object that is an argument
+ * to a security event handler.
+ */
+struct tsem_path {
+	bool created;
+	u64 creator;
+	u64 instance;
+	u8 owner[HASH_MAX_DIGESTSIZE];
+
+	dev_t dev;
+	char *pathname;
+};
+
+/**
+ * struct tsem_dentry - TSEM dentry definition.
+ * @have_inode: A flag variable to indicate that the dentry has an
+ *		inode associated with it.
+ * @inode: The TSEM characteristics of the inode associated with a dentry.
+ * @path: The path definition for the dentry.
+ *
+ * This structure is used to contain the TSEM representation of a
+ * dentry.
+ */
+struct tsem_dentry {
+	bool have_inode;
+	struct tsem_inode_cell inode;
+	struct tsem_path path;
+};
+
+/**
+ * struct tsem_inode_args - Arguments for inode security handlers.
+ * @mode: The access mode requested for an inode being created.
+ * @dev: For the inode_mknod handler, the device specification for
+ *	 device node being created.
+ * @in.old_name: In the case of the tsem_inode_symlink handler, this
+ *		 member contains a pointer to the filename of the target
+ *		 of the symbolic link.
+ * @in.dir: For handlers processing rename or movement of an inode,
+ *	    the inode of the directory that contains the inode to be moved.
+ * @in.new_dir: For handlers processing the rename or movement of an
+ *		inode, the inode of the directory that will contain
+ *		the destination inode.
+ * @in.dentry: The dentry argument to inode event handlers that take
+ *	       a dentry.
+ * @in.new_dentry: In the case of handlers that result in a new dentry
+ *		   a pointer to that dentry.
+ * @out.old_name: In the case of the tsem_inode_symlink handler this
+ *		  member contains a pointer to a copy of the name of
+ *		  the target of symbolic link.  This second
+ *		  representation is used to avoid warnings about the
+ *		  use of a constant character pointer in the arguments
+ *		  to the handler.
+ * @out.dir: The TSEM representation of the inode representing a directory
+ *	     that the security handler is acting on.
+ * @out.new_dir: For inode movements or renames, the TSEM representation
+ *		 of the new_dir argument.
+ * @out.dentry: The TSEM representation of the dentry argument to a
+ *		security handler.
+ * @out.new_dentry: For inode movements or renames, the
+ *		    representation of the new location of the inode.
+ *
+ * This structure is used to carry input parameters and their
+ * retained and translated TSEM equivalent for LSM security handlers
+ * that are acting on inodes and/or dentries.
+ */
+struct tsem_inode_args {
+	umode_t mode;
+	dev_t dev;
+
+	union {
+		struct {
+			const char *old_name;
+			struct inode *dir;
+			struct inode *new_dir;
+			struct dentry *dentry;
+			struct dentry *new_dentry;
+		} in;
+
+		struct {
+			char *old_name;
+			struct tsem_inode_cell dir;
+			struct tsem_inode_cell new_dir;
+			struct tsem_dentry dentry;
+			struct tsem_dentry new_dentry;
+		} out;
+	};
+};
+
+/**
+ * struct tsem_file_args - TSEM file argument description.
+ * @cmd: The command argument for security handlers that take a
+ *       command type arguement, ie. file_ioctl, file_fcntl, file_lock
+ *	 handlers.
+ * @in.pseudo_file: A flag indicating that the file was on a
+ *		    pseudo-filesystem and will not have a digest value.
+ * @in.file: A structure to the file that will be modeled.
+ * @out.path: The TSEM representation of the pathname to a file.
+ * @out.inode: The TSEM representation of the inode that backs a file
+ *	       description
+ * @out.flags: The flags value from the file structure.
+ * @out.digest: The cryptographic checksum of the contents of the file.
+ *
+ * This structure is used to carry the input file description and
+ * their TSEM retention values for security event handles that are
+ * provided with a struct file pointer.
+ */
+struct tsem_file_args {
+	unsigned int cmd;
+
+	union {
+		struct {
+			bool pseudo_file;
+			struct file *file;
+		} in;
+
+		struct {
+			struct tsem_path path;
+			struct tsem_inode_cell inode;
+			unsigned int flags;
+			u8 digest[HASH_MAX_DIGESTSIZE];
+		} out;
+
+	};
+};
+
+/**
+ * struct tsem_mmap_file_args - TSEM memory mapping arguments.
+ * @anonymous: A flag variable to indicate whether or not the mapping
+ *	       is file backed or anonymous.
+ * @file: If the handler is being called for a file backed mapping this
+ *	  structure will be populated with the TSEM description of the
+ *	  file.
+ * @prot: The protections that are being requested for the mapping.
+ * @flags: The control flags to the memory mapping call.
+ *
+ * This structure is used to encapsulate the arguments provided to the
+ * tsem_mmap_file security event handler.  The anonymous member of
+ * this structure is used internally by TSEM to indicate that the
+ * file pointer to the call was NULL, thus indicating that the mapping
+ * is for anonymous memory.
+ */
+struct tsem_mmap_file_args {
+	u32 anonymous;
+	struct tsem_file_args file;
+	u32 prot;
+	u32 flags;
+};
+
+/**
+ * struct tsem_socket - TSEM socket information
+ * @family: The family name of the socket whose creation is being
+ *	    requested.
+ * @type: The type of the socket being created.
+ * @protocol: The protocol family of the socket being created.
+ * @kern: A flag variable to indicate whether or not the socket being
+ *	  created is kernel or userspace based.
+ * @owner: The TASK_ID of the task that created the socket.
+ *
+ * This structure is used to encapsulate socket information for
+ * security handlers that take a socket description as an argument.
+ */
+struct tsem_socket {
+	int family;
+	int type;
+	int protocol;
+	int kern;
+	u8 owner[HASH_MAX_DIGESTSIZE];
+};
+
+/**
+ * struct tsem_socket_args - TSEM socket arguments
+ * @value: Possible numeric values passed to event handlers.
+ * @optname: The option name for the tsem_socket_setsockopt call.
+ * @in.socka: A pointer to the socket argument of a security handler.
+ * @in.sockb: A pointer to a second socket argument that may be supplied
+ *	      to the handler.
+ * @in.addr: In the case of handlers that accept an address
+ *	     description a pointer to that description.
+ * @out.socka: The TSEM representation of the first socket argument.
+ * @out.sockb: The TSEM representation of the second socket argument.
+ * @out.have_addr: A boolean flag used to indicate that either the
+ *		   ipv6 or ipv6 union members have been populated.
+ * @out.ipv4: The IPV4 address of an AF_INET socket.
+ * @out.ipv6: The IPV6 address of an AF_INET6 socket.
+ * @out.path: The path of an AF_UNIX socket.
+ * @out.mapping: The checksum of the socket address if the socket type
+ *		 is other than AF_INET, AF_INET6 or AF_UNIX.
+ *
+ * This structure is used to maintain arguments provided to LSM
+ * hooks that handle generic socket security events.
+ */
+struct tsem_socket_args {
+	int value;
+	int optname;
+
+	union {
+		struct {
+			struct sock *socka;
+			struct sock *sockb;
+			void *addr;
+		} in;
+
+		struct {
+			struct tsem_socket socka;
+			struct tsem_socket sockb;
+			bool have_addr;
+			union {
+				struct sockaddr_in ipv4;
+				struct sockaddr_in6 ipv6;
+				char path[UNIX_PATH_MAX + 1];
+				u8 mapping[HASH_MAX_DIGESTSIZE];
+			};
+		} out;
+	};
+};
+
+/**
+ * struct tsem_netlink_args - TSEM netlink event parameters
+ * @in.sock: The sock argument to the LSM event handler.
+ * @in.parms: The pointer to the netlink parameters from the sk_buff
+ *	      structure that was passed to the LSM hook.
+ * @out.sock: The TSEM representation of the sock argument.
+ * @out.uid: The UID, in the TSEM designated namespace of the uid in
+ *	     the netlink control block.
+ * @out.gid: THE GID, in the TSEM designated namespace of the gid in
+ *	     the netlink control block.
+ * @out.portid: The portid member of the netlink_skb_parms structure.
+ * @out.dst_group: The dst_group member of the netlink_skb_parms structure.
+ * @out.flags: The flags member of the netlink_skb_parms structure.
+ * @nsid_set: The nsid_set flag member of the netlink_skb_parms structure.
+ * @nsid: The nsid member of the netlink_skb_parms structure.
+ *
+ * This structure is used to encapsulate and retain the arguments
+ * provided to the tsem_netlink_send event handler.
+ *
+ */
+struct tsem_netlink_args {
+	union {
+		struct {
+			struct sock *sock;
+			struct netlink_skb_parms *parms;
+		} in;
+
+		struct {
+			struct tsem_socket sock;
+			uid_t uid;
+			gid_t gid;
+			__u32 portid;
+			__u32 dst_group;
+			__u32 flags;
+			bool nsid_set;
+			int nsid;
+		} out;
+	};
+};
+
+/**
+ * struct tsem_sb_args - TSEM parameters for superblock security events.
+ * flags: An integer value that was a component of the LSM argument
+ *	  for the sb_mount, sb_umount, sb_remount handlers.
+ * @in.sb: For the sb_remount handler the pointer to the superblock
+ *	   argument passed to the caller.
+ * @in.dentry: An incoming dentry argument.
+ * @in.dev_name: The name of the device to be used for the sb_mount
+ *		 command.
+ * @in.path: The path argument passed to the sb_mount commands.
+ * @in.type: A character pointer to the filesystem type being processed
+ *	     by the superblock security handlers.
+ * @in.path2: The second path argument passed to the move_mount and
+ *	      sb_pivotroot security handlers.
+ * @out.dentry: The TSEM representation of the dentry argument to the
+ *		handler.
+ * @out.inode: The TSEM representation of the inode backing the dentry
+ *	       argument to an LSM handler.
+ * @out.path: The TSEM representation of the incoming path argument.
+ * @out.dev_name: A an allocated copy of the dev_name argument.
+ * @out.type: A allocated copy of the filesystem type.
+ * @out.path2: The TSEM representation of the second path argument if
+ *	       used.
+ *
+ * This structure is used to encapsulate and retain the arguments for
+ * the family of security event handlers that deal with superblocks.  The
+ * list of these handlers is as follows:
+ *
+ * tsem_sb_mount
+ * tsem_sb_umount
+ * tsem_sb_remount
+ * tsem_move_mount
+ * tsem_sb_statfs
+ */
+struct tsem_sb_args {
+	unsigned long flags;
+
+	union {
+		struct {
+			struct super_block *sb;
+			struct dentry *dentry;
+			const char *dev_name;
+			const char *type;
+			const struct path *path;
+			const struct path *path2;
+		} in;
+
+		struct {
+			struct tsem_dentry dentry;
+			char *dev_name;
+			char *type;
+			struct tsem_path path;
+			struct tsem_path path2;
+		} out;
+	};
+};
+
+/**
+ * struct tsem_task_kill_args - TSEM task kill arguments.
+ * @u.value: The signed representation of an integer argument.
+ * @u.resource: The unsigned representation of an integer argument.
+ * @cur: The current resource limit for a task_setrlimit call.
+ * @max: The maximum resource limit for a task_setrlimit call.
+ * @cross_model: A flag variable used to indicate whether or not the
+ *		 signal is originating from a security modeling
+ *		 namespace other than the namespace of the target process.
+ * @signal: The number of the signal being sent.
+ * @source: The task identifier of the process sending the signal
+ * @target: The task identifier of the target process.
+ *
+ * This structure is used to encapsulate and retain the arguments
+ * provided to the tsem_task_kill security event handler.
+ *
+ */
+struct tsem_task_kill_args {
+	union {
+		int value;
+		unsigned int resource;
+	} u;
+	u64 cur;
+	u64 max;
+	u32 cross_model;
+	u32 signal;
+	u8 source[HASH_MAX_DIGESTSIZE];
+	u8 target[HASH_MAX_DIGESTSIZE];
+};
+
+/**
+ * struct tsem_task_prlimit_args - TSEM task prlimit arguments.
+ * @flags: The flag variable passed to the LSM handler.
+ * @in.cred: The cred pointer passed to the handler.
+ * @in.tcred: The tcred pointer passed to the handler.
+ * @out.cred: The TSEM representation of the in.cred pointer.
+ * @out.tcred: The TSEM representation of the in.tcred pointer.
+ *
+ * This structure is used to hold and retain the arguments provided to
+ * the tsem_task_prlimit security event handler.
+ */
+struct tsem_task_prlimit_args {
+	unsigned int flags;
+
+	union {
+		struct {
+			const struct cred *cred;
+			const struct cred *tcred;
+
+		} in;
+
+		struct {
+			struct tsem_COE cred;
+			struct tsem_COE tcred;
+		} out;
+
+	};
+};
+
+/**
+ * struct tsem_task_prctl - TSEM task prctl arguments.
+ * @option: The first argument to the task_prctl LSM handler
+ *	    specifying the command to be executed.
+ * @arg2: The first argument to the handler.
+ * @arg3: The second argument to the handler.
+ * @arg4: The third argument to the handler.
+ * @arg5: The fourth and final argument to the handler.
+ *
+ * This structure is used to encapsulate the arguments provided to the
+ * tsem_task_prctl security event handler.  The argument model is to
+ * specify the 'option' value which is the kernel prctl call that is
+ * to be executed.  The remaining positional arguments are without
+ * specific format and are designed to be interpreted by the prctl
+ * system call based on the command specified.
+ */
+struct tsem_task_prctl_args {
+	int option;
+	unsigned long arg2;
+	unsigned long arg3;
+	unsigned long arg4;
+	unsigned long arg5;
+};
+
+/**
+ * struct tsem_inode_attr_args - TSEM inode manipulation arguments.
+ * @in.path: In the case of the inode_getattr call the path to the
+ *	     inode being referenced.
+ * @in.dentry: In the case of the inode_setattr call the dentry that
+ *	       whose characteristics will be set.
+ * @in.iattr: A pointer to the iattr structure that was passed to the
+ *	      inode_setattr handler.
+ * @out.dentry: A TSEM dentry definition structure that will retain
+ *		the description of either a dentry or path argument
+ *		to a security handler.
+ * @out.valid: The ia_valid member from the iattr structure passed to the
+ *	       inode_setattr handler
+ * @out.mode: The ia_mode member from the iattr structure passed to the
+ *	      inode_setattr handler.
+ * @out.uid: The ia_uid member from the iattr structure passed to the
+ *	     inode_setattr handler.
+ * @out.gid: The ia_gid member from the iattr structure passed to the
+ *	     inode_setattr handler.
+ *	     hook.
+ * @out.size: The ia_size member from the iattr structure passed to the
+ *	      inode_setattr handler.
+ *
+ * This structure is used to encapsulate information on the arguments
+ * passed to the inode_getattr and inode_setattr LSM handler.  The in
+ * structure is used to hold the arguments passed that were passed to
+ * the handlers.  Argument information that is to be held for the life
+ * of the event description are in the out structure.
+ */
+struct tsem_inode_attr_args {
+	union {
+		struct {
+			const struct path *path;
+			struct dentry *dentry;
+			struct iattr *iattr;
+		} in;
+
+		struct {
+			struct tsem_dentry dentry;
+			unsigned int valid;
+			umode_t mode;
+			uid_t uid;
+			gid_t gid;
+			loff_t size;
+		} out;
+	};
+};
+
+/**
+ * struct tsem_inode_xattr_args - TSEM extended attribute arguments.
+ * @in.dentry: A pointer to the backing inode for the dentry that was
+ *	       passed to the LSM hook.  The relevant values from the inode
+ *	       will be copied into the tsem_file structure.
+ * @in.name: A pointer to the name of the extended attribute being
+ *	     queried.
+ * @in.size: The size of an extended attribute that may be set.
+ * @in.flags: The flag value specifying how an extended attributte is
+ *	      to be set.
+ * @out.dentry: The TSEM representation of the path that is being
+ *		action on.
+ * @out.name: The name of an attribute to be set or retrieved.
+ * @out.value: The binary value of the extended attribute that was
+ *	       passed to the inode_setxattr handler.  For an
+ *	       internally modeled namespace this value will be freed
+ *	       after the coefficient for the event is mapped.
+ * @out.encoded_value: The Base64 encoding of the extended attribute
+ *		       value that is used for either the export of
+ *		       the event or the trajectory history.  This
+ *		       memory will be allocated in order to support
+ *		       encoding of the attribute.
+ * @out.size: The size of the att
+ * @out.flags: The flags value that was passed to the inode_setxattr
+ *	       handler.
+ *
+ * This structure is used to encapsulate information on the arguments
+ * passed to the LSM hooks that manipulate extended attributes.  The
+ * in structure is used to hold the pointers to the arguments passed
+ * to the LSM hook while the out structure holds the arguments in
+ * converted form that will be held for the lifetime of the modeling
+ * namespace.
+ */
+struct tsem_inode_xattr_args {
+	union {
+		struct {
+			struct dentry *dentry;
+			const char *name;
+			const void *value;
+			size_t size;
+			int flags;
+		} in;
+
+		struct {
+			struct tsem_dentry dentry;
+			char *name;
+			char *value;
+			char *encoded_value;
+			size_t size;
+			int flags;
+		} out;
+	};
+};
+
+/**
+ * struct tsem_kernel_args - TSEM event descriptions for kernel requests.
+ * @id: For the tsem_kernel_load_data handler the indicator of the type
+ *     of data being requested.
+ * @contents: The boolean flag used to indicate whether or not the
+ *           security_kernel_post_load_data handler should be called.
+ * @in.file: A pointer to the file structure passwd to the
+ *	     tsem_kernel_file_file handler.
+ * @in.kmod_name: A pointer to the buffer containing the name of the
+ *		   module to load.
+ * @out.kmod_name: The retained copy of the kernel module name.
+ * @out.file: The TSEM representation of the file structure that was
+ *	      passed to the tsem_kernel_read_file handler.
+ *
+ * This structure is used to encapsulate information on the arguments
+ * passed to the following LSM hook handlers:
+ *
+ * tsem_kernel_module_request
+ * tsem_kernel_load_data
+ * tsem_kernel_read_file
+ */
+struct tsem_kernel_args {
+	enum kernel_load_data_id id;
+	bool contents;
+
+	union {
+		struct {
+			struct file *file;
+			char *kmod_name;
+		} in;
+
+		struct {
+			char *kmod_name;
+			struct tsem_file_args file;
+		} out;
+	};
+};
+
+/**
+ * struct tsem_time_args - TSEM event description for setting the time
+ * @have_ts: A flag variable to indicate if the time in seconds and
+ *	     nanoseconds is valid.
+ * @seconds: The number of seconds passed to the time set function.
+ * @nsecs: The number of nanoseconds to set the time to.
+ * @have_tz: A flag variable to indicate if the timezone information
+ *	     is valid.
+ * @minuteswest: The minutes west of GMT for the time being set.
+ * @dsttime: The daylight savings time offset.
+ *
+ * This structure is a simple encapsulation of the arguments passed to
+ * the TSEM_SETTIME handler.
+ */
+struct tsem_time_args {
+	bool have_ts;
+	long seconds;
+	long nsecs;
+
+	bool have_tz;
+	int minuteswest;
+	int dsttime;
+};
+
+/**
+ * struct tsem_quota_args - TSEM arguments for quota security management.
+ * @cmds: The cmds argument from the security_quotactl handler.
+ * @type: The type argument from the security_quotactl handler.
+ * @id: The id argument from the security_quotactl handler.
+ * @in.dentry: In the case of the quota_on LSM handler the dentry
+ *	       argument to the handler.
+ * @in.sb: The superblock pointer argument from the security_quotactl handler.
+ * @out.dentry: The TSEM dentry representation of a dentry arguement
+ *		to the quota handlers.
+ * @out.s_flags: In the case of the quotactl handler the flags from
+ *		 the superblock of the filesystem.
+ * @out.fstype: In the case of the quotactl handler the filesystem
+ *		type of the mountpoint.
+ *
+ * This structure is an encapsulation of the arguments and their
+ * retention values for the LSM security handlers that make security
+ * decisions relevant to filesystem quota manipulation.
+ */
+struct tsem_quota_args {
+	int cmds;
+	int type;
+	int id;
+
+	union {
+		struct {
+			struct dentry *dentry;
+			const struct super_block *sb;
+		} in;
+
+		struct {
+			struct tsem_dentry dentry;
+			unsigned long s_flags;
+			char *fstype;
+		} out;
+	};
+};
+
+/**
+ * struct tsem_key_args - TSEM key handler arguments.
+ * @flags: The flags value passed to the key_alloc handler.
+ * @in.cred: A pointer to the credential structures passed to the
+ *	     security handlers.
+ * @out.possessed: A flag variable indicating if a key is owned by a
+ *		  task.
+ * @out.uid: The owner id of a key.
+ * @out.gid: The group id of a key.
+ * @out.flags: The flags value retained for a key operation.
+ * @out.cred: The retained  credentials of a process attempting to
+ *	      access a key.
+ * @out.perm: The retained permissions value of a key.
+ *
+ * This structure is used to hold the arguments to the LSM hooks that
+ * handle key security event and their retained TSEM equivalents.
+ */
+struct tsem_key_args {
+	unsigned long flags;
+
+	union {
+		struct {
+			key_ref_t ref;
+			const struct cred *cred;
+
+		} in;
+
+		struct {
+			bool possessed;
+			uid_t uid;
+			gid_t gid;
+			unsigned long flags;
+			struct tsem_COE cred;
+			u32 perm;
+		} out;
+
+	};
+};
+
+/**
+ * struct tsem_bpf_args - TSEM bpf security handler arguments.
+ * @bpf.cmd: For the security_bpf LSM handler the command number passed
+ *	     the event handler.
+ * @bpf.size: For the security_bpf LSM handler the size argument passed
+ *	      to the event handler.
+ * @prog.type: For the security_bpf_prog LSM handler the type member of
+ *	       the bpf_prog structure passed to the event handler.
+ * @prog.attach_type: For the security_bpf LSM handler the attach_type
+ *		      member of the bpf_prog structure passed to the
+ *		      event handler.
+ * @map.map_type: For the security_map LSM handler the map_type member
+ *		  of the bpf_map structure passed to the event handler.
+ * @map.fmode: For the security_map LSM handler the fmode argument passed
+ *	       to the event handler.
+
+ * This structure is used to hold the arguments to the various LSM
+ * hooks that handle BPF security management.  This structure is a
+ * union over structures for each of the TSEM bpf handlers.
+ */
+struct tsem_bpf_args {
+	union {
+		struct {
+			int cmd;
+			unsigned int size;
+		} bpf;
+
+		struct {
+			int type;
+			int attach_type;
+		} prog;
+
+		struct {
+			int map_type;
+			fmode_t fmode;
+		} map;
+	};
+};
+
+/**
+ * struct tsem_ipc_perm - TSEM retained members of an IPC permission
+ *			  structure.
+ * @uid: The uid member of the IPC permission structure translated into
+ *	 the namespace reference for the modeling namespace.
+ * @gid: The gid member of the IPC permission structure translated into
+ *	 the namespace reference for the modeling namespace.
+ * @cuid: The cuid member of the IPC permission structure translated
+ *	  into the namespace reference for the modeling namespace.
+ * @cgid: The cgid member of the IPC permission structure translated
+ *	  into the namespace reference for the modeling namespace.
+ * @mode: The mode member of the IPC permission structure.
+ *
+ * This structure is used to hold the translated values from a
+ * kern_ipc_perm structure that is passed to one of the LSM IPC
+ * shared memory security handlers.
+ */
+struct tsem_ipc_perm {
+	uid_t uid;
+	gid_t gid;
+	uid_t cuid;
+	gid_t cgid;
+	umode_t mode;
+};
+
+/**
+ * struct tsem_ipc_args - TSEM arguments for IPC security handlers.
+ * @perm_flag: For the tsem_ipc_permission handler the permission flag.
+ * @value: A signed integer value that serves as an argument type to
+ *	   a number of the handlers.
+ * @nsops: In the came of the tsem_sem_semop handler the nsops argument
+ *	   to the handler.
+ * @type: The type argument to the msg_queue_msgrcv handler.
+ * @in.perm: The kern_ipc_perm structure that is passed to multiple
+ *	     handlers that define the permissions for the IPC
+ *	     object whose security status is being checked.
+ * @in.target: For the msg_queue_msgrc handler the TASK_ID of the
+ *	       process ending the message.
+ * @out.perm: The TSEM translated versions of the perm pointer that
+ *	      was passed to a handler.
+ * @out.owner: The TASK_ID of the task that created the IPC resource.
+ * @out.target: The retained version of the TASK_ID describing the
+ *		sender of a message.
+ *
+ * This structure is an encapsulation of the arguments and their
+ * retention values for the LSM security handlers that make security
+ * decisions relevant to IPC objects.
+ */
+struct tsem_ipc_args {
+	short perm_flag;
+	int value;
+	unsigned int nsops;
+	long type;
+
+	union {
+		struct {
+			struct kern_ipc_perm *perm;
+			struct task_struct *target;
+		} in;
+
+		struct {
+			struct tsem_ipc_perm perm;
+			u8 owner[HASH_MAX_DIGESTSIZE];
+			u8 target[HASH_MAX_DIGESTSIZE];
+		} out;
+	};
+};
+
+/**
+ * struct tsem_capability_args - TSEM arguments for capability handling.
+ * @cap: A capability specified for an event.
+ * @opts: Options for handling a capabilities command.
+ * @effective: The effective capability that is being manipulated.
+ * @inheritable: The inheritable capability that is being manipulated.
+ * @permitted: The permitted capability that is being manipulated.
+ * @target: The TASK_ID of the process whose capabilities are being
+ *	    requested.
+ *
+ * This structure is an encapsulation of the arguments to be retained
+ * for security event descriptions that describe security events
+ * involving process capabilities.
+ */
+struct tsem_capability_args {
+	int cap;
+	unsigned int opts;
+
+	kernel_cap_t effective;
+	kernel_cap_t inheritable;
+	kernel_cap_t permitted;
+
+	u8 target[HASH_MAX_DIGESTSIZE];
+};
+
+/**
+ * struct tsem_event - TSEM security event description.
+ * @kref: Reference count structure to track event lifetime.
+ * @list: The list of security events in a security modeling namespace.
+ * @work: The work structure that manages the workqueue being used to
+ *	  refill the event magazine structures.
+ * @event: The enumeration type describing the security event that the
+ *	   structure is defining.
+ * @context: The context number of the security modeling namespace that
+ *	     generated the event.
+ * @locked: A boolean flag used to indicate whether or not the
+ *	    security event is running in atomic context.
+ * @instance: The process instance number that is executing the
+ *	      event described by the structure.
+ * @p_instance: The parent process instance number of the process
+ *		executing the event described by the structure.
+ * @event_number: The sequence number of the event in the security modeling
+ *		  namespace that generated the event.
+ * @pid: The process id number, in the global pid namespace, of the
+ *	 task that is executing the security event.
+ * @comm: A pointer to a null terminated buffer containing the name of
+ *	  the process that is requesting the security event.
+ * @digestsize: The size in bytes of the cryptographic hash function
+ *		that is being used in the security modeling namespace
+ *		in which the event occurred.
+ * @task_id: The TSEM TASK_ID of the process that generated the
+ *	     security event described by an instance of this
+ *	     structure.
+ * @mapping: The security state coefficient that the event described
+ *	     by this structure generates.
+ * @COE: The tsem_COE structure that describes the Context Of
+ *	 Execution that generated the event described by this
+ *	 structure.
+ * @no_params: A boolean value that is set if the security event
+ *	       has no characterizing parameters.
+ * @CELL: The CELL union is used to hold the data structures that
+ *	  characterize the CELL mapping of the event.
+ * @CELL.value: A single numeric value that may be used in
+ *		characterizing an event.
+ * @CELL.netlink: A structure describing  parameters that characterize
+ *		  an event inolving a netlink event.
+ * @CELL.inode: A structure describing characters of security events
+ *		that address inode manipulation operations.
+ * @CELL.file: A structure characterizing a file used as an arguement
+ *	       for a security event.
+ * @CELL.mmap_file: The structure describing the characteristics of
+ *		    a security event involving a memory mapping event.
+ * @CELL.socket: A structure characterizing security events that
+ *		 involve a socket.
+ * @CELL.kernel: A structure characterizing kernel I/O or memory
+ *		 loading opeations.
+ * @CELL.task_kill: The structure describing the characteristics of an
+ *		    event sending a signal to a process.
+ * @CELL.task_prlimit: A structure describing a security event that
+ *		       sets process resource limits.
+ * @CELL.task_prctl: A structure describing an event involving the
+ *		     process control operations.
+ * @CELL.inode_attr: A structure describing events involving getting
+ *		     or setting of inode attributes.
+ * @CELL.inode_xattr: A structure describing events involving actions
+ *		      on inode extended attributes.
+ * @CELL.key: A structure describing events involving manipulation of
+ *	      a kernel key.
+ * @CELL.sb: A structure describing events that involve the a
+ *	     filesystem superblock.
+ * @CELL.quota: A structure describing events that involve the
+ *		manipulation of filesystem quotas.
+ * @CELL.time: A structure describing the setting of the system time
+ *	       or timezone.
+ * @CELL.bpf: A structure describing involves involving manipulation
+ *	      of BPF functionality
+ * @CELL.ipc: A structure describing events that are manipulating
+ *	      shared memory structures or operations.
+ * @CELL.capability: A structure describing events that manipulate
+ *		     the capabilities of a process.
+ *
+ * This structure is the primary data structure for describing
+ * security events that occur in a security modeling namespace.  Each
+ * unique security coefficient in the namespace will have one of these
+ * structures associated with it.
+ *
+ * This structure encapsulates the following three major sources of
+ * information about the event:
+ *
+ * * A description of the process initiating the event.
+ * * The characteristics of the COE identity of the event.
+ * * The characteristics of the CELL identity of the event.
+ *
+ * Since one event description has to ultimately characterize any
+ * security event that can occur, the strategy is to use a union that
+ * contains security event specific structures that describe the
+ * characteristics of the event.  The event member of the structure
+ * is used to indicate the structure that should be referenced.
+ *
+ * The kref member of this structure is used to track the lifetime of
+ * an instance of this structure.  For example, in the case of an
+ * externally modeled event, when the export of the event description
+ * is complete.  In the case of an internally modeled namespace the
+ * structure will be released if it represents a security state
+ * coefficient that is already present in the model.  The structures
+ * are also released when an internally modeled namespace terminates.
+ *
+ * The work member of this structure is used to support asynchronous
+ * updates to a TPM for the root modeling domain.  Asynchronous
+ * updates are used to improve the performance of modeling and to
+ * handle security events that are running in atomic context and
+ * cannot be scheduled away while the TPM transaction completes.
+ *
+ * The tsem_event_allocate() function is called by a TSEM security
+ * event handler to allocate and populate an instance of this
+ * structure.  The locked member of this structure is used to
+ * determine whether the structure should be allocated from the
+ * kmem_cache based structure pool or from the magazine of structures
+ * help for processes running in atomic context.
+ *
+ * After the event is mapped this structure is either passed to the
+ * internal trusted modeling agent or the contents of this structure
+ * is exported to the trust orchestrator attached to the namespace for
+ * modeling by an external trusted modeling agent.
+ */
+struct tsem_event {
+	struct kref kref;
+	struct list_head list;
+	struct work_struct work;
+	void (*event_free)(struct tsem_event *ep);
+
+	enum tsem_event_type event;
+	u64 context;
+	bool locked;
+	u64 instance;
+	u64 p_instance;
+	u64 timestamp;
+	u64 event_number;
+	pid_t pid;
+	char comm[TASK_COMM_LEN];
+
+	unsigned int digestsize;
+	u8 task_id[HASH_MAX_DIGESTSIZE];
+	u8 p_task_id[HASH_MAX_DIGESTSIZE];
+	u8 mapping[HASH_MAX_DIGESTSIZE];
+
+	struct tsem_COE COE;
+
+	bool no_params;
+	union {
+		int value;
+		struct tsem_netlink_args netlink;
+		struct tsem_inode_args inode;
+		struct tsem_file_args file;
+		struct tsem_mmap_file_args mmap_file;
+		struct tsem_socket_args socket;
+		struct tsem_kernel_args kernel;
+		struct tsem_task_kill_args task_kill;
+		struct tsem_task_prlimit_args task_prlimit;
+		struct tsem_task_prctl_args task_prctl;
+		struct tsem_inode_attr_args inode_attr;
+		struct tsem_inode_xattr_args inode_xattr;
+		struct tsem_key_args key;
+		struct tsem_sb_args sb;
+		struct tsem_quota_args quota;
+		struct tsem_time_args time;
+		struct tsem_bpf_args bpf;
+		struct tsem_ipc_args ipc;
+		struct tsem_capability_args capability;
+
+	} CELL;
+};
+
+/**
+ * struct tsem_event_point - TSEM security coefficient characteristics.
+ * @list: The list of all the security state coefficients for a
+ *	   modeling namespace.
+ * @valid: A boolean value use to indicate whether or not the security
+ *	   state point is a valid coefficient in the model.
+ * @count: The number of times this coefficient has been expressed by
+ *	   the security modeling namespace.
+ * @point: The security state coefficient for a security event.
+ *
+ * This structure is used by internal trusted modeling agents to
+ * represent each unique security coefficient in a security model.
+ * Security state coefficients are unique within a model so only one
+ * struct tsem_event_point structure will be generated regardless of
+ * how many times the security event that generates the point occurs.
+ * The count member of this structure represents the total number of
+ * security events that have occurred generated this point.
+ *
+ * The valid member of this structure is used to flag whether this
+ * is consistent with the model for the namespace or was generated by
+ * a 'forensic', ie. out of model, event.
+ *
+ * Within each security namespace these structures are linked together
+ * in a list that describes the functional security value of the
+ * namespace.  Entries are only added to this list and never removed.
+ *
+ * The desired state of a security model is created by using the TSEM
+ * control plane to inject a list of acceptable security state
+ * coefficients into the model.  Sealing a model causes any security
+ * events that produce a coefficient different from those already in
+ * the model to be rejected as an invalid security event and logged as
+ * a forensic event for the model.
+ */
+struct tsem_event_point {
+	struct list_head list;
+	bool valid;
+	u64 count;
+	u8 point[HASH_MAX_DIGESTSIZE];
+};
+
+/**
+ * struct tsem_inode - TSEM inode status structure.
+ * @create_mutex: The mutex that protects the create_list.
+ * @create_list: The list of structures that contain ownership and instance
+ *		 information for inodes created under a directory.
+ * @instance_mutex: The mutex protecting the instance_list.
+ * @instance_list: The list of task identities that have created inodes
+ *		   under a directory and the instance count of inodes
+ *		   for each TASK_ID.
+ * @digest_mutex: The mutex protecting the digest_list.
+ * @digest_list: A list of structures containing the digest values that
+ *		 have been calculated for the inode.
+ * @status: The status of the inode.  See the discussion of enum
+ *	    tsem_inode_state for the information that is conveyed
+ *	    by this member.
+ * @created: A boolean flag to indicate that this inode was created
+ *	     in the context of a security modeling namespace.
+ * @creator: The context identity of the security modeling namespace that
+ *	     created the inode.
+ * @instance: The inode instance number for the TASK_ID that created
+ *	      the inode.
+ * @owner: The TASK_ID of the process that created the inode.
+ *
+ * This structure is used to contain the TSEM security state of an
+ * inode.
+ *
+ * Three lists are managed by this structure:
+ *
+ * An inode that is a directory will have inodes that are create under
+ * it added to the create_list.  This list will be traversed when the
+ * inode is instantiated so creation information about the inode can
+ * be registered in the tsem_inode structure attached to that inode.
+ *
+ * The instance_list is also maintained by a directory inode and is
+ * used to track the instances of an inode that is created under the
+ * directory by specific TASK_ID's.
+ *
+ * The digest_list is used for inodes that are backing files and is
+ * used to track the various cryptographic digest values that have
+ * been computed for the file.  This supports the use of multiple
+ * simultaneous digest values across multiple security modeling
+ * namespaces.
+ *
+ * The status member of this function serves two purposes:
+ *
+ * For file based inodes the status member is used to indicate
+ * whether or not the digest value is being computed.  The
+ * tsem_file_open handler uses this status variable to determine
+ * whether or not the modeling of an event should be bypassed if the
+ * file is being opened by the kernel to compute the digest value of
+ * the file.
+ *
+ * The second role of the status member is to indicate that the inode
+ * is one of the TSEM control plane files.  This allows modeling of
+ * events involving this inode to be bypassed in order to avoid a
+ * 'Heisenberg Deadlock' situation.
+ */
+struct tsem_inode {
+	struct mutex create_mutex;
+	struct list_head create_list;
+
+	struct mutex instance_mutex;
+	struct list_head instance_list;
+
+	struct mutex digest_mutex;
+	struct list_head digest_list;
+
+	enum tsem_inode_state status;
+	bool created;
+	u64 creator;
+	u64 instance;
+	u8 owner[HASH_MAX_DIGESTSIZE];
+};
+
+/**
+ * struct tsem_ipc - TSEM IPC security structure.
+ * @owner: The identity of the task that created the IPC resource.
+ *
+ * This structure is used to track the TASK_ID of the process that
+ * created the IPC memory resource so that information can be
+ * integrated into security coefficients that are generated for
+ * shared memory events.
+ */
+struct tsem_ipc {
+	u8 owner[HASH_MAX_DIGESTSIZE];
+};
+
+/**
+ * struct tsem_inode_digest - Digest specific file checksum.
+ * @list:	The list structure used to link multiple digest values
+ *		for an inode.
+ * @name:	A pointer to an allocated null-terminated character
+ *		buffer containing the name of the hash function that
+ *		generated the digest value represented by an instance
+ *		of this structure.
+ * @version:	The version number of the inode that generated the digest
+ *		value that is currently represented.
+ * @value:	The digest value of the file represented by the inode..
+ *
+ * A linked list of these structures is maintained for each inode that
+ * is modeled by TSEM and is used to support multiple hash specific
+ * digest values for a file represented by the inode.  The tsem_inode
+ * structure that represents the TSEM security status of the inode
+ * contains a list of these structures.
+ *
+ * The name member of structure contains the name of the hash function
+ * that generated the checksum value.  This name is used to locate the
+ * correct structure by comparing its value against the hash function
+ * that is being used by the security modeling namespace that is
+ * traversing the list attempting to locate a previously computed
+ * digest value.
+ *
+ * The version member of the structure contains the inode version number
+ * that was in effect when the last digest value of this type was computed.
+ * This version number value is used to detect changes and to trigger an
+ * update of the digest value.
+ */
+struct tsem_inode_digest {
+	struct list_head list;
+	char *name;
+	u64 version;
+	u8 value[HASH_MAX_DIGESTSIZE];
+};
+
+/*
+ * The following four variables are the only globally visible
+ * variables used in the TSEM implementation.
+ *
+ * The tsem_blob_sizes variable is used by the LSM infrastructure to
+ * describe the amount of space that will be needed by the TSEM
+ * security structures.
+ *
+ * The tsem_names array is defined in the tsem.c file and contains an
+ * array of pointers to the strings that define the names for each of
+ * the TSEM security event handlers.  The enum tsem_event_type
+ * enumeration indexes this array.
+ *
+ * The tsem_root_actions array is also indexed by the tsem_event_type
+ * enumeration and is used to determine the type of response that a
+ * TSEM security event handler is to return to the caller, ie. either
+ * logging or enforcing.  The contents of this array is inherited by
+ * copying the array into the struct tsem_context structure for
+ * modeling namespaces that are subordinate to the root model.
+ */
+extern struct lsm_blob_sizes tsem_blob_sizes;
+extern const char * const tsem_names[TSEM_EVENT_CNT];
+extern enum tsem_action_type tsem_root_actions[TSEM_EVENT_CNT];
+extern const struct tsem_context_ops tsem_model0_ops;
+
+/*
+ * The following section of the file contains the definitions for the
+ * externally visible functions in each of the TSEM compilation units.
+ */
+extern struct dentry *tsem_fs_create_external(const char *name);
+extern void tsem_fs_show_trajectory(struct seq_file *c, struct tsem_event *ep);
+extern void tsem_fs_show_field(struct seq_file *c, const char *field);
+extern void tsem_fs_show_key(struct seq_file *c, char *term, char *key,
+			     char *fmt, ...);
+extern int tsem_fs_init(void);
+
+extern struct tsem_model *tsem_model_allocate(size_t size);
+extern void tsem_model_free(struct tsem_context *ctx);
+extern int tsem_model_event(struct tsem_event *ep);
+extern int tsem_model_load_point(u8 *point);
+extern int tsem_model_load_pseudonym(u8 *mapping);
+extern int tsem_model_has_pseudonym(struct tsem_inode *tsip, char *pathname);
+extern void tsem_model_load_base(u8 *mapping);
+extern int tsem_model_add_aggregate(void);
+extern void tsem_model_compute_state(void);
+extern void tsem_model_magazine_free(struct tsem_model *model);
+extern int tsem_model_cache_init(struct tsem_model *model, size_t size);
+
+extern void tsem_ns_put(struct tsem_context *ctx);
+extern int tsem_ns_event_key(u8 *task_key, const char *keystr, u8 *key);
+extern int tsem_ns_create(const enum tsem_control_type type,
+			  const char *digest, const enum tsem_ns_reference ns,
+			  const char *key, const unsigned int cache_size,
+			  const struct tsem_context_ops *ops);
+extern int tsem_ns_export_root(unsigned int magazine_size);
+
+extern int tsem_export_show(struct seq_file *m, void *v);
+extern int tsem_export_event(struct tsem_event *ep);
+extern int tsem_export_action(enum tsem_event_type event, bool locked);
+extern int tsem_export_aggregate(void);
+extern int tsem_export_magazine_allocate(struct tsem_external *ext,
+					 size_t size);
+extern void tsem_export_magazine_free(struct tsem_external *ext);
+extern int tsem_export_cache_init(void);
+
+extern int tsem_map_task(struct file *file, u8 *mapping);
+extern int tsem_map_event(struct tsem_event *ep);
+
+extern struct tsem_event *tsem_event_allocate(enum tsem_event_type event,
+					      bool locked);
+extern int tsem_event_init(struct tsem_event *ep);
+extern int tsem_event_generate(struct tsem_event *ep);
+extern void tsem_event_put(struct tsem_event *ep);
+extern void tsem_event_get(struct tsem_event *ep);
+extern int tsem_event_magazine_allocate(struct tsem_context *ctx, size_t size);
+extern void tsem_event_magazine_free(struct tsem_context *ctx);
+extern int tsem_event_cache_init(void);
+
+extern u8 *tsem_trust_aggregate(void);
+extern int tsem_trust_add_event(struct tsem_event *ep);
+
+/*
+ * The remaining inline function declarations follow the design
+ * pattern of the other LSM's and implement functions that return
+ * various TSEM characteristics of tasks, modeling contexts and
+ * inodes.
+ */
+static inline struct tsem_task *tsem_task(const struct task_struct *task)
+{
+	return task->security + tsem_blob_sizes.lbs_task;
+}
+
+static inline bool tsem_task_trusted(struct task_struct *task)
+{
+	return tsem_task(task)->trust_status & TSEM_TASK_TRUSTED;
+}
+
+static inline bool tsem_task_untrusted(struct task_struct *task)
+{
+	return tsem_task(task)->trust_status & ~TSEM_TASK_TRUSTED;
+}
+
+static inline struct tsem_context *tsem_context(struct task_struct *task)
+{
+	return tsem_task(task)->context;
+}
+
+static inline struct tsem_model *tsem_model(struct task_struct *task)
+{
+	return tsem_task(task)->context->model;
+}
+
+static inline struct tsem_inode *tsem_inode(struct inode *inode)
+{
+	return inode->i_security + tsem_blob_sizes.lbs_inode;
+}
+
+static inline struct tsem_ipc *tsem_ipc(struct kern_ipc_perm *kipc)
+{
+	return kipc->security + tsem_blob_sizes.lbs_ipc;
+}
+
+static inline struct crypto_shash *tsem_digest(void)
+{
+	return tsem_context(current)->tfm;
+}
+
+static inline unsigned int tsem_digestsize(void)
+{
+	return crypto_shash_digestsize(tsem_digest());
+}
Signature · 1 line
2.39.1
#27 lore raw

PATCH v4 4/14 Add primary TSEM implementation file.

In reply to Greg Wettstein

The tsem.c file is the 'master' file in the TSEM implementation. It is responsible for initializing the LSM and providing the implementation of the security event handlers.

---
 security/tsem/tsem.c | 2446 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 2446 insertions(+)
 create mode 100644 security/tsem/tsem.c
security/tsem/tsem.c new file +2446 -0
new file mode 100644
index 000000000000..76d65b3e62b3
@@ -0,0 +1,2446 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/*
+ * Copyright (C) 2024 Enjellic Systems Development, LLC
+ * Author: Dr. Greg Wettstein <[email protected]>
+ *
+ * This file is the primary implementation file for the tsem LSM.
+ *
+ * It implements initialization and setup functions that interpret
+ * kernel command-line arguments and prepares TSEM for operation.
+ *
+ * In addition it contains all of the TSEM specific security event
+ * handlers that are responsible for handling the LSM events that TSEM
+ * models.
+ *
+ * Each TSEM event handler calls the tsem_allocate_event() function to
+ * allocate a structure that will be used to describe the event.  The
+ * CELL union of this structure contains various structures that are
+ * used to hold these parameters.
+ *
+ * Since the event characterization parameters need to be retained for
+ * the lifetime of the tsem_event structure that is allocated.  In the
+ * case of internally modeled namespaces this lifespan is the lifetime
+ * of the security modeling namespace.  In the case of externally
+ * modeled namespaces, the lifespan is until the security event
+ * description is exported to an external trust orchestrator.
+ *
+ * In order to support this model, the event description structures
+ * are typically composed of a union over 'in' and 'out' structures.
+ * The 'in' structures are used to hold arguments to the event handler
+ * that may only be relevant for the duration of the call.  These
+ * values are translated into members of the 'out' structure that
+ * retain the values until the end of the lifetime of the tsem_event
+ * structure.
+ *
+ * Each TSEM event handler is responsible for allocating a tsem_event
+ * structure and populating the appropriate CELL structure with the
+ * input characteristics of the event.  The dispatch_event() function
+ * is called to handle the modeling of the event.  This function
+ * returns the permission value that is returned as the result of the
+ * LSM event handler.
+ *
+ * The dispatch_event() calls the tsem_event_init() function that is
+ * responsible for translating the input parameters into values that
+ * will be retained for the lifetime of the security event
+ * description.  The populated event description is then dispatched to
+ * either the tsem_model_event() or the tsem_export_event() for
+ * modeling by either the internal TMA or by a TMA associated with an
+ * external trust orchestrator.
+ */
+
+#define LOCK true
+#define NOLOCK false
+
+#include <linux/magic.h>
+#include <linux/mman.h>
+#include <linux/binfmts.h>
+#include <linux/bpf.h>
+#include <linux/mount.h>
+#include <linux/security.h>
+
+#include "tsem.h"
+#include "nsmgr.h"
+
+static const struct lsm_id tsem_lsmid = {
+	.name = "tsem",
+	.id = LSM_ID_TSEM
+};
+
+struct lsm_blob_sizes tsem_blob_sizes __ro_after_init = {
+	.lbs_task = sizeof(struct tsem_task),
+	.lbs_inode = sizeof(struct tsem_inode),
+	.lbs_ipc = sizeof(struct tsem_ipc),
+	.lbs_xattr_count = 1
+};
+
+enum tsem_action_type tsem_root_actions[TSEM_EVENT_CNT] = {
+	TSEM_ACTION_EPERM	/* Undefined. */
+};
+
+static atomic64_t task_instance;
+
+static struct tsem_model root_model = {
+	.point_lock = __SPIN_LOCK_INITIALIZER(root_model.point_lock),
+	.point_list = LIST_HEAD_INIT(root_model.point_list),
+	.point_end_mutex = __MUTEX_INITIALIZER(root_model.point_end_mutex),
+
+	.trajectory_lock = __SPIN_LOCK_INITIALIZER(root_model.trajectory_lock),
+	.trajectory_list = LIST_HEAD_INIT(root_model.trajectory_list),
+	.trajectory_end_mutex = __MUTEX_INITIALIZER(root_model.trajectory_end_mutex),
+
+	.forensics_lock = __SPIN_LOCK_INITIALIZER(root_model.forensics_lock),
+	.forensics_list = LIST_HEAD_INIT(root_model.forensics_list),
+	.forensics_end_mutex = __MUTEX_INITIALIZER(root_model.forensics_end_mutex),
+
+	.pseudonym_mutex = __MUTEX_INITIALIZER(root_model.pseudonym_mutex),
+	.pseudonym_list = LIST_HEAD_INIT(root_model.pseudonym_list),
+
+	.mount_mutex = __MUTEX_INITIALIZER(root_model.mount_mutex),
+	.mount_list = LIST_HEAD_INIT(root_model.mount_list)
+};
+
+static struct tsem_context root_context;
+
+DEFINE_STATIC_KEY_TRUE(tsem_not_ready);
+
+static bool tsem_available __ro_after_init;
+
+static unsigned int magazine_size __ro_after_init = TSEM_ROOT_MAGAZINE_SIZE;
+
+static enum mode_type {
+	FULL_MODELING,
+	NO_ROOT_MODELING,
+	ROOT_EXPORT_ONLY
+} tsem_mode __ro_after_init;
+
+static char *default_hash_function __ro_after_init;
+
+static const struct {
+	char *key;
+	enum mode_type mode;
+} mode_arguments[] __ro_after_init = {
+	{"no_root_modeling", NO_ROOT_MODELING},
+	{"root_export_only", ROOT_EXPORT_ONLY}
+};
+
+/*
+ * NOTE:
+ * The tsem_event_type enumerations are used to select the
+ * member of the tsem_names array that is to be used.  If the members
+ * of this array change position, or there are additions or deletions
+ * to this array, there needs to be coordinated changes made to the
+ * tsem_event_type enumeration in the tsem.h file.
+ */
+const char * const tsem_names[TSEM_EVENT_CNT] = {
+	"undefined",
+	"bprm_committed_creds",		/* TSEM_BPRM_COMMITTED_CREDS */
+	"task_kill",			/* TSEM_TASK_KILL */
+	"task_setpgid",			/* TSEM_TASK_SETPGID */
+	"task_getpgid",			/* TSEM_TASK_GETPGID */
+	"task_getsid",			/* TSEM_TASK_GETSID */
+	"task_setnice",			/* TSEM_TASK_SETNICE */
+	"task_setioprio",		/* TSEM_TASK_SETIOPRIO */
+	"task_getioprio",		/* TSEM_TASK_GETIOPRIO */
+	"task_prlimit",			/* TSEM_TASK_PRLIMIT */
+	"task_setrlimit",		/* TSEM_TASK_SETRLIMIT */
+	"task_setscheduler",		/* TSEM_TASK_SETSCHEDULER */
+	"task_getscheduler",		/* TSEM_TASK_GETSCHEDULER */
+	"task_prctl",			/* TSEM_TASK_PRCTL */
+	"file_open",			/* TSEM_FILE_OPEN */
+	"mmap_file",			/* TSEM_MMAP_FILE */
+	"file_ioctl",			/* TSEM_FILE_IOCTL */
+	"file_lock",			/* TSEM_FILE_LOCK */
+	"file_fcntl",			/* TSEM_FILE_FCNTL */
+	"file_receive",			/* TSEM_FILE_RECEIVE */
+	"unix_stream_connect",		/* TSEM_UNIX_STREAM_CONNECT */
+	"unix_may_send",		/* TSEM_UNIX_MAY_SEND */
+	"socket_create",		/* TSEM_SOCKET_CREATE */
+	"socket_connect",		/* TSEM_SOCKET_CONNECT */
+	"socket_bind",			/* TSEM_SOCKET_BIND */
+	"socket_accept",		/* TSEM_SOCKET_ACCEPT */
+	"socket_listen",		/* TSEM_SOCKET_LISTEN */
+	"socket_socketpair",		/* TSEM_SOCKET_SOCKETPAIR */
+	"socket_sendmsg",		/* TSEM_SOCKET_SENDMSG */
+	"socket_recvmsg",		/* TSEM_SOCKET_RECVMSG */
+	"socket_getsockname",		/* TSEM_SOCKET_GETSOCKNAME */
+	"socket_getpeername",		/* TSEM_SOCKET_GETPEERNAME */
+	"socket_setsockopt",		/* TSEM_SOCKET_SETSOCKOPT */
+	"socket_shutdown",		/* TSEM_SOCKET_SHUTDOWN */
+	"ptrace_traceme",		/* TSEM_PTRACE_TRACEME */
+	"kernel_module_request",	/* TSEM_KERNEL_MODULE_REQUEST */
+	"kernel_load_data",		/* TSEM_KERNEL_LOAD_DATA */
+	"kernel_read_file",		/* TSEM_KERNEL_READ_FILE */
+	"sb_mount",			/* TSEM_SB_MOUNT */
+	"sb_umount",			/* TSEM_SB_UMOUNT */
+	"sb_remount",			/* TSEM_SB_REMOUNT */
+	"sb_pivotroot",			/* TSEM_SB_PIVOTROOT */
+	"sb_statfs",			/* TSEM_SB_STATFS */
+	"move_mount",			/* TSEM_MOVE_MOUNT */
+	"shm_associate",		/* TSEM_SHM_ASSOCIATE */
+	"shm_shmctl",			/* TSEM_SHM_SHMCTL */
+	"shm_shmat",			/* TSEM_SHM_SHMAT */
+	"sem_associate",		/* TSEM_SEM_ASSOCIATE */
+	"sem_semctl",			/* TSEM_SEM_SEMCTL */
+	"sem_semop",			/* TSEM_SEM_SEMOP */
+	"syslog",			/* TSEM_SYSLOG */
+	"settime",			/* TSEM_SETTIME */
+	"quotactl",			/* TSEM_QUOTACTL */
+	"quota_on",			/* TSEM_QUOTA_ON */
+	"msg_queue_associate",		/* TSEM_MSG_QUEUE_ASSOCIATE */
+	"msg_queue_msgctl",		/* TSEM_MSG_QUEUE_MSGCTL */
+	"msg_queue_msgsnd",		/* TSEM_MSG_QUEUE_MSGSND */
+	"msg_queue_msgrcv",		/* TSEM_MSG_QUEUE_MSGRCV */
+	"ipc_permission",		/* TSEM_IPC_PERMISSION */
+	"key_alloc",			/* TSEM_KEY_ALLOC */
+	"key_permission",		/* TSEM_KEY_PERMISSION */
+	"netlink_send",			/* TSEM_NETLINK_SEND */
+	"inode_create",			/* TSEM_INODE_CREATE */
+	"inode_link",			/* TSEM_INODE_LINK */
+	"inode_unlink",			/* TSEM_INODE_UNLINK */
+	"inode_symlink",		/* TSEM_INODE_SYMLINK */
+	"inode_mkdir",			/* TSEM_INODE_MKDIR */
+	"inode_rmdir",			/* TSEM_INODE_RMDIR */
+	"inode_mknod",			/* TSEM_INODE_MKNOD */
+	"inode_rename",			/* TSEM_INODE_RENAME */
+	"inode_setattr",		/* TSEM_INODE_SETATTR */
+	"inode_getattr",		/* TSEM_INODE_GETATTR */
+	"inode_setxattr",		/* TSEM_INODE_SETXATTR */
+	"inode_getxattr",		/* TSEM_INODE_GETXATTR */
+	"inode_listxattr",		/* TSEM_INODE_LISTXATTR */
+	"inode_removexattr",		/* TSEM_INODE_REMOVEXATTR */
+	"inode_killpriv",		/* TSEM_INODE_KILLPRIV */
+	"tun_dev_create",		/* TSEM_TUN_DEV_CREATE */
+	"tun_dev_attach_queue",		/* TSEM_TUN_DEV_ATTACH_QUEUE */
+	"tun_dev_attach",		/* TSEM_TUN_DEV_ATTACH */
+	"tun_dev_open",			/* TSEM_TUN_DEV_OPEN */
+	"bpf",				/* TSEM_BPF */
+	"bpf_map",			/* TSEM_BPF_MAP */
+	"bpf_prog",			/* TSEM_BPF_PROG */
+	"ptrace_access_check",		/* TSEM_PTRACE_ACCESS_CHECK */
+	"capable",			/* TSEM_CAPABLE */
+	"capget",			/* TSEM_CAPGET */
+	"capset"			/* TSEM_CAPSET */
+};
+
+static const unsigned long pseudo_filesystems[] = {
+	PROC_SUPER_MAGIC,
+	SYSFS_MAGIC,
+	DEBUGFS_MAGIC,
+	TMPFS_MAGIC,
+	DEVPTS_SUPER_MAGIC,
+	BINFMTFS_MAGIC,
+	SECURITYFS_MAGIC,
+	SELINUX_MAGIC,
+	SMACK_MAGIC,
+	CGROUP_SUPER_MAGIC,
+	CGROUP2_SUPER_MAGIC,
+	NSFS_MAGIC,
+	EFIVARFS_MAGIC
+};
+
+static int __init set_magazine_size(char *magazine_value)
+{
+	if (kstrtouint(magazine_value, 0, &magazine_size))
+		pr_warn("tsem: Failed to parse root cache size.\n");
+
+	if (!magazine_size) {
+		pr_warn("tsem: Forcing non-zero cache size.\n");
+		magazine_size = TSEM_ROOT_MAGAZINE_SIZE;
+	}
+
+	pr_info("tsem: Setting default root cache size to %u.\n",
+		magazine_size);
+	return 1;
+}
+__setup("tsem_cache=", set_magazine_size);
+
+static int __init set_modeling_mode(char *mode_argument)
+{
+	unsigned int lp;
+
+	for (lp = 0; lp < ARRAY_SIZE(mode_arguments); ++lp) {
+		if (!strcmp(mode_argument, mode_arguments[lp].key)) {
+			tsem_mode = mode_arguments[lp].mode;
+			return 1;
+		}
+	}
+
+	pr_warn("tsem: Unknown tsem_mode %s specified, using full modeling.\n",
+		mode_argument);
+	return 1;
+}
+__setup("tsem_mode=", set_modeling_mode);
+
+static int __init set_default_hash_function(char *hash_function)
+{
+
+	default_hash_function = hash_function;
+	return 1;
+}
+__setup("tsem_digest=", set_default_hash_function);
+
+static int __init set_locked_status(char *str)
+{
+	tsem_nsmgr_lock(true);
+	pr_info("tsem: Model state locked by command-line request.\n");
+	return 1;
+}
+__setup("tsem_locked", set_locked_status);
+
+static bool bypass_event(const enum tsem_event_type event)
+{
+	if (tsem_context(current)->ops->bypasses[event])
+		return true;
+	if (tsem_mode == NO_ROOT_MODELING && !tsem_context(current)->id)
+		return true;
+	return false;
+}
+
+static bool pseudo_filesystem(struct inode *inode)
+{
+	unsigned int lp;
+
+	for (lp = 0; lp < ARRAY_SIZE(pseudo_filesystems); ++lp)
+		if (inode->i_sb->s_magic == pseudo_filesystems[lp])
+			return true;
+	return false;
+}
+
+static int untrusted_task(struct tsem_event *ep)
+{
+	int retn = 0;
+	struct tsem_context *ctx = tsem_context(current);
+
+	if (ctx->external) {
+		retn = tsem_export_action(ep->event, ep->locked);
+		if (retn)
+			return retn;
+	} else
+		pr_warn("Untrusted event %s: model_ns=%lld, comm=%s, pid=%d\n",
+			tsem_names[ep->event], ctx->id, current->comm,
+			task_pid_nr(current));
+
+	if (ctx->actions[ep->event] == TSEM_ACTION_EPERM)
+		retn = -EPERM;
+	return retn;
+}
+
+static int dispatch_event(struct tsem_event *ep)
+{
+	int retn;
+
+	if (unlikely(tsem_task_untrusted(current))) {
+		retn = untrusted_task(ep);
+		goto done;
+	}
+
+	retn = tsem_event_init(ep);
+	if (retn > 0) {
+		if (!tsem_context(current)->external)
+			retn = tsem_model_event(ep);
+		else
+			retn = tsem_export_event(ep);
+	}
+
+ done:
+	tsem_event_put(ep);
+	return retn;
+}
+
+static int tsem_file_open(struct file *file)
+{
+	struct inode *inode = file_inode(file);
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_FILE_OPEN))
+		return 0;
+	if (unlikely(tsem_inode(inode)->status == TSEM_INODE_CONTROL_PLANE)) {
+		if (capable(CAP_MAC_ADMIN))
+			return 0;
+		else
+			return -EPERM;
+	}
+
+	if (!S_ISREG(inode->i_mode))
+		return 0;
+	if (tsem_inode(inode)->status == TSEM_INODE_COLLECTING)
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_FILE_OPEN, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.file.in.file = file;
+	ep->CELL.file.in.pseudo_file = pseudo_filesystem(inode);
+
+	return dispatch_event(ep);
+}
+
+static int tsem_mmap_file(struct file *file, unsigned long prot,
+			  unsigned long flags, unsigned long extra)
+{
+	struct inode *inode = NULL;
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_MMAP_FILE))
+		return 0;
+
+	if (!file && !(prot & PROT_EXEC))
+		return 0;
+	if (file) {
+		inode = file_inode(file);
+		if (!S_ISREG(inode->i_mode))
+			return 0;
+		if (pseudo_filesystem(inode))
+			return 0;
+	}
+
+	ep = tsem_event_allocate(TSEM_MMAP_FILE, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.mmap_file.anonymous = file == NULL ? 1 : 0;
+	ep->CELL.mmap_file.file.in.file = file;
+	ep->CELL.mmap_file.prot = prot;
+	ep->CELL.mmap_file.flags = flags;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_file_ioctl(struct file *file, unsigned int cmd,
+			   unsigned long arg)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_FILE_IOCTL))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_FILE_IOCTL, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.file.cmd = cmd;
+	ep->CELL.file.in.file = file;
+	ep->CELL.file.in.pseudo_file = pseudo_filesystem(file_inode(file));
+
+	return dispatch_event(ep);
+}
+
+static int tsem_file_lock(struct file *file, unsigned int cmd)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_FILE_LOCK))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_FILE_LOCK, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.file.cmd = cmd;
+	ep->CELL.file.in.file = file;
+	ep->CELL.file.in.pseudo_file = pseudo_filesystem(file_inode(file));
+
+	return dispatch_event(ep);
+}
+
+static int tsem_file_fcntl(struct file *file, unsigned int cmd,
+			   unsigned long arg)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_FILE_FCNTL))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_FILE_FCNTL, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.file.cmd = cmd;
+	ep->CELL.file.in.file = file;
+	ep->CELL.file.in.pseudo_file = pseudo_filesystem(file_inode(file));
+
+	return dispatch_event(ep);
+}
+
+static int tsem_file_receive(struct file *file)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_FILE_RECEIVE))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_FILE_RECEIVE, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.file.in.file = file;
+	ep->CELL.file.in.pseudo_file = pseudo_filesystem(file_inode(file));
+
+	return dispatch_event(ep);
+}
+
+static int tsem_task_alloc(struct task_struct *new, unsigned long flags)
+{
+	struct tsem_task *old_task = tsem_task(current);
+	struct tsem_task *new_task = tsem_task(new);
+
+	new_task->instance = old_task->instance;
+	new_task->p_instance = old_task->instance;
+
+	new_task->trust_status = old_task->trust_status;
+	new_task->context = old_task->context;
+	memcpy(new_task->task_id, old_task->task_id, HASH_MAX_DIGESTSIZE);
+	memcpy(new_task->p_task_id, old_task->task_id, HASH_MAX_DIGESTSIZE);
+
+	if (!new_task->context->id)
+		return 0;
+
+	kref_get(&new_task->context->kref);
+	memcpy(new_task->task_key, old_task->task_key, HASH_MAX_DIGESTSIZE);
+	return 0;
+}
+
+static void tsem_task_free(struct task_struct *task)
+{
+	struct tsem_context *ctx = tsem_context(task);
+
+	if (ctx->id)
+		tsem_ns_put(ctx);
+}
+
+static int tsem_task_kill(struct task_struct *target,
+			  struct kernel_siginfo *info, int sig,
+			  const struct cred *cred)
+{
+	bool cross_model;
+	struct tsem_event *ep;
+	struct tsem_context *src_ctx = tsem_context(current);
+	struct tsem_context *tgt_ctx = tsem_context(target);
+
+	if (bypass_event(TSEM_TASK_KILL))
+		return 0;
+
+	cross_model = src_ctx->id != tgt_ctx->id;
+
+	if (info != SEND_SIG_NOINFO && SI_FROMKERNEL(info))
+		return 0;
+	if (sig == SIGURG)
+		return 0;
+	if (!capable(CAP_MAC_ADMIN) &&
+	    has_capability_noaudit(target, CAP_MAC_ADMIN))
+		return -EPERM;
+	if (!capable(CAP_MAC_ADMIN) && cross_model)
+		return -EPERM;
+
+	ep = tsem_event_allocate(TSEM_TASK_KILL, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.task_kill.signal = sig;
+	ep->CELL.task_kill.cross_model = cross_model;
+	memcpy(ep->CELL.task_kill.target, tsem_task(target)->task_id,
+	       tsem_digestsize());
+
+	return dispatch_event(ep);
+}
+
+static int tsem_ptrace_access_check(struct task_struct *child,
+				    unsigned int mode)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_PTRACE_ACCESS_CHECK))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_PTRACE_ACCESS_CHECK, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.task_kill.u.resource = mode;
+	memcpy(ep->CELL.task_kill.target, tsem_task(child)->task_id,
+	       tsem_digestsize());
+
+	return dispatch_event(ep);
+}
+
+static int tsem_ptrace_traceme(struct task_struct *parent)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_PTRACE_TRACEME))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_PTRACE_TRACEME, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	memcpy(ep->CELL.task_kill.source, tsem_task(parent)->task_id,
+	       tsem_digestsize());
+
+	return dispatch_event(ep);
+}
+
+static int tsem_capget(const struct task_struct *target,
+		       kernel_cap_t *effective, kernel_cap_t *inheritable,
+		       kernel_cap_t *permitted)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_CAPGET))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_CAPGET, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.capability.effective = *effective;
+	ep->CELL.capability.inheritable = *inheritable;
+	ep->CELL.capability.permitted = *permitted;
+	memcpy(ep->CELL.capability.target, tsem_task(target)->task_id,
+	       tsem_digestsize());
+
+	return dispatch_event(ep);
+}
+
+static int tsem_capset(struct cred *new, const struct cred *old,
+		       const kernel_cap_t *effective,
+		       const kernel_cap_t *inheritable,
+		       const kernel_cap_t *permitted)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_CAPSET))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_CAPSET, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.capability.effective = *effective;
+	ep->CELL.capability.inheritable = *inheritable;
+	ep->CELL.capability.permitted = *permitted;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_capable(const struct cred *cred, struct user_namespace *ns,
+			int cap, unsigned int opts)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_CAPABLE))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_CAPABLE, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.capability.cap = cap;
+	ep->CELL.capability.opts = opts;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_task_setpgid(struct task_struct *p, pid_t pgid)
+{
+	struct tsem_event *ep;
+	struct task_struct *src;
+
+	if (bypass_event(TSEM_TASK_SETPGID))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_TASK_SETPGID, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	memcpy(ep->CELL.task_kill.target, tsem_task(p)->task_id,
+	       tsem_digestsize());
+
+	if (!pgid)
+		memcpy(ep->CELL.task_kill.source, tsem_task(p)->task_id,
+		       tsem_digestsize());
+	else {
+		rcu_read_lock();
+		src = find_task_by_vpid(pgid);
+		rcu_read_unlock();
+		if (src)
+			memcpy(ep->CELL.task_kill.source,
+			       tsem_task(src)->task_id, tsem_digestsize());
+	}
+
+	return dispatch_event(ep);
+}
+
+static int tsem_task_getpgid(struct task_struct *p)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_TASK_GETPGID))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_TASK_GETPGID, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	memcpy(ep->CELL.task_kill.target, tsem_task(p)->task_id,
+	       tsem_digestsize());
+
+	return dispatch_event(ep);
+}
+
+static int tsem_task_getsid(struct task_struct *p)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_TASK_GETSID))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_TASK_GETSID, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	memcpy(ep->CELL.task_kill.target, tsem_task(p)->task_id,
+	       tsem_digestsize());
+
+	return dispatch_event(ep);
+}
+
+static int tsem_task_setnice(struct task_struct *p, int nice)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_TASK_SETNICE))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_TASK_SETNICE, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.task_kill.u.value = nice;
+	memcpy(ep->CELL.task_kill.target, tsem_task(p)->task_id,
+	       tsem_digestsize());
+
+	return dispatch_event(ep);
+}
+
+static int tsem_task_setioprio(struct task_struct *p, int ioprio)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_TASK_SETIOPRIO))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_TASK_SETIOPRIO, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.task_kill.u.value = ioprio;
+	memcpy(ep->CELL.task_kill.target, tsem_task(p)->task_id,
+	       tsem_digestsize());
+
+	return dispatch_event(ep);
+}
+
+static int tsem_task_getioprio(struct task_struct *p)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_TASK_GETIOPRIO))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_TASK_GETIOPRIO, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	memcpy(ep->CELL.task_kill.target, tsem_task(p)->task_id,
+	       tsem_digestsize());
+
+	return dispatch_event(ep);
+}
+
+static int tsem_task_prlimit(const struct cred *cred, const struct cred *tcred,
+			     unsigned int flags)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_TASK_PRLIMIT))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_TASK_PRLIMIT, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.task_prlimit.flags = flags;
+	ep->CELL.task_prlimit.in.cred = cred;
+	ep->CELL.task_prlimit.in.tcred = tcred;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_task_setrlimit(struct task_struct *p, unsigned int resource,
+			       struct rlimit *new_rlim)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_TASK_SETRLIMIT))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_TASK_SETRLIMIT, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.task_kill.u.resource = resource;
+	ep->CELL.task_kill.cur = new_rlim->rlim_cur;
+	ep->CELL.task_kill.max = new_rlim->rlim_max;
+	memcpy(ep->CELL.task_kill.target, tsem_task(p)->task_id,
+	       tsem_digestsize());
+
+	return dispatch_event(ep);
+}
+
+static int tsem_task_setscheduler(struct task_struct *p)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_TASK_SETSCHEDULER))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_TASK_SETSCHEDULER, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	memcpy(ep->CELL.task_kill.target, tsem_task(p)->task_id,
+	       tsem_digestsize());
+
+	return dispatch_event(ep);
+}
+
+static int tsem_task_getscheduler(struct task_struct *p)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_TASK_GETSCHEDULER))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_TASK_GETSCHEDULER, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	memcpy(ep->CELL.task_kill.target, tsem_task(p)->task_id,
+	       tsem_digestsize());
+
+	return dispatch_event(ep);
+}
+
+static int tsem_task_prctl(int option, unsigned long arg2, unsigned long arg3,
+			   unsigned long arg4, unsigned long arg5)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_TASK_PRCTL))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_TASK_PRCTL, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.task_prctl.option = option;
+	ep->CELL.task_prctl.arg2 = arg2;
+	ep->CELL.task_prctl.arg3 = arg3;
+	ep->CELL.task_prctl.arg4 = arg4;
+	ep->CELL.task_prctl.arg5 = arg5;
+
+	return dispatch_event(ep);
+}
+
+static void tsem_bprm_committed_creds(const struct linux_binprm *bprm)
+{
+	u8 task_id[HASH_MAX_DIGESTSIZE];
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return;
+
+	if (tsem_map_task(bprm->file, task_id))
+		memset(task_id, 0xff, sizeof(task_id));
+
+	tsem_task(current)->instance = atomic64_inc_return(&task_instance);
+	memcpy(tsem_task(current)->task_id, task_id, tsem_digestsize());
+}
+
+static int tsem_inode_alloc_security(struct inode *inode)
+{
+	struct tsem_inode *tsip = tsem_inode(inode);
+
+	mutex_init(&tsip->digest_mutex);
+	INIT_LIST_HEAD(&tsip->digest_list);
+
+	mutex_init(&tsip->create_mutex);
+	INIT_LIST_HEAD(&tsip->create_list);
+
+	mutex_init(&tsip->instance_mutex);
+	INIT_LIST_HEAD(&tsip->instance_list);
+
+	return 0;
+}
+
+static int tsem_inode_init_security(struct inode *inode, struct inode *dir,
+				    const struct qstr *qstr,
+				    struct xattr *xattrs, int *xattr_count)
+{
+	u8 *owner = tsem_task(current)->task_id;
+	struct tsem_inode *tsip = tsem_inode(inode);
+	struct tsem_inode_instance *entry, *retn = NULL;
+
+	mutex_lock(&tsem_inode(dir)->create_mutex);
+	list_for_each_entry(entry, &tsem_inode(dir)->create_list, list) {
+		if (!memcmp(entry->owner, owner, tsem_digestsize()) &&
+		    !strcmp(qstr->name, entry->pathname)) {
+			retn = entry;
+			break;
+		}
+	}
+
+	if (retn) {
+		tsip->created = true;
+		tsip->creator = retn->creator;
+		tsip->instance = retn->instance;
+		memcpy(tsip->owner, retn->owner, tsem_digestsize());
+		list_del(&retn->list);
+	}
+	mutex_unlock(&tsem_inode(dir)->create_mutex);
+
+	return -EOPNOTSUPP;
+}
+
+static void _release_inode_instances(u64 id, struct tsem_inode *tsip)
+{
+	struct tsem_inode_instance *owner, *tmp_owner;
+
+	mutex_lock(&tsip->instance_mutex);
+	list_for_each_entry_safe(owner, tmp_owner, &tsip->instance_list,
+				 list) {
+		if (id == owner->creator) {
+			list_del(&owner->list);
+			kfree(owner);
+		}
+	}
+	mutex_unlock(&tsip->instance_mutex);
+}
+
+static void tsem_inode_free_security(struct inode *inode)
+{
+	struct tsem_inode_instance *owner, *tmp_owner;
+	struct tsem_inode_digest *digest, *tmp_digest;
+	struct tsem_inode_entry *entry, *tmp_entry;
+	struct tsem_context *ctx = tsem_context(current);
+
+	mutex_lock(&ctx->inode_mutex);
+	list_for_each_entry_safe(entry, tmp_entry, &ctx->inode_list, list) {
+		if (entry->tsip == tsem_inode(inode)) {
+			list_del(&entry->list);
+			_release_inode_instances(ctx->id, entry->tsip);
+			kfree(entry);
+		}
+	}
+	mutex_unlock(&ctx->inode_mutex);
+
+	list_for_each_entry_safe(digest, tmp_digest,
+				 &tsem_inode(inode)->digest_list, list) {
+		list_del(&digest->list);
+		kfree(digest->name);
+		kfree(digest);
+	}
+
+	list_for_each_entry_safe(owner, tmp_owner,
+				 &tsem_inode(inode)->create_list, list) {
+		list_del(&owner->list);
+		kfree(owner);
+	}
+
+	list_for_each_entry_safe(owner, tmp_owner,
+				 &tsem_inode(inode)->instance_list, list) {
+		list_del(&owner->list);
+		kfree(owner);
+	}
+}
+
+static int tsem_unix_stream_connect(struct sock *sock, struct sock *other,
+				    struct sock *newsk)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_UNIX_STREAM_CONNECT))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_UNIX_STREAM_CONNECT, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.socket.in.socka = sock;
+	ep->CELL.socket.in.sockb = other;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_unix_may_send(struct socket *sock, struct socket *other)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_UNIX_MAY_SEND))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_UNIX_MAY_SEND, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.socket.in.socka = sock->sk;
+	ep->CELL.socket.in.sockb = other->sk;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_socket_post_create(struct socket *sock, int family, int type,
+				   int protocol, int kern)
+{
+	struct tsem_inode *tsip = tsem_inode(SOCK_INODE(sock));
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+
+	memcpy(tsip->owner, tsem_task(current)->task_id, tsem_digestsize());
+	return 0;
+}
+
+static int tsem_socket_create(int family, int type, int protocol, int kern)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_SOCKET_CREATE))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SOCKET_CREATE, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.socket.out.socka.family = family;
+	ep->CELL.socket.out.socka.type = type;
+	ep->CELL.socket.out.socka.protocol = protocol;
+	ep->CELL.socket.out.socka.kern = kern;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_socket_connect(struct socket *sock, struct sockaddr *addr,
+			     int addr_len)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SOCKET_CONNECT))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SOCKET_CONNECT, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.socket.in.socka = sock->sk;
+	ep->CELL.socket.in.addr = addr;
+	ep->CELL.socket.value = addr_len;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_socket_bind(struct socket *sock, struct sockaddr *addr,
+			    int addr_len)
+
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SOCKET_BIND))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SOCKET_BIND, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.socket.in.socka = sock->sk;
+	ep->CELL.socket.in.addr = addr;
+	ep->CELL.socket.value = addr_len;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_socket_accept(struct socket *sock, struct socket *newsock)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SOCKET_ACCEPT))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SOCKET_ACCEPT, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.socket.in.socka = sock->sk;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_socket_listen(struct socket *sock, int backlog)
+
+{
+	struct sock *sk = sock->sk;
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SOCKET_LISTEN))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SOCKET_LISTEN, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.socket.value = backlog;
+	ep->CELL.socket.in.socka = sk;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_socket_socketpair(struct socket *socka, struct socket *sockb)
+{
+	struct sock *ska = socka->sk, *skb = sockb->sk;
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SOCKET_SOCKETPAIR))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SOCKET_SOCKETPAIR, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.socket.in.socka = ska;
+	ep->CELL.socket.in.sockb = skb;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_socket_sendmsg(struct socket *sock, struct msghdr *msgmsg,
+			       int size)
+{
+	struct sock *sk = sock->sk;
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SOCKET_SENDMSG))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SOCKET_SENDMSG, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.socket.in.socka = sk;
+	ep->CELL.socket.in.addr = msgmsg->msg_name;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_socket_recvmsg(struct socket *sock, struct msghdr *msgmsg,
+			       int size, int flags)
+{
+	struct sock *sk = sock->sk;
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SOCKET_RECVMSG))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SOCKET_RECVMSG, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.socket.in.socka = sk;
+	if (msgmsg->msg_name && msgmsg->msg_namelen > 0)
+		ep->CELL.socket.in.addr = msgmsg->msg_name;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_socket_getsockname(struct socket *sock)
+{
+	struct sock *sk = sock->sk;
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SOCKET_GETSOCKNAME))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SOCKET_GETSOCKNAME, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.socket.in.socka = sk;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_socket_getpeername(struct socket *sock)
+{
+	struct sock *sk = sock->sk;
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SOCKET_GETPEERNAME))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SOCKET_GETPEERNAME, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.socket.in.socka = sk;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_socket_setsockopt(struct socket *sock, int level, int optname)
+{
+	struct sock *sk = sock->sk;
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SOCKET_SETSOCKOPT))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SOCKET_SETSOCKOPT, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.socket.value = level;
+	ep->CELL.socket.optname = optname;
+	ep->CELL.socket.in.socka = sk;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_socket_shutdown(struct socket *sock, int how)
+{
+	struct sock *sk = sock->sk;
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SOCKET_SHUTDOWN))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SOCKET_SHUTDOWN, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.socket.value = how;
+	ep->CELL.socket.in.socka = sk;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_kernel_module_request(char *kmod_name)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_KERNEL_MODULE_REQUEST))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_KERNEL_MODULE_REQUEST, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.kernel.in.kmod_name = kmod_name;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_kernel_load_data(enum kernel_load_data_id id, bool contents)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_KERNEL_LOAD_DATA))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_KERNEL_LOAD_DATA, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.kernel.id = id;
+	ep->CELL.kernel.contents = contents;
+
+	return dispatch_event(ep);
+}
+
+
+static int tsem_kernel_read_file(struct file *file,
+				 enum kernel_read_file_id id, bool contents)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_KERNEL_READ_FILE))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_KERNEL_READ_FILE, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.kernel.id = id;
+	ep->CELL.kernel.contents = contents;
+	ep->CELL.kernel.in.file = file;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_sb_mount(const char *dev_name, const struct path *path,
+			 const char *type, unsigned long flags, void *data)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_SB_MOUNT))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SB_MOUNT, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.sb.flags = flags;
+	ep->CELL.sb.in.dev_name = dev_name;
+	ep->CELL.sb.in.path = path;
+	ep->CELL.sb.in.type = type;
+
+	return dispatch_event(ep);
+}
+
+static	int tsem_sb_umount(struct vfsmount *mnt, int flags)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SB_UMOUNT))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SB_UMOUNT, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.sb.flags = flags;
+	ep->CELL.sb.in.dentry = mnt->mnt_root;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_sb_remount(struct super_block *sb, void *mnt_opts)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_SB_REMOUNT))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SB_REMOUNT, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.sb.in.sb = sb;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_sb_pivotroot(const struct path *old_path,
+			     const struct path *new_path)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SB_PIVOTROOT))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SB_PIVOTROOT, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.sb.in.path = old_path;
+	ep->CELL.sb.in.path2 = new_path;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_sb_statfs(struct dentry *dentry)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SB_STATFS))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SB_STATFS, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.sb.in.dentry = dentry;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_move_mount(const struct path *from_path,
+			   const struct path *to_path)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_MOVE_MOUNT))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_MOVE_MOUNT, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.sb.in.path = from_path;
+	ep->CELL.sb.in.path2 = to_path;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_shm_associate(struct kern_ipc_perm *perm, int shmflg)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SHM_ASSOCIATE))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SHM_ASSOCIATE, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.ipc.in.perm = perm;
+	ep->CELL.ipc.value = shmflg;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_shm_shmctl(struct kern_ipc_perm *perm, int cmd)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SHM_SHMCTL))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SHM_SHMCTL, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.ipc.in.perm = perm;
+	ep->CELL.ipc.value = cmd;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_shm_shmat(struct kern_ipc_perm *perm, char __user *shmaddr,
+			  int shmflg)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SHM_SHMAT))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SHM_SHMAT, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.ipc.in.perm = perm;
+	ep->CELL.ipc.value = shmflg;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_sem_associate(struct kern_ipc_perm *perm, int semflg)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SEM_ASSOCIATE))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SEM_ASSOCIATE, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.ipc.in.perm = perm;
+	ep->CELL.ipc.value = semflg;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_sem_semctl(struct kern_ipc_perm *perm, int cmd)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SEM_SEMCTL))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SEM_SEMCTL, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.ipc.in.perm = perm;
+	ep->CELL.ipc.value = cmd;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_sem_semop(struct kern_ipc_perm *perm, struct sembuf *sops,
+			  unsigned int nsops, int alter)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SEM_SEMOP))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SEM_SEMOP, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.ipc.in.perm = perm;
+	ep->CELL.ipc.nsops = nsops;
+	ep->CELL.ipc.value = alter;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_syslog(int type)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SYSLOG))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SYSLOG, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.value = type;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_settime(const struct timespec64 *ts, const struct timezone *tz)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_SETTIME))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_SETTIME, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	if (ts) {
+		ep->CELL.time.have_ts = true;
+		ep->CELL.time.seconds = ts->tv_sec;
+		ep->CELL.time.nsecs = ts->tv_nsec;
+	}
+	if (tz) {
+		ep->CELL.time.have_tz = true;
+		ep->CELL.time.minuteswest = tz->tz_minuteswest;
+		ep->CELL.time.dsttime = tz->tz_dsttime;
+	}
+
+	return dispatch_event(ep);
+}
+
+static int tsem_quotactl(int cmds, int type, int id,
+			 const struct super_block *sb)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_QUOTACTL))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_QUOTACTL, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.quota.cmds = cmds;
+	ep->CELL.quota.type = type;
+	ep->CELL.quota.id = id;
+	ep->CELL.quota.in.sb = sb;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_quota_on(struct dentry *dentry)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_QUOTA_ON))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_QUOTA_ON, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.quota.in.dentry = dentry;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_msg_queue_associate(struct kern_ipc_perm *perm, int msqflg)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_MSG_QUEUE_ASSOCIATE))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_MSG_QUEUE_ASSOCIATE, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.ipc.in.perm = perm;
+	ep->CELL.ipc.value = msqflg;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_msg_queue_msgsnd(struct kern_ipc_perm *perm,
+				 struct msg_msg *msgmsg, int msqflg)
+
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_MSG_QUEUE_MSGSND))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_MSG_QUEUE_MSGSND, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.ipc.in.perm = perm;
+	ep->CELL.ipc.value = msqflg;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_msg_queue_msgctl(struct kern_ipc_perm *perm, int cmd)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_MSG_QUEUE_MSGCTL))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_MSG_QUEUE_MSGCTL, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.ipc.in.perm = perm;
+	ep->CELL.ipc.value = cmd;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_msg_queue_msgrcv(struct kern_ipc_perm *perm,
+				 struct msg_msg *msgmsg,
+				 struct task_struct *target, long type,
+				 int mode)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_MSG_QUEUE_MSGRCV))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_MSG_QUEUE_MSGRCV, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.ipc.in.perm = perm;
+	ep->CELL.ipc.in.target = target;
+	ep->CELL.ipc.type = type;
+	ep->CELL.ipc.value = mode;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_ipc_alloc(struct kern_ipc_perm *kipc)
+{
+	struct tsem_ipc *tipc = tsem_ipc(kipc);
+
+	memcpy(tipc->owner, tsem_task(current)->task_id, tsem_digestsize());
+	return 0;
+}
+
+static int tsem_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_IPC_PERMISSION))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_IPC_PERMISSION, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.ipc.perm_flag = flag;
+	ep->CELL.ipc.in.perm = ipcp;
+
+	return dispatch_event(ep);
+}
+
+#ifdef CONFIG_KEYS
+static int tsem_key_alloc(struct key *key, const struct cred *cred,
+			  unsigned long flags)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_KEY_ALLOC))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_KEY_ALLOC, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.key.flags = flags;
+	ep->CELL.key.in.cred = cred;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_key_permission(key_ref_t key_ref, const struct cred *cred,
+			       unsigned int perm)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_KEY_PERMISSION))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_KEY_PERMISSION, LOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.key.flags = perm;
+	ep->CELL.key.in.cred = cred;
+	ep->CELL.key.in.ref = key_ref;
+
+	return dispatch_event(ep);
+}
+#endif
+
+static int tsem_netlink_send(struct sock *sk, struct sk_buff *skb)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_NETLINK_SEND))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_NETLINK_SEND, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.netlink.in.sock = sk;
+	ep->CELL.netlink.in.parms = (struct netlink_skb_parms *) skb->cb;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_inode_create(struct inode *dir, struct dentry *dentry,
+			     umode_t mode)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_INODE_CREATE))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_INODE_CREATE, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.inode.in.dir = dir;
+	ep->CELL.inode.in.dentry = dentry;
+	ep->CELL.inode.mode = mode;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_inode_link(struct dentry *old_dentry, struct inode *dir,
+			   struct dentry *new_dentry)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_INODE_LINK))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_INODE_LINK, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.inode.in.dir = dir;
+	ep->CELL.inode.in.dentry = old_dentry;
+	ep->CELL.inode.in.new_dentry = new_dentry;
+	ep->CELL.inode.mode = 0;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_inode_unlink(struct inode *dir, struct dentry *dentry)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_INODE_UNLINK))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_INODE_UNLINK, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.inode.in.dir = dir;
+	ep->CELL.inode.in.dentry = dentry;
+	ep->CELL.inode.mode = 0;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_inode_symlink(struct inode *dir, struct dentry *dentry,
+			      const char *old_name)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_INODE_SYMLINK))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_INODE_SYMLINK, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.inode.in.dir = dir;
+	ep->CELL.inode.in.dentry = dentry;
+	ep->CELL.inode.in.old_name = old_name;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_inode_mkdir(struct inode *dir, struct dentry *dentry,
+			    umode_t mode)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_INODE_MKDIR))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_INODE_MKDIR, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.inode.in.dir = dir;
+	ep->CELL.inode.in.dentry = dentry;
+	ep->CELL.inode.mode = mode;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_inode_rmdir(struct inode *dir, struct dentry *dentry)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_INODE_RMDIR))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_INODE_RMDIR, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.inode.in.dir = dir;
+	ep->CELL.inode.in.dentry = dentry;
+	ep->CELL.inode.mode = 0;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
+			     struct inode *new_dir, struct dentry *new_dentry)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_INODE_RENAME))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_INODE_RENAME, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.inode.in.dir = old_dir;
+	ep->CELL.inode.in.new_dir = new_dir;
+	ep->CELL.inode.in.dentry = old_dentry;
+	ep->CELL.inode.in.new_dentry = new_dentry;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_inode_mknod(struct inode *dir, struct dentry *dentry,
+			    umode_t mode, dev_t dev)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_INODE_MKNOD))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_INODE_MKNOD, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.inode.in.dir = dir;
+	ep->CELL.inode.in.dentry = dentry;
+	ep->CELL.inode.mode = mode;
+	ep->CELL.inode.dev = dev;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
+			      struct iattr *attr)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_INODE_SETATTR))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_INODE_SETATTR, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.inode_attr.in.dentry = dentry;
+	ep->CELL.inode_attr.in.iattr = attr;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_inode_getattr(const struct path *path)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_INODE_GETATTR))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_INODE_GETATTR, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.inode_attr.in.path = path;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_inode_setxattr(struct mnt_idmap *idmap,
+			       struct dentry *dentry, const char *name,
+			       const void *value, size_t size, int flags)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_INODE_SETXATTR))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_INODE_SETXATTR, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.inode_xattr.in.dentry = dentry;
+	ep->CELL.inode_xattr.in.name = name;
+	ep->CELL.inode_xattr.in.value = value;
+	ep->CELL.inode_xattr.in.size = size;
+	ep->CELL.inode_xattr.in.flags = flags;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_inode_getxattr(struct dentry *dentry, const char *name)
+{
+	struct tsem_event *ep = NULL;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_INODE_GETXATTR))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_INODE_GETXATTR, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.inode_xattr.in.dentry = dentry;
+	ep->CELL.inode_xattr.in.name = name;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_inode_listxattr(struct dentry *dentry)
+{
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_INODE_LISTXATTR))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_INODE_LISTXATTR, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.inode_xattr.in.dentry = dentry;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_inode_removexattr(struct mnt_idmap *idmap,
+				  struct dentry *dentry, const char *name)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_INODE_REMOVEXATTR))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_INODE_REMOVEXATTR, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.inode_xattr.in.dentry = dentry;
+	ep->CELL.inode_xattr.in.name = name;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_inode_killpriv(struct mnt_idmap *idmap,
+			       struct dentry *dentry)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_INODE_KILLPRIV))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_INODE_KILLPRIV, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.inode.in.dentry = dentry;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_tun_dev_create(void)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_TUN_DEV_CREATE))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_TUN_DEV_CREATE, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+	ep->no_params = true;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_tun_dev_attach_queue(void *security)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_TUN_DEV_ATTACH_QUEUE))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_TUN_DEV_ATTACH_QUEUE, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+	ep->no_params = true;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_tun_dev_attach(struct sock *sk, void *security)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_TUN_DEV_ATTACH))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_TUN_DEV_ATTACH, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.socket.in.socka = sk;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_tun_dev_open(void *security)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_TUN_DEV_OPEN))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_TUN_DEV_OPEN, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+	ep->no_params = true;
+
+	return dispatch_event(ep);
+}
+
+#ifdef CONFIG_BPF_SYSCALL
+static int tsem_bpf(int cmd, union bpf_attr *attr, unsigned int size)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_BPF))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_BPF, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.bpf.bpf.cmd = cmd;
+	ep->CELL.bpf.bpf.size = size;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_bpf_map(struct bpf_map *map, fmode_t fmode)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_BPF_MAP))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_BPF_MAP, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.bpf.map.fmode = fmode;
+	ep->CELL.bpf.map.map_type = map->map_type;
+
+	return dispatch_event(ep);
+}
+
+static int tsem_bpf_prog(struct bpf_prog *prog)
+{
+	struct tsem_event *ep;
+
+	if (bypass_event(TSEM_BPF_PROG))
+		return 0;
+
+	ep = tsem_event_allocate(TSEM_BPF_PROG, NOLOCK);
+	if (!ep)
+		return -ENOMEM;
+
+	ep->CELL.bpf.prog.type = prog->type;
+	ep->CELL.bpf.prog.attach_type = prog->expected_attach_type;
+
+	return dispatch_event(ep);
+}
+#endif
+
+static struct security_hook_list tsem_hooks[] __ro_after_init = {
+	LSM_HOOK_INIT(task_alloc, tsem_task_alloc),
+	LSM_HOOK_INIT(task_free, tsem_task_free),
+	LSM_HOOK_INIT(task_kill, tsem_task_kill),
+	LSM_HOOK_INIT(task_setpgid, tsem_task_setpgid),
+	LSM_HOOK_INIT(task_getpgid, tsem_task_getpgid),
+	LSM_HOOK_INIT(task_getsid, tsem_task_getsid),
+	LSM_HOOK_INIT(task_setnice, tsem_task_setnice),
+	LSM_HOOK_INIT(task_setioprio, tsem_task_setioprio),
+	LSM_HOOK_INIT(task_getioprio, tsem_task_getioprio),
+	LSM_HOOK_INIT(task_prlimit, tsem_task_prlimit),
+	LSM_HOOK_INIT(task_setrlimit, tsem_task_setrlimit),
+	LSM_HOOK_INIT(task_setscheduler, tsem_task_setscheduler),
+	LSM_HOOK_INIT(task_getscheduler, tsem_task_getscheduler),
+	LSM_HOOK_INIT(task_prctl, tsem_task_prctl),
+
+	LSM_HOOK_INIT(ptrace_access_check, tsem_ptrace_access_check),
+	LSM_HOOK_INIT(ptrace_traceme, tsem_ptrace_traceme),
+
+	LSM_HOOK_INIT(capget, tsem_capget),
+	LSM_HOOK_INIT(capset, tsem_capset),
+	LSM_HOOK_INIT(capable, tsem_capable),
+
+	LSM_HOOK_INIT(bprm_committed_creds, tsem_bprm_committed_creds),
+
+	LSM_HOOK_INIT(inode_alloc_security, tsem_inode_alloc_security),
+	LSM_HOOK_INIT(inode_init_security, tsem_inode_init_security),
+	LSM_HOOK_INIT(inode_free_security, tsem_inode_free_security),
+
+	LSM_HOOK_INIT(file_open, tsem_file_open),
+	LSM_HOOK_INIT(mmap_file, tsem_mmap_file),
+	LSM_HOOK_INIT(file_ioctl, tsem_file_ioctl),
+	LSM_HOOK_INIT(file_lock, tsem_file_lock),
+	LSM_HOOK_INIT(file_fcntl, tsem_file_fcntl),
+	LSM_HOOK_INIT(file_receive, tsem_file_receive),
+
+	LSM_HOOK_INIT(unix_stream_connect, tsem_unix_stream_connect),
+	LSM_HOOK_INIT(unix_may_send, tsem_unix_may_send),
+
+	LSM_HOOK_INIT(socket_post_create, tsem_socket_post_create),
+	LSM_HOOK_INIT(socket_create, tsem_socket_create),
+	LSM_HOOK_INIT(socket_connect, tsem_socket_connect),
+	LSM_HOOK_INIT(socket_bind, tsem_socket_bind),
+	LSM_HOOK_INIT(socket_accept, tsem_socket_accept),
+	LSM_HOOK_INIT(socket_listen, tsem_socket_listen),
+	LSM_HOOK_INIT(socket_socketpair, tsem_socket_socketpair),
+	LSM_HOOK_INIT(socket_sendmsg, tsem_socket_sendmsg),
+	LSM_HOOK_INIT(socket_recvmsg, tsem_socket_recvmsg),
+	LSM_HOOK_INIT(socket_getsockname, tsem_socket_getsockname),
+	LSM_HOOK_INIT(socket_getpeername, tsem_socket_getpeername),
+	LSM_HOOK_INIT(socket_setsockopt, tsem_socket_setsockopt),
+	LSM_HOOK_INIT(socket_shutdown, tsem_socket_shutdown),
+
+	LSM_HOOK_INIT(kernel_module_request, tsem_kernel_module_request),
+	LSM_HOOK_INIT(kernel_load_data, tsem_kernel_load_data),
+	LSM_HOOK_INIT(kernel_read_file, tsem_kernel_read_file),
+
+	LSM_HOOK_INIT(sb_mount, tsem_sb_mount),
+	LSM_HOOK_INIT(sb_umount, tsem_sb_umount),
+	LSM_HOOK_INIT(sb_remount, tsem_sb_remount),
+	LSM_HOOK_INIT(sb_pivotroot, tsem_sb_pivotroot),
+	LSM_HOOK_INIT(sb_statfs, tsem_sb_statfs),
+	LSM_HOOK_INIT(move_mount, tsem_move_mount),
+
+	LSM_HOOK_INIT(shm_alloc_security, tsem_ipc_alloc),
+	LSM_HOOK_INIT(shm_associate, tsem_shm_associate),
+	LSM_HOOK_INIT(shm_shmctl, tsem_shm_shmctl),
+	LSM_HOOK_INIT(shm_shmat, tsem_shm_shmat),
+
+	LSM_HOOK_INIT(sem_alloc_security, tsem_ipc_alloc),
+	LSM_HOOK_INIT(sem_associate, tsem_sem_associate),
+	LSM_HOOK_INIT(sem_semctl, tsem_sem_semctl),
+	LSM_HOOK_INIT(sem_semop, tsem_sem_semop),
+
+	LSM_HOOK_INIT(syslog, tsem_syslog),
+	LSM_HOOK_INIT(settime, tsem_settime),
+
+	LSM_HOOK_INIT(quotactl, tsem_quotactl),
+	LSM_HOOK_INIT(quota_on, tsem_quota_on),
+
+	LSM_HOOK_INIT(msg_queue_alloc_security, tsem_ipc_alloc),
+	LSM_HOOK_INIT(msg_queue_associate, tsem_msg_queue_associate),
+	LSM_HOOK_INIT(msg_queue_msgctl, tsem_msg_queue_msgctl),
+	LSM_HOOK_INIT(msg_queue_msgsnd, tsem_msg_queue_msgsnd),
+	LSM_HOOK_INIT(msg_queue_msgrcv, tsem_msg_queue_msgrcv),
+
+	LSM_HOOK_INIT(ipc_permission, tsem_ipc_permission),
+
+#ifdef CONFIG_KEYS
+	LSM_HOOK_INIT(key_alloc, tsem_key_alloc),
+	LSM_HOOK_INIT(key_permission, tsem_key_permission),
+#endif
+
+	LSM_HOOK_INIT(netlink_send, tsem_netlink_send),
+
+	LSM_HOOK_INIT(inode_create, tsem_inode_create),
+	LSM_HOOK_INIT(inode_link, tsem_inode_link),
+	LSM_HOOK_INIT(inode_unlink, tsem_inode_unlink),
+	LSM_HOOK_INIT(inode_symlink, tsem_inode_symlink),
+	LSM_HOOK_INIT(inode_mkdir, tsem_inode_mkdir),
+	LSM_HOOK_INIT(inode_rmdir, tsem_inode_rmdir),
+	LSM_HOOK_INIT(inode_mknod, tsem_inode_mknod),
+	LSM_HOOK_INIT(inode_rename, tsem_inode_rename),
+	LSM_HOOK_INIT(inode_setattr, tsem_inode_setattr),
+	LSM_HOOK_INIT(inode_getattr, tsem_inode_getattr),
+	LSM_HOOK_INIT(inode_setxattr, tsem_inode_setxattr),
+	LSM_HOOK_INIT(inode_getxattr, tsem_inode_getxattr),
+	LSM_HOOK_INIT(inode_listxattr, tsem_inode_listxattr),
+	LSM_HOOK_INIT(inode_removexattr, tsem_inode_removexattr),
+	LSM_HOOK_INIT(inode_killpriv, tsem_inode_killpriv),
+
+	LSM_HOOK_INIT(tun_dev_create, tsem_tun_dev_create),
+	LSM_HOOK_INIT(tun_dev_attach_queue, tsem_tun_dev_attach_queue),
+	LSM_HOOK_INIT(tun_dev_attach, tsem_tun_dev_attach),
+	LSM_HOOK_INIT(tun_dev_open, tsem_tun_dev_open),
+
+#ifdef CONFIG_BPF_SYSCALL
+	LSM_HOOK_INIT(bpf, tsem_bpf),
+	LSM_HOOK_INIT(bpf_map, tsem_bpf_map),
+	LSM_HOOK_INIT(bpf_prog, tsem_bpf_prog)
+#endif
+};
+
+static int configure_root_digest(void)
+{
+	int retn = 0;
+	char *digest = NULL;
+	u8 zero_digest[HASH_MAX_DIGESTSIZE];
+	struct crypto_shash *tfm;
+	SHASH_DESC_ON_STACK(shash, tfm);
+
+	if (default_hash_function && crypto_has_shash(default_hash_function,
+						      0, 0)) {
+		digest = default_hash_function;
+		pr_warn("tsem: Using digest %s from command-line.\n", digest);
+	}
+	if (!digest && default_hash_function)
+		pr_warn("tsem: Unknown root digest %s, using sha256.\n",
+			default_hash_function);
+	if (!digest)
+		digest = "sha256";
+
+	tsem_context(current)->digestname = kstrdup(digest, GFP_KERNEL);
+	if (!tsem_context(current)->digestname)
+		return -ENOMEM;
+
+	tfm = crypto_alloc_shash(digest, 0, 0);
+	if (IS_ERR(tfm))
+		return PTR_ERR(tfm);
+
+	shash->tfm = tfm;
+	retn = crypto_shash_digest(shash, NULL, 0, zero_digest);
+	if (retn)
+		goto done;
+
+	tsem_context(current)->tfm = tfm;
+	memcpy(root_context.zero_digest, zero_digest,
+	       crypto_shash_digestsize(tfm));
+
+ done:
+	if (retn) {
+		kfree(tsem_context(current)->digestname);
+		crypto_free_shash(tfm);
+	}
+
+	return retn;
+}
+
+static int __init set_ready(void)
+{
+	int retn;
+
+	if (!tsem_available)
+		return 0;
+
+	retn = configure_root_digest();
+	if (retn)
+		goto done;
+
+	retn = tsem_model_add_aggregate();
+	if (retn)
+		goto done;
+
+	retn = tsem_fs_init();
+	if (retn)
+		goto done;
+
+	if (tsem_mode == ROOT_EXPORT_ONLY) {
+		retn = tsem_ns_export_root(magazine_size);
+		if (retn)
+			goto done;
+	}
+
+	pr_info("tsem: Now active.\n");
+	static_branch_disable(&tsem_not_ready);
+
+ done:
+	return retn;
+}
+
+late_initcall(set_ready);
+
+/**
+ * tesm_init() - Register Trusted Security Event Modeling LSM.
+ *
+ * This function is responsible for initializing the TSEM LSM.  It is
+ * invoked at the fs_initcall level.  In addition to configuring the
+ * LSM hooks this function initializes the Trusted Modeling Agent
+ * context including the event actions.  The cache from which
+ * the tsem_event description structures is also initialized.
+ *
+ * Return: If the TSEM LSM is successfully initialized a value of zero
+ *	   is returned.  A non-zero error code is returned if
+ *	   initialization fails.  Currently the only failure mode can
+ *	   come from the initialization of the tsem_event cache.
+ */
+static int __init tsem_init(void)
+{
+	int retn;
+	char *msg;
+	struct tsem_task *tsk = tsem_task(current);
+	struct tsem_context *ctx = &root_context;
+	struct tsem_model *model = &root_model;
+
+	security_add_hooks(tsem_hooks, ARRAY_SIZE(tsem_hooks), &tsem_lsmid);
+
+	tsk->context = ctx;
+	kref_init(&ctx->kref);
+	kref_get(&ctx->kref);
+
+	mutex_init(&ctx->inode_mutex);
+	INIT_LIST_HEAD(&ctx->inode_list);
+
+	root_context.ops = &tsem_model0_ops;
+	root_context.model = &root_model;
+
+	retn = tsem_event_cache_init();
+	if (retn)
+		return retn;
+
+	retn = tsem_model_cache_init(model, magazine_size);
+	if (retn)
+		goto done;
+
+	retn = tsem_export_cache_init();
+	if (retn)
+		goto done;
+
+	retn = tsem_event_magazine_allocate(ctx, magazine_size);
+	if (retn)
+		goto done;
+	memcpy(ctx->actions, tsem_root_actions, sizeof(tsem_root_actions));
+
+	switch (tsem_mode) {
+	case FULL_MODELING:
+		msg = "full modeling";
+		break;
+	case NO_ROOT_MODELING:
+		msg = "namespace only modeling";
+		break;
+	case ROOT_EXPORT_ONLY:
+		msg = "root export only";
+		break;
+	}
+	pr_info("tsem: Initialized %s.\n", msg);
+
+	tsem_available = true;
+	tsk->trust_status = TSEM_TASK_TRUSTED;
+	retn = 0;
+
+ done:
+	if (retn) {
+		tsem_event_magazine_free(ctx);
+		tsem_model_magazine_free(model);
+	}
+	return retn;
+}
+
+DEFINE_LSM(tsem) = {
+	.name = "tsem",
+	.init = tsem_init,
+	.blobs = &tsem_blob_sizes,
+};
Signature · 1 line
2.39.1
#28 lore raw

Re: [PATCH v4 04/14] Add primary TSEM implementation file.

Quoted 68 lines · Greg Wettstein

The tsem.c file is the 'master' file in the TSEM implementation. It is responsible for initializing the LSM and providing the implementation of the security event handlers.

---
 security/tsem/tsem.c | 2446 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 2446 insertions(+)
 create mode 100644 security/tsem/tsem.c
security/tsem/tsem.c new file +54 -0
new file mode 100644
index 000000000000..76d65b3e62b3
@@ -0,0 +1,2446 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/*
+ * Copyright (C) 2024 Enjellic Systems Development, LLC
+ * Author: Dr. Greg Wettstein <[email protected]>
+ *
+ * This file is the primary implementation file for the tsem LSM.
+ *
+ * It implements initialization and setup functions that interpret
+ * kernel command-line arguments and prepares TSEM for operation.
+ *
+ * In addition it contains all of the TSEM specific security event
+ * handlers that are responsible for handling the LSM events that TSEM
+ * models.
+ *
+ * Each TSEM event handler calls the tsem_allocate_event() function to
+ * allocate a structure that will be used to describe the event.  The
+ * CELL union of this structure contains various structures that are
+ * used to hold these parameters.
+ *
+ * Since the event characterization parameters need to be retained for
+ * the lifetime of the tsem_event structure that is allocated.  In the
+ * case of internally modeled namespaces this lifespan is the lifetime
+ * of the security modeling namespace.  In the case of externally
+ * modeled namespaces, the lifespan is until the security event
+ * description is exported to an external trust orchestrator.
+ *
+ * In order to support this model, the event description structures
+ * are typically composed of a union over 'in' and 'out' structures.
+ * The 'in' structures are used to hold arguments to the event handler
+ * that may only be relevant for the duration of the call.  These
+ * values are translated into members of the 'out' structure that
+ * retain the values until the end of the lifetime of the tsem_event
+ * structure.
+ *
+ * Each TSEM event handler is responsible for allocating a tsem_event
+ * structure and populating the appropriate CELL structure with the
+ * input characteristics of the event.  The dispatch_event() function
+ * is called to handle the modeling of the event.  This function
+ * returns the permission value that is returned as the result of the
+ * LSM event handler.
+ *
+ * The dispatch_event() calls the tsem_event_init() function that is
+ * responsible for translating the input parameters into values that
+ * will be retained for the lifetime of the security event
+ * description.  The populated event description is then dispatched to
+ * either the tsem_model_event() or the tsem_export_event() for
+ * modeling by either the internal TMA or by a TMA associated with an
+ * external trust orchestrator.
+ */
+
+ ...
+
+static int tsem_file_open(struct file *file)

security/tsem/tsem.c line 64

Quoted 10 lines
security/tsem/tsem.c new file +10 -0
+{
+	struct inode *inode = file_inode(file);
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_FILE_OPEN))
+		return 0;
+	if (unlikely(tsem_inode(inode)->status == TSEM_INODE_CONTROL_PLANE)) {
+		if (capable(CAP_MAC_ADMIN))

Don't you mean CAP_MAC_OVERRIDE? CAP_MAC_ADMIN is for changes to the security state of the system, where CAP_MAC_OVERRIDE is for access control decision exceptions. Here (and elsewhere) you use the former in access checks.

author
#29 lore raw

Re: [PATCH v4 04/14] Add primary TSEM implementation file.

On Mon, Aug 26, 2024 at 08:53:31AM -0700, Casey Schaufler wrote:

Good morning Casey, I hope this note finds your day starting well.

Greetings to others on this 'last' week of summer.

Quoted 76 lines · Greg Wettstein
Quoted 75 lines

The tsem.c file is the 'master' file in the TSEM implementation. It is responsible for initializing the LSM and providing the implementation of the security event handlers.

---
 security/tsem/tsem.c | 2446 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 2446 insertions(+)
 create mode 100644 security/tsem/tsem.c
security/tsem/tsem.c new file +61 -0
new file mode 100644
index 000000000000..76d65b3e62b3
@@ -0,0 +1,2446 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/*
+ * Copyright (C) 2024 Enjellic Systems Development, LLC
+ * Author: Dr. Greg Wettstein <[email protected]>
+ *
+ * This file is the primary implementation file for the tsem LSM.
+ *
+ * It implements initialization and setup functions that interpret
+ * kernel command-line arguments and prepares TSEM for operation.
+ *
+ * In addition it contains all of the TSEM specific security event
+ * handlers that are responsible for handling the LSM events that TSEM
+ * models.
+ *
+ * Each TSEM event handler calls the tsem_allocate_event() function to
+ * allocate a structure that will be used to describe the event.  The
+ * CELL union of this structure contains various structures that are
+ * used to hold these parameters.
+ *
+ * Since the event characterization parameters need to be retained for
+ * the lifetime of the tsem_event structure that is allocated.  In the
+ * case of internally modeled namespaces this lifespan is the lifetime
+ * of the security modeling namespace.  In the case of externally
+ * modeled namespaces, the lifespan is until the security event
+ * description is exported to an external trust orchestrator.
+ *
+ * In order to support this model, the event description structures
+ * are typically composed of a union over 'in' and 'out' structures.
+ * The 'in' structures are used to hold arguments to the event handler
+ * that may only be relevant for the duration of the call.  These
+ * values are translated into members of the 'out' structure that
+ * retain the values until the end of the lifetime of the tsem_event
+ * structure.
+ *
+ * Each TSEM event handler is responsible for allocating a tsem_event
+ * structure and populating the appropriate CELL structure with the
+ * input characteristics of the event.  The dispatch_event() function
+ * is called to handle the modeling of the event.  This function
+ * returns the permission value that is returned as the result of the
+ * LSM event handler.
+ *
+ * The dispatch_event() calls the tsem_event_init() function that is
+ * responsible for translating the input parameters into values that
+ * will be retained for the lifetime of the security event
+ * description.  The populated event description is then dispatched to
+ * either the tsem_model_event() or the tsem_export_event() for
+ * modeling by either the internal TMA or by a TMA associated with an
+ * external trust orchestrator.
+ */
+
+ ...
+
+static int tsem_file_open(struct file *file)
+{
+	struct inode *inode = file_inode(file);
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
+	if (bypass_event(TSEM_FILE_OPEN))
Quoted 8 lines

security/tsem/tsem.c line 361

Quoted 3 lines
security/tsem/tsem.c new file +3 -0
+		return 0;
+	if (unlikely(tsem_inode(inode)->status == TSEM_INODE_CONTROL_PLANE)) {
+		if (capable(CAP_MAC_ADMIN))

Don't you mean CAP_MAC_OVERRIDE? CAP_MAC_ADMIN is for changes to the security state of the system, where CAP_MAC_OVERRIDE is for access control decision exceptions. Here (and elsewhere) you use the former in access checks.

You are clearly the mechanistic expert on capabilities so we would take your lead on this.

Some background information to hopefully assist in a discussion on the types of capability checks that should be implemented.

The capability checks we apply in TSEM gate the following five types of actions:

1.) The ability to issue TSEM control commands.

2.) The ability to register an event processing module.

3.) Access to state information on kernel based modeling agent instances.

4.) The ability to send signals to trust orchestration processes.

5.) The ability to send a signal to a different security modeling namespace.

If we understand the differentiation that you suggest between CAP_MAC_ADMIN and CAP_MAC_OVERRIDE we would conclude the following:

Checks 1, 2 and 4 would seem, in our opinion, have the ability to change the security state of a system. As such it would seem appropriate to use CAP_MAC_ADMIN for those checks.

Rather than belabor the issue now, we can entertain a subsequent discussion, if needed, on why we believe that actions 1, 2 and 4 can change the security state of the system.

By your definition, check type 3 would seem to be consistent with CAP_MAC_OVERRIDE, since it is gating access to potentially security sensitive information but which does not imply the ability to change the security state of the system.

That leaves category 5 as a possible open question. Given the trust orchestration model for externally modeled namespaces, we concluded that the only entities that should be able to issue signals that can manipulate, particularly terminate a process, should only come from within the security modeling namespace that the target process is running in. Given that, we would consider such operations as possibly affecting the security state of the system and thus suitable for CAP_MAC_ADMIN.

Based on what we have always understood, and that is confirmed by 'git grep', the only thing at this time that is using CAP_MAC_OVERRIDE is SMACK. If our analysis is correct, would you have any issues with us changing the type 3 checks to CAP_MAC_OVERRIDE?

With respect to the check that you call out in tsem.c:tsem_open_file(), the capability check is to avoid a model deadlock situation. If we adopt the model we discuss above, we would need to unequivocably allow the open if the process is carrying CAP_MAC_ADMIN or CAP_MAC_OVERRIDE in order to avoid a control deadlock.

We will look forward to your thoughts on if we should proceed with the above changes.

Have a good day.

As always,
Dr. Greg

The Quixote Project - Flailing at the Travails of Cybersecurity
https://github.com/Quixote-Project

#30 lore raw

Re: [PATCH v4 04/14] Add primary TSEM implementation file.

Quoted 145 lines · Dr. Greg

On Mon, Aug 26, 2024 at 08:53:31AM -0700, Casey Schaufler wrote:

Good morning Casey, I hope this note finds your day starting well.

Greetings to others on this 'last' week of summer.

Quoted 75 lines · Greg Wettstein
Quoted 74 lines

The tsem.c file is the 'master' file in the TSEM implementation. It is responsible for initializing the LSM and providing the implementation of the security event handlers.

---
 security/tsem/tsem.c | 2446 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 2446 insertions(+)
 create mode 100644 security/tsem/tsem.c
security/tsem/tsem.c new file +60 -0
new file mode 100644
index 000000000000..76d65b3e62b3
@@ -0,0 +1,2446 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/*
+ * Copyright (C) 2024 Enjellic Systems Development, LLC
+ * Author: Dr. Greg Wettstein <[email protected]>
+ *
+ * This file is the primary implementation file for the tsem LSM.
+ *
+ * It implements initialization and setup functions that interpret
+ * kernel command-line arguments and prepares TSEM for operation.
+ *
+ * In addition it contains all of the TSEM specific security event
+ * handlers that are responsible for handling the LSM events that TSEM
+ * models.
+ *
+ * Each TSEM event handler calls the tsem_allocate_event() function to
+ * allocate a structure that will be used to describe the event.  The
+ * CELL union of this structure contains various structures that are
+ * used to hold these parameters.
+ *
+ * Since the event characterization parameters need to be retained for
+ * the lifetime of the tsem_event structure that is allocated.  In the
+ * case of internally modeled namespaces this lifespan is the lifetime
+ * of the security modeling namespace.  In the case of externally
+ * modeled namespaces, the lifespan is until the security event
+ * description is exported to an external trust orchestrator.
+ *
+ * In order to support this model, the event description structures
+ * are typically composed of a union over 'in' and 'out' structures.
+ * The 'in' structures are used to hold arguments to the event handler
+ * that may only be relevant for the duration of the call.  These
+ * values are translated into members of the 'out' structure that
+ * retain the values until the end of the lifetime of the tsem_event
+ * structure.
+ *
+ * Each TSEM event handler is responsible for allocating a tsem_event
+ * structure and populating the appropriate CELL structure with the
+ * input characteristics of the event.  The dispatch_event() function
+ * is called to handle the modeling of the event.  This function
+ * returns the permission value that is returned as the result of the
+ * LSM event handler.
+ *
+ * The dispatch_event() calls the tsem_event_init() function that is
+ * responsible for translating the input parameters into values that
+ * will be retained for the lifetime of the security event
+ * description.  The populated event description is then dispatched to
+ * either the tsem_model_event() or the tsem_export_event() for
+ * modeling by either the internal TMA or by a TMA associated with an
+ * external trust orchestrator.
+ */
+
+ ...
+
+static int tsem_file_open(struct file *file)
+{
+	struct inode *inode = file_inode(file);
+	struct tsem_event *ep;
+
+	if (static_branch_unlikely(&tsem_not_ready))
+		return 0;
Quoted 8 lines

security/tsem/tsem.c line 361

Quoted 4 lines
security/tsem/tsem.c new file +4 -0
+	if (bypass_event(TSEM_FILE_OPEN))
+		return 0;
+	if (unlikely(tsem_inode(inode)->status == TSEM_INODE_CONTROL_PLANE)) {
+		if (capable(CAP_MAC_ADMIN))

Don't you mean CAP_MAC_OVERRIDE? CAP_MAC_ADMIN is for changes to the security state of the system, where CAP_MAC_OVERRIDE is for access control decision exceptions. Here (and elsewhere) you use the former in access checks.

You are clearly the mechanistic expert on capabilities so we would take your lead on this.

Some background information to hopefully assist in a discussion on the types of capability checks that should be implemented.

The capability checks we apply in TSEM gate the following five types of actions:

1.) The ability to issue TSEM control commands.

2.) The ability to register an event processing module.

3.) Access to state information on kernel based modeling agent instances.

4.) The ability to send signals to trust orchestration processes.

5.) The ability to send a signal to a different security modeling namespace.

If we understand the differentiation that you suggest between CAP_MAC_ADMIN and CAP_MAC_OVERRIDE we would conclude the following:

Checks 1, 2 and 4 would seem, in our opinion, have the ability to change the security state of a system. As such it would seem appropriate to use CAP_MAC_ADMIN for those checks.

Rather than belabor the issue now, we can entertain a subsequent discussion, if needed, on why we believe that actions 1, 2 and 4 can change the security state of the system.

By your definition, check type 3 would seem to be consistent with CAP_MAC_OVERRIDE, since it is gating access to potentially security sensitive information but which does not imply the ability to change the security state of the system.

That leaves category 5 as a possible open question. Given the trust orchestration model for externally modeled namespaces, we concluded that the only entities that should be able to issue signals that can manipulate, particularly terminate a process, should only come from within the security modeling namespace that the target process is running in. Given that, we would consider such operations as possibly affecting the security state of the system and thus suitable for CAP_MAC_ADMIN.

Based on what we have always understood, and that is confirmed by 'git grep', the only thing at this time that is using CAP_MAC_OVERRIDE is SMACK. If our analysis is correct, would you have any issues with us changing the type 3 checks to CAP_MAC_OVERRIDE?

With respect to the check that you call out in tsem.c:tsem_open_file(), the capability check is to avoid a model deadlock situation. If we adopt the model we discuss above, we would need to unequivocably allow the open if the process is carrying CAP_MAC_ADMIN or CAP_MAC_OVERRIDE in order to avoid a control deadlock.

Quoted 2 lines

We will look forward to your thoughts on if we should proceed with the above changes.

It seems you were right all along, that none of these capability checks really fit with CAP_MAC_OVERRIDE. Thank you for the clarification.

Quoted 8 lines

Have a good day.

As always,
Dr. Greg

The Quixote Project - Flailing at the Travails of Cybersecurity
https://github.com/Quixote-Project

#31 lore raw

PATCH v4 5/14 Add root domain trust implementation.

In reply to Greg Wettstein

The trust.c contains the support infrastructure for anchoring the root modeling domain to a Trusted Platform Modul (TPM) implementation if one is available.

The Platform Configuation Register (PCR) that is selected for the trust root is extended with the security state coefficients that each security event maps into.

Also included is functionality that computes the hardware platform aggregate measurement that is the linear extension sum over PCR register 0 through 8. The hardware aggregate measurement is generated and maintained in multiple cryptographic digest forms depending on the cryptographic hash functions used in the security modeling namespaces that request the value of the hardware aggregate.

---
 security/tsem/trust.c | 261 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 261 insertions(+)
 create mode 100644 security/tsem/trust.c
security/tsem/trust.c new file +261 -0
new file mode 100644
index 000000000000..762bca735afc
@@ -0,0 +1,261 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/*
+ * Copyright (C) 2024 Enjellic Systems Development, LLC
+ * Author: Dr. Greg Wettstein <[email protected]>
+ *
+ * On a platform that has access to a TPM device, this file is
+ * responsible for maintaining a root of trust based on that device.
+ *
+ * As with other trusted platform implementations the root of trust is
+ * a linear extension measurement maintained in a Platform
+ * Configuration Register (PCR) on the TPM device.
+ *
+ * The PCR is extended with each unique security state coefficient
+ * that is generated by the model being implemented for the
+ * root security modeling namespace.  As with other trusted systems
+ * the value of the PCR will be variable depending on scheduling
+ * artifacts that are experienced by the root modeling namespace.
+ *
+ * TSEM uses a strategy of executing the TPM extension transactions
+ * using an ordered workqueue rather than doing them at the time the
+ * security event is processed.  This is done both for performance
+ * reasons and the fact that the coefficient extensions may arise from
+ * security events that are being invoked by processes running in
+ * atomic context.
+ *
+ * If the trust_init() function detects the presence of a TPM an
+ * ordered workqueue with the following name is created:
+ *
+ * tsem_tpm
+ *
+ * The tsem_trust_add_event() function places a work request
+ * containing a description of the event on this workqueue that will
+ * then asynchronously extend the security state coefficient of the
+ * event into the PCR being used to measure the trust state of
+ * the root security modeling namespace.
+ *
+ * This file is also responsible for providing the hardware aggregate
+ * measurement for injection into both internally and externally
+ * modeled namespaces.  The hardware aggregate value is the linear
+ * extension sum of PCR registers 0 through 8.
+ *
+ * Since TSEM supports multiple cryptographic digest functions on a
+ * namespace by namespace basis the hardware aggregate value is
+ * maintained in multiple digest forms.  The tsem_trust_aggregate()
+ * function returns a pointer to the digest value for the
+ * cryptographic digest function that is being used by the security
+ * modeling namespace in effect for the calling process.
+ */
+
+#include <linux/tpm.h>
+
+#include "tsem.h"
+
+static struct workqueue_struct *tpm_update_wq;
+
+static u8 zero_aggregate[HASH_MAX_DIGESTSIZE];
+
+static struct tpm_chip *tpm;
+
+static struct tpm_digest *digests;
+
+struct hardware_aggregate {
+	struct list_head list;
+	char *name;
+	u8 value[HASH_MAX_DIGESTSIZE];
+};
+
+DEFINE_MUTEX(hardware_aggregate_mutex);
+LIST_HEAD(hardware_aggregate_list);
+
+static struct hardware_aggregate *find_aggregate(void)
+{
+	struct hardware_aggregate *aggregate;
+
+	list_for_each_entry(aggregate, &hardware_aggregate_list, list) {
+		if (!strcmp(aggregate->name,
+			    tsem_context(current)->digestname))
+			goto done;
+	}
+	aggregate = NULL;
+
+ done:
+	return aggregate;
+}
+
+static struct hardware_aggregate *add_aggregate(u8 *new_aggregate)
+{
+	struct hardware_aggregate *aggregate;
+
+	aggregate = kzalloc(sizeof(*aggregate), GFP_KERNEL);
+	if (!aggregate)
+		return NULL;
+
+	aggregate->name = kstrdup(tsem_context(current)->digestname,
+				  GFP_KERNEL);
+	if (!aggregate->name) {
+		kfree(aggregate);
+		return NULL;
+	}
+	memcpy(aggregate->value, new_aggregate, tsem_digestsize());
+
+	list_add(&aggregate->list, &hardware_aggregate_list);
+
+	return aggregate;
+}
+
+/**
+ * tsem_trust_aggregate() - Return a pointer to the hardware aggregate.
+ *
+ * This function returns a pointer to the hardware aggregate encoded
+ * with the hash function for the current modeling domain.
+ *
+ * Return: A pointer is returned to the hardware aggregate value that
+ *	   has been cached.
+ */
+u8 *tsem_trust_aggregate(void)
+{
+	u8 aggregate[HASH_MAX_DIGESTSIZE], *retn = zero_aggregate;
+	u16 size;
+	unsigned int lp;
+	struct tpm_digest pcr;
+	struct hardware_aggregate *hw_aggregate;
+	SHASH_DESC_ON_STACK(shash, tfm);
+
+	if (!tpm)
+		return retn;
+
+	mutex_lock(&hardware_aggregate_mutex);
+
+	hw_aggregate = find_aggregate();
+	if (hw_aggregate) {
+		retn = hw_aggregate->value;
+		goto done;
+	}
+
+	shash->tfm = tsem_digest();
+	if (crypto_shash_init(shash))
+		goto done;
+
+	if (tpm_is_tpm2(tpm))
+		pcr.alg_id = TPM_ALG_SHA256;
+	else
+		pcr.alg_id = TPM_ALG_SHA1;
+	memset(pcr.digest, '\0', TPM_MAX_DIGEST_SIZE);
+
+	for (lp = 0; lp < tpm->nr_allocated_banks; lp++) {
+		if (pcr.alg_id == tpm->allocated_banks[lp].alg_id) {
+			size = tpm->allocated_banks[lp].digest_size;
+			break;
+		}
+	}
+
+	for (lp = 0; lp < 8; ++lp) {
+		if (tpm_pcr_read(tpm, lp, &pcr))
+			goto done;
+		if (crypto_shash_update(shash, pcr.digest, size))
+			goto done;
+	}
+	if (!crypto_shash_final(shash, aggregate)) {
+		hw_aggregate = add_aggregate(aggregate);
+		if (hw_aggregate)
+			retn = hw_aggregate->value;
+	}
+
+ done:
+	mutex_unlock(&hardware_aggregate_mutex);
+
+	if (retn == zero_aggregate)
+		pr_warn("tsem: Error generating platform aggregate\n");
+
+	return retn;
+}
+
+static void tpm_update_worker(struct work_struct *work)
+{
+	int amt, bank, digestsize;
+	struct tsem_event *ep;
+
+	ep = container_of(work, struct tsem_event, work);
+	digestsize = ep->digestsize;
+
+	for (bank = 0; bank < tpm->nr_allocated_banks; bank++) {
+		if (tpm->allocated_banks[bank].digest_size > digestsize) {
+			amt = digestsize;
+			memset(digests[bank].digest, '\0',
+			       tpm->allocated_banks[bank].digest_size);
+		} else
+			amt = tpm->allocated_banks[bank].digest_size;
+		memcpy(digests[bank].digest, ep->mapping, amt);
+	}
+
+	if (tpm_pcr_extend(tpm, CONFIG_SECURITY_TSEM_ROOT_MODEL_PCR,
+			   digests))
+		pr_warn("tsem: Failed TPM update.\n");
+
+	tsem_event_put(ep);
+}
+
+/**
+ * tsem_trust_add_point() - Add a measurement to the trust root.
+ * @ep: A pointer to the security event description whose measurement
+ *	is to be extended into the TPM.
+ *
+ * This function extends the platform configuration register being
+ * used to document the hardware root of trust for internally modeled
+ * domains with a security event coefficient value.
+ *
+ * Return: If the extension fails the error return value from the
+ *	   TPM command is returned, otherwise a value of zero is
+ *	   returned.
+ */
+int tsem_trust_add_event(struct tsem_event *ep)
+{
+	bool retn;
+
+	if (!tpm)
+		return 0;
+
+	tsem_event_get(ep);
+	ep->digestsize = tsem_digestsize();
+
+	INIT_WORK(&ep->work, tpm_update_worker);
+	retn = queue_work(tpm_update_wq, &ep->work);
+
+	return 0;
+}
+
+static int __init trust_init(void)
+{
+	int retn = -EINVAL, lp;
+
+	tpm = tpm_default_chip();
+	if (!tpm)
+		return retn;
+
+	tpm_update_wq = alloc_ordered_workqueue("tsem_tpm", 0);
+	if (IS_ERR(tpm_update_wq)) {
+		retn = PTR_ERR(tpm_update_wq);
+		goto done;
+	}
+
+	digests = kcalloc(tpm->nr_allocated_banks, sizeof(*digests), GFP_NOFS);
+	if (!digests) {
+		tpm = NULL;
+		return retn;
+	}
+	for (lp = 0; lp < tpm->nr_allocated_banks; lp++)
+		digests[lp].alg_id = tpm->allocated_banks[lp].alg_id;
+	retn = 0;
+
+ done:
+	if (retn) {
+		destroy_workqueue(tpm_update_wq);
+		kfree(digests);
+	}
+
+	return retn;
+}
+
+device_initcall_sync(trust_init);
Signature · 1 line
2.39.1