[!IMPORTANT] 此仓库已归档。 Copy Fail 检查现已迁移至 cve-check,与其他漏洞检查以及可选的
--fix模式(用于应用修复)一同维护。有关此检查,请参见 checks/CVE-2026-31431。curl -fsSL https://raw.githubusercontent.com/codesource/cve-check/main/cve-check.sh | sudo bash -s -- CVE-2026-31431下方的
check_copyfail.sh仍然可用,但已不再更新。
用于检测 Linux 内核漏洞、检查缓解措施状态并指导修复的 Shell 脚本——设计为可在本地运行,也可通过 SSH、Ansible 或 pssh 在整个服务器集群中运行。
Copy Fail 是 Linux 内核 algif_aead 加密模块中的一个高危本地权限提升(LPE)漏洞。2017 年引入的一个逻辑缺陷允许任何非特权本地用户向任意可读文件的页缓存中写入 4 个受控字节——足以覆盖 setuid 二进制文件并获取 root 权限。目前已存在一个可用的 732 字节 Python 概念验证代码,并已公开。
| 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管道执行时,这也是更安全的选择。
该脚本设计为可在所有主流 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
提示: 在生产环境中固定到特定的 commit 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 # without root
sudo bash check_copyfail.sh # full results
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 身份运行脚本之前,请务必先审查脚本内容。