From f2023e8018fe18550ad6aec66fe72bd1376f8522 Mon Sep 17 00:00:00 2001 From: Andrea Bolognani Date: Thu, 13 Feb 2025 09:54:05 +0100 Subject: [PATCH] utils: Canonicalize paths before comparing them MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit In virFileIsSharedFSOverride() we compare a path against a list of overrides looking for a match. All overrides are canonicalized ahead of time though, so e.g. /var/run/foo will be turned into /run/foo due to /var/run being a symlink on modern Linux systems. But the path we're trying to match with the overrides doesn't get the same treatment, so in this scenario the comparison will always fail. Canonicalizing the path as well solves the issue. Resolves: https://issues.redhat.com/browse/RHEL-79165 Signed-off-by: Andrea Bolognani Reviewed-by: Daniel P. Berrangé --- src/util/virfile.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 6ac0f4efb3..7cab3d0cd6 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3823,10 +3823,13 @@ virFileIsSharedFSOverride(const char *path, if (!path || path[0] != '/' || !overrides) return false; - if (g_strv_contains((const char *const *) overrides, path)) - return true; + /* Overrides have been canonicalized ahead of time, so we need to + * do the same for the provided path or we'll never be able to + * find a match if symlinks are involved */ + dirpath = virFileCanonicalizePath(path); - dirpath = g_strdup(path); + if (g_strv_contains((const char *const *) overrides, dirpath)) + return true; /* Continue until we've scanned the entire path */ while (p != dirpath) { -- 2.47.2