From owner-svn-src-head@freebsd.org Sat Jul 7 19:11:44 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EADFC104359E; Sat, 7 Jul 2018 19:11:43 +0000 (UTC) (envelope-from mckusick@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 94B39865BD; Sat, 7 Jul 2018 19:11:43 +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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 75F9D1B793; Sat, 7 Jul 2018 19:11:43 +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 w67JBh6F008102; Sat, 7 Jul 2018 19:11:43 GMT (envelope-from mckusick@FreeBSD.org) Received: (from mckusick@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w67JBhtV008101; Sat, 7 Jul 2018 19:11:43 GMT (envelope-from mckusick@FreeBSD.org) Message-Id: <201807071911.w67JBhtV008101@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mckusick set sender to mckusick@FreeBSD.org using -f From: Kirk McKusick Date: Sat, 7 Jul 2018 19:11:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336074 - head/sys/ufs/ffs X-SVN-Group: head X-SVN-Commit-Author: mckusick X-SVN-Commit-Paths: head/sys/ufs/ffs X-SVN-Commit-Revision: 336074 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Jul 2018 19:11:44 -0000 Author: mckusick Date: Sat Jul 7 19:11:43 2018 New Revision: 336074 URL: https://svnweb.freebsd.org/changeset/base/336074 Log: Import commit from NetBSD with checkin message: Avoid Undefined Behavior in ffs_clusteracct() Change the type of 'bit' variable from int to unsigned int and use unsigned values consistently. sys/ufs/ffs/ffs_subr.c:336:10, shift exponent -1 is negative Detected with Kernel Undefined Behavior Sanitizer. Reported by Submitted by: Pedro Giffuni Modified: head/sys/ufs/ffs/ffs_subr.c Modified: head/sys/ufs/ffs/ffs_subr.c ============================================================================== --- head/sys/ufs/ffs/ffs_subr.c Sat Jul 7 19:10:00 2018 (r336073) +++ head/sys/ufs/ffs/ffs_subr.c Sat Jul 7 19:11:43 2018 (r336074) @@ -473,7 +473,8 @@ ffs_clusteracct(struct fs *fs, struct cg *cgp, ufs1_da int32_t *sump; int32_t *lp; u_char *freemapp, *mapp; - int i, start, end, forw, back, map, bit; + int i, start, end, forw, back, map; + u_int bit; if (fs->fs_contigsumsize <= 0) return; @@ -495,7 +496,7 @@ ffs_clusteracct(struct fs *fs, struct cg *cgp, ufs1_da end = cgp->cg_nclusterblks; mapp = &freemapp[start / NBBY]; map = *mapp++; - bit = 1 << (start % NBBY); + bit = 1U << (start % NBBY); for (i = start; i < end; i++) { if ((map & bit) == 0) break; @@ -516,7 +517,7 @@ ffs_clusteracct(struct fs *fs, struct cg *cgp, ufs1_da end = -1; mapp = &freemapp[start / NBBY]; map = *mapp--; - bit = 1 << (start % NBBY); + bit = 1U << (start % NBBY); for (i = start; i > end; i--) { if ((map & bit) == 0) break; @@ -524,7 +525,7 @@ ffs_clusteracct(struct fs *fs, struct cg *cgp, ufs1_da bit >>= 1; } else { map = *mapp--; - bit = 1 << (NBBY - 1); + bit = 1U << (NBBY - 1); } } back = start - i;