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 7B1892E06ED for ; Tue, 28 Oct 2025 11:53:20 +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=1761652400; cv=none; b=KlUQMGPT6Ki5Np794eQXHzv5oAGo+a6QlEned48y456DlJ4WInRfPu4zD08VmlKfzKW8j46+xXhiyVBByyfCQY/ozkcgAZ1xpAlPgdqjzWNlTiKc+mN/Ejr960Qan1pxfdYoPBXsxayb233RMTlOpJegEmRE45ZagYOz6lF7WNM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761652400; c=relaxed/simple; bh=kfowspOy6vbvF1eOk/TsLsvrbyxdxov+NZLQKCCzyuQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=vBkE1u+ca8lXAqImC81iSCwp4PtASRQpWB/JSNqTNg+PnVaj+SwqfyLLy9ZwiCHNxt8W0N8NDyt93wLGDy1dbFk/0XaJEMncfGl/SCAy6e80f5Q6g8iNGqYAY99Vc+PxnpO9745lAbI0mS8B2fLRPTkzKrY1SsWL4GxvjgjMUic= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=mL0XahGN; 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="mL0XahGN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 769E5C4CEE7; Tue, 28 Oct 2025 11:53:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1761652400; bh=kfowspOy6vbvF1eOk/TsLsvrbyxdxov+NZLQKCCzyuQ=; h=From:To:Cc:Subject:Date:Reply-to:From; b=mL0XahGNP2LeJF+TeCHqnEgq30lr5aZEPuGR7MFqCd8+wXkLeLF7b/DlydIm3ZsJs lymMyHvaQ7FrjkYfN3F3om4Qktoolww11NQRpspqmstGmMER0FeEYSOMHtozo3/wU2 K6toNUsuDg1ae7/SS5rF0NvFv/ETLuKbz5QUzf5s= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2025-40054: f2fs: fix UAF issue in f2fs_merge_page_bio() Date: Tue, 28 Oct 2025 12:48:31 +0100 Message-ID: <2025102815-CVE-2025-40054-c79b@gregkh> X-Mailer: git-send-email 2.51.1 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=4338; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=25iBzBK4rT93IY0re3aGk8UjOdppZPeFDdFY1o0smLg=; b=owGbwMvMwCRo6H6F97bub03G02pJDJkMa+vZFuc9EuOO/al+7z6j1ISdvO/Nvk0PWjNz3avQi e2hPgWLO2JZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAinzYyzE/vOd5Xonmjy/D1 4c1Tsl+wyjI65TIsOPR2R6V48LRk1e69yrW11RnazRtPAQA= 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: f2fs: fix UAF issue in f2fs_merge_page_bio() As JY reported in bugzilla [1], Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 pc : [0xffffffe51d249484] f2fs_is_cp_guaranteed+0x70/0x98 lr : [0xffffffe51d24adbc] f2fs_merge_page_bio+0x520/0x6d4 CPU: 3 UID: 0 PID: 6790 Comm: kworker/u16:3 Tainted: P B W OE 6.12.30-android16-5-maybe-dirty-4k #1 5f7701c9cbf727d1eebe77c89bbbeb3371e895e5 Tainted: [P]=PROPRIETARY_MODULE, [B]=BAD_PAGE, [W]=WARN, [O]=OOT_MODULE, [E]=UNSIGNED_MODULE Workqueue: writeback wb_workfn (flush-254:49) Call trace: f2fs_is_cp_guaranteed+0x70/0x98 f2fs_inplace_write_data+0x174/0x2f4 f2fs_do_write_data_page+0x214/0x81c f2fs_write_single_data_page+0x28c/0x764 f2fs_write_data_pages+0x78c/0xce4 do_writepages+0xe8/0x2fc __writeback_single_inode+0x4c/0x4b4 writeback_sb_inodes+0x314/0x540 __writeback_inodes_wb+0xa4/0xf4 wb_writeback+0x160/0x448 wb_workfn+0x2f0/0x5dc process_scheduled_works+0x1c8/0x458 worker_thread+0x334/0x3f0 kthread+0x118/0x1ac ret_from_fork+0x10/0x20 [1] https://bugzilla.kernel.org/show_bug.cgi?id=220575 The panic was caused by UAF issue w/ below race condition: kworker - writepages - f2fs_write_cache_pages - f2fs_write_single_data_page - f2fs_do_write_data_page - f2fs_inplace_write_data - f2fs_merge_page_bio - add_inu_page : cache page #1 into bio & cache bio in io->bio_list - f2fs_write_single_data_page - f2fs_do_write_data_page - f2fs_inplace_write_data - f2fs_merge_page_bio - add_inu_page : cache page #2 into bio which is linked in io->bio_list write - f2fs_write_begin : write page #1 - f2fs_folio_wait_writeback - f2fs_submit_merged_ipu_write - f2fs_submit_write_bio : submit bio which inclues page #1 and #2 software IRQ - f2fs_write_end_io - fscrypt_free_bounce_page : freed bounced page which belongs to page #2 - inc_page_count( , WB_DATA_TYPE(data_folio), false) : data_folio points to fio->encrypted_page the bounced page can be freed before accessing it in f2fs_is_cp_guarantee() It can reproduce w/ below testcase: Run below script in shell #1: for ((i=1;i>0;i++)) do xfs_io -f /mnt/f2fs/enc/file \ -c "pwrite 0 32k" -c "fdatasync" Run below script in shell #2: for ((i=1;i>0;i++)) do xfs_io -f /mnt/f2fs/enc/file \ -c "pwrite 0 32k" -c "fdatasync" So, in f2fs_merge_page_bio(), let's avoid using fio->encrypted_page after commit page into internal ipu cache. The Linux kernel CVE team has assigned CVE-2025-40054 to this issue. Affected and fixed versions =========================== Issue introduced in 5.5 with commit 0b20fcec8651569935a10afe03fedc0b812d044e and fixed in 6.17.3 with commit 01118321e0c8a5f3ece57d0d377bfc92d83cd210 Issue introduced in 5.5 with commit 0b20fcec8651569935a10afe03fedc0b812d044e and fixed in 6.18-rc1 with commit edf7e9040fc52c922db947f9c6c36f07377c52ea 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-40054 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/f2fs/data.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/01118321e0c8a5f3ece57d0d377bfc92d83cd210 https://git.kernel.org/stable/c/edf7e9040fc52c922db947f9c6c36f07377c52ea