[PATCH] qemu_shim: Require absolute path for root directory

Michal Privoznik posted 1 patch 1 year, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/b3f0f4120f04019f5f6f881cf7aa1f5f51a1303d.1679491375.git.mprivozn@redhat.com
src/qemu/qemu_shim.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
[PATCH] qemu_shim: Require absolute path for root directory
Posted by Michal Privoznik 1 year, 1 month ago
The virConnectOpen(), well virConnectOpenInternal() reports an
error if embed root is not an absolute path. This is a fair
requirement, but our qemu_shim doesn't check this requirement and
instead mkdir()-s passed path only to fail later on, leaving the
empty directory behind:

  $ ls -d asd
  ls: cannot access 'asd': No such file or directory

  $ virt-qemu-run -r asd whatever.xml
  virt-qemu-run: cannot open qemu:///embed?root=asd: unsupported configuration: root path must be absolute

  $ ls -d asd
  asd

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_shim.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_shim.c b/src/qemu/qemu_shim.c
index 7b58583074..33a6aa7d94 100644
--- a/src/qemu/qemu_shim.c
+++ b/src/qemu/qemu_shim.c
@@ -209,10 +209,18 @@ int main(int argc, char **argv)
         }
         tmproot = true;
 
-    } else if (g_mkdir_with_parents(root, 0755) < 0) {
-        g_printerr("%s: cannot create dir: %s\n",
-                   argv[0], g_strerror(errno));
-        goto cleanup;
+    } else {
+        if (!g_path_is_absolute(root)) {
+            g_printerr("%s: the root directory must be an absolute path\n",
+                       argv[0]);
+            goto cleanup;
+        }
+
+        if (g_mkdir_with_parents(root, 0755) < 0) {
+            g_printerr("%s: cannot create dir: %s\n",
+                       argv[0], g_strerror(errno));
+            goto cleanup;
+        }
     }
 
     if (chmod(root, 0755) < 0) {
-- 
2.39.2
Re: [PATCH] qemu_shim: Require absolute path for root directory
Posted by Kristina Hanicova 1 year, 1 month ago
On Wed, Mar 22, 2023 at 2:30 PM Michal Privoznik <mprivozn@redhat.com>
wrote:

> The virConnectOpen(), well virConnectOpenInternal() reports an
> error if embed root is not an absolute path. This is a fair
> requirement, but our qemu_shim doesn't check this requirement and
> instead mkdir()-s passed path only to fail later on, leaving the
> empty directory behind:

I would reword the commit message a bit:
This is a fair requirement, but our qemu_shim doesn't check this
requirement and passes the path to mkdir(), only to fail later on,
leaving the empty directory behind:


>
>   $ ls -d asd
>   ls: cannot access 'asd': No such file or directory
>
>   $ virt-qemu-run -r asd whatever.xml
>   virt-qemu-run: cannot open qemu:///embed?root=asd: unsupported
> configuration: root path must be absolute
>
>   $ ls -d asd
>   asd
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_shim.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
>


Reviewed-by: Kristina Hanicova <khanicov@redhat.com>

Kristina