Re: [PATCH 3/3] qemuDomainCreateDevice: Be more careful about device path

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

 



On Wed, Jan 04, 2017 at 03:13:57PM +0100, Michal Privoznik wrote:
Again, not something that I'd hit, but there is a chance in
theory that this might bite us. Currently the way we decide
whether or not to create /dev entry for a device is by marching
first four characters of path with "/dev". This might be not
enough. Just imagine somebody has a disk image stored under
"/devil/path/to/disk". We ought to be matching against "/dev/".


I haven't checked it, but I believe this code only gets absolure
canonicalized paths, otherwise you could theoretically still have
/dev/../some/other/path.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
src/qemu/qemu_domain.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 40bed1b396..3ecc30c7b5 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6917,6 +6917,8 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev,
}


+#define DEVPREFIX "/dev/"
+
#if defined(__linux__)
static int
qemuDomainCreateDevice(const char *device,
@@ -6927,7 +6929,7 @@ qemuDomainCreateDevice(const char *device,
    struct stat sb;
    int ret = -1;

-    if (!STRPREFIX(device, "/dev")) {
+    if (!STRPREFIX(device, DEVPREFIX)) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("invalid device: %s"),
                       device);
@@ -6935,7 +6937,7 @@ qemuDomainCreateDevice(const char *device,
    }

    if (virAsprintf(&devicePath, "%s/%s",
-                    path, device + 4) < 0)
+                    path, device + strlen(DEVPREFIX)) < 0)

And we'll get rid of the double path separator as a bonus.

ACK

Attachment: signature.asc
Description: Digital signature

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

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux