[libvirt] [PATCH] conf: storage: also sanitize source dir

Ján Tomko posted 1 patch 6 years, 7 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/b6d61c90c45764d75aa62a4ecd4912d56e729eeb.1561463073.git.jtomko@redhat.com
src/conf/storage_conf.c                       |  5 ++++-
.../storagepoolxml2xmlin/pool-netfs-slash.xml | 20 +++++++++++++++++++
.../pool-netfs-slash.xml                      | 20 +++++++++++++++++++
tests/storagepoolxml2xmltest.c                |  1 +
4 files changed, 45 insertions(+), 1 deletion(-)
create mode 100644 tests/storagepoolxml2xmlin/pool-netfs-slash.xml
create mode 100644 tests/storagepoolxml2xmlout/pool-netfs-slash.xml
[libvirt] [PATCH] conf: storage: also sanitize source dir
Posted by Ján Tomko 6 years, 7 months ago
Commit a7fb2258 added sanitization of storage pool target paths,
however source dir paths were left unsanitized.

A netfs pool with:
<source>
  <host name='10.20.30.40'/>
  <dir path='/nfs/'/>
</source>
will not be correctly detected as mounted by
virStorageBackendFileSystemIsMounted, because it shows up in the
mount list without the trailing slash.

Sanitize the source dir as well.

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
---
 src/conf/storage_conf.c                       |  5 ++++-
 .../storagepoolxml2xmlin/pool-netfs-slash.xml | 20 +++++++++++++++++++
 .../pool-netfs-slash.xml                      | 20 +++++++++++++++++++
 tests/storagepoolxml2xmltest.c                |  1 +
 4 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 tests/storagepoolxml2xmlin/pool-netfs-slash.xml
 create mode 100644 tests/storagepoolxml2xmlout/pool-netfs-slash.xml

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 29988c36c4..397bd66870 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -533,6 +533,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
     VIR_AUTOFREE(char *) port = NULL;
     VIR_AUTOFREE(char *) ver = NULL;
     VIR_AUTOFREE(xmlNodePtr *) nodeset = NULL;
+    VIR_AUTOFREE(char *) sourcedir = NULL;
 
     relnode = ctxt->node;
     ctxt->node = node;
@@ -630,7 +631,9 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
 
     }
 
-    source->dir = virXPathString("string(./dir/@path)", ctxt);
+    sourcedir = virXPathString("string(./dir/@path)", ctxt);
+    if (sourcedir)
+        source->dir = virFileSanitizePath(sourcedir);
     /* In gluster, a missing dir defaults to "/" */
     if (!source->dir && pool_type == VIR_STORAGE_POOL_GLUSTER &&
         VIR_STRDUP(source->dir, "/") < 0)
diff --git a/tests/storagepoolxml2xmlin/pool-netfs-slash.xml b/tests/storagepoolxml2xmlin/pool-netfs-slash.xml
new file mode 100644
index 0000000000..63f5d401ba
--- /dev/null
+++ b/tests/storagepoolxml2xmlin/pool-netfs-slash.xml
@@ -0,0 +1,20 @@
+<pool type='netfs'>
+  <name>nfsimages</name>
+  <uuid>7641d5a8-af11-f730-a34e-0a7dfcede71f</uuid>
+  <capacity>0</capacity>
+  <allocation>0</allocation>
+  <available>0</available>
+  <source>
+    <host name='localhost'/>
+    <dir path='/var/lib/libvirt/images/'/>
+    <format type='nfs'/>
+  </source>
+  <target>
+    <path>/mnt</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-netfs-slash.xml b/tests/storagepoolxml2xmlout/pool-netfs-slash.xml
new file mode 100644
index 0000000000..8a5f272137
--- /dev/null
+++ b/tests/storagepoolxml2xmlout/pool-netfs-slash.xml
@@ -0,0 +1,20 @@
+<pool type='netfs'>
+  <name>nfsimages</name>
+  <uuid>7641d5a8-af11-f730-a34e-0a7dfcede71f</uuid>
+  <capacity unit='bytes'>0</capacity>
+  <allocation unit='bytes'>0</allocation>
+  <available unit='bytes'>0</available>
+  <source>
+    <host name='localhost'/>
+    <dir path='/var/lib/libvirt/images'/>
+    <format type='nfs'/>
+  </source>
+  <target>
+    <path>/mnt</path>
+    <permissions>
+      <mode>0700</mode>
+      <owner>0</owner>
+      <group>0</group>
+    </permissions>
+  </target>
+</pool>
diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c
index b6f4cb4226..96dd04faec 100644
--- a/tests/storagepoolxml2xmltest.c
+++ b/tests/storagepoolxml2xmltest.c
@@ -73,6 +73,7 @@ mymain(void)
     DO_TEST("pool-iscsi");
     DO_TEST("pool-iscsi-auth");
     DO_TEST("pool-netfs");
+    DO_TEST("pool-netfs-slash");
     DO_TEST("pool-netfs-auto");
     DO_TEST("pool-netfs-protocol-ver");
     DO_TEST("pool-netfs-gluster");
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] conf: storage: also sanitize source dir
Posted by Peter Krempa 6 years, 7 months ago
On Tue, Jun 25, 2019 at 13:44:36 +0200, Ján Tomko wrote:
> Commit a7fb2258 added sanitization of storage pool target paths,
> however source dir paths were left unsanitized.
> 
> A netfs pool with:
> <source>
>   <host name='10.20.30.40'/>
>   <dir path='/nfs/'/>
> </source>
> will not be correctly detected as mounted by
> virStorageBackendFileSystemIsMounted, because it shows up in the
> mount list without the trailing slash.
> 
> Sanitize the source dir as well.
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=1723247
> 
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> ---

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