[libvirt] [PATCH 4/4] qemu: Call chmod() after mknod()

Andrea Bolognani posted 4 patches 157 weeks ago

[libvirt] [PATCH 4/4] qemu: Call chmod() after mknod()

Posted by Andrea Bolognani 157 weeks ago
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.
---
 src/qemu/qemu_domain.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index f62bf8f..3adec5c 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -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) {
-- 
2.7.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 4/4] qemu: Call chmod() after mknod()

Posted by Michal Privoznik 157 weeks ago
On 02/14/2017 04:33 PM, Andrea Bolognani wrote:
> 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.
> ---
>  src/qemu/qemu_domain.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)

ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list