Back to Blog

Implementing Integrity Measurement Architecture (IMA) in Linux

Implementing Integrity Measurement Architecture (IMA) in Linux

In the modern security landscape, the perimeter has effectively dissolved. While technologies like UEFI Secure Boot ensure that the bootloader and kernel are authentic, a critical "trust gap" remains once the kernel takes control. From the moment the kernel initializes until the system is shut down, the runtime environment is vulnerable to unauthorized modifications, persistent rootkits, and sophisticated supply chain attacks.

Standard Discretionary Access Control (DAC) and Mandatory Access Control (MAC) like SELinux or AppArmor focus on what a process can do. However, they are often blind to what a process is-specifically, whether the binary itself has been tampered with on disk. This is where the Linux Integrity Measurement Architecture (IMA) becomes indispensable. IMA extends the concept of trust from the boot process into the runtime execution of every file, library, and script on the system.

The Architecture: Measurement, Appraisal, and EVM

To implement IMA effectively, one must understand that it is not a single monolithic feature, but a triad of distinct but interlocking mechanisms: Measurement, Appraisal, and the Extended Verification Module (EVM).

1. IMA Measurement

The measurement component is an auditing mechanism. When a file is accessed (e.g., via `execve()`, `open()`, or `mmap()`), the kernel calculates a cryptographic hash (typically SHA-256) of the file's contents. This hash is then appended to a runtime measurement list maintained in kernel memory.

Crucially, to ensure the integrity of this list, the kernel "extends" the hash into a Platform Configuration Register (PCR)-usually PCR 10-within the Trusted Platform Module (TPM). Because the TPM's `extend` operation is a one-way cryptographic function ($NewPCR = Hash(OldPCR || NewMeasurement)$), an attacker cannot retroactively alter the measurement list without leaving a detectable discrepancy in the TPM.

2. IMA Appraisal

While measurement provides visibility, Appraisal provides enforcement. IMA Appraisal compares the current hash of a file against a "known good" value stored in the file's extended attributes (`security.ima`).

If the calculated hash does not match the value in the attribute, the kernel denies the access request. This turns IMA from a passive logger into an active gatekeeper, preventing the execution of unauthorized binaries or the loading of corrupted shared libraries.

3. The Extended Verification Module (EVM)

Appraisal alone has a structural weakness: an attacker with root privileges could simply recalculate the hash of a malicious file and overwrite the `security.ima` extended attribute. EVM mitigates this by protecting the file's metadata. EVM calculates a HMAC or digital signature over a set of critical file attributes (including `security.ima`, `security.selinux`, UID, GID, and mode) using a key protected by the TPM. If an attacker modifies the file's permissions or the IMA attribute, the EVM verification fails, and the file becomes inaccessible.

Implementation Workflow

Implementing IMA in a production environment is a high-stakes operation. It requires a disciplined approach to key management and a robust deployment pipeline.

Step 1: Kernel Configuration

Your kernel must be compiled with the necessary primitives. Ensure the following `Kconfig` options are enabled:

  • `CONFIG_IMA=y`
  • `CONFIG_IMA_APPRAISE=y`
  • `CONFIG_IMA_WRITE_POLICY=y`
  • `CONFIG_EVM=y`
  • `CONFIG_IMA_SEE_TSS=y` (for TPM integration)

Step 2: Defining the IMA Policy

The IMA policy determines which files are measured and which are appraised. A common mistake is attempting to appraise the entire filesystem, which leads to massive performance degradation and system instability. A targeted policy is essential.

A sample policy snippet in `/etc/ima/ima-policy` might look like this:

```text

Measure all binaries being executed

measure func=BPRM_CHECK mask=MAY_EXEC

Appraise all executables and libraries

appraise func=BPRM_CHECK mask=MAY_EXEC

appraise func=MMAP_CHECK mask=MAY_EXEC

Appraise all files opened for writing to prevent tampering

appraise func=FILE_CHECK mask=MAY_WRITE

```

Step 3: Digital Signatures and Key Management

For a scalable deployment, you should not use simple hash-based appraisal (which requires updating `security.ima` on every change). Instead, use asymmetric digital signatures.

The workflow involves:

  1. Generating a Keypair: Create an RSA keypair where the private key is kept in a secure, offline build environment.
  2. Signing Binaries: During your CI/CD process, use `evmctl` (from the `ima-evm-utils` package) to sign the binaries:

```bash

evmctl ima_sign --key /path/to/private_key.pem /usr/bin/critical_service

```

  1. Distributing the Public Key: The public key must be loaded into the kernel's `.ima` keyring at boot time, often via the `.system_keyring` or by embedding it in the initramfs.

Operational Considerations and Risks

The transition from a standard Linux deployment to an IMA-enforced environment is fraught with operational complexity.

The "Bricking" Risk

The most significant risk is a self-inflicted Denial of Service (DoS). If you enable `ima_appraise=enforce` and your

Conclusion

As shown across "The Architecture: Measurement, Appraisal, and EVM", "Implementation Workflow", "Operational Considerations and Risks", a secure implementation for implementing integrity measurement architecture (ima) in linux depends on execution discipline as much as design.

The practical hardening path is to enforce certificate lifecycle governance with strict chain/revocation checks, host hardening baselines with tamper-resistant telemetry, and provenance-attested build pipelines and enforceable release gates. This combination reduces both exploitability and attacker dwell time by forcing failures across multiple independent control layers.

Operational confidence should be measured, not assumed: track policy-gate coverage and vulnerable artifact escape rate and certificate hygiene debt (expired/weak/mis-scoped credentials), then use those results to tune preventive policy, detection fidelity, and response runbooks on a fixed review cadence.

Related Articles

Explore related cybersecurity topics:

Recommended Next Steps

If this topic is relevant to your organisation, use one of these paths: