7.8
HIGH CVSS 3.1
CVE-2025-40303
btrfs: ensure no dirty metadata is written back for an fs with errors
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.

INFO

Published Date :

Dec. 8, 2025, 1:16 a.m.

Last Modified :

Oct. 14, 2026, 10:10 p.m.

Remotely Exploit :

No

Source :

416baaa9-dc9f-4396-8d5f-8c081fb06d67
Affected Products

The following products are affected by CVE-2025-40303 vulnerability. Even if cvefeed.io is aware of the exact versions of the products that are affected, the information is not represented in the table below.

ID Vendor Product Action
1 Linux linux_kernel
CVSS Scores
The Common Vulnerability Scoring System is a standardized framework for assessing the severity of vulnerabilities in software and systems. We collect and displays CVSS scores from various sources for each CVE.
Score Version Severity Vector Exploitability Score Impact Score Source
CVSS 3.1 HIGH 416baaa9-dc9f-4396-8d5f-8c081fb06d67
Solution
Address filesystem error handling and metadata writeback to prevent use-after-free and corruption.
  • Update the Linux kernel to the latest version.
  • Ensure filesystem metadata is clean before writing.
  • Avoid metadata writes on error-marked filesystems.
  • Test filesystem stability after applying updates.
References to Advisories, Solutions, and Tools
CWE - Common Weakness Enumeration

While CVE identifies specific instances of vulnerabilities, CWE categorizes the common flaws or weaknesses that can lead to vulnerabilities. CVE-2025-40303 is associated with the following CWEs:

Common Attack Pattern Enumeration and Classification (CAPEC)

Common Attack Pattern Enumeration and Classification (CAPEC) stores attack patterns, which are descriptions of the common attributes and approaches employed by adversaries to exploit the CVE-2025-40303 weaknesses.

We scan GitHub repositories to detect new proof-of-concept exploits. Following list is a collection of public exploits and proof-of-concepts, which have been published on GitHub (sorted by the most recently updated).

Results are limited to the first 15 repositories due to potential performance issues.

The following list is the news that have been mention CVE-2025-40303 vulnerability anywhere in the article.

The following table lists the changes that have been made to the CVE-2025-40303 vulnerability over time.

Vulnerability history details can be useful for understanding the evolution of a vulnerability, and for identifying the most recent changes that may impact the vulnerability's severity, exploitability, or other characteristics.

  • CVE Translated by [email protected]

    Oct. 14, 2026

    Action Type Old Value New Value
    Added Translation Title: Linux, Description: En el kernel de Linux, la siguiente vulnerabilidad ha sido resuelta: btrfs: asegurar que no se escriban metadatos sucios para un sistema de archivos con errores [ERROR] Durante el desarrollo de una característica menor (asegurar que todas las llamadas a btrfs_bio::end_io() se realicen en contexto de tarea), noté un fallo en generic/388, donde las escrituras de metadatos activaron nuevos trabajos después de btrfs_stop_all_workers(). Resulta que puede ocurrir incluso sin ninguna modificación de código, solo usando RAID5 para metadatos y la misma carga de trabajo de generic/388 va a activar el uso después de liberación. [CAUSA] Si btrfs encuentra un error, el sistema de archivos se marca como error, no se permite ninguna nueva transacción, por lo tanto, los metadatos están en un estado congelado. Pero hay algunas modificaciones de metadatos antes de ese error, y todavía están en la caché de páginas de inodos del btree. Dado que no habrá una confirmación de transacción real, todos esos folios sucios se mantienen tal cual en la caché de páginas, y no pueden ser invalidados por la llamada a invalidate_inode_pages2() dentro de close_ctree(), porque están sucios. Y finalmente después de btrfs_stop_all_workers(), llamamos a iput() en el inodo del btree, lo que activa la escritura de esos metadatos sucios. Y si el sistema de archivos está usando metadatos RAID56, esto activará RMW y encolará nuevos trabajos en rmw_workers, que ya está detenido, causando una advertencia de queue_work() y uso después de liberación. [SOLUCIÓN] Añadir un manejo especial para write_one_eb(), que si el sistema de archivos ya está en un estado de error, marque inmediatamente el bbio como fallo, en lugar de realmente enviarlos. Luego, durante close_ctree(), iput() simplemente descartará todos esos bloques de árbol sucios sin realmente escribirlos de vuelta, por lo tanto, no más trabajos nuevos para las colas de trabajo ya detenidas y liberadas. El descarte adicional en write_one_eb() también actúa como una red de seguridad adicional. Por ejemplo, la anulación de la transacción es activada por algunas corrupciones del árbol de extensiones/espacio libre, y dado que el árbol de extensiones/espacio libre ya está corrupto, algunos bloques de árbol pueden ser asignados donde no deberían (sobrescribiendo bloques de árbol existentes). En ese caso, escribirlos de vuelta corromperá aún más el sistema de archivos.
  • CVE Modified by 416baaa9-dc9f-4396-8d5f-8c081fb06d67

    Jul. 30, 2026

    Action Type Old Value New Value
    Added CVSS V3.1 AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
  • CVE Modified by 416baaa9-dc9f-4396-8d5f-8c081fb06d67

    Jun. 17, 2026

    Action Type Old Value New Value
    Added Affected [{'repo': 'https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git', 'vendor': 'Linux', 'product': 'Linux', 'versions': [{'status': 'affected', 'version': '13e6c37b989859e70b0d73d3f2cb0aa022159b17', 'lessThan': '066ee13f05fbd82ada01883e51f0695172f98dff', 'versionType': 'git'}, {'status': 'affected', 'version': '13e6c37b989859e70b0d73d3f2cb0aa022159b17', 'lessThan': 'e2b3859067bf012d53c49b3f885fef40624a2c83', 'versionType': 'git'}, {'status': 'affected', 'version': '13e6c37b989859e70b0d73d3f2cb0aa022159b17', 'lessThan': '54a5b5a15588e3b0b294df31474d08a2678d4291', 'versionType': 'git'}, {'status': 'affected', 'version': '13e6c37b989859e70b0d73d3f2cb0aa022159b17', 'lessThan': '2618849f31e7cf51fadd4a5242458501a6d5b315', 'versionType': 'git'}], 'programFiles': ['fs/btrfs/extent_io.c'], 'defaultStatus': 'unaffected'}, {'repo': 'https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git', 'vendor': 'Linux', 'product': 'Linux', 'versions': [{'status': 'affected', 'version': '3.10'}, {'status': 'unaffected', 'version': '0', 'lessThan': '3.10', 'versionType': 'semver'}, {'status': 'unaffected', 'version': '6.6.117', 'versionType': 'semver', 'lessThanOrEqual': '6.6.*'}, {'status': 'unaffected', 'version': '6.12.58', 'versionType': 'semver', 'lessThanOrEqual': '6.12.*'}, {'status': 'unaffected', 'version': '6.17.8', 'versionType': 'semver', 'lessThanOrEqual': '6.17.*'}, {'status': 'unaffected', 'version': '6.18', 'versionType': 'original_commit_for_fix', 'lessThanOrEqual': '*'}], 'programFiles': ['fs/btrfs/extent_io.c'], 'defaultStatus': 'affected'}]
  • New CVE Received by 416baaa9-dc9f-4396-8d5f-8c081fb06d67

    Dec. 08, 2025

    Action Type Old Value New Value
    Added 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.
    Added Reference https://git.kernel.org/stable/c/066ee13f05fbd82ada01883e51f0695172f98dff
    Added Reference https://git.kernel.org/stable/c/2618849f31e7cf51fadd4a5242458501a6d5b315
    Added Reference https://git.kernel.org/stable/c/54a5b5a15588e3b0b294df31474d08a2678d4291
    Added Reference https://git.kernel.org/stable/c/e2b3859067bf012d53c49b3f885fef40624a2c83
EPSS is a daily estimate of the probability of exploitation activity being observed over the next 30 days. Following chart shows the EPSS score history of the vulnerability.