Date: Mon, 4 Mar 2019 10:55:01 +0000 (UTC) From: Fedor Uporov <fsu@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r344752 - head/sys/fs/ext2fs Message-ID: <201903041055.x24At19c013199@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <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: 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_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201903041055.x24At19c013199>