Documentation/translations/zh_CN/security/IMA-templates.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_CN/security/IMA-templates.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_CN/security/IMA-templates.rst- Extension
.rst- Size
- 4887 bytes
- Lines
- 98
- Domain
- Support Tooling And Documentation
- Bucket
- Documentation
- Inferred role
- Support Tooling And Documentation: documentation
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
.. SPDX-License-Identifier: GPL-2.0
.. include:: ../disclaimer-zh_CN.rst
:Original: Documentation/security/IMA-templates.rst
:翻译:
赵硕 Shuo Zhao <zhaoshuo@cqsoftware.com.cn>
===============
IMA模板管理机制
===============
介绍
====
原始的 ``ima`` 模板是固定长度的,包含文件数据的哈希值和路径名。文件数据
哈希值限制为20字节(md5/sha1)。路径名是一个以空字符终止的字符串,长度限
制为255个字符内。
为了克服这些限制并添加额外的文件元数据,通过定义额外的模板来扩展当前版本
的IMA这是有必要的。例如,可能报告的信息包括索引节点的 UID/GID或索引节点
及访问它进程的LSM标签。
然而,引入这个功能的主要问题是,每次定义一个新模板时,生成和显示度量列表
的函数都需要包含处理新格式的代码,因此,这些函数的规模随着时间的推移会
显著增长。
提出的解决方案通过将模板管理与其余IMA代码分离来解决这个问题。该解决方案
的核心是定义两个新的数据结构:一个是模板描述符,用于确定度量列表中应包含
哪些信息;另一个是模板字段,用于生成和显示给定类型的数据。
使用这些结构管理模板非常简单。为了支持一种新的数据类型,开发人员定义字段
标识符,并实现两个函数,分别为init()和show(),用于生成和显示度量条目。
定义一个新的模板描述符需要通过 ``ima_template_fmt`` 内核命令行参数指定
模板格式(一个由 ``|`` 字符分隔的字段标识符字符串)。在启动时,IMA通过将格
式转换从支持的模板字段集合中选取模板字段数组,来初始化所选的模板描述符。
在初始化步骤之后,IMA将调用 ``ima_alloc_init_template()`` (这是为新模板
管理机制所打补丁中定义的新函数),通过使用在内核配置选择的模板描述符或者新引
入的 ``ima_template`` 和 ``ima_template_fmt`` 内核命令行参数,生成一个新
的度量条目。在这一阶段,新架构的优势得以清晰展示:后一个函数将不会包含处理给
定模板的特定代码,而是简单地调用与所选模板描述符关联的模板字段的 ``init()``
方法,并将结果(指向已分配数据的指针和数据长度)存储在度量条目结构中。
相同的机制也用于显示度量条目。函数 ``ima[_ascii]_measurements_show()`` 会为
每个条目检索用于生成该条目的模板描述符,并为模板字段结构数组中的每一项调用show()
方法。
支持的模板字段和描述符
======================
下面是支持的模板字段列表 ``('<identifier>': description)`` ,可以通过将其标识符
添加到格式字符串中用于定义新的模板描述符(后续将添加对更多数据类型的支持):
- 'd':事件的摘要(即测量文件的摘要),通过SHA1或MD5哈希算法计算;
- 'n':事件的名称(即文件名),大小至多255字节;
- 'd-ng':事件的摘要,通过任意哈希算法计算(字段格式:<hash algo>:digest);
- 'd-ngv2':与d-ng相同,但以"ima"或"verity"摘要类型为前缀
(字段格式:<digest type>:<hash algo>:digest);
- 'd-modsig':不含附加modsig的事件摘要;
- 'n-ng':事件的名称,没有大小限制;
- 'sig':文件签名,基于文件的/文件系统验证的摘要[1],或EVM便携式签名,
如果'security.ima'包含文件哈希;
- 'modsig':附加的文件签名;
- 'buf':用于生成哈希的缓冲区数据,没有大小限制;
- 'evmsig':EVM便携式签名;
- 'iuid':索引节点的UID;
- 'igid':索引节点的GID;
Annotation
- Atlas domain: Support Tooling And Documentation / Documentation.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.