
🔴 CVE-2025-40271: Critical Use-After-Free Vulnerability in the Linux Kernel
CVE-2025-40271 is a critical Use-After-Free (UAF) vulnerability affecting the /proc filesystem of the Linux kernel. The flaw resides in the proc_readdir_de() function, responsible for listing the contents of directories within /proc.
When a directory entry (PDE) is removed from the red-black tree (rbtree) via rb_erase(), the kernel did not mark the node as empty. This creates a dangerous scenario:
/proc/pid/net/dev_snmp6/) while another removes network interfaces (such as tun devices), the pointer may end up pointing to already freed memory.The kernel development team implemented a critical patch that replaces node handling with RB_CLEAR_NODE(). This ensures that:
NULL instead of a pointer to freed memory.The patch is already available in the following stable branches:
To review the exact patch code, see these commits:
"In the Linux kernel, the following vulnerability has been resolved: fs/proc: fix uaf in proc_readdir_de(). PDE is erased from subdir rbtree through
rb_erase(), but not set the node to EMPTY, which may result in UAF access. We should useRB_CLEAR_NODE()to set the erased node to EMPTY, thenpde_subdir_next()will returnNULLto avoid UAF access."
getdent to traverse /proc/pid/net/dev_snmp6/ (the current pointer is tun3).tun3 and tun2), removing them from the tree.
tun3 is removed, then tun2 (freed to the slab).getdent, but pde_subdir_next() returns tun2 (already freed), causing UAF.| CWE-ID | Name | Source |
|---|---|---|
| CWE-416 | Use After Free | NVD |
| URL | Description |
|---|---|
| NVD - CVE-2025-40271 | Official details (still without CVSS score) |
| Kernel.org Commits | Source code of patches |
⚠️ Final Recommendation:
If you use kernel versions 6.1.x, 6.6.x, 6.12.x or 6.13.x, update immediately to a patched version. If not possible, consider applying the commits manually or restricting access to /proc via security policies (e.g. chroot, SELinux).
| Field | Detail |
|---|
| ID | CVE-2025-40271 |
| Component | Linux Kernel (fs/proc) |
| Severity | High (though not yet officially scored by NVD/NIST) |
| Origin | Detected with stress-ng (simultaneous getdent and tun cases) |
| NVD Status | Not prioritized for enrichment (limited resources) |