Date: Mon, 18 Mar 2019 12:31:08 +0000 (UTC) From: Fedor Uporov <fsu@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r345271 - stable/12/sys/fs/ext2fs Message-ID: <201903181231.x2ICV8xh000441@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: fsu Date: Mon Mar 18 12:31:07 2019 New Revision: 345271 URL: https://svnweb.freebsd.org/changeset/base/345271 Log: MFC: r344752: Add additional on-disk inode checks. Reviewed by: pfg Differential Revision: https://reviews.freebsd.org/D19323 Modified: stable/12/sys/fs/ext2fs/ext2_csum.c stable/12/sys/fs/ext2fs/ext2_inode_cnv.c stable/12/sys/fs/ext2fs/ext2_vfsops.c stable/12/sys/fs/ext2fs/ext2fs.h Modified: stable/12/sys/fs/ext2fs/ext2_csum.c ============================================================================== --- stable/12/sys/fs/ext2fs/ext2_csum.c Mon Mar 18 12:26:25 2019 (r345270) +++ stable/12/sys/fs/ext2fs/ext2_csum.c Mon Mar 18 12:31:07 2019 (r345271) @@ -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: stable/12/sys/fs/ext2fs/ext2_inode_cnv.c ============================================================================== --- stable/12/sys/fs/ext2fs/ext2_inode_cnv.c Mon Mar 18 12:26:25 2019 (r345270) +++ stable/12/sys/fs/ext2fs/ext2_inode_cnv.c Mon Mar 18 12:31:07 2019 (r345271) @@ -34,7 +34,6 @@ #include <sys/stat.h> #include <sys/vnode.h> -#include <fs/ext2fs/ext2fs.h> #include <fs/ext2fs/fs.h> #include <fs/ext2fs/inode.h> #include <fs/ext2fs/ext2fs.h> @@ -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: stable/12/sys/fs/ext2fs/ext2_vfsops.c ============================================================================== --- stable/12/sys/fs/ext2fs/ext2_vfsops.c Mon Mar 18 12:26:25 2019 (r345270) +++ stable/12/sys/fs/ext2fs/ext2_vfsops.c Mon Mar 18 12:31:07 2019 (r345271) @@ -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: stable/12/sys/fs/ext2fs/ext2fs.h ============================================================================== --- stable/12/sys/fs/ext2fs/ext2fs.h Mon Mar 18 12:26:25 2019 (r345270) +++ stable/12/sys/fs/ext2fs/ext2fs.h Mon Mar 18 12:31:07 2019 (r345271) @@ -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_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201903181231.x2ICV8xh000441>