Skip to content

[Deepin-Kernel-SIG] [linux 6.6.y] ima: Make it independent from 'integrity' LSM - #2135

Open
opsiff wants to merge 1 commit into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-09-09-ima
Open

[Deepin-Kernel-SIG] [linux 6.6.y] ima: Make it independent from 'integrity' LSM#2135
opsiff wants to merge 1 commit into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-09-09-ima

Conversation

@opsiff

@opsiff opsiff commented Sep 10, 2026

Copy link
Copy Markdown
Member

Make the 'ima' LSM independent from the 'integrity' LSM by introducing IMA own integrity metadata (ima_iint_cache structure, with IMA-specific fields from the integrity_iint_cache structure), and by managing it directly from the 'ima' LSM.

Create ima_iint.c and introduce the same integrity metadata management functions found in iint.c (renamed with ima_). However, instead of putting metadata in an rbtree, reserve space from IMA in the inode security blob for a pointer, and introduce the ima_inode_set_iint()/ima_inode_get_iint() primitives to store/retrieve that pointer. This improves search time from logarithmic to constant.

Consequently, don't include the inode pointer as field in the ima_iint_cache structure, since the association with the inode is clear. Since the inode field is missing in ima_iint_cache, pass the extra inode parameter to ima_get_verity_digest().

Prefer storing the pointer instead of the entire ima_iint_cache structure, to avoid too much memory pressure. Use the same mechanism as before, a cache named ima_iint_cache (renamed from iint_cache), to quickly allocate a new ima_iint_cache structure when requested by the IMA policy.

Create the new ima_iint_cache in ima_iintcache_init(), called by init_ima_lsm(), during the initialization of the 'ima' LSM. And, register ima_inode_free_security() to free the ima_iint_cache structure, if exists.

Replace integrity_iint_cache with ima_iint_cache in various places of the IMA code. Also, replace integrity_inode_get() and integrity_iint_find(), respectively with ima_inode_get() and ima_iint_find().

Finally, move the remaining IMA-specific flags
to security/integrity/ima/ima.h, since they are now unnecessary in the common integrity layer.

Reviewed-by: Casey Schaufler casey@schaufler-ca.com
Reviewed-by: Stefan Berger stefanb@linux.ibm.com
Reviewed-by: Mimi Zohar zohar@linux.ibm.com
Acked-by: Mimi Zohar zohar@linux.ibm.com

(cherry picked from commit 4de2f08)

Summary by Sourcery

Decouple IMA integrity metadata management from the shared integrity LSM while retaining compatibility with EVM.

New Features:

  • Give IMA its own inode integrity metadata and lifecycle management as an independent LSM.

Enhancements:

  • Store IMA metadata pointers in inode security blobs for constant-time lookup and reduce dependence on shared integrity metadata.
  • Separate IMA-specific metadata flags and cache handling from the common integrity layer while preserving EVM integration.

Build:

  • Include the new IMA inode metadata implementation in the IMA build.

Make the 'ima' LSM independent from the 'integrity' LSM by introducing IMA
own integrity metadata (ima_iint_cache structure, with IMA-specific fields
from the integrity_iint_cache structure), and by managing it directly from
the 'ima' LSM.

Create ima_iint.c and introduce the same integrity metadata management
functions found in iint.c (renamed with ima_). However, instead of putting
metadata in an rbtree, reserve space from IMA in the inode security blob
for a pointer, and introduce the ima_inode_set_iint()/ima_inode_get_iint()
primitives to store/retrieve that pointer. This improves search time from
logarithmic to constant.

Consequently, don't include the inode pointer as field in the
ima_iint_cache structure, since the association with the inode is clear.
Since the inode field is missing in ima_iint_cache, pass the extra inode
parameter to ima_get_verity_digest().

Prefer storing the pointer instead of the entire ima_iint_cache structure,
to avoid too much memory pressure. Use the same mechanism as before, a
cache named ima_iint_cache (renamed from iint_cache), to quickly allocate
a new ima_iint_cache structure when requested by the IMA policy.

Create the new ima_iint_cache in ima_iintcache_init(),
called by init_ima_lsm(), during the initialization of the 'ima' LSM. And,
register ima_inode_free_security() to free the ima_iint_cache structure, if
exists.

Replace integrity_iint_cache with ima_iint_cache in various places of the
IMA code. Also, replace integrity_inode_get() and integrity_iint_find(),
respectively with ima_inode_get() and ima_iint_find().

Finally, move the remaining IMA-specific flags
to security/integrity/ima/ima.h, since they are now unnecessary in the
common integrity layer.

Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Acked-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
(cherry picked from commit 4de2f08)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@sourcery-ai

sourcery-ai Bot commented Sep 10, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR decouples IMA inode metadata from the shared integrity LSM by storing an IMA-specific cache pointer in the inode security blob, managing it through a new IMA LSM and slab cache, migrating all IMA consumers to the new type and APIs, and explicitly preserving EVM interoperability.

Sequence diagram for IMA inode cache lifecycle

sequenceDiagram
    participant Init as IMA LSM initialization
    participant IMA as IMA cache manager
    participant Inode as Inode
    participant Blob as Inode security blob
    participant Slab as ima_iint_cache slab

    Init->>IMA: ima_iintcache_init()
    IMA->>Slab: kmem_cache_create()
    IMA->>Init: security_add_hooks()
    IMA->>Inode: ima_inode_get(inode)
    IMA->>Blob: ima_inode_get_iint(inode)
    alt cache absent
        IMA->>Slab: kmem_cache_alloc()
        IMA->>Blob: ima_inode_set_iint(inode, iint)
    end
    Inode->>IMA: inode_free_security
    IMA->>Blob: ima_inode_set_iint(inode, NULL)
    IMA->>Slab: kmem_cache_free()
Loading

File-Level Changes

Change Details Files
Introduce IMA-owned inode integrity metadata and lifecycle management.
  • Added the IMA-specific cache structure, flags, and inode-blob pointer accessors.
  • Added allocation, lookup, initialization, lockdep annotation, and inode-free cleanup in a dedicated implementation file.
  • Registered an IMA LSM inode security blob and inode-free hook, and initialized the dedicated slab cache during LSM startup.
security/integrity/ima/ima.h
security/integrity/ima/ima_iint.c
security/integrity/ima/ima_main.c
security/integrity/ima/Makefile
Migrate IMA processing from the shared integrity cache to the new IMA cache.
  • Changed measurement, appraisal, policy, violation, hash, and file/inode hook interfaces to use ima_iint_cache.
  • Replaced shared cache lookup/allocation calls with IMA-specific primitives throughout IMA code.
  • Removed the cached inode field and passed the inode explicitly for fs-verity digest retrieval.
security/integrity/ima/ima.h
security/integrity/ima/ima_api.c
security/integrity/ima/ima_appraise.c
security/integrity/ima/ima_init.c
security/integrity/ima/ima_main.c
security/integrity/ima/ima_policy.c
Keep EVM integration working while separating IMA state from shared integrity state.
  • Retained EVM's integrity cache usage for xattr verification and propagated the new-file flag to both caches when EVM is enabled.
  • Removed IMA-specific flags and cache definitions from the common integrity header, leaving EVM-specific state there.
security/integrity/ima/ima_appraise.c
security/integrity/ima/ima_main.c
security/integrity/integrity.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from opsiff. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants