CVE-2026-31516 Overview
A race condition vulnerability has been identified in the Linux kernel's XFRM (IPsec transformation) subsystem. The vulnerability exists in the handling of policy_hthresh.work during network namespace teardown operations. When a XFRM_MSG_NEWSPDINFO request queues the per-net work item onto the system workqueue, the callback function xfrm_hash_rebuild() retrieves the enclosing struct net via container_of(). If the network namespace is torn down before the queued work executes, the associated struct net may already be freed, leading to a use-after-free condition when xfrm_hash_rebuild() dereferences stale memory.
Critical Impact
This race condition can result in use-after-free memory access in kernel space, potentially leading to system instability, denial of service, or privilege escalation depending on how the freed memory is reallocated.
Affected Products
- Linux Kernel (multiple stable versions)
- Systems utilizing XFRM/IPsec transformations with network namespaces
- Container environments using network namespace isolation
Discovery Timeline
- 2026-04-22 - CVE CVE-2026-31516 published to NVD
- 2026-04-23 - Last updated in NVD database
Technical Details for CVE-2026-31516
Vulnerability Analysis
This vulnerability is a classic race condition between asynchronous work queue processing and resource cleanup. The XFRM subsystem uses a per-network-namespace work item (policy_hthresh.work) that can be queued via XFRM_MSG_NEWSPDINFO netlink requests. The vulnerability arises because xfrm_policy_fini(), which handles network namespace teardown cleanup, already flushes policy_hash_work but fails to synchronize policy_hthresh.work.
The xfrm_hash_rebuild() callback uses container_of() to obtain a pointer to the parent struct net from the work item structure. This is a common kernel pattern, but it becomes dangerous when the parent structure can be freed while the work item remains queued. The race window exists between queuing the work and the network namespace being destroyed.
Root Cause
The root cause is incomplete synchronization during network namespace teardown in xfrm_policy_fini(). While the function properly flushes policy_hash_work, it neglects to cancel or flush policy_hthresh.work. This oversight creates a time-of-check-time-of-use (TOCTOU) window where the work item can execute after its associated network namespace has been freed.
The fix involves adding proper synchronization for policy_hthresh.work in xfrm_policy_fini(), ensuring the queued work cannot outlive the network namespace teardown and access freed memory structures.
Attack Vector
The vulnerability can be triggered by an attacker with the ability to send netlink messages and manipulate network namespaces. The attack vector involves:
- Creating a network namespace
- Sending XFRM_MSG_NEWSPDINFO requests to queue the policy_hthresh.work item
- Racing to destroy the network namespace before the work executes
- The xfrm_hash_rebuild() callback then operates on freed memory
While local access is typically required, container environments and systems allowing unprivileged user namespaces may be at increased risk.
Detection Methods for CVE-2026-31516
Indicators of Compromise
- Kernel oops or panic messages referencing xfrm_hash_rebuild or XFRM-related functions
- KASAN (Kernel Address Sanitizer) reports indicating use-after-free in XFRM subsystem
- Unexpected system crashes during network namespace creation/destruction operations
- Memory corruption artifacts in kernel logs related to netlink processing
Detection Strategies
- Enable KASAN on development/staging systems to detect memory safety violations in the XFRM subsystem
- Monitor kernel logs for oops, panics, or warnings involving xfrm_policy_fini, xfrm_hash_rebuild, or related functions
- Implement audit rules for XFRM_MSG_NEWSPDINFO netlink messages to track potential exploitation attempts
- Use kernel tracing tools (ftrace, eBPF) to monitor XFRM work queue operations during namespace teardown
Monitoring Recommendations
- Deploy runtime kernel integrity monitoring solutions to detect anomalous kernel behavior
- Configure centralized logging for all kernel messages to enable correlation of XFRM-related events
- Implement SentinelOne Singularity Platform for real-time kernel-level threat detection and behavioral analysis
- Monitor container orchestration platforms for unusual network namespace churn patterns
How to Mitigate CVE-2026-31516
Immediate Actions Required
- Apply the latest kernel security patches from your distribution vendor
- Restrict network namespace creation to privileged users where possible by setting user.max_user_namespaces sysctl
- Audit systems using IPsec/XFRM transformations in containerized environments
- Enable kernel lockdown mode where supported to limit attack surface
Patch Information
Multiple kernel patches have been released to address this vulnerability. The fix adds synchronization for policy_hthresh.work in xfrm_policy_fini() to ensure proper cleanup ordering. The following commits contain the fix:
- Kernel Patch Commit 29fe3a6
- Kernel Patch Commit 4e2e778
- Kernel Patch Commit 56ea225
- Kernel Patch Commit 8854e93
Workarounds
- Limit access to netlink sockets and network namespace operations to trusted users and processes
- Disable unprivileged user namespaces if not required by setting kernel.unprivileged_userns_clone=0
- Implement network policy enforcement to restrict container networking operations in orchestrated environments
- Consider deploying mandatory access control (SELinux/AppArmor) policies to limit XFRM subsystem access
# Disable unprivileged user namespaces as a temporary mitigation
echo 'kernel.unprivileged_userns_clone=0' >> /etc/sysctl.d/99-security.conf
sysctl -p /etc/sysctl.d/99-security.conf
# Limit maximum user namespaces per user
echo 'user.max_user_namespaces=0' >> /etc/sysctl.d/99-security.conf
sysctl -p /etc/sysctl.d/99-security.conf
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.


