用于检测 Linux 内核漏洞、检查缓解状态并指导修复的 Shell 脚本——设计用于本地运行或通过 SSH、Ansible 或 pssh 在服务器集群中运行。
Copy Fail 是 Linux 内核 algif_aead 加密模块中的一个高危本地权限提升(LPE)漏洞。该漏洞源于 2017 年引入的一个逻辑缺陷,允许任何无特权的本地用户向任意可读文件的页缓存中写入 4 个受控字节——足以覆盖 setuid 二进制文件并获得 root 权限。一个可用的 732 字节 Python 概念验证(PoC)已公开可用。
| CVE | CVE-2026-31431 |
| CVSS | 7.8(高危) |
| 披露日期 | 2026 年 4 月 29 日 |
| 受影响版本 | Linux 内核 4.13 – 6.x(2017–2026) |
| 发行版 | Ubuntu、RHEL、SUSE、Debian、Amazon Linux 及大多数其他发行版 |
| 可远程利用 | 否——需要本地访问权限 |
| 可用补丁 | 部分——请查看您发行版的安全公告 |
| 检查项 | 需要 root 权限? |
|---|---|
| 内核版本——是否处于受影响范围(≥ 4.13) | 否 |
algif_aead 模块——是否已加载、磁盘上是否存在或被列入黑名单 | 否 |
启动参数——initcall_blacklist=algif_aead_init 是否存在 | 否 |
| AF_ALG 套接字可达性——利用路径是否开放 | 否 |
| SELinux 状态 | 否 |
| AppArmor 状态 | 是——无 root 权限时仅输出部分结果 |
| 发行版补丁状态——CVE 是否列在内核变更日志中 | 否 |
运行脚本不需要 root 权限——除 AppArmor 状态外,所有检查均可以普通用户身份运行。建议使用
sudo运行以获得完整结果,并且在使用curl管道执行时,使用sudo是更安全的选择。
该脚本设计用于在所有主流 Linux 发行版上运行:
| 发行版系列 | 包管理器检查 | 模块路径 |
|---|---|---|
| Debian、Ubuntu | dpkg + 内核变更日志 | /lib/modules/ |
| RHEL、CentOS、Amazon Linux | rpm(kernel、kernel-rt) | /lib/modules/ |
| SUSE、openSUSE | rpm(kernel-default) | /lib/modules/ |
| Arch Linux | pacman + 安全公告链接 | /usr/lib/modules/ |
| Fedora | rpm + /usr/lib/modules/ 回退 | /usr/lib/modules/ |
需要
bash——该脚本使用 bash 特有的语法,无法在sh、ash或dash下运行。在 Alpine Linux(默认使用 busybox ash)上,请先安装 bash:apk add bash
无 root 权限——大多数检查可正常工作:
curl -fsSL https://raw.githubusercontent.com/codesource/copyfail-check/main/check_copyfail.sh | bash
使用 root 权限——完整结果,包括 AppArmor 状态:
curl -fsSL https://raw.githubusercontent.com/codesource/copyfail-check/main/check_copyfail.sh | sudo bash
提示: 在生产环境中请固定到特定的提交 SHA,以免脚本在您不知情的情况下被更改:
curl -fsSL https://raw.githubusercontent.com/codesource/copyfail-check/COMMIT_SHA/check_copyfail.sh | sudo bash
curl -fsSL https://raw.githubusercontent.com/codesource/copyfail-check/main/check_copyfail.sh -o check_copyfail.sh
less check_copyfail.sh
bash check_copyfail.sh # 无 root 权限
sudo bash check_copyfail.sh # 完整结果
SSH 循环
for HOST in server1 server2 server3; do
echo "=== $HOST ==="
ssh "$HOST" "curl -fsSL https://raw.githubusercontent.com/codesource/copyfail-check/main/check_copyfail.sh | sudo bash"
done
Ansible
- name: Check Copy Fail vulnerability
hosts: all
tasks:
- name: Run check script
script: check_copyfail.sh
become: yes
并行 SSH
pssh -h hosts.txt -i \
"curl -fsSL https://raw.githubusercontent.com/codesource/copyfail-check/main/check_copyfail.sh | sudo bash"
============================================================
Copy Fail CVE-2026-31431 – Vulnerability Check
============================================================
>>> Kernel Version
[INFO] Running kernel: 5.15.0-107-generic
[WARN] Kernel 5.15.0-107-generic is in the affected range (4.13 – 6.x).
>>> algif_aead Module Status
[WARN] algif_aead module is currently LOADED — system is exploitable.
[WARN] Module file found at: /lib/modules/5.15.0-107-generic/kernel/crypto/algif_aead.ko
[WARN] algif_aead is NOT blacklisted — it can be loaded on demand.
>>> Kernel Boot Parameter Mitigation
[WARN] initcall_blacklist=algif_aead_init is NOT set in boot parameters.
>>> AF_ALG Socket Reachability
[WARN] AF_ALG sockets are reachable by this user — exploit path is open.
>>> Mandatory Access Control (SELinux / AppArmor)
[WARN] Neither SELinux nor AppArmor tools detected — no MAC layer present.
>>> Distribution Patch Status
[WARN] Could not confirm CVE-2026-31431 is listed as fixed in running kernel's changelog.
============================================================
SUMMARY
============================================================
!! LIKELY VULNERABLE — No confirmed mitigation detected.
Recommended actions (in order of preference):
1. Apply your distro's kernel update as soon as available.
2. Add to /etc/modprobe.d/copyfail.conf:
blacklist algif_aead
install algif_aead /bin/true
Then run: sudo depmod -a && sudo update-initramfs -u
3. Add to kernel boot parameters (grub):
initcall_blacklist=algif_aead_init
4. Immediately unload the module if loaded:
sudo rmmod algif_aead
============================================================
请按优先顺序应用以下措施:
1. 修补内核 (最佳修复方案)
# Debian / Ubuntu
sudo apt update && sudo apt upgrade linux-image-$(uname -r)
# RHEL / CentOS / Amazon Linux
sudo yum update kernel
# SUSE
sudo zypper update kernel-default
2. 将模块列入黑名单 (立即生效,持久有效)
sudo tee /etc/modprobe.d/copyfail.conf << 'EOF'
blacklist algif_aead
install algif_aead /bin/true
EOF
sudo depmod -a
# Debian/Ubuntu
sudo update-initramfs -u
# RHEL/Fedora
sudo dracut -f
3. 立即卸载模块 (立即生效,重启后不持久)
sudo rmmod algif_aead
4. 内核启动参数 (黑名单的替代方案)
将 initcall_blacklist=algif_aead_init 添加到 GRUB 配置中并重启。
MIT — 可自由使用,不提供任何担保。始终在以 root 身份运行脚本之前对其进行审查。