Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCF321DD525 for ; Thu, 11 Sep 2025 16:57:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757609833; cv=none; b=dvZhS9KpVSzjN/Wl4haC+2aDPpRjzBdpcVoDyK/L5zWedJTx+JvrkVmjU9jpQl2MRxpQk/h3DaEcfqGxtCyTL3Yta8QIUDuAhvZiLbfh4sqh8s5TpPpJEPBor+YIHUN3ZDwypYWuSoNRYsnFgufLvSsCIQoJYyrucQrG+W7EAzo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757609833; c=relaxed/simple; bh=Ky5U0QemK8LPBtliJrYME2amMYdAQIbvz0++V7ijj5E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=EF1b98kgSLNrJIP2nc2JpvW31Rv6eV0DAOtaPKlPeQGvtDM62JfDVkxUKAaaKPoCXF5eibHJWlPsS04en4TSnHV+qELjzdYYmGZhnYz2ZT3EjRzPqiWI42HN0LYNbc+1bwnX/fk2K+3M904rKjjomoLZHU7wGlkiHI/JRZe0NlM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MAgg88Wz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="MAgg88Wz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50B0AC4CEF0; Thu, 11 Sep 2025 16:57:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1757609833; bh=Ky5U0QemK8LPBtliJrYME2amMYdAQIbvz0++V7ijj5E=; h=From:To:Cc:Subject:Date:Reply-to:From; b=MAgg88Wzq/UKWRt2+KbHussQkWr6xrCIuPpWRSAx5AiTib0XTlG8UN63gN7w8cru0 mJuR8HSVeCdp8nRuvMTsC9YJXVZF8cHEGPGw2NK/jQ6EIL7zbWrT3laNP0bpW+Bzwc dOAGGeb5xFiWh5vz7o9gdTc69Q8ikTKqOMbbbT44= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2025-39779: btrfs: subpage: keep TOWRITE tag until folio is cleaned Date: Thu, 11 Sep 2025 18:56:57 +0200 Message-ID: <2025091148-CVE-2025-39779-7d77@gregkh> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=5628; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=8kHUXbP1ooEtxB9Y2DUYOGEVlk+NugZLCOff2XGe/ok=; b=owGbwMvMwCRo6H6F97bub03G02pJDBmH/gf8+38o1T+ptEXw/osTZ7TPKuzt8LhpIpg3l+F4e v+vnvJbHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjCR3LsMC45PreCcdIhxFvtO fgnf57E6DOYHhBnmJzsv9muVMdowdWXhvKLm23u1y43OAAA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit From: Greg Kroah-Hartman 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: ? 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 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. The Linux kernel CVE team has assigned CVE-2025-39779 to this issue. Affected and fixed versions =========================== Issue introduced in 5.13 with commit 3470da3b7d87fde4b9729d4e29c2dc074cd59c10 and fixed in 6.12.44 with commit 3d61136945a7008fc90d013c3c67007ce0c96131 Issue introduced in 5.13 with commit 3470da3b7d87fde4b9729d4e29c2dc074cd59c10 and fixed in 6.16.4 with commit bce7a5c77a1e7a759e227b7713dde18c52da4759 Issue introduced in 5.13 with commit 3470da3b7d87fde4b9729d4e29c2dc074cd59c10 and fixed in 6.17-rc3 with commit b1511360c8ac882b0c52caa263620538e8d73220 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2025-39779 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: fs/btrfs/subpage.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/3d61136945a7008fc90d013c3c67007ce0c96131 https://git.kernel.org/stable/c/bce7a5c77a1e7a759e227b7713dde18c52da4759 https://git.kernel.org/stable/c/b1511360c8ac882b0c52caa263620538e8d73220