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 22C071A6192; Tue, 30 Jul 2024 16:36:42 +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=1722357402; cv=none; b=P975ctIIvg76F+PiC1lnMkgB0DL+eGVq/oiG3Y7HBGDB8Htatx7yvO9yUKQmSBbtSDMwWKpqJWD+NdoAk6u4Uc4QkEy5sACKQVybLVm5GJRP7XhMnAdIKNbBfthB8PxvZ9h5ctp9UC4iqq1xud6YcLxEK9zk9H3K7Z6i/WutTek= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722357402; c=relaxed/simple; bh=ka4H7K3Y6pOsuPSHLdu3z6zWPCso6YNnSfsSFcyhBME=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k3nU8t/bBVfBMsaUXhBLWanax496XILZ9GAyU7TFh35DRp7G7OVKeGqhjCoA5EsMmz6Af3eTd7RKRoLHfLQPUCVCurGeomI90otXTlQaniNdwebmqSJiaRyLH9SFLTDGHIFQK8FQxHWvHGXb1uOTGzLrdCnHMO3bUiQ1EH7E3lI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1pvQ0+Bn; 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="1pvQ0+Bn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 822A0C32782; Tue, 30 Jul 2024 16:36:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1722357402; bh=ka4H7K3Y6pOsuPSHLdu3z6zWPCso6YNnSfsSFcyhBME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1pvQ0+BncD63vhVOUc4VuijgCIpv/GRa3zsZ4p9/LO4s3gihQ+HyFeKpibcvZOcII zudpFfUKocettfpXVe2BJIBft2ATWUKDgiHD9JPko/vf+fQDgC1Ju8PAEdJXPA5evk yq8DVkEl5vDPzEytiNt6abWFq/f1y7eftMkj1RuU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jan Kara Subject: [PATCH 6.1 289/440] ext2: Verify bitmap and itable block numbers before using them Date: Tue, 30 Jul 2024 17:48:42 +0200 Message-ID: <20240730151627.122166345@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240730151615.753688326@linuxfoundation.org> References: <20240730151615.753688326@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 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jan Kara commit 322a6aff03937aa1ece33b4e46c298eafaf9ac41 upstream. Verify bitmap block numbers and inode table blocks are sane before using them for checking bits in the block bitmap. CC: stable@vger.kernel.org Signed-off-by: Jan Kara Signed-off-by: Greg Kroah-Hartman --- fs/ext2/balloc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/fs/ext2/balloc.c +++ b/fs/ext2/balloc.c @@ -79,26 +79,33 @@ static int ext2_valid_block_bitmap(struc ext2_grpblk_t next_zero_bit; ext2_fsblk_t bitmap_blk; ext2_fsblk_t group_first_block; + ext2_grpblk_t max_bit; group_first_block = ext2_group_first_block_no(sb, block_group); + max_bit = ext2_group_last_block_no(sb, block_group) - group_first_block; /* check whether block bitmap block number is set */ bitmap_blk = le32_to_cpu(desc->bg_block_bitmap); offset = bitmap_blk - group_first_block; - if (!ext2_test_bit(offset, bh->b_data)) + if (offset < 0 || offset > max_bit || + !ext2_test_bit(offset, bh->b_data)) /* bad block bitmap */ goto err_out; /* check whether the inode bitmap block number is set */ bitmap_blk = le32_to_cpu(desc->bg_inode_bitmap); offset = bitmap_blk - group_first_block; - if (!ext2_test_bit(offset, bh->b_data)) + if (offset < 0 || offset > max_bit || + !ext2_test_bit(offset, bh->b_data)) /* bad block bitmap */ goto err_out; /* check whether the inode table block number is set */ bitmap_blk = le32_to_cpu(desc->bg_inode_table); offset = bitmap_blk - group_first_block; + if (offset < 0 || offset > max_bit || + offset + EXT2_SB(sb)->s_itb_per_group - 1 > max_bit) + goto err_out; next_zero_bit = ext2_find_next_zero_bit(bh->b_data, offset + EXT2_SB(sb)->s_itb_per_group, offset);