mount.cifs 中的 open_cred_file() 会将 credentials 文件中的 username= 值复制到绑定内核的挂载选项字符串中,且不进行逗号分词。该值是在 mount.cifs 的逐 token 清理器已经运行之后才落入的,因此像 uid=0,forceuid,file_mode=04755 这样的注入选项会直接传递到内核。内核 CIFS 解析器对重复键采用后写覆盖(last-write-wins)策略。
控制 credentials 文件的非特权用户可获得任意内核挂载选项。这足以获得 root shell。
在 SELinux enforcing 模式下可正常工作,且零 AVC 拒绝。
AV:L/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:N = 8.4 High
mount.cifs.c,即 open_cred_file 中的 CRED_USER 分支:
case CRED_USER:
strlcpy(parsed_info->username, temp_val,
sizeof(parsed_info->username));
temp_val 是 cred 文件中 username= 之后的原始值。没有校验,没有逗号拆分。随后在第 1942 行:
strlcat(parsed_info->options, "user=", ...);
strlcat(parsed_info->options, parsed_info->username, ...);
这发生在清理器已经输出 uid=N,gid=N 之后。因此,包含 username=smbuser,uid=0,forceuid,file_mode=04755 的 cred 文件会产生:
...,uid=1000,gid=1000,user=smbuser,uid=0,forceuid,file_mode=04755,...
内核从左到右遍历,后写覆盖。uid=0 覆盖 uid=1000。
现实世界中常见的触发点是如下 fstab 条目:
//server/share /mnt/data cifs credentials=/home/user/.smbcredentials 0 0
用户拥有该 cred 文件。修改 username= 行,等待下一次特权挂载。也可通过 autofs、systemd .mount 单元、管理员脚本,或任何以 root 身份调用 mount.cifs 且 credentials= 指向你可写文件的方式触发。
PoC 演示了完整的 root shell:注入 uid=0,forceuid,file_mode=04755,在共享上放置一个二进制文件,挂载点上的每个文件都会变为 SUID root。