From nobody Sat May 27 23:08:13 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QTHWx2GFkz4Ww0S; Sat, 27 May 2023 23:08:13 +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 4QTHWx1nmqz3HyR; Sat, 27 May 2023 23:08:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685228893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VGIpE+VSTD7yUQVdEduRauiN8mkPT7LD059y91WrShU=; b=T6yjb+b04CxGmJg80VeHo8RRRxJfWMIhAnJIbmPtAfeHQ++2x/5KAJ1ldDHz/9RlYUTs43 EcV15Z0LzX3U1jn5C0IvQHqFLgG3s0Rj/3N9FVJjHhVw9ErJmc3N5vfidrgTO4AALOz0Q7 9/9yklBBHi7oXvYcIMuez3HytdL1sMhqelIWHsnTeOhb5Q2d52y0WoTrTU3VVDp50P5Q1+ 925W1gOPjR57SLKJMfo+/8YmmjfQhBGW86B7bDjXB4NQOqxD7Ma7oPpq5PJBaeAN3LJ4CF wspJT3xCnEyRW3RbPqKepaXXPWRO3MhgzbnwOi3xquo1Hw6hTr3DlURDZa8gGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685228893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VGIpE+VSTD7yUQVdEduRauiN8mkPT7LD059y91WrShU=; b=iv9w8VHV9AlKYHMIlHfONKBI8qTYqDn5L3nEof1cACNa4Hi3aMuYZI6hAcdbPpXPNR0krv DgXSbtiWurTFU0MIWQLPvQlO4S+TWkE1Rz8jEFYjzyteyOvw/FdUs+WQ8bqXQJjzA/Ohbe cFyJJbrdAiJD0QEzY9BC+Bp3Op+9Kghh9ZE3gAlFpUeQtAuLDpWUxsClu9zVX0CJoTmDxB k02IctVnVNBLh1tFPn5zMbMBXg3Qb5416zaK5ZQy9iqIrZfgw0tC9VWGevftZXiE43GHQo dO8p5Dh8Vqd8I+n1MbD+ttA511z9zVfxyW2IjbGRZSuXlbvGk/EfIdRT09n0ug== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685228893; a=rsa-sha256; cv=none; b=AQvU1D4NyB4RTDpKrREaOC0XJCbENNJsBnyDS7vTvTQddODAz+fGmLgxRUC1Rt//WNbCUp 5/jlaQZoQMHKTj3W8mm1TQAVmV8n336zZpy6xZGi++iovy2qoRmlM0PXcisEyZtP0eG8Ty 8r4qBCKK7SPzzlZPsXAs0349TR1PlSqNwxX33V+7o0yweHm9F4L8XOz50vYkp0meRUgs27 Y/dkHqbQv6YBeP8MusCEQG8LQyHPy3BSLflzb9OELG56R91S/Ho3vQEBVLDmeMmqsqsQS0 kAFH2j6w39oARndhHBSbvUX+v9VhandSxynlPpotmCG2gnnoGa4+Htt/+eAVEw== 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 4QTHWx0rp8z16ZD; Sat, 27 May 2023 23:08:13 +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 34RN8DAS075507; Sat, 27 May 2023 23:08:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34RN8DLi075506; Sat, 27 May 2023 23:08:13 GMT (envelope-from git) Date: Sat, 27 May 2023 23:08:13 GMT Message-Id: <202305272308.34RN8DLi075506@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: 11ce203e0535 - main - Fix a bug in fsck_ffs(8) triggered by corrupted filesystems. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org 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: 11ce203e0535c1c8f520c9bda81ab9326cf5db80 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=11ce203e0535c1c8f520c9bda81ab9326cf5db80 commit 11ce203e0535c1c8f520c9bda81ab9326cf5db80 Author: Kirk McKusick AuthorDate: 2023-05-27 23:07:09 +0000 Commit: Kirk McKusick CommitDate: 2023-05-27 23:07:09 +0000 Fix a bug in fsck_ffs(8) triggered by corrupted filesystems. The last valid inode in the filesystem is maxino - 1, not maxino. Thus validity checks should ino < maxino, not ino <= maxino. Reported-by: Robert Morris PR: 271312 MFC-after: 1 week Sponsored-by: The FreeBSD Foundation --- sbin/fsck_ffs/dir.c | 4 ++-- sbin/fsck_ffs/fsutil.c | 2 +- sbin/fsck_ffs/inode.c | 14 ++++++++------ sbin/fsck_ffs/pass2.c | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/sbin/fsck_ffs/dir.c b/sbin/fsck_ffs/dir.c index e5f0e1e7e7f4..7ea471bcb30a 100644 --- a/sbin/fsck_ffs/dir.c +++ b/sbin/fsck_ffs/dir.c @@ -126,7 +126,7 @@ check_dirdepth(struct inoinfo *inp) if (inp->i_depth == 0 && updateasked == 0) { updateasked = 1; if (preen) { - pwarn("UPDATING FILESYSTEM TO TRACK DIRECTORY DEPTH"); + pwarn("UPDATING FILESYSTEM TO TRACK DIRECTORY DEPTH\n"); dirdepthupdate = 1; } else { /* @@ -437,7 +437,7 @@ fileerror(ino_t cwd, ino_t ino, const char *errmesg) char pathbuf[MAXPATHLEN + 1]; pwarn("%s ", errmesg); - if (ino < UFS_ROOTINO || ino > maxino) { + if (ino < UFS_ROOTINO || ino >= maxino) { pfatal("out-of-range inode number %ju", (uintmax_t)ino); return; } diff --git a/sbin/fsck_ffs/fsutil.c b/sbin/fsck_ffs/fsutil.c index 5e60aecf1826..7602203e6e90 100644 --- a/sbin/fsck_ffs/fsutil.c +++ b/sbin/fsck_ffs/fsutil.c @@ -170,7 +170,7 @@ inoinfo(ino_t inum) struct inostatlist *ilp; int iloff; - if (inum > maxino) + if (inum >= maxino) errx(EEXIT, "inoinfo: inumber %ju out of range", (uintmax_t)inum); ilp = &inostathead[inum / sblock.fs_ipg]; diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c index 00a60157138c..7dca95129ed1 100644 --- a/sbin/fsck_ffs/inode.c +++ b/sbin/fsck_ffs/inode.c @@ -433,8 +433,9 @@ void ginode(ino_t inumber, struct inode *ip) { ufs2_daddr_t iblk; + struct ufs2_dinode *dp; - if (inumber < UFS_ROOTINO || inumber > maxino) + if (inumber < UFS_ROOTINO || inumber >= maxino) errx(EEXIT, "bad inode number %ju to ginode", (uintmax_t)inumber); ip->i_number = inumber; @@ -473,14 +474,15 @@ ginode(ino_t inumber, struct inode *ip) } ip->i_dp = (union dinode *) &ip->i_bp->b_un.b_dinode2[inumber - ip->i_bp->b_index]; - if (ffs_verify_dinode_ckhash(&sblock, (struct ufs2_dinode *)ip->i_dp)) { + dp = (struct ufs2_dinode *)ip->i_dp; + /* Do not check hash of inodes being created */ + if (dp->di_mode != 0 && ffs_verify_dinode_ckhash(&sblock, dp)) { pwarn("INODE CHECK-HASH FAILED"); prtinode(ip); if (preen || reply("FIX") != 0) { if (preen) printf(" (FIXED)\n"); - ffs_update_dinode_ckhash(&sblock, - (struct ufs2_dinode *)ip->i_dp); + ffs_update_dinode_ckhash(&sblock, dp); inodirty(ip); } } @@ -1292,7 +1294,7 @@ findino(struct inodesc *idesc) if (dirp->d_ino == 0) return (KEEPON); if (strcmp(dirp->d_name, idesc->id_name) == 0 && - dirp->d_ino >= UFS_ROOTINO && dirp->d_ino <= maxino) { + dirp->d_ino >= UFS_ROOTINO && dirp->d_ino < maxino) { idesc->id_parent = dirp->d_ino; return (STOP|FOUND); } @@ -1322,7 +1324,7 @@ prtinode(struct inode *ip) dp = ip->i_dp; printf(" I=%lu ", (u_long)ip->i_number); - if (ip->i_number < UFS_ROOTINO || ip->i_number > maxino) + if (ip->i_number < UFS_ROOTINO || ip->i_number >= maxino) return; printf(" OWNER="); if ((pw = getpwuid((int)DIP(dp, di_uid))) != NULL) diff --git a/sbin/fsck_ffs/pass2.c b/sbin/fsck_ffs/pass2.c index 8200209cc03e..48bf27a8b142 100644 --- a/sbin/fsck_ffs/pass2.c +++ b/sbin/fsck_ffs/pass2.c @@ -371,7 +371,7 @@ chk1: dirp->d_reclen = proto.d_reclen; } if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") == 0) { - if (dirp->d_ino > maxino) { + if (dirp->d_ino >= maxino) { direrror(idesc->id_number, "BAD INODE NUMBER FOR '..'"); /* * If we know parent set it now, otherwise let it @@ -471,7 +471,7 @@ chk2: } idesc->id_entryno++; n = 0; - if (dirp->d_ino > maxino) { + if (dirp->d_ino >= maxino) { fileerror(idesc->id_number, dirp->d_ino, "I OUT OF RANGE"); n = reply("REMOVE"); } else if (((dirp->d_ino == UFS_WINO && dirp->d_type != DT_WHT) ||