[PATCH] qemu_namespace: Fix detection of nested mount points

Michal Privoznik posted 1 patch 1 year, 4 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/6aac70f94dd8e96686878180c85af7950049f2af.1672763247.git.mprivozn@redhat.com
src/qemu/qemu_namespace.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] qemu_namespace: Fix detection of nested mount points
Posted by Michal Privoznik 1 year, 4 months ago
When deciding whether to bind mount a path in domain's namespace,
we look at the QEMU mount table (/proc/$pid/mounts) and try to
match prefix of given path with one of mount points. Well, we
do that in a bit clumsy way. For instance, if there's
"/dev/hugepages" already mounted inside the namespace and we are
deciding whether to bind mount "/dev/hugepages1G/..." we decide
to skip over the path and NOT bind mount it. This is because
plain STRPREFIX() is used and yes, the former is prefix of the
latter. What we need to check also is whether the next character
after the prefix is slash.

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

diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c
index fb79460109..fc348c043e 100644
--- a/src/qemu/qemu_namespace.c
+++ b/src/qemu/qemu_namespace.c
@@ -1264,9 +1264,11 @@ qemuNamespacePrepareOneItem(qemuNamespaceMknodData *data,
             bool found = false;
 
             for (n = devMountsPath; n && *n; n++) {
+                const char *p;
+
                 if (STREQ(*n, "/dev"))
                     continue;
-                if (STRPREFIX(item.file, *n)) {
+                if ((p = STRSKIP(item.file, *n)) && *p == '/') {
                     found = true;
                     break;
                 }
-- 
2.38.2
Re: [PATCH] qemu_namespace: Fix detection of nested mount points
Posted by Peter Krempa 1 year, 4 months ago
On Tue, Jan 03, 2023 at 17:27:27 +0100, Michal Privoznik wrote:
> When deciding whether to bind mount a path in domain's namespace,
> we look at the QEMU mount table (/proc/$pid/mounts) and try to
> match prefix of given path with one of mount points. Well, we
> do that in a bit clumsy way. For instance, if there's
> "/dev/hugepages" already mounted inside the namespace and we are
> deciding whether to bind mount "/dev/hugepages1G/..." we decide
> to skip over the path and NOT bind mount it. This is because
> plain STRPREFIX() is used and yes, the former is prefix of the
> latter. What we need to check also is whether the next character
> after the prefix is slash.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_namespace.c | 4 +++-

Reviewed-by: Peter Krempa <pkrempa@redhat.com>