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 479A413AA2F; Tue, 27 Feb 2024 13:44:37 +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=1709041477; cv=none; b=XcY79vOHCGqppWxah38xC9cTnXwd3S9IfTHneeY6P4R49MFjsE6261S45NSF1fXYm+3Ivdz8wJWBARsk6X3SzFBwKEMpL1uoiGgfI84e0z0e5eAZZGZJ6drPUYBrwXjirRRQ4aSTqcCSAQoXBeUffXaFV9EjQ9OPSX2PMKXuDWo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709041477; c=relaxed/simple; bh=pNk/U3NLJNfNxUPc6U9HPAfg3fjB8suFvXbsCnI8jN0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PMohRfWpgTmIrZf/CdM28erUvsu/DLYgig5Inhe3Uu6w1D/LRcsNG4szzK/N1bwcr5l7hf3ONKRqQIhFdtuxDj0wrOQnIeacxmLXTZUFo4uxLJuNEcM2K/XYPZLWyqj2nh8N7RaQmfIr0on+200U1oALVObiuKXurLPJq3ynZF0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=b5EBEX1i; 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="b5EBEX1i" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7C62C43390; Tue, 27 Feb 2024 13:44:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1709041477; bh=pNk/U3NLJNfNxUPc6U9HPAfg3fjB8suFvXbsCnI8jN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b5EBEX1iGxLliQ8nEQtcAGWuYcOyULNpiYNEDCKD4h0++X4j6i2ckhD5c91YGfzeT e8JVrNBpxpnK7mozSQ+xPrHpDNo9KB7Ys3YrZ3WIlSP74YFYv2OvMXku1BR0RWkxhk Xa/duUe0xRGbATepQ17ud7ANEZC8wJBbkrM50QPU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Baokun Li , Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 4.19 19/52] ext4: avoid allocating blocks from corrupted group in ext4_mb_try_best_found() Date: Tue, 27 Feb 2024 14:26:06 +0100 Message-ID: <20240227131549.165300344@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240227131548.514622258@linuxfoundation.org> References: <20240227131548.514622258@linuxfoundation.org> User-Agent: quilt/0.67 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Baokun Li [ Upstream commit 4530b3660d396a646aad91a787b6ab37cf604b53 ] Determine if the group block bitmap is corrupted before using ac_b_ex in ext4_mb_try_best_found() to avoid allocating blocks from a group with a corrupted block bitmap in the following concurrency and making the situation worse. ext4_mb_regular_allocator ext4_lock_group(sb, group) ext4_mb_good_group // check if the group bbitmap is corrupted ext4_mb_complex_scan_group // Scan group gets ac_b_ex but doesn't use it ext4_unlock_group(sb, group) ext4_mark_group_bitmap_corrupted(group) // The block bitmap was corrupted during // the group unlock gap. ext4_mb_try_best_found ext4_lock_group(ac->ac_sb, group) ext4_mb_use_best_found mb_mark_used // Allocating blocks in block bitmap corrupted group Signed-off-by: Baokun Li Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/20240104142040.2835097-7-libaokun1@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/mballoc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index df390979058fd..e0dd01cb1a0e7 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -1802,6 +1802,9 @@ int ext4_mb_try_best_found(struct ext4_allocation_context *ac, return err; ext4_lock_group(ac->ac_sb, group); + if (unlikely(EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info))) + goto out; + max = mb_find_extent(e4b, ex.fe_start, ex.fe_len, &ex); if (max > 0) { @@ -1809,6 +1812,7 @@ int ext4_mb_try_best_found(struct ext4_allocation_context *ac, ext4_mb_use_best_found(ac, e4b); } +out: ext4_unlock_group(ac->ac_sb, group); ext4_mb_unload_buddy(e4b); -- 2.43.0