Skip to contentSkip to conversation

xfs: fix maxicount division by zero error

PATCH In review Darrick J. Wong 2 participants 2 messages Aug 26, 2019 – Aug 27, 2019 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: fix maxicount division by zero error

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

In xfs_ialloc_setup_geometry, it's possible for a malicious/corrupt fs image to set an unreasonably large value for sb_inopblog which will cause ialloc_blks to be zero. If sb_imax_pct is also set, this results in a division by zero error in the second do_div call. Therefore, force maxicount to zero if ialloc_blks is zero.

Note that the kernel metadata verifiers will catch the garbage inopblog value and abort the fs mount long before it tries to set up the inode geometry; this is needed to avoid a crash in xfs_db while setting up the xfs_mount structure.

Found by fuzzing sb_inopblog to 122 in xfs/350.

---
 fs/xfs/libxfs/xfs_ialloc.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/libxfs/xfs_ialloc.c +1 -1
index 1a14067aa4d4..5e95648c346c 100644
@@ -2811,7 +2811,7 @@ xfs_ialloc_setup_geometry(
 			inodes);
 
 	/* Set the maximum inode count for this filesystem. */
-	if (sbp->sb_imax_pct) {
+	if (sbp->sb_imax_pct && igeo->ialloc_blks) {
 		/*
 		 * Make sure the maximum inode count is a multiple
 		 * of the units we allocate inodes in.
Reviewed-by on v1 1/1
#1 lore raw

Hi.

Quoted 8 lines · Darrick J. Wong

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

In xfs_ialloc_setup_geometry, it's possible for a malicious/corrupt fs image to set an unreasonably large value for sb_inopblog which will cause ialloc_blks to be zero. If sb_imax_pct is also set, this results in a division by zero error in the second do_div call. Therefore, force maxicount to zero if ialloc_blks is zero.

Quoted 6 lines

Note that the kernel metadata verifiers will catch the garbage inopblog value and abort the fs mount long before it tries to set up the inode geometry; this is needed to avoid a crash in xfs_db while setting up the xfs_mount structure.

Found by fuzzing sb_inopblog to 122 in xfs/350.

The patch looks good, but maybe a comment is worth so we don't need to check the git log to understand why we need to check ialloc_blks here?

fs/xfs/libxfs/xfs_ialloc.c xfs_ialloc_setup_geometry( · line 2811

Quoted 12 lines
---
 fs/xfs/libxfs/xfs_ialloc.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/libxfs/xfs_ialloc.c +0 -0
index 1a14067aa4d4..5e95648c346c 100644
@@ -2811,7 +2811,7 @@ xfs_ialloc_setup_geometry(
 			inodes);

Something like:

	/*
	 * Set the maximum inode count for this filesystem, being careful
	 * ialloc_blks is not zeroed due a corrupted sb_agblklog
	 */
	if (sbp->sb_imax_pct) {
	if (sbp->sb_imax_pct && igeo->ialloc_blks) {

fs/xfs/libxfs/xfs_ialloc.c xfs_ialloc_setup_geometry( · line 2817

Quoted 3 lines
fs/xfs/libxfs/xfs_ialloc.c +0 -0
 		/*
 		 * Make sure the maximum inode count is a multiple
 		 * of the units we allocate inodes in.

The comment is just a suggestion anyway, you can add to the patch:

Signature · 1 line
Carlos