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 2C0B31D016B; Wed, 2 Oct 2024 13:34:05 +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=1727876045; cv=none; b=ZYpcNtgv02xCHIL/e883hi0P29B+ZQKceXVMQyVWR5QanS8wRLPmP9w75/OrfjWWF7No3Ugm4ABqrItkfF+FvQ2jorBqEB4Cb1PR8H81kxzTDE2J3Rd47Pz69gVWXJ/OySIqjMUaxc4ap+wG2MHlBzF9v0Arba7fL38PITWdrVs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727876045; c=relaxed/simple; bh=cCOT51SHwsG5fXbGRx7mjCWlxFMa9hxgERrSPFSBRTM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bMv+IVX5Vjpv3mrvu+cOtGTfO37pMdd2h/LL6QbOP/xZOTYfz6cJwoCIPaxzF48kpSv+HmzZt7iHRYYyW0qhOD8hNJyBIPzuFaeYrc7RiwiMu7sJ1ckG4ftrL1/e8G7XlScSNo3oTNKK6wKO1uaDi90cTWQN9xW+zNji5QzHVdY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=pov0OM5i; 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="pov0OM5i" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A29C8C4CEC5; Wed, 2 Oct 2024 13:34:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1727876045; bh=cCOT51SHwsG5fXbGRx7mjCWlxFMa9hxgERrSPFSBRTM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pov0OM5iFmt8G9p5vQPRojwTNgNihOX0qVePuxqjje5bRBSajWvdAX49kmubaFAvL DqV/rWo/tZth4YWyAzCfXGpmvxY4yz2LfWoavoBwIGdKXRAT9N6i75ZGTXKzOrOB9Q mx6RBEL4HIPyxs4FnIeytnW8MFJ2GO+uOSdH/0ek= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kemeng Shi , Theodore Tso , Sasha Levin Subject: [PATCH 6.11 309/695] ext4: avoid potential buffer_head leak in __ext4_new_inode() Date: Wed, 2 Oct 2024 14:55:07 +0200 Message-ID: <20241002125834.782224237@linuxfoundation.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241002125822.467776898@linuxfoundation.org> References: <20241002125822.467776898@linuxfoundation.org> User-Agent: quilt/0.67 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.11-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kemeng Shi [ Upstream commit 227d31b9214d1b9513383cf6c7180628d4b3b61f ] If a group is marked EXT4_GROUP_INFO_IBITMAP_CORRUPT after it's inode bitmap buffer_head was successfully verified, then __ext4_new_inode() will get a valid inode_bitmap_bh of a corrupted group from ext4_read_inode_bitmap() in which case inode_bitmap_bh misses a release. Hnadle "IS_ERR(inode_bitmap_bh)" and group corruption separately like how ext4_free_inode() does to avoid buffer_head leak. Fixes: 9008a58e5dce ("ext4: make the bitmap read routines return real error codes") Signed-off-by: Kemeng Shi Link: https://patch.msgid.link/20240820132234.2759926-3-shikemeng@huaweicloud.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/ialloc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index ad7f13976dc60..9e2c08a8665f2 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -1054,12 +1054,13 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap, brelse(inode_bitmap_bh); inode_bitmap_bh = ext4_read_inode_bitmap(sb, group); /* Skip groups with suspicious inode tables */ - if (((!(sbi->s_mount_state & EXT4_FC_REPLAY)) - && EXT4_MB_GRP_IBITMAP_CORRUPT(grp)) || - IS_ERR(inode_bitmap_bh)) { + if (IS_ERR(inode_bitmap_bh)) { inode_bitmap_bh = NULL; goto next_group; } + if (!(sbi->s_mount_state & EXT4_FC_REPLAY) && + EXT4_MB_GRP_IBITMAP_CORRUPT(grp)) + goto next_group; repeat_in_this_group: ret2 = find_inode_bit(sb, group, inode_bitmap_bh, &ino); -- 2.43.0