svn commit: r362098 - stable/12/sys/fs/ext2fs

Fedor Uporov fsu at FreeBSD.org
Fri Jun 12 13:54:42 UTC 2020


Author: fsu
Date: Fri Jun 12 13:54:41 2020
New Revision: 362098
URL: https://svnweb.freebsd.org/changeset/base/362098

Log:
  MFC r361135:
  Restrict the max runp and runb return values in case of extents mapping.
  
  This restriction already present in case of indirect mapping, do the same
  in case of extents.
  
  PR:		246182
  Reported by:	Teran McKinney

Modified:
  stable/12/sys/fs/ext2fs/ext2_bmap.c

Modified: stable/12/sys/fs/ext2fs/ext2_bmap.c
==============================================================================
--- stable/12/sys/fs/ext2fs/ext2_bmap.c	Fri Jun 12 13:53:50 2020	(r362097)
+++ stable/12/sys/fs/ext2fs/ext2_bmap.c	Fri Jun 12 13:54:41 2020	(r362098)
@@ -94,21 +94,28 @@ ext4_bmapext(struct vnode *vp, int32_t bn, int64_t *bn
 {
 	struct inode *ip;
 	struct m_ext2fs *fs;
+	struct mount *mp;
+	struct ext2mount *ump;
 	struct ext4_extent_header *ehp;
 	struct ext4_extent *ep;
 	struct ext4_extent_path *path = NULL;
 	daddr_t lbn;
-	int error, depth;
+	int error, depth, maxrun = 0, bsize;
 
 	ip = VTOI(vp);
 	fs = ip->i_e2fs;
+	mp = vp->v_mount;
+	ump = VFSTOEXT2(mp);
 	lbn = bn;
 	ehp = (struct ext4_extent_header *)ip->i_data;
 	depth = ehp->eh_depth;
+	bsize = EXT2_BLOCK_SIZE(ump->um_e2fs);
 
 	*bnp = -1;
-	if (runp != NULL)
+	if (runp != NULL) {
+		maxrun = mp->mnt_iosize_max / bsize - 1;
 		*runp = 0;
+	}
 	if (runb != NULL)
 		*runb = 0;
 
@@ -119,18 +126,21 @@ ext4_bmapext(struct vnode *vp, int32_t bn, int64_t *bn
 	ep = path[depth].ep_ext;
 	if(ep) {
 		if (lbn < ep->e_blk) {
-			if (runp != NULL)
-				*runp = ep->e_blk - lbn - 1;
+			if (runp != NULL) {
+				*runp = min(maxrun, ep->e_blk - lbn - 1);
+			}
 		} else if (ep->e_blk <= lbn && lbn < ep->e_blk + ep->e_len) {
 			*bnp = fsbtodb(fs, lbn - ep->e_blk +
 			    (ep->e_start_lo | (daddr_t)ep->e_start_hi << 32));
-			if (runp != NULL)
-				*runp = ep->e_len - (lbn - ep->e_blk) - 1;
+			if (runp != NULL) {
+				*runp = min(maxrun,
+				    ep->e_len - (lbn - ep->e_blk) - 1);
+			}
 			if (runb != NULL)
-				*runb = lbn - ep->e_blk;
+				*runb = min(maxrun, lbn - ep->e_blk);
 		} else {
 			if (runb != NULL)
-				*runb = ep->e_blk + lbn - ep->e_len;
+				*runb = min(maxrun, ep->e_blk + lbn - ep->e_len);
 		}
 	}
 


More information about the svn-src-all mailing list