Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/fs/tmpfs Fix a race where thread1 runs VOP_REMOVE() and ...



details:   https://anonhg.NetBSD.org/src/rev/44c133de6351
branches:  trunk
changeset: 792465:44c133de6351
user:      hannken <hannken%NetBSD.org@localhost>
date:      Sat Jan 04 12:36:49 2014 +0000

description:
Fix a race where thread1 runs VOP_REMOVE() and gets preempted in
tmpfs_reclaim() before the call to tmpfs_free_node().  Thread2
runs VFS_FHTOVP() and gets a new vnode attached to the node thread1
is about to destroy.

Change tmpfs_fhtovp() to check the generation number after
tmpfs_vnode_get() succeeded.

diffstat:

 sys/fs/tmpfs/tmpfs_vfsops.c |  27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diffs (60 lines):

diff -r 23b7d35b6208 -r 44c133de6351 sys/fs/tmpfs/tmpfs_vfsops.c
--- a/sys/fs/tmpfs/tmpfs_vfsops.c       Sat Jan 04 08:58:51 2014 +0000
+++ b/sys/fs/tmpfs/tmpfs_vfsops.c       Sat Jan 04 12:36:49 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tmpfs_vfsops.c,v 1.55 2013/11/23 16:35:32 rmind Exp $  */
+/*     $NetBSD: tmpfs_vfsops.c,v 1.56 2014/01/04 12:36:49 hannken Exp $        */
 
 /*
  * Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.55 2013/11/23 16:35:32 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.56 2014/01/04 12:36:49 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -282,6 +282,7 @@
        tmpfs_mount_t *tmp = VFS_TO_TMPFS(mp);
        tmpfs_node_t *node;
        tmpfs_fid_t tfh;
+       int error;
 
        if (fhp->fid_len != sizeof(tmpfs_fid_t)) {
                return EINVAL;
@@ -290,19 +291,25 @@
 
        mutex_enter(&tmp->tm_lock);
        LIST_FOREACH(node, &tmp->tm_nodes, tn_entries) {
-               if (node->tn_id != tfh.tf_id) {
-                       continue;
+               if (node->tn_id == tfh.tf_id) {
+                       mutex_enter(&node->tn_vlock);
+                       break;
                }
-               if (TMPFS_NODE_GEN(node) != tfh.tf_gen) {
-                       continue;
-               }
-               mutex_enter(&node->tn_vlock);
-               break;
        }
        mutex_exit(&tmp->tm_lock);
 
+       if (node == NULL)
+               return ESTALE;
        /* Will release the tn_vlock. */
-       return node ? tmpfs_vnode_get(mp, node, vpp) : ESTALE;
+       if ((error = tmpfs_vnode_get(mp, node, vpp)) != 0)
+               return error;
+       if (TMPFS_NODE_GEN(node) != tfh.tf_gen) {
+               vput(*vpp);
+               *vpp = NULL;
+               return ESTALE;
+       }
+
+       return 0;
 }
 
 static int



Home | Main Index | Thread Index | Old Index