CVE-2025-21731 Overview
CVE-2025-21731 is a use-after-free vulnerability [CWE-416] in the Linux kernel's Network Block Device (NBD) subsystem. The flaw allows a local attacker with privileges to trigger a race condition between the nbd_genl_disconnect() and nbd_genl_reconfigure() netlink handlers. Successful exploitation frees the nbd_config structure while a worker thread still references it, leading to memory corruption in kernel space. This can result in kernel crashes, privilege escalation, or arbitrary code execution at ring 0. The issue affects multiple Linux kernel branches and has been patched in stable trees.
Critical Impact
Local attackers can trigger a kernel use-after-free in the NBD subsystem, potentially escalating privileges or crashing the host.
Affected Products
- Linux kernel (multiple stable branches prior to fix commits)
- Debian LTS distributions (patched via DLA advisories March and May 2025)
- Siemens industrial products referencing kernel (per Siemens advisory SSA-019113)
Discovery Timeline
- 2025-02-27 - CVE-2025-21731 published to the National Vulnerability Database
- 2026-07-14 - Last updated in NVD database
Technical Details for CVE-2025-21731
Vulnerability Analysis
The vulnerability resides in the Network Block Device (NBD) driver's netlink control path. NBD exports remote block devices over the network and manages connection state through nbd_config structures protected by reference counting. The bug occurs when a thread holds a temporary reference to nbd_config while another thread executes disconnect and reconfigure operations in sequence.
When nbd_genl_disconnect() runs, it flushes the receive workqueue and calls nbd_config_put(). However, because a temporary reference remains, the config object is not freed. The NBD_RT_BOUND bit remains set, allowing a subsequent nbd_genl_reconfigure() call to succeed and requeue recv_work(). Once the temporary reference is released, the config drops to zero and is freed, but the queued worker still holds a stale pointer. When recv_work() executes and calls atomic_dec(&config->recv_threads), it dereferences freed memory.
Root Cause
The root cause is missing state invalidation during disconnect. The nbd_genl_disconnect() handler did not clear the NBD_RT_BOUND flag, allowing reconnect operations to proceed against a config object that was scheduled for teardown. This produced a classic use-after-free [CWE-416] window between reference-counted teardown and worker execution.
Attack Vector
Exploitation requires local access with permissions to issue NBD netlink commands (typically CAP_SYS_ADMIN). An attacker races NBD_CMD_DISCONNECT and NBD_CMD_RECONFIGURE netlink messages against an active NBD device to trigger the freed nbd_config dereference. Successful races corrupt kernel heap state and may be leveraged for local privilege escalation.
No public proof-of-concept exploit is currently listed for this CVE. Technical details of the fix are available in the kernel stable commits.
Detection Methods for CVE-2025-21731
Indicators of Compromise
- Unexpected kernel oops or panic messages referencing nbd_config_put, recv_work, or atomic_dec in dmesg and kernel ring buffers.
- KASAN reports flagging use-after-free reads or writes inside the NBD driver (drivers/block/nbd.c).
- Repeated NBD_CMD_DISCONNECT followed by NBD_CMD_RECONFIGURE netlink activity from a single process.
Detection Strategies
- Monitor auditd rules for nbd netlink family usage (NBD_GENL_FAMILY_NAME) from unprivileged or unexpected processes.
- Enable KASAN and lockdep in test kernels to surface UAF races before deployment.
- Correlate NBD device state transitions with process ancestry to identify anomalous reconfigure patterns.
Monitoring Recommendations
- Alert on kernel crash artifacts (vmcore, kdump) that reference NBD symbols.
- Track kernel package versions across the fleet and flag hosts running pre-patch builds.
- Log all invocations of nbd-client and equivalent tooling for post-incident review.
How to Mitigate CVE-2025-21731
Immediate Actions Required
- Apply the latest stable kernel updates from your distribution vendor that include the upstream fix clearing NBD_RT_BOUND in nbd_genl_disconnect().
- On Debian systems, install the kernel updates announced in the Debian LTS advisory (March 2025) and the Debian LTS advisory (May 2025).
- For Siemens industrial systems, follow remediation guidance in Siemens Security Advisory SSA-019113.
Patch Information
The upstream fix ensures NBD_RT_BOUND is cleared during disconnect so that subsequent reconfigure attempts fail cleanly. Fix commits are available in the kernel stable tree, including 844b8cdc6816, e70a578487a4, and 9793bd5ae4bd, among others listed in the vendor advisory set.
Workarounds
- Unload the nbd kernel module on systems that do not require Network Block Device functionality: modprobe -r nbd.
- Blacklist the module to prevent auto-load: add blacklist nbd to /etc/modprobe.d/blacklist-nbd.conf.
- Restrict CAP_SYS_ADMIN and netlink access to trusted administrators to reduce the local attack surface.
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

