# CVE-2025-40303: btrfs: ensure no dirty metadata is written back for an fs with errors

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

- **Severity:** HIGH 7.8
- **CVSS:** 7.8 (v3.1, CNA) `CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H`
- **CVSS metrics:** Attack vector: Local; Attack complexity: Low; Privileges required: Low; User interaction: None; Scope: Unchanged; Confidentiality impact: High; Integrity impact: High; Availability impact: High
- **Exploited in the wild:** Not in CISA KEV
- **Public exploit / PoC:** None known
- **Remote exploitation:** Not remotely exploitable (local or adjacent access needed)
- **EPSS:** 0.23% (percentile 8, 2026-11-26)
- **Published:** 2025-12-08T00:46:27.820Z
- **Modified:** 2026-10-14T22:10:00.210Z

## Who should check

- Anyone running Linux \>= 13e6c37b989859e70b0d73d3f2cb0aa022159b17, \< 066ee13f05fbd82ada01883e51f0695172f98dff; \>= 13e6c37b989859e70b0d73d3f2cb0aa022159b17, \< e2b3859067bf012d53c49b3f885fef40624a2c83; \>= 13e6c37b989859e70b0d73d3f2cb0aa022159b17, \< 54a5b5a15588e3b0b294df31474d08a2678d4291; \>= 13e6c37b989859e70b0d73d3f2cb0aa022159b17, \< 2618849f31e7cf51fadd4a5242458501a6d5b315
- Anyone running Linux 3.10

## Description

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

btrfs: ensure no dirty metadata is written back for an fs with errors

\[BUG\]
During development of a minor feature (make sure all btrfs\_bio::end\_io()
is called in task context), I noticed a crash in generic/388, where
metadata writes triggered new works after btrfs\_stop\_all\_workers().

It turns out that it can even happen without any code modification, just
using RAID5 for metadata and the same workload from generic/388 is going
to trigger the use-after-free.

\[CAUSE\]
If btrfs hits an error, the fs is marked as error, no new
transaction is allowed thus metadata is in a frozen state.

But there are some metadata modifications before that error, and they are
still in the btree inode page cache.

Since there will be no real transaction commit, all those dirty folios
are just kept as is in the page cache, and they can not be invalidated
by invalidate\_inode\_pages2() call inside close\_ctree(), because they are
dirty.

And finally after btrfs\_stop\_all\_workers(), we call iput() on btree
inode, which triggers writeback of those dirty metadata.

And if the fs is using RAID56 metadata, this will trigger RMW and queue
new works into rmw\_workers, which is already stopped, causing warning
from queue\_work() and use-after-free.

\[FIX\]
Add a special handling for write\_one\_eb(), that if the fs is already in
an error state, immediately mark the bbio as failure, instead of really
submitting them.

Then during close\_ctree(), iput() will just discard all those dirty
tree blocks without really writing them back, thus no more new jobs for
already stopped-and-freed workqueues.

The extra discard in write\_one\_eb() also acts as an extra safenet.
E.g. the transaction abort is triggered by some extent/free space
tree corruptions, and since extent/free space tree is already corrupted
some tree blocks may be allocated where they shouldn't be (overwriting
existing tree blocks). In that case writing them back will further
corrupting the fs.

## Affected and fixed versions

- Linux: \>= 13e6c37b989859e70b0d73d3f2cb0aa022159b17, \< 066ee13f05fbd82ada01883e51f0695172f98dff; \>= 13e6c37b989859e70b0d73d3f2cb0aa022159b17, \< e2b3859067bf012d53c49b3f885fef40624a2c83; \>= 13e6c37b989859e70b0d73d3f2cb0aa022159b17, \< 54a5b5a15588e3b0b294df31474d08a2678d4291; \>= 13e6c37b989859e70b0d73d3f2cb0aa022159b17, \< 2618849f31e7cf51fadd4a5242458501a6d5b315 (cvelist)
- Linux: 3.10 (cvelist)

## Mitigation

- Upgrade Linux to 2618849f31e7cf51fadd4a5242458501a6d5b315 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-40303. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/CVE-2025-40303.md
Affected: Linux >= 13e6c37b989859e70b0d73d3f2cb0aa022159b17, < 066ee13f05fbd82ada01883e51f0695172f98dff; >= 13e6c37b989859e70b0d73d3f2cb0aa022159b17, < e2b3859067bf012d53c49b3f885fef40624a2c83; >= 13e6c37b989859e70b0d73d3f2cb0aa022159b17, < 54a5b5a15588e3b0b294df31474d08a2678d4291; >= 13e6c37b989859e70b0d73d…
Fixed in: Linux 066ee13f05fbd82ada01883e51f0695172f98dff, Linux 54a5b5a15588e3b0b294df31474d08a2678d4291, Linux 2618849f31e7cf51fadd4a5242458501a6d5b315

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-40303 being exploited?

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

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

High: CVSS 7.8 (v3.1, scored by CNA). Not remotely exploitable (local or adjacent access needed).

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

Linux \>= 13e6c37b989859e70b0d73d3f2cb0aa022159b17, \< 066ee13f05fbd82ada01883e51f0695172f98dff; \>= 13e6c37b989859e70b0d73d3f2cb0aa022159b17, \< e2b3859067bf012d53c49b3f885fef40624a2c83; \>= 13e6c37b989859e70b0d73d3f2cb0aa022159b17, \< 54a5b5a15588e3b0b294df31474d08a2678d4291; \>= 13e6c37b989859e70b0d73d3f2cb0aa022159b17, \< 2618849f31e7cf51fadd4a5242458501a6d5b315; Linux 3.10.

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

Yes. Fixed in Linux 066ee13f05fbd82ada01883e51f0695172f98dff, Linux 54a5b5a15588e3b0b294df31474d08a2678d4291, Linux 2618849f31e7cf51fadd4a5242458501a6d5b315. Upgrade Linux to 2618849f31e7cf51fadd4a5242458501a6d5b315 or later.

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

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

- other: <https://git.kernel.org/stable/c/066ee13f05fbd82ada01883e51f0695172f98dff>
- other: <https://git.kernel.org/stable/c/e2b3859067bf012d53c49b3f885fef40624a2c83>
- other: <https://git.kernel.org/stable/c/54a5b5a15588e3b0b294df31474d08a2678d4291>
- other: <https://git.kernel.org/stable/c/2618849f31e7cf51fadd4a5242458501a6d5b315>

## 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-40303>

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