Module Name:    src
Committed By:   martin
Date:           Sun Feb  4 12:52:02 UTC 2018

Modified Files:
        src/sys/ufs/ffs [netbsd-8]: ffs_vfsops.c
        src/sys/ufs/ufs [netbsd-8]: ufs_inode.c

Log Message:
Pull up following revision(s) (requested by christos in ticket #523):
        sys/ufs/ffs/ffs_vfsops.c: revision 1.356
        sys/ufs/ufs/ufs_inode.c: revision 1.103
Make sure inode blocks and size are zero when VOP_INACTIVE()
finalises a now unlinked inode.
Counterpart of the check in ffs_newvnode().
Prevent use-after-free where genfs_node_destroy() would destroy
a lock residing in the just freed inode data.


To generate a diff of this commit:
cvs rdiff -u -r1.353 -r1.353.4.1 src/sys/ufs/ffs/ffs_vfsops.c
cvs rdiff -u -r1.101.2.1 -r1.101.2.2 src/sys/ufs/ufs/ufs_inode.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vfsops.c
diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.353 src/sys/ufs/ffs/ffs_vfsops.c:1.353.4.1
--- src/sys/ufs/ffs/ffs_vfsops.c:1.353	Mon Apr 17 08:32:01 2017
+++ src/sys/ufs/ffs/ffs_vfsops.c	Sun Feb  4 12:52:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vfsops.c,v 1.353 2017/04/17 08:32:01 hannken Exp $	*/
+/*	$NetBSD: ffs_vfsops.c,v 1.353.4.1 2018/02/04 12:52:02 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.353 2017/04/17 08:32:01 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.353.4.1 2018/02/04 12:52:02 martin Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -2030,14 +2030,14 @@ ffs_deinit_vnode(struct ufsmount *ump, s
 {
 	struct inode *ip = VTOI(vp);
 
+	genfs_node_destroy(vp);
+	vp->v_data = NULL;
+
 	if (ump->um_fstype == UFS1)
 		pool_cache_put(ffs_dinode1_cache, ip->i_din.ffs1_din);
 	else
 		pool_cache_put(ffs_dinode2_cache, ip->i_din.ffs2_din);
 	pool_cache_put(ffs_inode_cache, ip);
-
-	genfs_node_destroy(vp);
-	vp->v_data = NULL;
 }
 
 /*

Index: src/sys/ufs/ufs/ufs_inode.c
diff -u src/sys/ufs/ufs/ufs_inode.c:1.101.2.1 src/sys/ufs/ufs/ufs_inode.c:1.101.2.2
--- src/sys/ufs/ufs/ufs_inode.c:1.101.2.1	Thu Nov  2 21:29:53 2017
+++ src/sys/ufs/ufs/ufs_inode.c	Sun Feb  4 12:52:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_inode.c,v 1.101.2.1 2017/11/02 21:29:53 snj Exp $	*/
+/*	$NetBSD: ufs_inode.c,v 1.101.2.2 2018/02/04 12:52:02 martin Exp $	*/
 
 /*
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_inode.c,v 1.101.2.1 2017/11/02 21:29:53 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_inode.c,v 1.101.2.2 2018/02/04 12:52:02 martin Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -149,6 +149,15 @@ out:
 	 */
 	*ap->a_recycle = (ip->i_mode == 0);
 
+	if (ip->i_mode == 0 && (DIP(ip, size) != 0 || DIP(ip, blocks) != 0)) {
+		printf("%s: unlinked ino %" PRId64 " on \"%s\" has"
+		    " non zero size %" PRIx64 " or blocks %" PRIx64
+		    " with allerror %d\n",
+		    __func__, ip->i_number, mp->mnt_stat.f_mntonname,
+		    DIP(ip, size), DIP(ip, blocks), allerror);
+		panic("%s: dirty filesystem?", __func__);
+	}
+
 	return (allerror);
 }
 

Reply via email to