From owner-svn-src-all@freebsd.org Mon Mar 4 10:55:03 2019 Return-Path: Delivered-To: svn-src-all@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 2C363150C48C; Mon, 4 Mar 2019 10:55:03 +0000 (UTC) (envelope-from fsu@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id BF17393781; Mon, 4 Mar 2019 10:55:02 +0000 (UTC) (envelope-from fsu@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 994DD2F2A; Mon, 4 Mar 2019 10:55:02 +0000 (UTC) (envelope-from fsu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x24At2EU013203; Mon, 4 Mar 2019 10:55:02 GMT (envelope-from fsu@FreeBSD.org) Received: (from fsu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x24At19c013199; Mon, 4 Mar 2019 10:55:01 GMT (envelope-from fsu@FreeBSD.org) Message-Id: <201903041055.x24At19c013199@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: fsu set sender to fsu@FreeBSD.org using -f From: Fedor Uporov Date: Mon, 4 Mar 2019 10:55:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r344752 - head/sys/fs/ext2fs X-SVN-Group: head X-SVN-Commit-Author: fsu X-SVN-Commit-Paths: head/sys/fs/ext2fs X-SVN-Commit-Revision: 344752 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: BF17393781 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.98)[-0.981,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 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: Mon, 04 Mar 2019 10:55:03 -0000 Author: fsu Date: Mon Mar 4 10:55:01 2019 New Revision: 344752 URL: https://svnweb.freebsd.org/changeset/base/344752 Log: Add additional on-disk inode checks. Reviewed by: pfg MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D19323 Modified: head/sys/fs/ext2fs/ext2_csum.c head/sys/fs/ext2fs/ext2_inode_cnv.c head/sys/fs/ext2fs/ext2_vfsops.c head/sys/fs/ext2fs/ext2fs.h Modified: head/sys/fs/ext2fs/ext2_csum.c ============================================================================== --- head/sys/fs/ext2fs/ext2_csum.c Mon Mar 4 10:42:25 2019 (r344751) +++ head/sys/fs/ext2fs/ext2_csum.c Mon Mar 4 10:55:01 2019 (r344752) @@ -629,6 +629,8 @@ ext2_ei_csum_verify(struct inode *ip, struct ext2fs_di if (!memcmp(ei, &ei_zero, sizeof(struct ext2fs_dinode))) return (0); + printf("WARNING: Bad inode %ju csum - run fsck\n", ip->i_number); + return (EIO); } Modified: head/sys/fs/ext2fs/ext2_inode_cnv.c ============================================================================== --- head/sys/fs/ext2fs/ext2_inode_cnv.c Mon Mar 4 10:42:25 2019 (r344751) +++ head/sys/fs/ext2fs/ext2_inode_cnv.c Mon Mar 4 10:55:01 2019 (r344752) @@ -34,7 +34,6 @@ #include #include -#include #include #include #include @@ -92,8 +91,31 @@ ext2_print_inode(struct inode *in) int ext2_ei2i(struct ext2fs_dinode *ei, struct inode *ip) { + struct m_ext2fs *fs = ip->i_e2fs; + if ((ip->i_number < EXT2_FIRST_INO(fs) && ip->i_number != EXT2_ROOTINO) || + (ip->i_number < EXT2_ROOTINO) || + (ip->i_number > fs->e2fs->e2fs_icount)) { + printf("ext2fs: bad inode number %ju\n", ip->i_number); + return (EINVAL); + } + + if (ip->i_number == EXT2_ROOTINO && ei->e2di_nlink == 0) { + printf("ext2fs: root inode unallocated\n"); + return (EINVAL); + } ip->i_nlink = ei->e2di_nlink; + + /* Check extra inode size */ + if (EXT2_INODE_SIZE(fs) > E2FS_REV0_INODE_SIZE) { + if (E2FS_REV0_INODE_SIZE + ei->e2di_extra_isize > + EXT2_INODE_SIZE(fs) || (ei->e2di_extra_isize & 3)) { + printf("ext2fs: bad extra inode size %u, inode size=%u\n", + ei->e2di_extra_isize, EXT2_INODE_SIZE(fs)); + return (EINVAL); + } + } + /* * Godmar thinks - if the link count is zero, then the inode is * unused - according to ext2 standards. Ufs marks this fact by Modified: head/sys/fs/ext2fs/ext2_vfsops.c ============================================================================== --- head/sys/fs/ext2fs/ext2_vfsops.c Mon Mar 4 10:42:25 2019 (r344751) +++ head/sys/fs/ext2fs/ext2_vfsops.c Mon Mar 4 10:55:01 2019 (r344752) @@ -773,11 +773,18 @@ loop: MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp); return (error); } - ext2_ei2i((struct ext2fs_dinode *)((char *)bp->b_data + + + error = ext2_ei2i((struct ext2fs_dinode *)((char *)bp->b_data + EXT2_INODE_SIZE(fs) * ino_to_fsbo(fs, ip->i_number)), ip); + brelse(bp); VOP_UNLOCK(vp, 0); vrele(vp); + + if (error) { + MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp); + return (error); + } } return (0); } @@ -1208,8 +1215,6 @@ ext2_vget(struct mount *mp, ino_t ino, int flags, stru error = ext2_ei2i((struct ext2fs_dinode *)((char *)bp->b_data + EXT2_INODE_SIZE(fs) * ino_to_fsbo(fs, ino)), ip); if (error) { - printf("ext2fs: Bad inode %lu csum - run fsck\n", - (unsigned long)ino); brelse(bp); vput(vp); *vpp = NULL; Modified: head/sys/fs/ext2fs/ext2fs.h ============================================================================== --- head/sys/fs/ext2fs/ext2fs.h Mon Mar 4 10:42:25 2019 (r344751) +++ head/sys/fs/ext2fs/ext2fs.h Mon Mar 4 10:55:01 2019 (r344752) @@ -422,4 +422,11 @@ struct ext2_gd { EXT2F_INCOMPAT_64BIT) ? ((s)->e2fs_bsize / sizeof(struct ext2_gd)) : \ ((s)->e2fs_bsize / E2FS_REV0_GD_SIZE)) +/* + * Macro-instructions used to manage inodes + */ +#define EXT2_FIRST_INO(s) ((EXT2_SB(s)->e2fs->e2fs_rev == E2FS_REV0) ? \ + EXT2_FIRSTINO : \ + EXT2_SB(s)->e2fs->e2fs_first_ino) + #endif /* !_FS_EXT2FS_EXT2FS_H_ */