
Bash script to mitigate and patch CVE-2026-31431 (Copy Fail), a Linux kernel LPE, by blacklisting AF_ALG modules, flushing page cache, and updating the kernel.
This repository contains a specialized bash script designed to mitigate and patch CVE-2026-31431, also known as "Copy Fail". This vulnerability is a critical Local Privilege Escalation (LPE) in the Linux Kernel that allows unprivileged users to gain root access by poisoning the Page Cache via the AF_ALG (Crypto API) and splice() system calls.
CVE-2026-31431 exploits a logic flaw in the kernel's cryptographic templates. By chaining specific syscalls, an attacker can overwrite the Page Cache of SUID binaries (like /usr/bin/su) in memory without altering the physical file on disk. This results in a "fileless" privilege escalation that is difficult to detect with traditional file integrity monitoring tools.
Linux Kernels (v4.10 up to v6.18.x)
Major distributions including Kali Linux, Debian, Ubuntu, and RHEL.
The patch_copy_fail.sh script provides a three-layered defense mechanism:
Immediate Workaround: Blacklists the af_alg and algif_aead modules to disable the exploit's primary communication vector.
Memory Sanitization: Flushes the system Page Cache (drop_caches) to remove any existing malicious payloads residing in RAM.
Permanent Remediation: Automates the update to the latest patched kernel version for Debian/Kali-based systems.
[!CAUTION] Always audit scripts before running them with root privileges.
Clone the repository:
git clone https://github.com/xsanflip/CVE-2026-31431-Patch.git
cd CVE-2026-31431-Patch
Make the script executable:
chmod +x patch_copy_fail.sh
Run the script with sudo:
sudo ./patch_copy_fail.sh
Reboot: A system reboot is required to initialize the new, patched kernel.
The script performs the following actions:
Creates /etc/modprobe.d/blacklist-copyfail.conf.
Executes sync and echo 3 > /proc/sys/vm/drop_caches.
Runs apt update && apt install for the generic linux-image.
This script is provided "as is" for educational and system administration purposes. The author is not responsible for any misuse or damage caused by this script. Always test in a staging environment before deploying to production.
Author: XsanLahci
Date: April 2026