Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 Nov 2016 14:00:50 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r308887 - head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
Message-ID:  <201611201400.uAKE0o8M093028@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Sun Nov 20 14:00:50 2016
New Revision: 308887
URL: https://svnweb.freebsd.org/changeset/base/308887

Log:
  fix unsafe modification of zfs_vnodeops when DIAGNOSTIC is enabled
  
  The idea was to avoid a false assertion in zfs_lock, but it was
  implemented very dangerously and incorrectly.
  
  Reported by:	pho
  Tested by:	pho
  MFC after:	1 week

Modified:
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
==============================================================================
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c	Sun Nov 20 13:44:27 2016	(r308886)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c	Sun Nov 20 14:00:50 2016	(r308887)
@@ -5963,6 +5963,10 @@ zfs_vptocnp(struct vop_vptocnp_args *ap)
 }
 
 #ifdef DIAGNOSTIC
+#define CHECK_LOR	((flags & LK_NOWAIT) == 0 && vp->v_mount != NULL && \
+    (vp->v_iflag & VI_DOOMED) == 0 && vp->v_data != NULL && \
+    (zp->z_pflags & ZFS_XATTR) == 0)
+
 static int
 zfs_lock(ap)
 	struct vop_lock1_args /* {
@@ -5979,22 +5983,21 @@ zfs_lock(ap)
 	int err;
 
 	vp = ap->a_vp;
+	zp = vp->v_data;
 	flags = ap->a_flags;
-	if ((flags & LK_INTERLOCK) == 0 && (flags & LK_NOWAIT) == 0 &&
-	    (vp->v_iflag & VI_DOOMED) == 0 && (zp = vp->v_data) != NULL &&
-	    (zp->z_pflags & ZFS_XATTR) == 0) {
+	if ((flags & LK_INTERLOCK) == 0 && CHECK_LOR) {
 		zfsvfs = zp->z_zfsvfs;
 		VERIFY(!RRM_LOCK_HELD(&zfsvfs->z_teardown_lock));
 	}
 	err = vop_stdlock(ap);
-	if ((flags & LK_INTERLOCK) != 0 && (flags & LK_NOWAIT) == 0 &&
-	    (vp->v_iflag & VI_DOOMED) == 0 && (zp = vp->v_data) != NULL &&
-	    (zp->z_pflags & ZFS_XATTR) == 0) {
+	if ((flags & LK_INTERLOCK) != 0 && CHECK_LOR) {
 		zfsvfs = zp->z_zfsvfs;
 		VERIFY(!RRM_LOCK_HELD(&zfsvfs->z_teardown_lock));
 	}
 	return (err);
 }
+
+#undef CHECK_LOR
 #endif
 
 struct vop_vector zfs_vnodeops;

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c
==============================================================================
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c	Sun Nov 20 13:44:27 2016	(r308886)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c	Sun Nov 20 14:00:50 2016	(r308887)
@@ -727,14 +727,7 @@ zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_bu
 	/*
 	 * Acquire vnode lock before making it available to the world.
 	 */
-#ifdef DIAGNOSTIC
-	vop_lock1_t *orig_lock = vp->v_op->vop_lock1;
-	vp->v_op->vop_lock1 = vop_stdlock;
 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
-	vp->v_op->vop_lock1 = orig_lock;
-#else
-	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
-#endif
 	VN_LOCK_AREC(vp);
 	if (vp->v_type != VFIFO)
 		VN_LOCK_ASHARE(vp);



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