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

Martin Kletzander mkletzan at redhat.com
Wed Jan 4 14:32:05 UTC 2017


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 at redhat.com>
>---
> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20170104/a6c8ffd5/attachment-0001.sig>


More information about the libvir-list mailing list