getfattr 提示 “Removing leading ‘/’ from absolute path names”

现象

getfattr -d -m security /sysroot/bin/bash

# 输出
getfattr: Removing leading '/' from absolute path names
# file: sysroot/bin/bash
security.selinux="system_u:object_r:shell_exec_t:s0"

原因

这是 getfattr 的默认行为,不是错误。

  1. 扩展属性备份格式(dump/restore)使用相对路径
  2. 便于跨系统恢复(不同系统的根路径可能不同)
  3. 工具会自动去掉路径开头的 /

getfattr 常用选项

getfattr [选项] path...
选项长选项功能
-d--dump获取所有扩展属性值
-n name--name=name获取指定名称的扩展属性
-e en--encoding=...编码格式:text, hex, base64
-m pattern--match=pattern只显示匹配模式的属性
-h--no-dereference不解引用符号链接
--absolute-names保留开头的 /(绝对路径)
-R--recursive递归子目录
-L--logical逻辑遍历,跟随符号链接
-P--physical物理遍历,不跟随符号链接
--only-values只输出值,不输出属性名
--version显示版本
--help显示帮助

使用示例

1. 查看所有 security 相关属性

# 默认(相对路径)
getfattr -d -m security /sysroot/bin/bash

# 输出
getfattr: Removing leading '/' from absolute path names
# file: sysroot/bin/bash
security.selinux="system_u:object_r:shell_exec_t:s0"

2. 保留绝对路径(使用 –absolute-names)

getfattr --absolute-names -d -m security /sysroot/bin/bash

# 输出(没有提示,路径带 /)
# file: /sysroot/bin/bash
security.selinux="system_u:object_r:shell_exec_t:s0"

3. 查看指定属性

# 只查看 security.ima
getfattr -n security.ima /sysroot/bin/bash

# 只查看 security.evm
getfattr -n security.evm /sysroot/bin/bash

4. 使用十六进制编码

getfattr -e hex -d -m security /sysroot/bin/bash

5. 递归查看目录

getfattr -R -d -m security /sysroot/usr/lib

6. 只输出值(不显示属性名)

getfattr --only-values -n security.selinux /sysroot/bin/bash

IMA/EVM 常用属性说明

属性说明
security.selinuxSELinux 标签
security.imaIMA 签名/哈希
security.evmEVM 签名
security.capability文件能力(capabilities)
security.SMACK64SMACK 标签

验证签名常用命令

# 查看所有 security 属性
getfattr -d -m security /path/to/file

# 查看并保留绝对路径
getfattr --absolute-names -d -m security /path/to/file

# 查看 IMA 签名
getfattr -n security.ima /path/to/file

# 查看 EVM 签名
getfattr -n security.evm /path/to/file

# 使用 evmctl 验证 IMA
evmctl ima_verify /path/to/file

# 使用 evmctl 验证 EVM
evmctl verify /path/to/file

补充:setfattr(设置扩展属性)

# 设置属性
setfattr -n security.ima -v "value" /path/to/file

# 删除属性
setfattr -x security.ima /path/to_file