{"dataType":"CVE_RECORD","dataVersion":"5.2","cveMetadata":{"cveId":"CVE-2025-40303","assignerOrgId":"416baaa9-dc9f-4396-8d5f-8c081fb06d67","state":"PUBLISHED","assignerShortName":"Linux","dateReserved":"2025-04-16T07:20:57.185Z","datePublished":"2025-12-08T00:46:27.820Z","dateUpdated":"2026-08-05T12:09:22.649Z"},"containers":{"cna":{"providerMetadata":{"orgId":"416baaa9-dc9f-4396-8d5f-8c081fb06d67","shortName":"Linux","dateUpdated":"2026-08-05T12:09:22.649Z"},"descriptions":[{"lang":"en","value":"In the Linux kernel, the following vulnerability has been resolved:\n\nbtrfs: ensure no dirty metadata is written back for an fs with errors\n\n[BUG]\nDuring development of a minor feature (make sure all btrfs_bio::end_io()\nis called in task context), I noticed a crash in generic/388, where\nmetadata writes triggered new works after btrfs_stop_all_workers().\n\nIt turns out that it can even happen without any code modification, just\nusing RAID5 for metadata and the same workload from generic/388 is going\nto trigger the use-after-free.\n\n[CAUSE]\nIf btrfs hits an error, the fs is marked as error, no new\ntransaction is allowed thus metadata is in a frozen state.\n\nBut there are some metadata modifications before that error, and they are\nstill in the btree inode page cache.\n\nSince there will be no real transaction commit, all those dirty folios\nare just kept as is in the page cache, and they can not be invalidated\nby invalidate_inode_pages2() call inside close_ctree(), because they are\ndirty.\n\nAnd finally after btrfs_stop_all_workers(), we call iput() on btree\ninode, which triggers writeback of those dirty metadata.\n\nAnd if the fs is using RAID56 metadata, this will trigger RMW and queue\nnew works into rmw_workers, which is already stopped, causing warning\nfrom queue_work() and use-after-free.\n\n[FIX]\nAdd a special handling for write_one_eb(), that if the fs is already in\nan error state, immediately mark the bbio as failure, instead of really\nsubmitting them.\n\nThen during close_ctree(), iput() will just discard all those dirty\ntree blocks without really writing them back, thus no more new jobs for\nalready stopped-and-freed workqueues.\n\nThe extra discard in write_one_eb() also acts as an extra safenet.\nE.g. the transaction abort is triggered by some extent/free space\ntree corruptions, and since extent/free space tree is already corrupted\nsome tree blocks may be allocated where they shouldn't be (overwriting\nexisting tree blocks). In that case writing them back will further\ncorrupting the fs."}],"metrics":[{"cvssV3_1":{"version":"3.1","vectorString":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","baseScore":7.8,"baseSeverity":"HIGH"},"scenarios":[{"lang":"en","value":"AV:L - btrfs is a local filesystem; the bug is reached through ordinary local filesystem activity that dirties btree metadata plus the unmount path (`close_ctree()`), with no network-facing component.\nAC:L - The sequence (fs error state with pending dirty metadata → unmount → writeback into the already-destroyed rmw_workers workqueue) is deterministic rather than a race, and the author reproduced it with an unmodified kernel using the stock generic/388 workload on RAID5 metadata, a profile an attacker supplying the image chooses freely.\nPR:L - An unprivileged local user with write access to a btrfs mount generates the dirty metadata and can drive the workload; on desktop/kiosk systems udisks2 auto-mounts and unmounts attacker-supplied removable media without any root credential, so real root in the initial namespace is not required.\nUI:N - No separate victim action is needed — the attacker's own workload dirties the metadata and the unmount/eject that triggers the freed-workqueue use is performed by the attacker or occurs automatically during normal system operation.\nS:U - The corruption stays within kernel memory and the filesystem managed by the same kernel; no VM, IOMMU, or sandbox boundary is crossed.\nC:H - queue_work() dereferences the freed workqueue_struct and its per-CPU pwq/pool, reading freed slab memory that an attacker can reclaim with sprayed objects, yielding an information-disclosure primitive on kernel memory.\nI:H - The use-after-free performs list insertions into the freed workqueue/pool structures, giving a write primitive into attacker-groomed memory, and the commit additionally documents that submitting these tree blocks can overwrite live metadata and further corrupt the on-disk filesystem.\nA:H - The bug produces a queue_work() WARN and a use-after-free during unmount, crashing the kernel on a code path that runs after the workqueues have been torn down."}]}],"affected":[{"product":"Linux","vendor":"Linux","defaultStatus":"unaffected","repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["fs/btrfs/extent_io.c"],"versions":[{"version":"13e6c37b989859e70b0d73d3f2cb0aa022159b17","lessThan":"066ee13f05fbd82ada01883e51f0695172f98dff","status":"affected","versionType":"git"},{"version":"13e6c37b989859e70b0d73d3f2cb0aa022159b17","lessThan":"e2b3859067bf012d53c49b3f885fef40624a2c83","status":"affected","versionType":"git"},{"version":"13e6c37b989859e70b0d73d3f2cb0aa022159b17","lessThan":"54a5b5a15588e3b0b294df31474d08a2678d4291","status":"affected","versionType":"git"},{"version":"13e6c37b989859e70b0d73d3f2cb0aa022159b17","lessThan":"2618849f31e7cf51fadd4a5242458501a6d5b315","status":"affected","versionType":"git"}]},{"product":"Linux","vendor":"Linux","defaultStatus":"affected","repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["fs/btrfs/extent_io.c"],"versions":[{"version":"3.10","status":"affected"},{"version":"0","lessThan":"3.10","status":"unaffected","versionType":"semver"},{"version":"6.6.117","lessThanOrEqual":"6.6.*","status":"unaffected","versionType":"semver"},{"version":"6.12.58","lessThanOrEqual":"6.12.*","status":"unaffected","versionType":"semver"},{"version":"6.17.8","lessThanOrEqual":"6.17.*","status":"unaffected","versionType":"semver"},{"version":"6.18","lessThanOrEqual":"*","status":"unaffected","versionType":"original_commit_for_fix"}]}],"cpeApplicability":[{"nodes":[{"operator":"OR","negate":false,"cpeMatch":[{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"3.10","versionEndExcluding":"6.6.117"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"3.10","versionEndExcluding":"6.12.58"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"3.10","versionEndExcluding":"6.17.8"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"3.10","versionEndExcluding":"6.18"}]}]}],"references":[{"url":"https://git.kernel.org/stable/c/066ee13f05fbd82ada01883e51f0695172f98dff"},{"url":"https://git.kernel.org/stable/c/e2b3859067bf012d53c49b3f885fef40624a2c83"},{"url":"https://git.kernel.org/stable/c/54a5b5a15588e3b0b294df31474d08a2678d4291"},{"url":"https://git.kernel.org/stable/c/2618849f31e7cf51fadd4a5242458501a6d5b315"}],"title":"btrfs: ensure no dirty metadata is written back for an fs with errors","x_generator":{"engine":"bippy-1.2.0"}}}}