Module Name:    src
Committed By:   riastradh
Date:           Tue Sep 25 16:11:42 UTC 2012

Modified Files:
        src/sys/fs/tmpfs: tmpfs_rename.c

Log Message:
Check tmpfs_rmdired_p after tmpfs_vnode_get when walking up the tree.

tmpfs_vnode_get drops all locks except possibly the reclaiming bit
lock to keep the tmpfs node from being reclaimed while we're still
interested in it.  Consequently, it does not keep the directory's
existence invariant, so we must check that after tmpfs_vnode_get.

Fixes PR kern/46990.  Tested by Wolfgang Stukenbrock.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/fs/tmpfs/tmpfs_rename.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/fs/tmpfs/tmpfs_rename.c
diff -u src/sys/fs/tmpfs/tmpfs_rename.c:1.2 src/sys/fs/tmpfs/tmpfs_rename.c:1.3
--- src/sys/fs/tmpfs/tmpfs_rename.c:1.2	Wed May  9 22:46:25 2012
+++ src/sys/fs/tmpfs/tmpfs_rename.c	Tue Sep 25 16:11:42 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: tmpfs_rename.c,v 1.2 2012/05/09 22:46:25 riastradh Exp $	*/
+/*	$NetBSD: tmpfs_rename.c,v 1.3 2012/09/25 16:11:42 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_rename.c,v 1.2 2012/05/09 22:46:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_rename.c,v 1.3 2012/09/25 16:11:42 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/errno.h>
@@ -551,6 +551,17 @@ tmpfs_gro_genealogy(struct mount *mp, ka
 		error = tmpfs_vnode_get(mp, dnode, &vp);
 		if (error)
 			return error;
+
+		/*
+		 * tmpfs_vnode_get only guarantees that dnode will not
+		 * be freed while we get a vnode for it.  It does not
+		 * preserve any other invariants, so we must check
+		 * whether the parent has been removed in the meantime.
+		 */
+		if (tmpfs_rmdired_p(vp)) {
+			vput(vp);
+			return ENOENT;
+		}
 	}
 }
 

Reply via email to