Skip to main content
Vulnerability Database/CVE-2025-21714

CVE-2025-21714: Linux Kernel Use-After-Free Vulnerability

CVE-2025-21714 is a use-after-free vulnerability in Linux Kernel RDMA/mlx5 that occurs during implicit ODP memory region destruction. This post covers the technical details, affected versions, and mitigation strategies.

Updated:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2025-21714 Overview

CVE-2025-21714 is a use-after-free vulnerability [CWE-416] in the Linux kernel's RDMA/mlx5 driver. The flaw resides in the implicit On-Demand Paging (ODP) memory region (MR) destruction path. The kernel could queue the same MR destroy work item twice, allowing the second work item to execute after the MR had already been freed by the first. The fix uses __xa_cmpxchg() to ensure exactly one destroy operation is queued per MR. The vulnerability affects local users on systems running Mellanox ConnectX RDMA hardware with the mlx5_ib driver loaded.

Critical Impact

A local attacker with access to RDMA verbs interfaces can trigger memory corruption in the kernel, leading to privilege escalation, kernel information disclosure, or denial of service.

Affected Products

  • Linux Kernel (mainline branches prior to the fix commits)
  • Linux Kernel stable branches missing backports 7cc8f681, d3d93041, and edfb65db
  • Distributions shipping mlx5_ib with implicit ODP support enabled

Discovery Timeline

  • 2025-02-27 - CVE CVE-2025-21714 published to NVD
  • 2025-03-24 - Last updated in NVD database

Technical Details for CVE-2025-21714

Vulnerability Analysis

The vulnerability lives in the mlx5_ib driver path responsible for tearing down implicit ODP child memory regions. RDMA/mlx5 uses an XArray to track MR objects and queues a workqueue item (free_implicit_child_mr_work) to perform asynchronous cleanup. Without an atomic compare-and-exchange on the XArray entry, two concurrent invalidation paths could both observe a valid MR pointer and both schedule destroy work for the same object.

The second worker executes after the first has already dropped the final reference and freed the MR. This produces the observed refcount_t: underflow; use-after-free warning from refcount_warn_saturate and dereferences memory belonging to a freed mlx5_ib_mr structure. Successful exploitation requires local access and the ability to interact with RDMA user verbs, but the resulting kernel heap corruption can be steered toward privilege escalation.

Root Cause

The destroy path read the MR pointer from the XArray and queued work without atomically clearing the slot. Two threads racing on the same implicit ODP MR could both pass the existence check and both enqueue free_implicit_child_mr_work, violating the single-owner invariant required for safe refcount handling.

Attack Vector

A local user with permission to open /dev/infiniband/uverbs* and create ODP-enabled memory regions can race MR invalidation events, for example by repeatedly unmapping memory regions registered with implicit ODP. The race window is small but reachable from unprivileged user space if RDMA device nodes are exposed, which is common on HPC and AI cluster nodes using Mellanox ConnectX adapters.

// Vulnerability mechanism (prose description - no verified PoC available)
// Thread A: invalidates implicit child MR -> reads xa entry -> queues destroy work
// Thread B: invalidates same MR concurrently -> reads same xa entry -> queues destroy work
// Worker 1: executes free_implicit_child_mr_work -> frees mlx5_ib_mr, drops final refcount
// Worker 2: executes free_implicit_child_mr_work -> refcount_dec on freed memory -> UAF
//
// Fix: __xa_cmpxchg() atomically replaces the entry with NULL, so only the winning
// thread proceeds to queue the destroy work.

Detection Methods for CVE-2025-21714

Indicators of Compromise

  • Kernel log entries containing refcount_t: underflow; use-after-free originating from refcount_warn_saturate+0x12b/0x130.
  • Stack traces referencing free_implicit_child_mr_work in the mlx5_ib module.
  • Unexpected kernel oops or panic events on hosts with mlx5_core and mlx5_ib loaded.
  • Workqueue traces showing events_unbound executing free_implicit_child_mr_work repeatedly for the same MR.

Detection Strategies

  • Parse dmesg and /var/log/kern.log for refcount underflow warnings tied to mlx5_ib symbols.
  • Enable CONFIG_DEBUG_KMEMLEAK and KASAN on test kernels to surface UAF behavior during fuzzing of RDMA verbs.
  • Audit running kernel versions against the patched commits 7cc8f681, d3d93041, and edfb65db using package inventory data.

Monitoring Recommendations

  • Forward kernel ring buffer messages to a central log pipeline and alert on refcount_warn_saturate and free_implicit_child_mr_work strings.
  • Track which local users open /dev/infiniband/uverbs* devices and monitor for abnormal frequency of MR registration and deregistration.
  • Correlate kernel warnings with process-level telemetry to identify the user context triggering the race.

How to Mitigate CVE-2025-21714

Immediate Actions Required

  • Apply the upstream patches 7cc8f681f6d4, d3d930411ce3, and edfb65dbb9ff or upgrade to a distribution kernel that includes them.
  • Restrict access to /dev/infiniband/* device nodes to trusted users and service accounts only.
  • On systems that do not require RDMA, unload or blacklist the mlx5_ib module to remove the vulnerable code path.

Patch Information

The fix introduces __xa_cmpxchg() in the implicit ODP destroy path so that only one caller can transition the XArray slot from a valid MR pointer to NULL and proceed to queue free_implicit_child_mr_work. Reference the upstream commits: Linux Kernel Commit 7cc8f68, Linux Kernel Commit d3d9304, and Linux Kernel Commit edfb65d.

Workarounds

  • Tighten permissions on RDMA character devices using udev rules so only members of a dedicated rdma group can open them.
  • Disable implicit ODP on workloads that do not require it by reconfiguring application MR registration flags.
  • Blacklist mlx5_ib on hosts without RDMA workloads to eliminate the attack surface entirely.
bash
# Restrict RDMA device access and optionally blacklist the driver
# /etc/udev/rules.d/90-rdma-restrict.rules
KERNEL=="uverbs*", GROUP="rdma", MODE="0660"
KERNEL=="rdma_cm", GROUP="rdma", MODE="0660"

# Disable mlx5_ib on hosts that do not need RDMA
echo "blacklist mlx5_ib" | sudo tee /etc/modprobe.d/blacklist-mlx5_ib.conf
sudo update-initramfs -u

# Verify kernel version includes the fix
uname -r

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.