]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
fsdev-proxy-helper: avoid TOC/TOU race
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 27 Nov 2015 11:43:05 +0000 (12:43 +0100)
committerGreg Kurz <gkurz@linux.vnet.ibm.com>
Mon, 30 Nov 2015 11:31:53 +0000 (12:31 +0100)
There is a minor time of check/time of use race between statfs and chroot.
It can be fixed easily by stat-ing the root after it has been changed.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
fsdev/virtfs-proxy-helper.c

index 9097d15c989ca243a8a0c51ff61ae1f47ecc523b..ad1da0d6f5301c9e35fe2a807f3923561122f4b8 100644 (file)
@@ -1128,10 +1128,19 @@ int main(int argc, char **argv)
         }
     }
 
+    if (chdir("/") < 0) {
+        do_perror("chdir");
+        goto error;
+    }
+    if (chroot(rpath) < 0) {
+        do_perror("chroot");
+        goto error;
+    }
+
     get_version = false;
 #ifdef FS_IOC_GETVERSION
     /* check whether underlying FS support IOC_GETVERSION */
-    retval = statfs(rpath, &st_fs);
+    retval = statfs("/", &st_fs);
     if (!retval) {
         switch (st_fs.f_type) {
         case EXT2_SUPER_MAGIC:
@@ -1144,16 +1153,7 @@ int main(int argc, char **argv)
     }
 #endif
 
-    if (chdir("/") < 0) {
-        do_perror("chdir");
-        goto error;
-    }
-    if (chroot(rpath) < 0) {
-        do_perror("chroot");
-        goto error;
-    }
     umask(0);
-
     if (init_capabilities() < 0) {
         goto error;
     }