From patchwork Wed Dec 31 22:29:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1153 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220295; bh=j6SPQgm28reDuQ3vwaxwgavO+jxUOvhYvmHJJJB6vbc=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=jJvEg+bjHJ3ifHlg4Yt2C/WZcWTVSgJcXTdm/pWpo1nbfi7Vwm0Al4jXwkEHP7mG/ y2HHdbA4IdFVyej8kd9TNlcp3sbnP3q+d+MMnuVbfxYEFou/0s+UXCj8+ic1s8WM/D r+nkdIdJ+gurUkj/O815Dq2vs74TicM1b4Tur6UysqIE5WlAOeqESyuRpPVa46gUaT Q9NpirKacTnyzL3t1zW56Wl8xpxVo/SibQ5XJ24ArfQP0cPw1onmPsAjnNPplIKbgF d+XMhu0ZMDM8tmex8NSiVPvB9BiXmb+MVdO9qNfkA8Swe8hO7e1rNe45rgIyMPA9mi MfwgJNU49g9CQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 93FB668FE6 for ; Wed, 31 Dec 2025 15:31:35 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 6crjM480431k for ; Wed, 31 Dec 2025 15:31:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220295; bh=j6SPQgm28reDuQ3vwaxwgavO+jxUOvhYvmHJJJB6vbc=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=jJvEg+bjHJ3ifHlg4Yt2C/WZcWTVSgJcXTdm/pWpo1nbfi7Vwm0Al4jXwkEHP7mG/ y2HHdbA4IdFVyej8kd9TNlcp3sbnP3q+d+MMnuVbfxYEFou/0s+UXCj8+ic1s8WM/D r+nkdIdJ+gurUkj/O815Dq2vs74TicM1b4Tur6UysqIE5WlAOeqESyuRpPVa46gUaT Q9NpirKacTnyzL3t1zW56Wl8xpxVo/SibQ5XJ24ArfQP0cPw1onmPsAjnNPplIKbgF d+XMhu0ZMDM8tmex8NSiVPvB9BiXmb+MVdO9qNfkA8Swe8hO7e1rNe45rgIyMPA9mi MfwgJNU49g9CQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8321B68FD3 for ; Wed, 31 Dec 2025 15:31:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220294; bh=+bi/dR+ir7ssEIOl6ngft4hZHlljKXAmPId3zpWM2s8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NTTsLj/7Q7543+U26fqoDvtgcUs6G9m5v/QY3P8wTnLsYz3Tejdx9M8kUHe2XZ4UE c5EH23xK0rg8V+lFpR+2z3CrDuNBG57YyUV5OegCpNU1avcEPFxuwLwFeAlBqzVsoK z+eRtPzVRgbQh621vodAoeERix07bwQQaZH01fv/QJMr4sKtbbV82X4bkrSpBuqBWh VXOMLY/v7RQkhlPIKXOWf7jm6EecKu+8bssHlc8U6UjfVpTwHNPyFwUQ+ufNUVnOD4 zC594u2DlNlIFllAjHJJc+9DTWKuErJaC43A54mNggrK57zxBhC9HWrdz+VZcW0kU7 55K8cjKtibqJQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6904668F65; Wed, 31 Dec 2025 15:31:34 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id im6cSqmYiBTy; Wed, 31 Dec 2025 15:31:34 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767220290; bh=x8Xv4zk8OpYLgPgQ8SshF6mFni7sZAxU/RrRt7sM3OM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CszanSYuLUb5pJ/5++TjeiKtsKKV3YYntTHy0Vk4Sx3UfNzycFj/e81D2u5LFChfS uSBzwtDXVgCH5nl36r3dE3Wpp8SSVR50hgd8QHnEKDkumd4ydmHdQnodrfX4Ye35Mq KWcs/WPhflBUZtN3fls4j3g53e8M8BzhUiVdDCDIRGANQSInd77YjAAGQp8ovK1FaM jbMGlgPNKLy9VOhgoR6NejlHH/qcNOX1qWUKHt5WJ68LO8d1P0+vwjOVBMdmygKTfe jJ28eMk7pMuXHc926M4tIRJRJCjm5tRcvufCCKsi15Nxcg4xG6muqX5/fB5rYRNZe5 GQo2LHCr5Duzg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0CE1E68F61; Wed, 31 Dec 2025 15:31:29 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 31 Dec 2025 15:29:48 -0700 Message-ID: <20251231223008.3251711-16-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251231223008.3251711-1-sjg@u-boot.org> References: <20251231223008.3251711-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: QNWKPVLNMY7BVMSMJNPC4KKZZS5CPVGP X-Message-ID-Hash: QNWKPVLNMY7BVMSMJNPC4KKZZS5CPVGP X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 15/26] ext4l: Add bh_cache_release_jbd() to clean up journal references List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add bh_cache_release_jbd() to forcibly release any journal_heads still attached to buffer_heads after journal destroy. This must be called after journal destroy but before bh_cache_clear() to ensure all journal_heads are properly released, even if journal destroy did not fully clean up (e.g., on abort). The function clears b_bh in each journal_head to prevent use-after-free when the buffer_head is later freed, and resets transaction pointers. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 1 + fs/ext4l/support.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index ba4b4266daa..00419fe834e 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -2891,6 +2891,7 @@ void free_buffer_head(struct buffer_head *bh); /* ext4l support functions (support.c) */ void ext4l_crc32c_init(void); +void bh_cache_release_jbd(void); void bh_cache_clear(void); int bh_cache_sync(void); int ext4l_read_block(sector_t block, size_t size, void *buffer); diff --git a/fs/ext4l/support.c b/fs/ext4l/support.c index 3133a4ebead..aaaf89092eb 100644 --- a/fs/ext4l/support.c +++ b/fs/ext4l/support.c @@ -332,6 +332,42 @@ void bh_cache_clear(void) } } +/** + * bh_cache_release_jbd() - Release all JBD references from buffer cache + * + * This must be called after journal destroy but before bh_cache_clear(). + * It ensures all journal_heads are properly released from buffer_heads + * even if the journal destroy didn't fully clean up (e.g., on abort). + */ +void bh_cache_release_jbd(void) +{ + int i; + struct bh_cache_entry *entry; + + for (i = 0; i < BH_CACHE_SIZE; i++) { + for (entry = bh_cache[i]; entry; entry = entry->next) { + if (entry->bh && buffer_jbd(entry->bh)) { + struct buffer_head *bh = entry->bh; + struct journal_head *jh = bh2jh(bh); + + /* + * Forcibly release the journal_head. + * Clear b_bh to prevent use-after-free when + * the buffer_head is later freed. + */ + if (jh) { + jh->b_bh = NULL; + jh->b_transaction = NULL; + jh->b_next_transaction = NULL; + jh->b_cp_transaction = NULL; + } + clear_buffer_jbd(bh); + bh->b_private = NULL; + } + } + } +} + /** * bh_cache_sync() - Sync all dirty buffers to disk *