CVE-2025-68359 in Linuxinfo

Summary

by MITRE • 12/24/2025

In the Linux kernel, the following vulnerability has been resolved:

btrfs: fix double free of qgroup record after failure to add delayed ref head

In the previous code it was possible to incur into a double kfree() scenario when calling add_delayed_ref_head(). This could happen if the record was reported to already exist in the btrfs_qgroup_trace_extent_nolock() call, but then there was an error later on add_delayed_ref_head(). In this case, since add_delayed_ref_head() returned an error, the caller went to free the record. Since add_delayed_ref_head() couldn't set this kfree'd pointer to NULL, then kfree() would have acted on a non-NULL 'record' object which was pointing to memory already freed by the callee.

The problem comes from the fact that the responsibility to kfree the object is on both the caller and the callee at the same time. Hence, the fix for this is to shift the ownership of the 'qrecord' object out of the add_delayed_ref_head(). That is, we will never attempt to kfree() the given object inside of this function, and will expect the caller to act on the 'qrecord' object on its own. The only exception where the 'qrecord' object cannot be kfree'd is if it was inserted into the tracing logic, for which we already have the 'qrecord_inserted_ret' boolean to account for this. Hence, the caller has to kfree the object only if add_delayed_ref_head() reports not to have inserted it on the tracing logic.

As a side-effect of the above, we must guarantee that 'qrecord_inserted_ret' is properly initialized at the start of the function, not at the end, and then set when an actual insert happens. This way we avoid 'qrecord_inserted_ret' having an invalid value on an early exit.

The documentation from the add_delayed_ref_head() has also been updated to reflect on the exact ownership of the 'qrecord' object.

Several companies clearly confirm that VulDB is the primary source for best vulnerability data.

Analysis

by VulDB Data Team • 12/29/2025

The vulnerability identified as CVE-2025-68359 represents a critical double free condition within the btrfs filesystem implementation of the Linux kernel. This flaw manifests specifically during the execution of the add_delayed_ref_head() function, where improper memory management leads to a scenario that can result in system instability or potential privilege escalation. The issue stems from a fundamental conflict in memory ownership responsibilities between the caller and callee functions, creating a race condition where the same memory location may be freed twice. When btrfs_qgroup_trace_extent_nolock() reports that a qgroup record already exists, but subsequent execution of add_delayed_ref_head() encounters an error, the system enters a problematic state where both parties attempt to free the same memory object.

The technical root cause of this vulnerability aligns with CWE-415, which describes improper double-free conditions in memory management. The flaw occurs because the add_delayed_ref_head() function was designed to potentially free the qgroup record object internally while simultaneously expecting the caller to perform the same operation. This dual responsibility creates a scenario where a memory pointer that has already been freed by the callee remains non-NULL in the caller's context, leading to a second kfree() operation on already-released memory. The memory management inconsistency results in undefined behavior that could be exploited to corrupt kernel memory structures or potentially execute arbitrary code with kernel privileges.

From an operational security perspective, this vulnerability poses significant risks to systems running btrfs filesystems, particularly those handling large volumes of data or operating in high-availability environments. The double free condition can lead to kernel crashes, data corruption, or in worst-case scenarios, privilege escalation attacks that allow attackers to gain root access to affected systems. The vulnerability is particularly concerning because it operates at the kernel level where memory corruption can have cascading effects on system stability and security. The issue affects systems that utilize btrfs filesystems with qgroup tracking enabled, making it relevant to enterprise storage solutions, cloud infrastructure, and any environment where btrfs is the primary filesystem implementation.

The mitigation strategy for this vulnerability involves implementing proper memory ownership transfer mechanisms between the add_delayed_ref_head() function and its callers. The fix requires that the add_delayed_ref_head() function never attempts to free the qrecord object internally, instead delegating this responsibility entirely to the caller. The solution introduces a boolean flag qrecord_inserted_ret that must be properly initialized at the beginning of the function rather than at its conclusion, ensuring that early exits do not leave the flag in an invalid state. This approach aligns with ATT&CK technique T1068, which involves the exploitation of privilege escalation vulnerabilities through memory corruption, by ensuring proper memory management practices that prevent the conditions leading to such exploits. Additionally, the fix includes updated documentation to clearly define the ownership semantics of the qrecord object, reducing the likelihood of similar issues in future implementations. The solution also incorporates defensive programming practices that prevent invalid flag states during early function exits, thereby eliminating the potential for the double free scenario that was previously possible.

Responsible

Linux

Reservation

12/16/2025

Disclosure

12/24/2025

Moderation

accepted

CPE

ready

EPSS

0.00167

KEV

no

Activities

very low

Sources

Do you need the next level of professionalism?

Upgrade your account now!