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 6FCF13C1974; Thu, 15 Jan 2026 17:50:39 +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=1768499439; cv=none; b=lHiD6jJSrqoY1m8b6+fUp1v7pM1m+qhP4bLMbQ05d2m7Gx3J4rIwSkXKUkn/3hGV7ltOBrfzzwMocwzUcUQ+AjA8ExeQa5662jSqVY+4C9E2PV8B/f4MzaKvn5an2PSLjrcvbKpbVeVPivoFBMpPbur3q24YXWKV16VgXQukpgA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768499439; c=relaxed/simple; bh=5ZhdE8FlHk55a6i5XgaU1tLMXNL8hAG8PoMT3cn5ZHE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YoxMmP4+a4hhYFTyW/Fb//A898DOENtlJruB0+r2LXaZEazE7sBJdAuyk1FcTqdnMnL+jSYODtZdQMOLU+hFO03ma/2fOmiDSQP9VRyUZcdZqBQMvaR9/xLn7+O1TgQmINv1t3oUvyqH5GV+IsMo+vbfaZwl9HqFMiSn4p6Gks4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=klIiHV53; 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="klIiHV53" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E27EFC116D0; Thu, 15 Jan 2026 17:50:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1768499439; bh=5ZhdE8FlHk55a6i5XgaU1tLMXNL8hAG8PoMT3cn5ZHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=klIiHV53B48Eqt2hx3EQUkAyKpjWhmPyLDWGMfgczokHqe8tiMxb6BYf8UrIS8XJQ aNNAizjYO4P+u1qDyDZOKtqo6ulR+DRoaVoB4kh+V2oFYDpOVwcHHqK2re08zJMYbR a4FOy14kUjqfCS8YiOfBHZUfVL0g+Gru0NZ3ECJw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yongjian Sun , Baokun Li , Jan Kara , Theodore Tso , stable@kernel.org Subject: [PATCH 5.10 226/451] ext4: fix incorrect group number assertion in mb_check_buddy Date: Thu, 15 Jan 2026 17:47:07 +0100 Message-ID: <20260115164239.071693574@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260115164230.864985076@linuxfoundation.org> References: <20260115164230.864985076@linuxfoundation.org> User-Agent: quilt/0.69 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 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yongjian Sun commit 3f7a79d05c692c7cfec70bf104b1b3c3d0ce6247 upstream. When the MB_CHECK_ASSERT macro is enabled, an assertion failure can occur in __mb_check_buddy when checking preallocated blocks (pa) in a block group: Assertion failure in mb_free_blocks() : "groupnr == e4b->bd_group" This happens when a pa at the very end of a block group (e.g., pa_pstart=32765, pa_len=3 in a group of 32768 blocks) becomes exhausted - its pa_pstart is advanced by pa_len to 32768, which lies in the next block group. If this exhausted pa (with pa_len == 0) is still in the bb_prealloc_list during the buddy check, the assertion incorrectly flags it as belonging to the wrong group. A possible sequence is as follows: ext4_mb_new_blocks ext4_mb_release_context pa->pa_pstart += EXT4_C2B(sbi, ac->ac_b_ex.fe_len) pa->pa_len -= ac->ac_b_ex.fe_len __mb_check_buddy for each pa in group ext4_get_group_no_and_offset MB_CHECK_ASSERT(groupnr == e4b->bd_group) To fix this, we modify the check to skip block group validation for exhausted preallocations (where pa_len == 0). Such entries are in a transitional state and will be removed from the list soon, so they should not trigger an assertion. This change prevents the false positive while maintaining the integrity of the checks for active allocations. Fixes: c9de560ded61f ("ext4: Add multi block allocator for ext4") Signed-off-by: Yongjian Sun Reviewed-by: Baokun Li Reviewed-by: Jan Kara Message-ID: <20251106060614.631382-2-sunyongjian@huaweicloud.com> Signed-off-by: Theodore Ts'o Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/mballoc.c | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -706,6 +706,8 @@ static void __mb_check_buddy(struct ext4 ext4_group_t groupnr; struct ext4_prealloc_space *pa; pa = list_entry(cur, struct ext4_prealloc_space, pa_group_list); + if (!pa->pa_len) + continue; ext4_get_group_no_and_offset(sb, pa->pa_pstart, &groupnr, &k); MB_CHECK_ASSERT(groupnr == e4b->bd_group); for (i = 0; i < pa->pa_len; i++)