[PATCH 4/2] mkfs: don't crash on dswidth overflow

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Darrick J. Wong <darrick.wong@xxxxxxxxxx>

I ran mkfs.xfs -d su=1048576,sw=$((18 * 1048576)), forgetting that sw
takes a multiple of su (unlike swidth which takes any space unit).  I
was surprised when we hit a floating point exception, which I traced
back to an integer overflow when we calculate swidth from dsw.

So, do the 64-bit multiplication so we can detect the overflow and
complain about it.

Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx>
---
 mkfs/xfs_mkfs.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 5f1ac9f..7c9d148 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -2211,6 +2211,7 @@ calc_stripe_factors(
 	struct cli_params	*cli,
 	struct fs_topology	*ft)
 {
+	long long int	big_dswidth;
 	int		dsunit = 0;
 	int		dswidth = 0;
 	int		lsunit = 0;
@@ -2251,7 +2252,14 @@ _("data su must be a multiple of the sector size (%d)\n"), cfg->sectorsize);
 		}
 
 		dsunit  = (int)BTOBBT(dsu);
-		dswidth = dsunit * dsw;
+		big_dswidth = (long long int)dsunit * dsw;
+		if (big_dswidth > INT_MAX) {
+			fprintf(stderr,
+_("data stripe width (%lld) is too large of a multiple of the data stripe unit (%d)\n"),
+				big_dswidth, dsunit);
+			usage();
+		}
+		dswidth = big_dswidth;
 	}
 
 	if (dsunit && (dswidth % dsunit != 0)) {
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux