]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Call chmod() after mknod()
authorAndrea Bolognani <abologna@redhat.com>
Tue, 14 Feb 2017 14:46:23 +0000 (15:46 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Tue, 14 Feb 2017 18:23:05 +0000 (19:23 +0100)
mknod() is affected my the current umask, so we're not
guaranteed the newly-created device node will have the
right permissions.

Call chmod(), which is not affected by the current umask,
immediately afterwards to solve the issue.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1421036

src/qemu/qemu_domain.c

index f62bf8f1d8db54552f75ae295889ef3fe1a49eeb..3adec5c14000f4361dd0a861bb3756c6f21476ab 100644 (file)
@@ -7152,6 +7152,16 @@ qemuDomainCreateDeviceRecursive(const char *device,
             }
             goto cleanup;
         }
+
+        /* Set the file permissions again: mknod() is affected by the
+         * current umask, and as such might not have set them correctly */
+        if (create &&
+            chmod(devicePath, sb.st_mode) < 0) {
+            virReportSystemError(errno,
+                                 _("Failed to set permissions for device %s"),
+                                 devicePath);
+            goto cleanup;
+        }
     }
 
     if (!create) {