# CVE-2025-39779: btrfs: subpage: keep TOWRITE tag until folio is cleaned

> 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.24% (percentile 9, 2026-11-26)
- **Published:** 2025-09-11T16:56:30.395Z
- **Modified:** 2026-10-19T21:10:00.160Z

## Who should check

- Anyone running Linux \>= 3470da3b7d87fde4b9729d4e29c2dc074cd59c10, \< 3d61136945a7008fc90d013c3c67007ce0c96131; \>= 3470da3b7d87fde4b9729d4e29c2dc074cd59c10, \< bce7a5c77a1e7a759e227b7713dde18c52da4759; \>= 3470da3b7d87fde4b9729d4e29c2dc074cd59c10, \< b1511360c8ac882b0c52caa263620538e8d73220
- Anyone running Linux 5.13

## Description

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

btrfs: subpage: keep TOWRITE tag until folio is cleaned

btrfs\_subpage\_set\_writeback() calls folio\_start\_writeback() the first time
a folio is written back, and it also clears the PAGECACHE\_TAG\_TOWRITE tag
even if there are still dirty blocks in the folio. This can break ordering
guarantees, such as those required by btrfs\_wait\_ordered\_extents().

That ordering breakage leads to a real failure. For example, running
generic/464 on a zoned setup will hit the following ASSERT. This happens
because the broken ordering fails to flush existing dirty pages before the
file size is truncated.

  assertion failed: !list\_empty(&ordered-\>list) :: 0, in fs/btrfs/zoned.c:1899
  ------------\[ cut here \]------------
  kernel BUG at fs/btrfs/zoned.c:1899!
  Oops: invalid opcode: 0000 \[\#1\] SMP NOPTI
  CPU: 2 UID: 0 PID: 1906169 Comm: kworker/u130:2 Kdump: loaded Not tainted 6.16.0-rc6-BTRFS-ZNS+ \#554 PREEMPT(voluntary)
  Hardware name: Supermicro Super Server/H12SSL-NT, BIOS 2.0 02/22/2021
  Workqueue: btrfs-endio-write btrfs\_work\_helper \[btrfs\]
  RIP: 0010:btrfs\_finish\_ordered\_zoned.cold+0x50/0x52 \[btrfs\]
  RSP: 0018:ffffc9002efdbd60 EFLAGS: 00010246
  RAX: 000000000000004c RBX: ffff88811923c4e0 RCX: 0000000000000000
  RDX: 0000000000000000 RSI: ffffffff827e38b1 RDI: 00000000ffffffff
  RBP: ffff88810005d000 R08: 00000000ffffdfff R09: ffffffff831051c8
  R10: ffffffff83055220 R11: 0000000000000000 R12: ffff8881c2458c00
  R13: ffff88811923c540 R14: ffff88811923c5e8 R15: ffff8881c1bd9680
  FS:  0000000000000000(0000) GS:ffff88a04acd0000(0000) knlGS:0000000000000000
  CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
  CR2: 00007f907c7a918c CR3: 0000000004024000 CR4: 0000000000350ef0
  Call Trace:
   \<TASK\>
   ? srso\_return\_thunk+0x5/0x5f
   btrfs\_finish\_ordered\_io+0x4a/0x60 \[btrfs\]
   btrfs\_work\_helper+0xf9/0x490 \[btrfs\]
   process\_one\_work+0x204/0x590
   ? srso\_return\_thunk+0x5/0x5f
   worker\_thread+0x1d6/0x3d0
   ? \_\_pfx\_worker\_thread+0x10/0x10
   kthread+0x118/0x230
   ? \_\_pfx\_kthread+0x10/0x10
   ret\_from\_fork+0x205/0x260
   ? \_\_pfx\_kthread+0x10/0x10
   ret\_from\_fork\_asm+0x1a/0x30
   \</TASK\>

Consider process A calling writepages() with WB\_SYNC\_NONE. In zoned mode or
for compressed writes, it locks several folios for delalloc and starts
writing them out. Let's call the last locked folio folio X. Suppose the
write range only partially covers folio X, leaving some pages dirty.
Process A calls btrfs\_subpage\_set\_writeback() when building a bio. This
function call clears the TOWRITE tag of folio X, whose size = 8K and
the block size = 4K. It is following state.

   0     4K    8K
   \|/////\|/////\|  (flag: DIRTY, tag: DIRTY)
   \<-----\> Process A will write this range.

Now suppose process B concurrently calls writepages() with WB\_SYNC\_ALL. It
calls tag\_pages\_for\_writeback() to tag dirty folios with
PAGECACHE\_TAG\_TOWRITE. Since folio X is still dirty, it gets tagged. Then,
B collects tagged folios using filemap\_get\_folios\_tag() and must wait for
folio X to be written before returning from writepages().

   0     4K    8K
   \|/////\|/////\|  (flag: DIRTY, tag: DIRTY\|TOWRITE)

However, between tagging and collecting, process A may call
btrfs\_subpage\_set\_writeback() and clear folio X's TOWRITE tag.
   0     4K    8K
   \|     \|/////\|  (flag: DIRTY\|WRITEBACK, tag: DIRTY)

As a result, process B won't see folio X in its batch, and returns without
waiting for it. This breaks the WB\_SYNC\_ALL ordering requirement.

Fix this by using btrfs\_subpage\_set\_writeback\_keepwrite(), which retains
the TOWRITE tag. We now manually clear the tag only after the folio becomes
clean, via the xas operation.

## Affected and fixed versions

- Linux: \>= 3470da3b7d87fde4b9729d4e29c2dc074cd59c10, \< 3d61136945a7008fc90d013c3c67007ce0c96131; \>= 3470da3b7d87fde4b9729d4e29c2dc074cd59c10, \< bce7a5c77a1e7a759e227b7713dde18c52da4759; \>= 3470da3b7d87fde4b9729d4e29c2dc074cd59c10, \< b1511360c8ac882b0c52caa263620538e8d73220 (cvelist)
- Linux: 5.13 (cvelist)

## Mitigation

- No fix listed yet: follow the vendor advisory.

## Check your systems with an agent

Paste this into a coding agent:

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

Details: https://flawdb.com/CVE-2025-39779.md
Affected: Linux >= 3470da3b7d87fde4b9729d4e29c2dc074cd59c10, < 3d61136945a7008fc90d013c3c67007ce0c96131; >= 3470da3b7d87fde4b9729d4e29c2dc074cd59c10, < bce7a5c77a1e7a759e227b7713dde18c52da4759; >= 3470da3b7d87fde4b9729d4e29c2dc074cd59c10, < b1511360c8ac882b0c52caa263620538e8d73220; Linux 5.13
Fixed in: Linux 3d61136945a7008fc90d013c3c67007ce0c96131

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

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

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

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

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

Linux \>= 3470da3b7d87fde4b9729d4e29c2dc074cd59c10, \< 3d61136945a7008fc90d013c3c67007ce0c96131; \>= 3470da3b7d87fde4b9729d4e29c2dc074cd59c10, \< bce7a5c77a1e7a759e227b7713dde18c52da4759; \>= 3470da3b7d87fde4b9729d4e29c2dc074cd59c10, \< b1511360c8ac882b0c52caa263620538e8d73220; Linux 5.13.

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

Yes. Fixed in Linux 3d61136945a7008fc90d013c3c67007ce0c96131. No fix listed yet: follow the vendor advisory.

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

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/3d61136945a7008fc90d013c3c67007ce0c96131>
- patch: <https://git.kernel.org/stable/c/bce7a5c77a1e7a759e227b7713dde18c52da4759>
- patch: <https://git.kernel.org/stable/c/b1511360c8ac882b0c52caa263620538e8d73220>

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

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