From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 D39164BEE38; Sat, 12 Sep 2026 16:19:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789229984; cv=none; b=Fe4aBO43ZzlDVOOo+SF/Brkk90VOM2KyYo533e/6Xqq99WDgnutX6MeGRnMpYzEI/G/QKSVSLrRVvVDVa6hjoMxMV6OazaGRgtAq7awA5dIExagoa31R7qXS0Cm887OhLSox4vpjhZAlbYosbs8/33rfuMXtqjNO2I/S4+t/9GI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789229984; c=relaxed/simple; bh=XTNzVXeWXj3bdEp+4M/Pizpp7uXRUekCokquYKVXwxw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rwlHJOUNo2u0MaIyaTe0aDMZOZuUgDZxnAQ8NVgd7vBRTFDWpOf3oGPHeWjE//+j8tCdowswR6YMXY4sPh5DFHsAQylXepPUyfKTBzuWQLlY4Em48Z++21y+YCdi3hDdB/DYE0+nQtluxmqtxZURmmwoITZc259MTRTMHvSLypE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jqEqDn0y; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="jqEqDn0y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8566C1F000FF; Sat, 12 Sep 2026 16:19:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789229982; bh=mEG2JDApq+ZZGcq8oCWc82H4NcxdPdY93GVYLYf5XxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jqEqDn0y+6+g7uraJSwXgj0EaBKMrKpAYy2KVEnaYowJeWRDeTit+c/tlg+YIwyi7 mndLPs+Be9sdAzEPOeeZsEIEsVsvJdq545MN+vnpRfKkYHdpPPKiAzWOR3kpMdY0Fy IWXydwAznbOyOgg8Vl10ZFVV2HKXiQ+xbDAf20hg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Guanghui Yang <3497809730@qq.com>, Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 6.1 0702/1191] ext4: fix buffer_head leak in ext4_init_orphan_info Date: Sat, 12 Sep 2026 08:57:10 +0200 Message-ID: <20260912065604.033765965@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065548.086904252@linuxfoundation.org> References: <20260912065548.086904252@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guanghui Yang <3497809730@qq.com> [ Upstream commit 05704335803b69c1bfa8637b7ada942bf2ee8a41 ] ext4_init_orphan_info() reads orphan file blocks with ext4_bread() and stores the returned buffer_head in oi->of_binfo[i].ob_bh. If ext4_bread() succeeds but the orphan block magic or checksum validation fails, the function jumps to out_free. However, the old out_free loop starts releasing buffers from i - 1, so the current buffer_head at index i is skipped. This leaks the buffer_head reference obtained by ext4_bread() on the bad magic and bad checksum error paths. Fix this by tracking the number of successfully read buffer_heads and releasing exactly those buffer_heads on the error path. Fixes: 02f310fcf47f ("ext4: Speedup ext4 orphan inode handling") Signed-off-by: Guanghui Yang <3497809730@qq.com> Reviewed-by: Jan Kara Link: https://patch.msgid.link/tencent_B38798612A159E21450ECF959016371B0807@qq.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/orphan.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/ext4/orphan.c b/fs/ext4/orphan.c index d06e6aef4683d..7a5893dc18114 100644 --- a/fs/ext4/orphan.c +++ b/fs/ext4/orphan.c @@ -573,6 +573,7 @@ int ext4_init_orphan_info(struct super_block *sb) int i, j; int ret; int free; + int loaded = 0; __le32 *bdata; int inodes_per_ob = ext4_inodes_per_orphan_block(sb); struct ext4_orphan_block_tail *ot; @@ -616,6 +617,7 @@ int ext4_init_orphan_info(struct super_block *sb) ret = -EIO; goto out_free; } + loaded++; ot = ext4_orphan_block_tail(sb, oi->of_binfo[i].ob_bh); if (le32_to_cpu(ot->ob_magic) != EXT4_ORPHAN_BLOCK_MAGIC) { ext4_error(sb, "orphan file block %d: bad magic", i); @@ -638,8 +640,10 @@ int ext4_init_orphan_info(struct super_block *sb) iput(inode); return 0; out_free: - for (i--; i >= 0; i--) - brelse(oi->of_binfo[i].ob_bh); + while (loaded > 0) { + loaded--; + brelse(oi->of_binfo[loaded].ob_bh); + } kvfree(oi->of_binfo); out_put: iput(inode); -- 2.53.0