Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 15 Dec 2018 18:35:47 +0000 (UTC)
From:      Kirk McKusick <mckusick@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r342133 - head/sys/ufs/ffs
Message-ID:  <201812151835.wBFIZlDU081291@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mckusick
Date: Sat Dec 15 18:35:46 2018
New Revision: 342133
URL: https://svnweb.freebsd.org/changeset/base/342133

Log:
  Reorder ffs_verify_dinode_ckhash() so that it checks the inode check-hash
  before copying in the inode so that the mode and link-count are not set
  if the check-hash fails. This change ensures that the vnode will be properly
  unwound and recycled rather than being held in the cache.
  
  Initialize the file mode is zero so that if the loading of the inode
  fails (for example because of a check-hash failure), the vnode will be
  properly unwound and recycled.
  
  Reported by:  Gary Jennejohn (gj)
  Sponsored by: Netflix

Modified:
  head/sys/ufs/ffs/ffs_subr.c
  head/sys/ufs/ffs/ffs_vfsops.c

Modified: head/sys/ufs/ffs/ffs_subr.c
==============================================================================
--- head/sys/ufs/ffs/ffs_subr.c	Sat Dec 15 18:11:41 2018	(r342132)
+++ head/sys/ufs/ffs/ffs_subr.c	Sat Dec 15 18:35:46 2018	(r342133)
@@ -135,8 +135,14 @@ ffs_load_inode(struct buf *bp, struct inode *ip, struc
 		ip->i_gid = dip1->di_gid;
 		return (0);
 	}
+	dip2 = ((struct ufs2_dinode *)bp->b_data + ino_to_fsbo(fs, ino));
+	if ((error = ffs_verify_dinode_ckhash(fs, dip2)) != 0) {
+		printf("%s: inode %jd: check-hash failed\n", fs->fs_fsmnt,
+		    (intmax_t)ino);
+		return (error);
+	}
+	*ip->i_din2 = *dip2;
 	dip2 = ip->i_din2;
-	*dip2 = *((struct ufs2_dinode *)bp->b_data + ino_to_fsbo(fs, ino));
 	ip->i_mode = dip2->di_mode;
 	ip->i_nlink = dip2->di_nlink;
 	ip->i_effnlink = dip2->di_nlink;
@@ -145,9 +151,7 @@ ffs_load_inode(struct buf *bp, struct inode *ip, struc
 	ip->i_gen = dip2->di_gen;
 	ip->i_uid = dip2->di_uid;
 	ip->i_gid = dip2->di_gid;
-	if ((error = ffs_verify_dinode_ckhash(fs, dip2)) != 0)
-		printf("Inode %jd: check-hash failed\n", (intmax_t)ino);
-	return (error);
+	return (0);
 }
 #endif /* _KERNEL */
 

Modified: head/sys/ufs/ffs/ffs_vfsops.c
==============================================================================
--- head/sys/ufs/ffs/ffs_vfsops.c	Sat Dec 15 18:11:41 2018	(r342132)
+++ head/sys/ufs/ffs/ffs_vfsops.c	Sat Dec 15 18:35:46 2018	(r342133)
@@ -1692,6 +1692,7 @@ ffs_vgetf(mp, ino, flags, vpp, ffs_flags)
 	ip->i_ea_refs = 0;
 	ip->i_nextclustercg = -1;
 	ip->i_flag = fs->fs_magic == FS_UFS1_MAGIC ? 0 : IN_UFS2;
+	ip->i_mode = 0; /* ensure error cases below throw away vnode */
 #ifdef QUOTA
 	{
 		int i;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201812151835.wBFIZlDU081291>