From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379936; b=4IaLfNKtJ66KEnwM18NoXbqFDT4wTiiKW1eeaqHcj+3QsoNvCdWV0ZBIZuKshhAHa1RK ehmpDViMnl+rsfwGTFdU/ADAhi2GK2ITaARYx9cHMUtJmEQu8H0YF7qOb6FCx0lOV8OSj CaEzwA7hHYyygMfDnLMgRoWZ7kiW80rew3V0ykwvb7m4R+Gcn9nt/s8UMj7wfiYUG9qTP HwMpHK/Ve4Z3FiBfmsMpB+YZizoCPaQJUFjqoeZHQbNeY8Z+UEx0s9OiupmNBWxhmg//z AfXskwB2A+LqFq1VmjTEVRNOWpAfuI7FsKFMP3J56CgJLQQJcyJFHp7tj0qH2z7mmZw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379936; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=z89GN/TDe+oOfdnxudmJgvSoBFFzuta7Kk4sjQApu/w=; b=3vr1aRRqtfpPUYN2yjT7gp3wPLk3VUOMpzlKi9/2cUgXXE396MiuxfrrsiIbkfRBPH/C 2y8LjCYjLBKR43Rc62TaEU9H2xxzTojV5wQuqt0coUZeuE6xvMfZewbg2BfB65m0LU+cS Goysi8xHmMe8oV4HbrxEizyBL+M9yNKEW1XF+ZDa5H+0vWKyRwDy3FUqK1DeOqsXM5sfx FHoYMoqtwipUBnIIvmRb7mlOA4DfhWPWvMZ5BQb1dBgWeoFrL1M/6ichqH8gLtwPLnA6u gE1fC1K2BhDrsxSJw9l1KIFA6exmtmLJlRcAbyfH1C0a+oSZ4Sh/c23xA6hpZuz/QBw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="TS/pwLRP"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28098606A322; Fri, 4 Dec 2026 10:25:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=TS/pwLRP Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46C8B1F000CE; Fri, 4 Dec 2026 10:25:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379935; bh=z89GN/TDe+oOfdnxudmJgvSoBFFzuta7Kk4sjQApu/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TS/pwLRPWhGFOGh7FI8Q1ApG+lmXHX6C97sDq3SapCE1PDsewpb4HCdhil8IhjQ96 4NTNjsqcv5kkcaHBWBRF9NLZAOiLnSEhnE9aq+VaOPylisbkecVOmnIbJqqQfvC338 IxL02qD293P7zkU3+uavleiYPkQX/vqUH1xtqUrM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Theodore Tso , Sasha Levin Subject: [PATCH 7.3 033/742] ext4: dont track metadata buffers on an inode during fast commit replay Date: Fri, 4 Dec 2026 18:58:17 +0900 Message-ID: <20261204100635.930305583@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Theodore Ts'o [ Upstream commit aceadbccd428fb8e6593b27a3091d961f80225d1 ] Fast commit replay runs without a journal handle and before EXT4_SB(sb)->s_journal is set, so it effectively runs in nojournal mode. __ext4_handle_dirty_metadata() then hands every extent tree block and directory block it dirties to mmb_mark_buffer_dirty(). Commit d4fdde3257a5 ("fs: set I_METADATA_WRITEBACK in mmb_mark_buffer_dirty()") sets this flag on the inode, which can trigger a NULL pointer dereference on a per-cpu pointer during the fast commit replay. This is because the iput at the end of each fast commit update triggers write_inode_now(), and with I_METADATA_WRITEBACK set, writeback_single_inode() will end up calling ext4_writepages(), before ext4_percpu_param_init() has initialized s_writepages_rwsem. A similar crash was fixed in commit 0ecd56573c1f ("ext4: Avoid entering writeback paths during fastcommit replay") by not setting this flag in ext4_mark_iloc_dirty(). This commit applies the same fix to __ext4_handle_dirty_metadata(). Once the fast commit replay is complete, jbd2_journal_recover() syncs and flushes the whole block device, o the buffer is still written out before the mount proceeds. Reproduced with generic/311 using "-O inline_data,fast_commit" (the ext4/adv test configuration). Fixes: d4fdde3257a5 ("fs: set I_METADATA_WRITEBACK in mmb_mark_buffer_dirty()") Cc: stable@vger.kernel.org Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/ext4_jbd2.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c index 53ddedb52a6f7..d81ce9b8a5407 100644 --- a/fs/ext4/ext4_jbd2.c +++ b/fs/ext4/ext4_jbd2.c @@ -412,7 +412,19 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line, err); } } else { - if (inode) { + /* + * Fast commit replay runs without a handle, before the + * writeback paths are set up. Don't track the buffer in the + * inode's metadata list then: mmb_mark_buffer_dirty() sets + * I_METADATA_WRITEBACK, and since the superblock isn't active + * yet the iput() ending the replay step writes the inode out + * and enters ext4_writepages() before s_writepages_rwsem is + * initialized. Journal recovery flushes the whole block + * device once replay is done, so the buffer still gets + * written. + */ + if (inode && !(EXT4_SB(inode->i_sb)->s_mount_state & + EXT4_FC_REPLAY)) { if (!ext4_i_metadata_bhs(inode)) ext4_inode_attach_mmb(inode); mmb_mark_buffer_dirty(bh, ext4_i_metadata_bhs(inode)); -- 2.53.0