Author: fsu
Date: Sun May 17 14:10:46 2020
New Revision: 361135
URL: https://svnweb.freebsd.org/changeset/base/361135

Log:
  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
  MFC after:    2 weeks

Modified:
  head/sys/fs/ext2fs/ext2_bmap.c

Modified: head/sys/fs/ext2fs/ext2_bmap.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_bmap.c      Sun May 17 14:03:13 2020        
(r361134)
+++ head/sys/fs/ext2fs/ext2_bmap.c      Sun May 17 14:10:46 2020        
(r361135)
@@ -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);
                }
        }
 
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to