IMA 在内核审计子系统(auditd)中新增了一组专用事件类型(不同于 IMA-Measurement 或 IMA-Audit 自身日志),专门记录与“完整性校验失败、TPM 扩展失败、策略加载失败”等关键场景相关的审计痕迹。下面按“事件类别 → 日志格式 → 典型示例 → 排查思路”逐层说明。
一、事件类别总览
触发时机 | 事件名 | 内核审计消息类型 | 是否需要策略规则 |
---|---|---|---|
文件被篡改或签名/哈希不匹配 | integrity violation | INTEGRITY_RULE / INTEGRITY_PCR |
✅ 需 appraise 或 measure 规则 |
无法把度量值写进 TPM PCR | failure to extend PCR | INTEGRITY_PCR |
✅ 需 measure 规则 |
mmap/exec/open 完整性校验失败 | failure to mmap/exec/open | INTEGRITY_RULE |
✅ 需 appraise 规则 |
计算文件哈希出错(磁盘坏块、权限不足等) | failure to calculate hash | INTEGRITY_RULE |
✅ 需任意规则 |
加载 IMA 策略失败 | policy load failure | INTEGRITY_RULE |
❌ 与规则无关 |
启动阶段无法生成 boot_aggregate | boot_aggregate failure | INTEGRITY_PCR |
❌ 与规则无关 |
Events that require a measure policy rule include:integrity violationsfailure to extend the TPM PCREvents that require an appraise policy rule include:failure to mmap a filefailure to load or update a IMA policyEvents that require any policy rule include:failure to calculate a file hashEvents that occur independent of policy rules include:failure to calculate the boot_aggregateloading IMA policy rules
二、日志字段说明(以 INTEGRITY_PCR
为例)
type=INTEGRITY_PCR msg=audit(1721934216.094:1227):pid=3546 uid=0 auid=1000 ses=2op=invalid_pcr cause=open_writerscomm="grep" name="/var/log/audit/audit.log" dev="sda3"ino=21348467 res=1 errno=0
关键字段速查
-
op=
或cause=
:失败原因,常见值-
open_writers
—— 文件先被写打开,后又被读打开,出现 ToMToU 竞争。 -
tomtou
—— Time-of-Measure/Time-of-Use 攻击。 -
invalid_signature
—— 签名验证失败。 -
unknown_hash_algo
—— 不支持的哈希算法。
-
-
name=
:触发事件的文件绝对路径。 -
comm=
:触发进程名,便于快速定位。 -
res=1
:表示完整性校验失败;res=0
仅记录日志但允许继续访问(log 模式)。
官方示例:
type=INTEGRITY_PCR msg=audit(1721934216.094:1227): pid=3546 uid=0 auid=1000 ses=2 subj=unconfined_u:unconfined_r:unconfined_t:s0 op=invalid_pcr cause=open_writers comm="grep" name="/var/log/audit/audit.log" dev="sda3" ino=21348467 res=1 errno=0UID="root" AUID="kgold"
三、典型场景与示例
-
文件被篡改后执行
type=INTEGRITY_RULE msg=audit(...):name="/usr/bin/sshd" hash="sha256:bad..." res=1
→ 说明/usr/bin/sshd
哈希与security.ima
不符,系统拒绝执行。 -
open_writers 竞争
type=INTEGRITY_PCR cause=open_writers name="/var/log/audit/audit.log"
→ 日志文件在被auditd
写的同时又被grep
读,IMA 检测到潜在篡改。 -
PCR 10 扩展失败
type=INTEGRITY_PCR cause=tpm_extend_error
→ TPM 忙或硬件故障导致度量值无法写 PCR,远程证明将失败。
四、启用与调试方法
-
内核配置
CONFIG_IMA=y CONFIG_IMA_AUDIT=y # 允许 ima_audit=1 参数
-
启动参数(按需打开详细审计)
ima_audit=1
-
策略示例(在
/etc/ima/ima-policy
或启动参数里)audit func=BPRM_CHECK mask=MAY_EXEC
-
实时查看
tail -f /var/log/audit/audit.log | egrep 'INTEGRITY_RULE|INTEGRITY_PCR'
五、一句话总结
IMA Integrity Audit Events 把每一次“完整性校验失败”都变成不可抵赖的审计记录,配合
ausearch -m INTEGRITY_RULE
或 SIEM 工具,可快速定位“文件何时、被谁、以何种方式”被篡改,为事后取证和合规审计提供核心证据链。