From owner-svn-src-all@freebsd.org Sun Oct 15 14:03:55 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8EF7FE43E3F; Sun, 15 Oct 2017 14:03:55 +0000 (UTC) (envelope-from fsu@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 67F6777711; Sun, 15 Oct 2017 14:03:55 +0000 (UTC) (envelope-from fsu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v9FE3sOJ040113; Sun, 15 Oct 2017 14:03:54 GMT (envelope-from fsu@FreeBSD.org) Received: (from fsu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v9FE3san040109; Sun, 15 Oct 2017 14:03:54 GMT (envelope-from fsu@FreeBSD.org) Message-Id: <201710151403.v9FE3san040109@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: fsu set sender to fsu@FreeBSD.org using -f From: Fedor Uporov Date: Sun, 15 Oct 2017 14:03:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r324627 - stable/11/sys/fs/ext2fs X-SVN-Group: stable-11 X-SVN-Commit-Author: fsu X-SVN-Commit-Paths: stable/11/sys/fs/ext2fs X-SVN-Commit-Revision: 324627 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Oct 2017 14:03:55 -0000 Author: fsu Date: Sun Oct 15 14:03:53 2017 New Revision: 324627 URL: https://svnweb.freebsd.org/changeset/base/324627 Log: MFC r324064: Add check to avoid raw inode iblocks fields overflow in case of huge_file feature. Use the Linux logic for now. Approved by: pfg (mentor) Differential Revision: https://reviews.freebsd.org/D12131 Modified: stable/11/sys/fs/ext2fs/ext2_alloc.c stable/11/sys/fs/ext2fs/ext2_extern.h stable/11/sys/fs/ext2fs/ext2_inode.c stable/11/sys/fs/ext2fs/ext2_inode_cnv.c Modified: stable/11/sys/fs/ext2fs/ext2_alloc.c ============================================================================== --- stable/11/sys/fs/ext2fs/ext2_alloc.c Sun Oct 15 11:46:11 2017 (r324626) +++ stable/11/sys/fs/ext2fs/ext2_alloc.c Sun Oct 15 14:03:53 2017 (r324627) @@ -56,7 +56,6 @@ static daddr_t ext2_alloccg(struct inode *, int, daddr_t, int); static daddr_t ext2_clusteralloc(struct inode *, int, daddr_t, int); static u_long ext2_dirpref(struct inode *); -static void ext2_fserr(struct m_ext2fs *, uid_t, char *); static u_long ext2_hashalloc(struct inode *, int, long, int, daddr_t (*)(struct inode *, int, daddr_t, int)); @@ -1303,7 +1302,7 @@ ext2_mapsearch(struct m_ext2fs *fs, char *bbp, daddr_t * The form of the error message is: * fs: error message */ -static void +void ext2_fserr(struct m_ext2fs *fs, uid_t uid, char *cp) { Modified: stable/11/sys/fs/ext2fs/ext2_extern.h ============================================================================== --- stable/11/sys/fs/ext2fs/ext2_extern.h Sun Oct 15 11:46:11 2017 (r324626) +++ stable/11/sys/fs/ext2fs/ext2_extern.h Sun Oct 15 14:03:53 2017 (r324627) @@ -62,9 +62,10 @@ int ext2_bmap(struct vop_bmap_args *); int ext2_bmaparray(struct vnode *, daddr_t, daddr_t *, int *, int *); void ext2_clusteracct(struct m_ext2fs *, char *, int, daddr_t, int); void ext2_dirbad(struct inode *ip, doff_t offset, char *how); +void ext2_fserr(struct m_ext2fs *, uid_t, char *); void ext2_ei2i(struct ext2fs_dinode *, struct inode *); int ext2_getlbns(struct vnode *, daddr_t, struct indir *, int *); -void ext2_i2ei(struct inode *, struct ext2fs_dinode *); +int ext2_i2ei(struct inode *, struct ext2fs_dinode *); void ext2_itimes(struct vnode *vp); int ext2_reallocblks(struct vop_reallocblks_args *); int ext2_reclaim(struct vop_reclaim_args *); Modified: stable/11/sys/fs/ext2fs/ext2_inode.c ============================================================================== --- stable/11/sys/fs/ext2fs/ext2_inode.c Sun Oct 15 11:46:11 2017 (r324626) +++ stable/11/sys/fs/ext2fs/ext2_inode.c Sun Oct 15 14:03:53 2017 (r324627) @@ -90,8 +90,12 @@ ext2_update(struct vnode *vp, int waitfor) brelse(bp); return (error); } - ext2_i2ei(ip, (struct ext2fs_dinode *)((char *)bp->b_data + + error = ext2_i2ei(ip, (struct ext2fs_dinode *)((char *)bp->b_data + EXT2_INODE_SIZE(fs) * ino_to_fsbo(fs, ip->i_number))); + if (error) { + brelse(bp); + return (error); + } if (waitfor && !DOINGASYNC(vp)) return (bwrite(bp)); else { Modified: stable/11/sys/fs/ext2fs/ext2_inode_cnv.c ============================================================================== --- stable/11/sys/fs/ext2fs/ext2_inode_cnv.c Sun Oct 15 11:46:11 2017 (r324626) +++ stable/11/sys/fs/ext2fs/ext2_inode_cnv.c Sun Oct 15 14:03:53 2017 (r324627) @@ -136,11 +136,13 @@ ext2_ei2i(struct ext2fs_dinode *ei, struct inode *ip) /* * inode to raw ext2 inode */ -void +int ext2_i2ei(struct inode *ip, struct ext2fs_dinode *ei) { + struct m_ext2fs *fs; int i; + fs = ip->i_e2fs; ei->e2di_mode = ip->i_mode; ei->e2di_nlink = ip->i_nlink; /* @@ -167,8 +169,19 @@ ext2_i2ei(struct inode *ip, struct ext2fs_dinode *ei) ei->e2di_flags |= (ip->i_flags & UF_NODUMP) ? EXT2_NODUMP : 0; ei->e2di_flags |= (ip->i_flag & IN_E3INDEX) ? EXT3_INDEX : 0; ei->e2di_flags |= (ip->i_flag & IN_E4EXTENTS) ? EXT4_EXTENTS : 0; - ei->e2di_nblock = ip->i_blocks & 0xffffffff; - ei->e2di_nblock_high = ip->i_blocks >> 32 & 0xffff; + if (ip->i_blocks > ~0U && + !EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_HUGE_FILE)) { + ext2_fserr(fs, ip->i_uid, "i_blocks value is out of range"); + return (EIO); + } + if (ip->i_blocks <= 0xffffffffffffULL) { + ei->e2di_nblock = ip->i_blocks & 0xffffffff; + ei->e2di_nblock_high = ip->i_blocks >> 32 & 0xffff; + } else { + ei->e2di_flags |= EXT4_HUGE_FILE; + ei->e2di_nblock = dbtofsb(fs, ip->i_blocks); + ei->e2di_nblock_high = dbtofsb(fs, ip->i_blocks) >> 32 & 0xffff; + } ei->e2di_facl = ip->i_facl & 0xffffffff; ei->e2di_facl_high = ip->i_facl >> 32 & 0xffff; ei->e2di_gen = ip->i_gen; @@ -181,4 +194,6 @@ ext2_i2ei(struct inode *ip, struct ext2fs_dinode *ei) ei->e2di_blocks[i] = ip->i_db[i]; for (i = 0; i < NIADDR; i++) ei->e2di_blocks[EXT2_NDIR_BLOCKS + i] = ip->i_ib[i]; + + return (0); }