From mboxrd@z Thu Jan 1 00:00:00 1970 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 7112D29A1; Tue, 17 Feb 2026 20:54:30 +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=1771361670; cv=none; b=CPmzbkJmx0UBTYSl33+9H8Gy/DFGZI8gllAhBwy02EgdQ/h3uH3bcN3mlR70uZin2aIPJ1pnnNvYAo8r/KaqqKoHs3T6ASHxBPunCe6nSswexnl3mNVwgP489iTf4uES41EjQz6NKiq63nVGzA1E72BsDJ+KgcGE6MYG2oYqdbs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771361670; c=relaxed/simple; bh=yJV2JVEyoR9B+XcPguL8kzB9R3RnWtMBbkBKUE6S6v0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RMNVTZs1WEYlwbeUqnFCuYODQfZTGWNO0CVDGtb48YaIdAc+g3nyHJfSBZw5V+9pLqf4vg6f0rX1RjXTxOmjNf9jdRMkX07YX7HM8PeP22oExX4kW1eXOlHAx2wzkL7/WZ8xjDJyE0b7uW2pLAXhXBRpbGF922F03hqwwn0JGOA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Qhp4TSAS; 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="Qhp4TSAS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC220C4CEF7; Tue, 17 Feb 2026 20:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1771361670; bh=yJV2JVEyoR9B+XcPguL8kzB9R3RnWtMBbkBKUE6S6v0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qhp4TSASSRDA/qL6QEMsQORMFXmEoisjNZgcpkJtwdq7y5GGfjMjK6duq493NqqPD 8CsxGnVMofRkg58EtUxLvPEhjv/EljApWvn19aXeA9G47Pd2smnvo5i/x6jAHohCXA G9HFv/1XkMQ9317u6SExwsPKjqc/RXNSEbDogClg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable@kernel.org, syzbot+b4444e3c972a7a124187@syzkaller.appspotmail.com, Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 6.12 40/42] f2fs: fix to avoid UAF in f2fs_write_end_io() Date: Tue, 17 Feb 2026 21:32:31 +0100 Message-ID: <20260217200007.532108477@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260217200005.998240758@linuxfoundation.org> References: <20260217200005.998240758@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chao Yu [ Upstream commit ce2739e482bce8d2c014d76c4531c877f382aa54 ] As syzbot reported an use-after-free issue in f2fs_write_end_io(). It is caused by below race condition: loop device umount - worker_thread - loop_process_work - do_req_filebacked - lo_rw_aio - lo_rw_aio_complete - blk_mq_end_request - blk_update_request - f2fs_write_end_io - dec_page_count - folio_end_writeback - kill_f2fs_super - kill_block_super - f2fs_put_super : free(sbi) : get_pages(, F2FS_WB_CP_DATA) accessed sbi which is freed In kill_f2fs_super(), we will drop all page caches of f2fs inodes before call free(sbi), it guarantee that all folios should end its writeback, so it should be safe to access sbi before last folio_end_writeback(). Let's relocate ckpt thread wakeup flow before folio_end_writeback() to resolve this issue. Cc: stable@kernel.org Fixes: e234088758fc ("f2fs: avoid wait if IO end up when do_checkpoint for better performance") Reported-by: syzbot+b4444e3c972a7a124187@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=b4444e3c972a7a124187 Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim [ folio => page ] Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/f2fs/data.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -357,14 +357,20 @@ static void f2fs_write_end_io(struct bio page_folio(page)->index != nid_of_node(page)); dec_page_count(sbi, type); + + /* + * we should access sbi before end_page_writeback() to + * avoid racing w/ kill_f2fs_super() + */ + if (type == F2FS_WB_CP_DATA && !get_pages(sbi, type) && + wq_has_sleeper(&sbi->cp_wait)) + wake_up(&sbi->cp_wait); + if (f2fs_in_warm_node_list(sbi, page)) f2fs_del_fsync_node_entry(sbi, page); clear_page_private_gcing(page); end_page_writeback(page); } - if (!get_pages(sbi, F2FS_WB_CP_DATA) && - wq_has_sleeper(&sbi->cp_wait)) - wake_up(&sbi->cp_wait); bio_put(bio); }