]> Zhao Yanbai Git Server - minix.git/commitdiff
VFS: fix TOCTOU bug in sync
authorThomas Veerman <thomas@minix3.org>
Wed, 14 Nov 2012 13:24:53 +0000 (13:24 +0000)
committerThomas Veerman <thomas@minix3.org>
Wed, 14 Nov 2012 13:24:53 +0000 (13:24 +0000)
servers/vfs/misc.c

index f32ec88e2ad11825035dc392f6448bb25be5a711..cd7319f466e5d0349460408e29a3124a4f2a25e6 100644 (file)
@@ -299,13 +299,13 @@ int do_sync()
   int r = OK;
 
   for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; ++vmp) {
+       if ((r = lock_vmnt(vmp, VMNT_EXCL)) != OK)
+               break;
        if (vmp->m_dev != NO_DEV && vmp->m_fs_e != NONE &&
                 vmp->m_root_node != NULL) {
-               if ((r = lock_vmnt(vmp, VMNT_EXCL)) != OK)
-                       break;
                req_sync(vmp->m_fs_e);
-               unlock_vmnt(vmp);
        }
+       unlock_vmnt(vmp);
   }
 
   return(r);