From owner-dev-commits-src-all@freebsd.org Sat May 29 02:37:58 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 0947863772F; Sat, 29 May 2021 02:37:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FsQhP6d6Hz3NGd; Sat, 29 May 2021 02:37:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CB96D22866; Sat, 29 May 2021 02:37:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 14T2bviN071799; Sat, 29 May 2021 02:37:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 14T2bvfv071798; Sat, 29 May 2021 02:37:57 GMT (envelope-from git) Date: Sat, 29 May 2021 02:37:57 GMT Message-Id: <202105290237.14T2bvfv071798@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kirk McKusick Subject: git: 5c9e9eb7a27f - main - Fix fsck_ufs segfault when it needs to rerun. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mckusick X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5c9e9eb7a27feb24136c16706f3db8ce7c8bbc47 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 May 2021 02:37:58 -0000 The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=5c9e9eb7a27feb24136c16706f3db8ce7c8bbc47 commit 5c9e9eb7a27feb24136c16706f3db8ce7c8bbc47 Author: Kirk McKusick AuthorDate: 2021-05-29 02:41:05 +0000 Commit: Kirk McKusick CommitDate: 2021-05-29 02:41:50 +0000 Fix fsck_ufs segfault when it needs to rerun. The segfault was being hit in the rerun of Pass 1 in ginode() when trying to get an inode that needs to be repaired. When the first run of fsck_ffs finishes it clears the inode cache, but ginode() was failing to check properly and tried to access the deallocated cache entry. Reported by: Peter Holm Reviewed by: Chuck Silvers Tested by: Peter Holm and Chuck Silvers MFC after: 3 days Sponsored by: Netflix --- sbin/fsck_ffs/inode.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c index d4e5723f559f..ba2d5892238e 100644 --- a/sbin/fsck_ffs/inode.c +++ b/sbin/fsck_ffs/inode.c @@ -416,14 +416,14 @@ void ginode(ino_t inumber, struct inode *ip) { ufs2_daddr_t iblk; - static ino_t startinum = -1; if (inumber < UFS_ROOTINO || inumber > maxino) errx(EEXIT, "bad inode number %ju to ginode", (uintmax_t)inumber); ip->i_number = inumber; - if (startinum != -1 && - inumber >= startinum && inumber < startinum + INOPB(&sblock)) { + if (icachebp != NULL && + inumber >= icachebp->b_index && + inumber < icachebp->b_index + INOPB(&sblock)) { /* take an additional reference for the returned inode */ icachebp->b_refcnt++; } else { @@ -433,14 +433,14 @@ ginode(ino_t inumber, struct inode *ip) brelse(icachebp); icachebp = getdatablk(iblk, sblock.fs_bsize, BT_INODES); if (icachebp->b_errs != 0) { + icachebp = NULL; ip->i_bp = NULL; ip->i_dp = &zino; return; } - startinum = rounddown(inumber, INOPB(&sblock)); /* take a cache-hold reference on new icachebp */ icachebp->b_refcnt++; - icachebp->b_index = startinum; + icachebp->b_index = rounddown(inumber, INOPB(&sblock)); } ip->i_bp = icachebp; if (sblock.fs_magic == FS_UFS1_MAGIC) {