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 的默认行为,不是错误。
- 扩展属性备份格式(
dump/restore)使用相对路径 - 便于跨系统恢复(不同系统的根路径可能不同)
- 工具会自动去掉路径开头的
/
getfattr 常用选项#
| 选项 | 长选项 | 功能 |
|---|
-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.selinux | SELinux 标签 |
security.ima | IMA 签名/哈希 |
security.evm | EVM 签名 |
security.capability | 文件能力(capabilities) |
security.SMACK64 | SMACK 标签 |
验证签名常用命令#
# 查看所有 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