From owner-svn-src-all@freebsd.org Fri Oct 28 20:15:20 2016 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 8F8E3C25D7B; Fri, 28 Oct 2016 20:15:20 +0000 (UTC) (envelope-from mckusick@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 4F2EFC0E; Fri, 28 Oct 2016 20:15:20 +0000 (UTC) (envelope-from mckusick@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u9SKFJ2j010174; Fri, 28 Oct 2016 20:15:19 GMT (envelope-from mckusick@FreeBSD.org) Received: (from mckusick@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u9SKFJdY010173; Fri, 28 Oct 2016 20:15:19 GMT (envelope-from mckusick@FreeBSD.org) Message-Id: <201610282015.u9SKFJdY010173@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mckusick set sender to mckusick@FreeBSD.org using -f From: Kirk McKusick Date: Fri, 28 Oct 2016 20:15:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r308064 - head/sys/ufs/ffs X-SVN-Group: head 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: Fri, 28 Oct 2016 20:15:20 -0000 Author: mckusick Date: Fri Oct 28 20:15:19 2016 New Revision: 308064 URL: https://svnweb.freebsd.org/changeset/base/308064 Log: Avoid possible overflow when calclating malloc size for auxillary data structure sizes when mounting and reloading UFS/FFS filesystems by using a u_long rather than an int for the size. Reported by: Mariusz Zaborski MFC after: 1 week Modified: head/sys/ufs/ffs/ffs_vfsops.c Modified: head/sys/ufs/ffs/ffs_vfsops.c ============================================================================== --- head/sys/ufs/ffs/ffs_vfsops.c Fri Oct 28 19:46:08 2016 (r308063) +++ head/sys/ufs/ffs/ffs_vfsops.c Fri Oct 28 20:15:19 2016 (r308064) @@ -588,7 +588,8 @@ ffs_reload(struct mount *mp, struct thre struct fs *fs, *newfs; struct ufsmount *ump; ufs2_daddr_t sblockloc; - int i, blks, size, error; + int i, blks, error; + u_long size; int32_t *lp; ump = VFSTOUFS(mp); @@ -658,7 +659,7 @@ ffs_reload(struct mount *mp, struct thre size += fs->fs_ncg * sizeof(int32_t); size += fs->fs_ncg * sizeof(u_int8_t); free(fs->fs_csp, M_UFSMNT); - space = malloc((u_long)size, M_UFSMNT, M_WAITOK); + space = malloc(size, M_UFSMNT, M_WAITOK); fs->fs_csp = space; for (i = 0; i < blks; i += fs->fs_frag) { size = fs->fs_bsize; @@ -751,7 +752,8 @@ ffs_mountfs(devvp, mp, td) struct cdev *dev; void *space; ufs2_daddr_t sblockloc; - int error, i, blks, size, ronly; + int error, i, blks, len, ronly; + u_long size; int32_t *lp; struct ucred *cred; struct g_consumer *cp; @@ -856,11 +858,11 @@ ffs_mountfs(devvp, mp, td) /* * Get journal provider name. */ - size = 1024; - mp->mnt_gjprovider = malloc(size, M_UFSMNT, M_WAITOK); - if (g_io_getattr("GJOURNAL::provider", cp, &size, + len = 1024; + mp->mnt_gjprovider = malloc((u_long)len, M_UFSMNT, M_WAITOK); + if (g_io_getattr("GJOURNAL::provider", cp, &len, mp->mnt_gjprovider) == 0) { - mp->mnt_gjprovider = realloc(mp->mnt_gjprovider, size, + mp->mnt_gjprovider = realloc(mp->mnt_gjprovider, len, M_UFSMNT, M_WAITOK); MNT_ILOCK(mp); mp->mnt_flag |= MNT_GJOURNAL; @@ -912,7 +914,7 @@ ffs_mountfs(devvp, mp, td) if (fs->fs_contigsumsize > 0) size += fs->fs_ncg * sizeof(int32_t); size += fs->fs_ncg * sizeof(u_int8_t); - space = malloc((u_long)size, M_UFSMNT, M_WAITOK); + space = malloc(size, M_UFSMNT, M_WAITOK); fs->fs_csp = space; for (i = 0; i < blks; i += fs->fs_frag) { size = fs->fs_bsize; @@ -997,8 +999,8 @@ ffs_mountfs(devvp, mp, td) #endif } if ((fs->fs_flags & FS_TRIM) != 0) { - size = sizeof(int); - if (g_io_getattr("GEOM::candelete", cp, &size, + len = sizeof(int); + if (g_io_getattr("GEOM::candelete", cp, &len, &ump->um_candelete) == 0) { if (!ump->um_candelete) printf("WARNING: %s: TRIM flag on fs but disk "