# CVE-2025-38365: btrfs: fix a race between renames and directory logging

> Archived entry. Full-text search covers entries since 2026-11-10; exact IDs work for all years.

- **Severity:** CRITICAL 9.1
- **CVSS:** 9.1 (v3.1, CNA) `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:H`
- **CVSS metrics:** Attack vector: Network; Attack complexity: Low; Privileges required: None; User interaction: None; Scope: Unchanged; Confidentiality impact: None; Integrity impact: High; Availability impact: High
- **Exploited in the wild:** Not in CISA KEV
- **Public exploit / PoC:** None known
- **Remote exploitation:** Remote, no login needed
- **EPSS:** 0.52% (percentile 37, 2026-11-26)
- **CWE:** CWE-362
- **Published:** 2025-07-25T12:47:35.387Z
- **Modified:** 2026-08-05T12:01:22.398Z

## Who should check

- Anyone running Linux \>= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, \< 51bd363c7010d033d3334daf457c824484bf9bf0; \>= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, \< aeeae8feeaae4445a86f9815273e81f902dc1f5b; \>= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, \< 2088895d5903082bb9021770b919e733c57edbc1; \>= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, \< 8c6874646c21bd820cf475e2874e62c133954023; \>= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, \< 3ca864de852bc91007b32d2a0d48993724f4abad
- Anyone running Linux 5.18

## Description

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

btrfs: fix a race between renames and directory logging

We have a race between a rename and directory inode logging that if it
happens and we crash/power fail before the rename completes, the next time
the filesystem is mounted, the log replay code will end up deleting the
file that was being renamed.

This is best explained following a step by step analysis of an interleaving
of steps that lead into this situation.

Consider the initial conditions:

1) We are at transaction N;

2) We have directories A and B created in a past transaction (\< N);

3) We have inode X corresponding to a file that has 2 hardlinks, one in
   directory A and the other in directory B, so we'll name them as
   "A/foo\_link1" and "B/foo\_link2". Both hard links were persisted in a
   past transaction (\< N);

4) We have inode Y corresponding to a file that as a single hard link and
   is located in directory A, we'll name it as "A/bar". This file was also
   persisted in a past transaction (\< N).

The steps leading to a file loss are the following and for all of them we
are under transaction N:

 1) Link "A/foo\_link1" is removed, so inode's X last\_unlink\_trans field
    is updated to N, through btrfs\_unlink() -\> btrfs\_record\_unlink\_dir();

 2) Task A starts a rename for inode Y, with the goal of renaming from
    "A/bar" to "A/baz", so we enter btrfs\_rename();

 3) Task A inserts the new BTRFS\_INODE\_REF\_KEY for inode Y by calling
    btrfs\_insert\_inode\_ref();

 4) Because the rename happens in the same directory, we don't set the
    last\_unlink\_trans field of directoty A's inode to the current
    transaction id, that is, we don't cal btrfs\_record\_unlink\_dir();

 5) Task A then removes the entries from directory A (BTRFS\_DIR\_ITEM\_KEY
    and BTRFS\_DIR\_INDEX\_KEY items) when calling \_\_btrfs\_unlink\_inode()
    (actually the dir index item is added as a delayed item, but the
    effect is the same);

 6) Now before task A adds the new entry "A/baz" to directory A by
    calling btrfs\_add\_link(), another task, task B is logging inode X;

 7) Task B starts a fsync of inode X and after logging inode X, at
    btrfs\_log\_inode\_parent() it calls btrfs\_log\_all\_parents(), since
    inode X has a last\_unlink\_trans value of N, set at in step 1;

 8) At btrfs\_log\_all\_parents() we search for all parent directories of
    inode X using the commit root, so we find directories A and B and log
    them. Bu when logging direct A, we don't have a dir index item for
    inode Y anymore, neither the old name "A/bar" nor for the new name
    "A/baz" since the rename has deleted the old name but has not yet
    inserted the new name - task A hasn't called yet btrfs\_add\_link() to
    do that.

    Note that logging directory A doesn't fallback to a transaction
    commit because its last\_unlink\_trans has a lower value than the
    current transaction's id (see step 4);

 9) Task B finishes logging directories A and B and gets back to
    btrfs\_sync\_file() where it calls btrfs\_sync\_log() to persist the log
    tree;

10) Task B successfully persisted the log tree, btrfs\_sync\_log() completed
    with success, and a power failure happened.

    We have a log tree without any directory entry for inode Y, so the
    log replay code deletes the entry for inode Y, name "A/bar", from the
    subvolume tree since it doesn't exist in the log tree and the log
    tree is authorative for its index (we logged a BTRFS\_DIR\_LOG\_INDEX\_KEY
    item that covers the index range for the dentry that corresponds to
    "A/bar").

    Since there's no other hard link for inode Y and the log replay code
    deletes the name "A/bar", the file is lost.

The issue wouldn't happen if task B synced the log only after task A
called btrfs\_log\_new\_name(), which would update the log with the new name
for inode Y ("A/bar").

Fix this by pinning the log root during renames before removing the old
directory entry, and unpinning af
---truncated---

## Affected and fixed versions

- Linux: \>= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, \< 51bd363c7010d033d3334daf457c824484bf9bf0; \>= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, \< aeeae8feeaae4445a86f9815273e81f902dc1f5b; \>= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, \< 2088895d5903082bb9021770b919e733c57edbc1; \>= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, \< 8c6874646c21bd820cf475e2874e62c133954023; \>= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, \< 3ca864de852bc91007b32d2a0d48993724f4abad (cvelist)
- Linux: 5.18 (cvelist)

## Mitigation

- Upgrade Linux to 3ca864de852bc91007b32d2a0d48993724f4abad or later.

## Check your systems with an agent

Paste this into a coding agent:

```text
Check whether anything I run is affected by CVE-2025-38365. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/CVE-2025-38365.md
Affected: Linux >= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, < 51bd363c7010d033d3334daf457c824484bf9bf0; >= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, < aeeae8feeaae4445a86f9815273e81f902dc1f5b; >= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, < 2088895d5903082bb9021770b919e733c57edbc1; >= 259c4b96d78dda8477a3ac2…
Fixed in: Linux 51bd363c7010d033d3334daf457c824484bf9bf0, Linux 2088895d5903082bb9021770b919e733c57edbc1, Linux 8c6874646c21bd820cf475e2874e62c133954023, Linux 3ca864de852bc91007b32d2a0d48993724f4abad

Steps:
1. Search this machine and project for Linux: dependency manifests and lockfiles, installed packages, container images and running services.
2. For each match, note the installed version and whether it is inside the affected range.
3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
```

## FAQ

### Is CVE-2025-38365 being exploited?

There is no confirmed exploitation: CVE-2025-38365 is not in the CISA Known Exploited Vulnerabilities catalog. No public exploit code is known. EPSS estimates a 0.52% chance of exploitation in the next 30 days (as of 2026-11-26).

### How serious is CVE-2025-38365?

Critical: CVSS 9.1 (v3.1, scored by CNA). Remote, no login needed.

### Which versions are affected by CVE-2025-38365?

Linux \>= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, \< 51bd363c7010d033d3334daf457c824484bf9bf0; \>= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, \< aeeae8feeaae4445a86f9815273e81f902dc1f5b; \>= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, \< 2088895d5903082bb9021770b919e733c57edbc1; \>= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, \< 8c6874646c21bd820cf475e2874e62c133954023; \>= 259c4b96d78dda8477a3ac21d6b3cf0eb9f75c8b, \< 3ca864de852bc91007b32d2a0d48993724f4abad; Linux 5.18.

### Is there a fix for CVE-2025-38365?

Yes. Fixed in Linux 51bd363c7010d033d3334daf457c824484bf9bf0, Linux 2088895d5903082bb9021770b919e733c57edbc1, Linux 8c6874646c21bd820cf475e2874e62c133954023, Linux 3ca864de852bc91007b32d2a0d48993724f4abad. Upgrade Linux to 3ca864de852bc91007b32d2a0d48993724f4abad or later.

### How do I check if I'm affected by CVE-2025-38365?

Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.

## References

- patch: <https://git.kernel.org/stable/c/51bd363c7010d033d3334daf457c824484bf9bf0>
- patch: <https://git.kernel.org/stable/c/aeeae8feeaae4445a86f9815273e81f902dc1f5b>
- patch: <https://git.kernel.org/stable/c/2088895d5903082bb9021770b919e733c57edbc1>
- patch: <https://git.kernel.org/stable/c/8c6874646c21bd820cf475e2874e62c133954023>
- patch: <https://git.kernel.org/stable/c/3ca864de852bc91007b32d2a0d48993724f4abad>
- other: <https://lists.debian.org/debian-lts-announce/2025/10/msg00008.html>

## Attribution

- CVE Program: CVE® is a registered trademark of The MITRE Corporation. CVE records © 1999–2026 The MITRE Corporation. <https://www.cve.org/Legal/TermsOfUse>
- NVD: This product uses data from the NVD API but is not endorsed or certified by the NVD. <https://nvd.nist.gov/vuln/detail/CVE-2025-38365>

HTML: <https://flawdb.com/CVE-2025-38365> · JSON: <https://flawdb.com/api/v1/entries/CVE-2025-38365>
