All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Baokun Li <libaokun1@huawei.com>, Jan Kara <jack@suse.cz>,
	Theodore Ts'o <tytso@mit.edu>, Sasha Levin <sashal@kernel.org>,
	adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org
Subject: [PATCH AUTOSEL 6.1 12/14] ext4: unify the type of flexbg_size to unsigned int
Date: Mon, 15 Jan 2024 20:06:14 -0500	[thread overview]
Message-ID: <20240116010642.218876-12-sashal@kernel.org> (raw)
In-Reply-To: <20240116010642.218876-1-sashal@kernel.org>

From: Baokun Li <libaokun1@huawei.com>

[ Upstream commit 658a52344fb139f9531e7543a6e0015b630feb38 ]

The maximum value of flexbg_size is 2^31, but the maximum value of int
is (2^31 - 1), so overflow may occur when the type of flexbg_size is
declared as int.

For example, when uninit_mask is initialized in ext4_alloc_group_tables(),
if flexbg_size == 2^31, the initialized uninit_mask is incorrect, and this
may causes set_flexbg_block_bitmap() to trigger a BUG_ON().

Therefore, the flexbg_size type is declared as unsigned int to avoid
overflow and memory waste.

Signed-off-by: Baokun Li <libaokun1@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20231023013057.2117948-2-libaokun1@huawei.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/ext4/resize.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 9833ab6db117..31f5da7f9f6c 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -241,7 +241,7 @@ struct ext4_new_flex_group_data {
  *
  * Returns NULL on failure otherwise address of the allocated structure.
  */
-static struct ext4_new_flex_group_data *alloc_flex_gd(unsigned long flexbg_size)
+static struct ext4_new_flex_group_data *alloc_flex_gd(unsigned int flexbg_size)
 {
 	struct ext4_new_flex_group_data *flex_gd;
 
@@ -296,7 +296,7 @@ static void free_flex_gd(struct ext4_new_flex_group_data *flex_gd)
  */
 static int ext4_alloc_group_tables(struct super_block *sb,
 				struct ext4_new_flex_group_data *flex_gd,
-				int flexbg_size)
+				unsigned int flexbg_size)
 {
 	struct ext4_new_group_data *group_data = flex_gd->groups;
 	ext4_fsblk_t start_blk;
@@ -397,12 +397,12 @@ static int ext4_alloc_group_tables(struct super_block *sb,
 		group = group_data[0].group;
 
 		printk(KERN_DEBUG "EXT4-fs: adding a flex group with "
-		       "%d groups, flexbg size is %d:\n", flex_gd->count,
+		       "%u groups, flexbg size is %u:\n", flex_gd->count,
 		       flexbg_size);
 
 		for (i = 0; i < flex_gd->count; i++) {
 			ext4_debug(
-			       "adding %s group %u: %u blocks (%d free, %d mdata blocks)\n",
+			       "adding %s group %u: %u blocks (%u free, %u mdata blocks)\n",
 			       ext4_bg_has_super(sb, group + i) ? "normal" :
 			       "no-super", group + i,
 			       group_data[i].blocks_count,
@@ -1624,7 +1624,7 @@ static int ext4_flex_group_add(struct super_block *sb,
 static int ext4_setup_next_flex_gd(struct super_block *sb,
 				    struct ext4_new_flex_group_data *flex_gd,
 				    ext4_fsblk_t n_blocks_count,
-				    unsigned long flexbg_size)
+				    unsigned int flexbg_size)
 {
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
 	struct ext4_super_block *es = sbi->s_es;
@@ -2010,8 +2010,9 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
 	ext4_fsblk_t o_blocks_count;
 	ext4_fsblk_t n_blocks_count_retry = 0;
 	unsigned long last_update_time = 0;
-	int err = 0, flexbg_size = 1 << sbi->s_log_groups_per_flex;
+	int err = 0;
 	int meta_bg;
+	unsigned int flexbg_size = ext4_flex_bg_size(sbi);
 
 	/* See if the device is actually as big as what was requested */
 	bh = ext4_sb_bread(sb, n_blocks_count - 1, 0);
-- 
2.43.0


  parent reply	other threads:[~2024-01-16  1:07 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-16  1:06 [PATCH AUTOSEL 6.1 01/14] arch: consolidate arch_irq_work_raise prototypes Sasha Levin
2024-01-16  1:06 ` Sasha Levin
2024-01-16  1:06 ` Sasha Levin
2024-01-16  1:06 ` Sasha Levin
2024-01-16  1:06 ` [PATCH AUTOSEL 6.1 02/14] s390/vfio-ap: fix sysfs status attribute for AP queue devices Sasha Levin
2024-01-16  1:06 ` [PATCH AUTOSEL 6.1 03/14] Hexagon: Make pfn accessors statics inlines Sasha Levin
2024-01-16  1:06 ` [PATCH AUTOSEL 6.1 04/14] s390/ptrace: handle setting of fpc register correctly Sasha Levin
2024-01-16  1:06 ` [PATCH AUTOSEL 6.1 05/14] KVM: s390: fix setting of fpc register Sasha Levin
2024-01-16  1:06 ` [PATCH AUTOSEL 6.1 06/14] arm64: Fix circular header dependency Sasha Levin
2024-01-16  1:06   ` Sasha Levin
2024-01-16  1:06 ` [PATCH AUTOSEL 6.1 07/14] SUNRPC: Fix a suspicious RCU usage warning Sasha Levin
2024-01-16  1:06 ` [PATCH AUTOSEL 6.1 08/14] ext4: enable dioread_nolock as default for bs < ps case Sasha Levin
2024-01-16 20:47   ` Pavel Machek
2024-01-24  5:56     ` Ojaswin Mujoo
2024-01-16  1:06 ` [PATCH AUTOSEL 6.1 09/14] smb: client: Fix minor whitespace errors and warnings Sasha Levin
2024-01-16 20:48   ` Pavel Machek
2024-01-16  1:06 ` [PATCH AUTOSEL 6.1 10/14] ecryptfs: Reject casefold directory inodes Sasha Levin
2024-01-16  1:06 ` [PATCH AUTOSEL 6.1 11/14] ext4: fix inconsistent between segment fstrim and full fstrim Sasha Levin
2024-01-16  1:06 ` Sasha Levin [this message]
2024-01-16  1:06 ` [PATCH AUTOSEL 6.1 13/14] ext4: remove unnecessary check from alloc_flex_gd() Sasha Levin
2024-01-16  1:06 ` [PATCH AUTOSEL 6.1 14/14] ext4: avoid online resizing failures due to oversized flex bg Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240116010642.218876-12-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=libaokun1@huawei.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.