
Audits and hardens Linux systems against AF_ALG local privilege escalation (CVE-2026-31431) by checking kernel crypto API exposure, restricting modules, and providing restore scripts.
This tool implements Structural Blocking to mitigate CVE-2026-31431 by physically renaming kernel modules and purging them from memory. Before use, please be aware of the following architectural risks:
/lib/modules/ directory, rendering the previous obstruction void.AF_ALG (Kernel Crypto API) may break specific applications or services that rely on kernel-level hardware acceleration (e.g., specialized VPNs, disk encryption utilities, or custom security tools).[cite: 3]Use at your own risk. Always verify your system's critical functions after running solution.sh.[cite: 3]
A tool kit for discovering, diagnosing, and containing LPE (Local Privilege Escalation) vectors through the Linux Kernel Crypto API (AF_ALG).
The tool uses Structural Blocking to address CVE-2026-31431 by renaming kernel modules and purging them from memory. Key architectural risks include:
/lib/modules/ directory, rendering the previous obstruction void.Use at your own risk.
This repository provides two scripts that form a diagnose → contain → verify workflow against privilege escalation attacks via AF_ALG (socket(38, 5, 0)):
check.sh — Multi-layer security posture audit (runs unprivileged)solution.sh — Force-evicts AF_ALG modules from memory + checks for physical module files (root required)restore.sh — Re-loads AF_ALG modules and restores the system to pre-solution.sh state (root required)./check.sh
sudo ./solution.sh
sudo ./restore.sh
restore.sh reverses the effects of solution.sh by reloading the AF_ALG kernel modules (af_alg, algif_rng, algif_aead, algif_skcipher, algif_hash). If the physical module file (af_alg.ko.xz) was renamed or removed, the script will warn you and prompt for manual restoration before attempting to load modules.
Running solution.sh on a live system that actively uses AF_ALG (e.g., a system with IPsec, dm-crypt/LUKS, or any hardware crypto offload) will instantly break all kernel crypto operations. This includes:
algif_* socket interfacesThe script force-unloads AF_ALG kernel modules. Kernel crypto operations will fail until reboot. This script is intended only for air-gapped, non-production, or disposable systems for testing and analysis purposes. Do not run it on production or critical infrastructure.
check.sh requires no dependencies beyond POSIX shell and /proc//syssolution.sh requires root privilegesrestore.sh requires root privilegesaf_alg_block.so requires root privileges to install via /etc/ld.so.preloadThis POC has been tested on WSL2. Be aware of the following:
wsl --shutdown). This includes kernel module state changes from solution.sh, file renames, check.sh results, and any local file modifications in this repository..wslconfig, /etc/wsl.conf, or an auto-start script (e.g., /etc/rc.local) separately.To definitively close the AF_ALG attack vector:
Blacklist the kernel module (most reliable):
echo "blacklist af_alg" | sudo tee /etc/modprobe.d/af_alg-blacklist.conf
Or rename the physical file:
sudo mv /lib/modules/$(uname -r)/kernel/crypto/af_alg.ko.xz \
/lib/modules/$(uname -r)/kernel/crypto/af_alg.ko.xz.bak
Disable AF_ALG via sysctl:
sudo sysctl -w net.core.af_alg_disabled=1
Block AF_ALG socket creation via SELinux / AppArmor policy
Disable unprivileged user namespaces (container environments):
sudo sysctl -w kernel.unprivileged_userns_clone=0
Block AF_ALG at the socket() syscall via LD_PRELOAD (WSL2 workaround):
# Install system-wide (requires root)
echo /absolute/path/to/af_alg_block.so | sudo tee -a /etc/ld.so.preload
A prebuilt shared library (af_alg_block.so) is included in the repository. It intercepts and returns when the domain is (38). All other socket calls pass through to the real implementation unchanged.
MIT
| Check | What it examines | Severity |
|---|
| Process Context | Current UID/GID and effective capabilities | Low |
| AF_ALG Crypto Socket | Kernel Crypto API accessibility via socket(AF_ALG, ...) | High |
| kptr_restrict | Kernel pointer visibility to userspace | Medium |
| dmesg_restrict | Kernel ring buffer access restriction | Medium |
| SELinux | Enforcing / Permissive / Disabled state | Medium |
| /proc hidepid | Whether /proc hides other processes' info | Low |
socket(2)EAFNOSUPPORTAF_ALGThis approach is primarily intended for WSL2 where single-user semantics and reset-on-reboot behavior make system-wide LD_PRELOAD practical. On traditional multi-user Linux systems, prefer method 1 (module blacklisting) instead — injecting via /etc/ld.so.preload affects every process on the system and may silently break AF_ALG-dependent services.
Note: Requires glibc (not musl). /etc/ld.so.preload requires root to modify. Removal is done by deleting the corresponding line from the file.