From nobody Mon Sep 8 21:39:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1748519645; cv=none; d=zohomail.com; s=zohoarc; b=C0rimtZ6bCIt8FHOU82no7D06nXbFpEUt/uq4dei590kxQEMDQeLoi3rGlqTWw0m7+gAGWEP+L5xfFuTeqextSxntTN/XT7+xU7gThUxkuG4tNCgjjnWaFlUVjq6qIjOreyuCAQNsbPhoGyZTecvMzpg5VCtsZocRCMeaJ/afho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748519645; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=AhJLVExzyPG4EcWMJcmsC2es/8dGIMYZRas8RpSBf2A=; b=BjCk2+nhlaSNIg0YipOGdF4BCb7ijL6/LMLOz2zSJuEd4SvwbWX392Tq39KmF1uU7/fjI24nBhvbpJ51uAH/x3nAGmVulNS1OZuGRWsoPv4Larq9NIIBqMVCVB6p9b6KfhXBxJp6rgWCsWrc5FfWJo0UplXNoMZptdlTDD9+q58= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1748519645531888.1927774953461; Thu, 29 May 2025 04:54:05 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 880C2154E; Thu, 29 May 2025 07:54:04 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 28B9E17F4; Thu, 29 May 2025 07:53:31 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id A0C1913F5; Thu, 29 May 2025 07:53:26 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 298CF1367 for ; Thu, 29 May 2025 07:53:26 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-361--B02mZonPiK0d2gr6JfZcQ-1; Thu, 29 May 2025 07:53:24 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9DFA9180035F for ; Thu, 29 May 2025 11:53:23 +0000 (UTC) Received: from orkuz (unknown [10.43.3.115]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1EEC219560AF for ; Thu, 29 May 2025 11:53:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748519605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IEBGtEp7IW0NS01SezR8PM5nBnLFpHcNUGwmFe+tiuw=; b=cxz3FwfTTsANNM3AWGwxK2nf1z0LgUPxl5r/18nQ1vuBZOUWXrvn4cAZK7iU0v1UKa5UEu A2u+0Gy+siFVSQZO9JtWsPHn4uZXHawlH9ky3cqKv+3N6rTVXSvhBbISpCRCSynQgIcFzD FQOt9hCU89Q0JsbSOXljRNftyEnIs5o= X-MC-Unique: -B02mZonPiK0d2gr6JfZcQ-1 X-Mimecast-MFC-AGG-ID: -B02mZonPiK0d2gr6JfZcQ_1748519603 To: devel@lists.libvirt.org Subject: [PATCH 1/3] util: Document limitation of virFileCanonicalizePath Date: Thu, 29 May 2025 13:53:16 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Dk2FxVALqhDUKm30G61lSa6YPcQbIQeQYNb2QrduLTk_1748519603 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: DXICGKXYA7PLZNYGVVEWM45KE2NIGD4L X-Message-ID-Hash: DXICGKXYA7PLZNYGVVEWM45KE2NIGD4L X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Jiri Denemark via Devel Reply-To: Jiri Denemark X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748519646611116600 Content-Type: text/plain; charset="utf-8" From: Jiri Denemark On most platforms virFileCanonicalizePath is implemented using realpath(), which only works on existing paths. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/util/virfile.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 7cab3d0cd6..242aa7ff88 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3408,7 +3408,8 @@ virFileSanitizePath(const char *path) /** * virFileCanonicalizePath: * - * Returns the canonical representation of @path. + * Returns the canonical representation of @path. This function is only + * guaranteed to work when @path exists. It may return NULL otherwise. * * The returned string must be freed after use. */ --=20 2.49.0 From nobody Mon Sep 8 21:39:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1748519667; cv=none; d=zohomail.com; s=zohoarc; b=Z85pQjKerLrn2odl9+oRoDsVQ/l1Dbpn+/BOSjRaPqfSeJCCkqI7YKPhwPMqb2Qr3/vX0g323kG+ExSkMnATK5kvZ4Nz6k01owU2a479vFdjr/hbT6caBti8tKsjmmFYqdYivORfRopAFXrcUCrVUz3S1RrwKV+oWtaL4xqqgek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748519667; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=CCcSPF1u4zSsFZrcWJQxCXJQeG+q2OnMHPe1TGp3huU=; b=HvTGAV+XFe4haBhAog4ByM7MLQ4A8pUKxFlN4ZG0tSaziD6E2dM7azWri3Yvgl8eoG41fb9urW2gv1ywpGRZx5NBRuwGgkSyESbyVrqj34nCu91CNwrFNxm1YkhhceLDXAig+uUgbxP3drL0GhLfNOblCN2Rsnt41FSfytnsE+0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1748519667075560.9728712413132; Thu, 29 May 2025 04:54:27 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2D82C17CE; Thu, 29 May 2025 07:54:26 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id B3385155E; Thu, 29 May 2025 07:53:32 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id DD92015CC; Thu, 29 May 2025 07:53:28 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 2034913F5 for ; Thu, 29 May 2025 07:53:28 -0400 (EDT) Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-408-HRS9YnBZMBG71exLkeYOqQ-1; Thu, 29 May 2025 07:53:26 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9827A1956089 for ; Thu, 29 May 2025 11:53:25 +0000 (UTC) Received: from orkuz (unknown [10.43.3.115]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 244DE1955D82 for ; Thu, 29 May 2025 11:53:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748519607; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wrphp3wMhjWE9gdbsVXhZ7UGAXgWBj5hUBCMAM6RKpY=; b=db79MVV6ODDP2rc4lcs0AMaZe1oWHt8YmvCMyCmN95sgRfpTg/k2+e0qQYUxLkkQtwxVeW x++RxYuEPRLGqLU9hWa2Nm55WvcRL+toEp5is0++pHMD0IFLiw/4e1u/9owBB0gyrOpXH3 Gr8zHKzy+JAdC4qzmSS6TUzvzkIOLgo= X-MC-Unique: HRS9YnBZMBG71exLkeYOqQ-1 X-Mimecast-MFC-AGG-ID: HRS9YnBZMBG71exLkeYOqQ_1748519605 To: devel@lists.libvirt.org Subject: [PATCH 2/3] util: Introduce virFileGetExistingParent helper Date: Thu, 29 May 2025 13:53:17 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: gbBLPLQ_CglQaOxwLKYzS45fz0S2RxKqfxoFlG_D7jk_1748519605 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: TWEPC3ZZ2QAUFNFU2LMKPMTZTYNJMNDZ X-Message-ID-Hash: TWEPC3ZZ2QAUFNFU2LMKPMTZTYNJMNDZ X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Jiri Denemark via Devel Reply-To: Jiri Denemark X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748519668895116600 Content-Type: text/plain; charset="utf-8" From: Jiri Denemark The code from virFileIsSharedFSType which finds the longest existing path for a given input is separated into a new helper so that it can be reused elsewhere. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: If you wonder why the code is almost the same as the original one, but not exactly the same, it's because I rewrote the code using stat(), but than realized that mocking it for our tests would be a nightmare. So I replaced stat() with statfs() :-) src/util/virfile.c | 60 ++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 242aa7ff88..ef1bc0bbf3 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3557,6 +3557,34 @@ virFileIsSharedFsFUSE(const char *path, } =20 =20 +static char * +virFileGetExistingParent(const char *path) +{ + g_autofree char *dirpath =3D g_strdup(path); + struct statfs sb; + char *p =3D NULL; + + /* Try less and less of the path until we get to a directory we can st= at. + * Even if we don't have 'x' permission on any directory in the path o= n the + * NFS server (assuming it's NFS), we will be able to stat the mount p= oint. + */ + while (statfs(dirpath, &sb) < 0 && p !=3D dirpath) { + if (!(p =3D strrchr(dirpath, '/'))) { + virReportSystemError(EINVAL, + _("Invalid relative path '%1$s'"), path); + return NULL; + } + + if (p =3D=3D dirpath) + *(p + 1) =3D '\0'; + else + *p =3D '\0'; + } + + return g_steal_pointer(&dirpath); +} + + static const struct virFileSharedFsData virFileSharedFs[] =3D { { .fstype =3D VIR_FILE_SHFS_NFS, .magic =3D NFS_SUPER_MAGIC }, { .fstype =3D VIR_FILE_SHFS_GFS2, .magic =3D GFS2_MAGIC }, @@ -3576,40 +3604,14 @@ virFileIsSharedFSType(const char *path, unsigned int fstypes) { g_autofree char *dirpath =3D NULL; - char *p =3D NULL; struct statfs sb; - int statfs_ret; long long f_type =3D 0; size_t i; =20 - dirpath =3D g_strdup(path); + if (!(dirpath =3D virFileGetExistingParent(path))) + return -1; =20 - statfs_ret =3D statfs(dirpath, &sb); - - while ((statfs_ret < 0) && (p !=3D dirpath)) { - /* Try less and less of the path until we get to a - * directory we can stat. Even if we don't have 'x' - * permission on any directory in the path on the NFS - * server (assuming it's NFS), we will be able to stat the - * mount point, and that will properly tell us if the - * fstype is NFS. - */ - - if ((p =3D strrchr(dirpath, '/')) =3D=3D NULL) { - virReportSystemError(EINVAL, - _("Invalid relative path '%1$s'"), path); - return -1; - } - - if (p =3D=3D dirpath) - *(p+1) =3D '\0'; - else - *p =3D '\0'; - - statfs_ret =3D statfs(dirpath, &sb); - } - - if (statfs_ret < 0) { + if (statfs(dirpath, &sb) < 0) { virReportSystemError(errno, _("cannot determine filesystem for '%1$s'"), path); --=20 2.49.0 From nobody Mon Sep 8 21:39:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1748519691; cv=none; d=zohomail.com; s=zohoarc; b=F2LTPEqTsqYyxPGMEGrRUUO8w6jSjLOpkYApcvQUsEodxr7wkRn1qaKYgjGPtsChya+PuYo0B6imdKhlvYuj4RRtXjTmiQDqqqnQHKgtn8ohviRucvkkW3cI2GJ+xsv7JhljMv5cWD6wv2eRxt+z/EyxaGmf1LHPXhl8B5CeCa8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748519691; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=m1Zs8U69KlliVsHxNK3Nrd04WHnR7Y3kzFbjWSmLYNo=; b=byTp46DmYgXLAvavTYkxJbhHegrLSbeE1zIWMz7IoZ7NZkQvbNfp20+ZiERCE8FZUhABIAfEAtjst0nyZsC+CSbp/d7RObxl7aoUOjj7GGlyZ370ouScJVyP0NaYKtbAKU6gOO+Ud1WDfCiUgPIXAfb9/kiCuqD6cooqVAafewM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 174851969129022.668407339815303; Thu, 29 May 2025 04:54:51 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 517D21527; Thu, 29 May 2025 07:54:50 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id BD825171B; Thu, 29 May 2025 07:53:42 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B3E1018A4; Thu, 29 May 2025 07:53:37 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 267641777 for ; Thu, 29 May 2025 07:53:30 -0400 (EDT) Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-133-0n2LGrakM8KTPlH4r-2F0A-1; Thu, 29 May 2025 07:53:28 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8D87A1955E7A for ; Thu, 29 May 2025 11:53:27 +0000 (UTC) Received: from orkuz (unknown [10.43.3.115]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 183EE30002C0 for ; Thu, 29 May 2025 11:53:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748519609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Futswib1PaotyKkQiWY0oaA5QF0bRX95SDrTE9mv9Dw=; b=NqGC7TG0g2ChekYK5eeqNDmGOj5SNby3mXEJJNROsH8kQYbuoXQFAO4YH8M441rD+sO0Kb eCMcsTUf4+2+dNXosyUkKz6OjS3eiNLHlClIj2AUblkHY54yHOSc9coybJPL5wvVEKXHEl uJk5aF8cERBTZYj7ZNVPb5UVM332Cvs= X-MC-Unique: 0n2LGrakM8KTPlH4r-2F0A-1 X-Mimecast-MFC-AGG-ID: 0n2LGrakM8KTPlH4r-2F0A_1748519607 To: devel@lists.libvirt.org Subject: [PATCH 3/3] util: Fix virFileIsSharedFSOverride on nonexistent paths Date: Thu, 29 May 2025 13:53:18 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: PVrYEftx8-tdTC37Ayk2JLqxP8aFcGJzJ-W3v33tEx8_1748519607 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: NIGXL7F5GRKZ3YWMJH7CMVUPH7BM2EBD X-Message-ID-Hash: NIGXL7F5GRKZ3YWMJH7CMVUPH7BM2EBD X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Jiri Denemark via Devel Reply-To: Jiri Denemark X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748519693132116600 Content-Type: text/plain; charset="utf-8" From: Jiri Denemark Commit v11.0.0-162-gf2023e8018 added path canonicalization to virFileIsSharedFSOverride to make sure we can properly match shared filesystem override paths which include symlinks. But virFileCanonicalizePath only works on existing paths, while virFileIsSharedFSOverride may be called on paths that do not exist yet. Matching paths against overrides has always worked even for nonexistent paths. To fix the regression we need to first get the longest existing sub-path and canonicalize only this part and use the result for searching in overrides. Clearly any portion of the path we dynamically create is not going to end up on a different filesystem to what the parent directory is stored in. So checking just the existing parent is enough. https://issues.redhat.com/browse/RHEL-86592 Fixes: f2023e8018fe18550ad6aec66fe72bd1376f8522 Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/util/virfile.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index ef1bc0bbf3..06e8e08ddc 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3821,15 +3821,26 @@ virFileIsSharedFSOverride(const char *path, char *const *overrides) { g_autofree char *dirpath =3D NULL; + g_autofree char *existing =3D NULL; char *p =3D NULL; =20 if (!path || path[0] !=3D '/' || !overrides) return false; =20 + /* We only care about the longest existing sub-path. Further components + * may will later be created by libvirt will not magically become a sh= ared + * filesystem. */ + if (!(existing =3D virFileGetExistingParent(path))) + return false; + /* 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 =3D virFileCanonicalizePath(path); + if (!(dirpath =3D virFileCanonicalizePath(existing))) { + VIR_DEBUG("Cannot canonicalize parent '%s' of path '%s'", + existing, path); + return false; + } =20 if (g_strv_contains((const char *const *) overrides, dirpath)) return true; --=20 2.49.0