Skip to contentSkip to conversation

ext4: limit entries returned when counting fsmap records

PATCH Applied Darrick J. Wong 2 participants 2 messages Oct 1, 2020 – Oct 3, 2020 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: limit entries returned when counting fsmap records

From: Darrick J. Wong <[email protected]>

If userspace asked fsmap to try to count the number of entries, we cannot return more than UINT_MAX entries because fmh_entries is u32. Therefore, stop counting if we hit this limit or else we will waste time to return truncated results.

Fixes 0c9ec4beecac ("ext4: support GETFSMAP ioctls")
---
 fs/ext4/fsmap.c |    3 +++
 1 file changed, 3 insertions(+)
fs/ext4/fsmap.c +3 -0
index dbccf46f1770..37347ba868b7 100644
@@ -108,6 +108,9 @@ static int ext4_getfsmap_helper(struct super_block *sb,
 
 	/* Are we just counting mappings? */
 	if (info->gfi_head->fmh_count == 0) {
+		if (info->gfi_head->fmh_entries == UINT_MAX)
+			return EXT4_QUERY_RANGE_ABORT;
+
 		if (rec_fsblk > info->gfi_next_fsblk)
 			info->gfi_head->fmh_entries++;
 
maintainer Applied
#1 lore raw
Quoted 9 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

If userspace asked fsmap to try to count the number of entries, we cannot return more than UINT_MAX entries because fmh_entries is u32. Therefore, stop counting if we hit this limit or else we will waste time to return truncated results.

Fixes 0c9ec4beecac ("ext4: support GETFSMAP ioctls")

Applied, thanks.

- Ted