]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
ext4: limit entries returned when counting fsmap records
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 1 Oct 2020 22:21:48 +0000 (15:21 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 30 Oct 2020 09:38:22 +0000 (10:38 +0100)
[ Upstream commit af8c53c8bc087459b1aadd4c94805d8272358d79 ]

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")
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Link: https://lore.kernel.org/r/20201001222148.GA49520@magnolia
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ext4/fsmap.c

index 4b99e2db95b8bca58e99f8629ecfce17417e25d3..6f3f245f3a8032fefb771d96d3bfab5fe6d5c50c 100644 (file)
@@ -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++;