]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
xfs: limit entries returned when counting fsmap records
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 1 Oct 2020 17:56:07 +0000 (10:56 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Oct 2020 08:57:47 +0000 (09:57 +0100)
[ Upstream commit acd1ac3aa22fd58803a12d26b1ab7f70232f8d8d ]

If userspace asked fsmap 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: e89c041338ed ("xfs: implement the GETFSMAP ioctl")
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/xfs/xfs_fsmap.c

index c13754e119be126bc391c24dd0a9e08a4f87f336..5b864985bc64876dd5612c4806eae809f16c8b62 100644 (file)
@@ -255,6 +255,9 @@ xfs_getfsmap_helper(
 
        /* Are we just counting mappings? */
        if (info->head->fmh_count == 0) {
+               if (info->head->fmh_entries == UINT_MAX)
+                       return -ECANCELED;
+
                if (rec_daddr > info->next_daddr)
                        info->head->fmh_entries++;