VYPR
Unrated severityNVD Advisory· Published Nov 12, 2025· Updated Apr 15, 2026

CVE-2025-40205

CVE-2025-40205

Description

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

btrfs: avoid potential out-of-bounds in btrfs_encode_fh()

The function btrfs_encode_fh() does not properly account for the three cases it handles.

Before writing to the file handle (fh), the function only returns to the user BTRFS_FID_SIZE_NON_CONNECTABLE (5 dwords, 20 bytes) or BTRFS_FID_SIZE_CONNECTABLE (8 dwords, 32 bytes).

However, when a parent exists and the root ID of the parent and the inode are different, the function writes BTRFS_FID_SIZE_CONNECTABLE_ROOT (10 dwords, 40 bytes).

If *max_len is not large enough, this write goes out of bounds because BTRFS_FID_SIZE_CONNECTABLE_ROOT is greater than BTRFS_FID_SIZE_CONNECTABLE originally returned.

This results in an 8-byte out-of-bounds write at fid->parent_root_objectid = parent_root_id.

A previous attempt to fix this issue was made but was lost.

https://lore.kernel.org/all/4CADAEEC020000780001B32C@vpn.id2.novell.com/

Although this issue does not seem to be easily triggerable, it is a potential memory corruption bug that should be fixed. This patch resolves the issue by ensuring the function returns the appropriate size for all three cases and validates that *max_len is large enough before writing any data.

AI Insight

LLM-synthesized narrative grounded in this CVE's description and references.

A missing size check in btrfs_encode_fh() can cause an out-of-bounds write when handling connectable file handles, potentially corrupting kernel memory.

Root

Cause

In the Linux kernel's BTRFS filesystem, the btrfs_encode_fh() function does not properly validate the provided buffer size (*max_len) against the actual size required for all three possible file handle types it can produce. The function initially returns to the caller sizes such as BTRFS_FID_SIZE_NON_CONNECTABLE (5 dwords) or BTRFS_FID_SIZE_CONNECTABLE (8 dwords). However, when a parent inode exists and the root IDs differ, the function writes BTRFS_FID_SIZE_CONNECTABLE_ROOT (10 dwords, 40 bytes) without checking that the buffer is large enough. This results in an 8-byte out-of-bounds write to fid->parent_root_objectid [1].

Exploitation

To trigger the bug, an attacker would need to invoke an operation that encodes a file handle for a BTRFS inode where a parent exists and the parent's root ID differs from the inode's root ID. The file handle's *max_len must be set to a value smaller than 40 bytes but larger than or equal to 32 bytes. While the issue is considered not easily triggerable in typical usage, it can be provoked by a specially crafted system call or a container escape scenario that passes a small buffer to the fh argument. The primary risk arises when the kernel writes beyond the intended buffer, leading to memory corruption [1].

Impact

An out-of-bounds write can corrupt adjacent kernel slab memory, potentially causing a system crash (denial of service) or, in more sophisticated attacks, allowing an escalation of privileges. Because the write occurs within a kernel function that is reachable from user space via system calls like name_to_handle_at(), a local attacker may exploit this to overwrite sensitive kernel structures. The exact exploitability depends on memory layout and mitigations such as KASLR, but the vulnerability is classified as a potential memory corruption bug [1].

Mitigation

The fix, applied in the upstream Linux kernel, ensures that btrfs_encode_fh() returns the correct size for all three handled cases and validates that *max_len is sufficiently large before writing any data. Users should update their kernel to include commits 43143776b0a7, 0276c8582488, d3a9a8e1275e, or 361d67276eb8 [1][2][3][4]. There is no known workaround other than applying the patch, as the vulnerability stems from incomplete bounds checking in core filesystem code.

AI Insight generated on May 19, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.

Affected products

2
  • Linux/Kernelinferred2 versions
    (expand)+ 1 more
    • (no CPE)
    • (no CPE)

Patches

8

Vulnerability mechanics

Generated on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

8

News mentions

0

No linked articles in our index yet.