From nobody Thu Dec 30 06:15:19 2021 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 7AE731920786; Thu, 30 Dec 2021 06:15:20 +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 4JPdL00Ndsz3mDs; Thu, 30 Dec 2021 06:15:20 +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 C68CD13D93; Thu, 30 Dec 2021 06:15:19 +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 1BU6FJ3K064979; Thu, 30 Dec 2021 06:15:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BU6FJi2064978; Thu, 30 Dec 2021 06:15:19 GMT (envelope-from git) Date: Thu, 30 Dec 2021 06:15:19 GMT Message-Id: <202112300615.1BU6FJi2064978@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Fedor Uporov Subject: git: ced217282230 - main - Add more accurate check for root inode 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: fsu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ced21728223016429242d1f7cd5e8a160c8a88cb Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640844920; 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=Zm9IbqTo707jonUTvKbpc2/7vFUL5ZPS55W2KhiKYGs=; b=D9IzZFELjI8UxLBa/BBWJ7+dpuIsBUcLPQd30sd4EL/mqGVuhvzYxfSCSCQRYC9+1ezOcR LvPwcrWL5DL29ex5WzARJJyY/x08oaQtcrBSUyLfkMW9CTRAvoW3Xz9N/YP6qRiI0cnLon oUx+IxrRzbjdXcZ7rYXNB8BNrzj2KN0tNLqmcvm/aVGb5KuZmlZxs2wBATXgDuzvQmOIkh 3I+3WsDNcgRMqgQo65oybzkYmQqcvgqWhGt60wyKpHiswfr80cNQv6F69zixhpJsnn64N8 5DZOsZY8xp/DA0zWqIznG+k0Q4clAAzhU9v0lDQFFulCZ/9ANx5DLjpo28M1qQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640844920; a=rsa-sha256; cv=none; b=LrTZ3uMs1gonq7s11SKk2SEahP/eqzD4RiuaMztFRXEO7BO8aVDR/MBaifNaF5cRHITTdf +95Uwf5h9I0OdwfD0Y0CI6guUYwNg/k9Bj7nn+qa91vOY+895Zsa7PgsvlvuhlSonofpd+ AAHUozb6Q2we1yGgpX38MjU5M633tWrYKNpnZ4BZ6bPIDoXn54eLeWqM0QTNQ6hHSJKDkj 9OSge+JvNOciO24RMG/Wh+VPyB+WTBKiazPzOzJNo5bNlLVzMHcp0vGC+6IcCJ+yMaFiD1 9sPNvBSDTmpfz/SB0Thsx608LffCShgqce8qTJTyiz0sqfh7UbdiE9PufR4C0g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by fsu: URL: https://cgit.FreeBSD.org/src/commit/?id=ced21728223016429242d1f7cd5e8a160c8a88cb commit ced21728223016429242d1f7cd5e8a160c8a88cb Author: Fedor Uporov AuthorDate: 2021-12-24 14:11:25 +0000 Commit: Fedor Uporov CommitDate: 2021-12-30 06:14:45 +0000 Add more accurate check for root inode Check that root inode has links and is directory. PR: 259105 Reported by: Robert Morris MFC after: 2 weeks --- sys/fs/ext2fs/ext2_inode_cnv.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/sys/fs/ext2fs/ext2_inode_cnv.c b/sys/fs/ext2fs/ext2_inode_cnv.c index 181ea3e04622..445000c509db 100644 --- a/sys/fs/ext2fs/ext2_inode_cnv.c +++ b/sys/fs/ext2fs/ext2_inode_cnv.c @@ -157,9 +157,17 @@ ext2_ei2i(struct ext2fs_dinode *ei, struct inode *ip) return (EINVAL); } + /* + * Godmar thinks - if the link count is zero, then the inode is + * unused - according to ext2 standards. Ufs marks this fact by + * setting i_mode to zero - why ? I can see that this might lead to + * problems in an undelete. + */ ip->i_nlink = le16toh(ei->e2di_nlink); - if (ip->i_number == EXT2_ROOTINO && ip->i_nlink == 0) { - SDT_PROBE2(ext2fs, , trace, inode_cnv, 1, "root inode unallocated"); + ip->i_mode = ip->i_nlink ? le16toh(ei->e2di_mode) : 0; + if (ip->i_number == EXT2_ROOTINO && + (ip->i_nlink < 2 || !S_ISDIR(ip->i_mode))) { + SDT_PROBE2(ext2fs, , trace, inode_cnv, 1, "root inode invalid"); return (EINVAL); } @@ -174,13 +182,6 @@ ext2_ei2i(struct ext2fs_dinode *ei, struct inode *ip) } } - /* - * Godmar thinks - if the link count is zero, then the inode is - * unused - according to ext2 standards. Ufs marks this fact by - * setting i_mode to zero - why ? I can see that this might lead to - * problems in an undelete. - */ - ip->i_mode = ip->i_nlink ? le16toh(ei->e2di_mode) : 0; ip->i_size = le32toh(ei->e2di_size); if (S_ISREG(ip->i_mode)) ip->i_size |= (uint64_t)le32toh(ei->e2di_size_high) << 32;