From nobody Mon Sep 8 22:02:02 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=1749732614; cv=none; d=zohomail.com; s=zohoarc; b=ZeE0ESToCiJWRM/FgyeUYGL2P4ToUYPDk5TLP4rNhVti/xFRKC4Kl4hMUyzx29u4eTJ5dKYIQ+NOP3s0kR4YTi5A+qDUA+GpOHDmhYnbUi/aXlbM1Bks+zKOkUNNLRB/x7PPl3mByvOXvKwKAeXk3wjMt3jVlsYb+aYZ7W6mmAw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732614; 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=hlbQ7+e3v/T7eAWWGih2grt1ms/CJWUCdxGH7YGseY0=; b=gzUSIOW1k2Mv91vJo/4V7al9GZroxgoL0GN0LJj2QUhEkqFhd3lPTPgPfS0An9/j3i7LOZuS56O8R1O3Gvm/wq8AWos5fS1D9zHLE0fL66HmVtE7j5ltqBhX1gFOpcHN0YqCNQiD+VVauYvF5p0a5tOtzntH0uqpdMW72f9KVNM= 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 1749732614640941.2922209705371; Thu, 12 Jun 2025 05:50:14 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 9DC68E6B; Thu, 12 Jun 2025 08:50:13 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9EEB112C1; Thu, 12 Jun 2025 08:49:02 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D952AD44; Thu, 12 Jun 2025 08:48:56 -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 5EF51D46 for ; Thu, 12 Jun 2025 08:48:56 -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-596-4qJ53-RhPAqZ110WXOEBYg-1; Thu, 12 Jun 2025 08:48:53 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 5AE8E1800294 for ; Thu, 12 Jun 2025 12:48:52 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 98F7E195609D for ; Thu, 12 Jun 2025 12:48:51 +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=1749732536; 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=kCIz3fepH+iX7GMwBoJhf0uM08dMS27cU6SjRsc4hiA=; b=SXI8pIdCa6ypRlmNKUU5GCTFxLJWAvW9lu3co1/eVsX1crN6Lmy+/GSgbMAP7/dIS4lDDn ppjMVHP5munXZ9VUbtA9UmHbQJ6LXgJDLSz0srg0RegQgyzH1x99e4MyfRPURF8UqJcgs9 CFZpHkMqdgvlmEw6dfsj5ddp80DUf6k= X-MC-Unique: 4qJ53-RhPAqZ110WXOEBYg-1 X-Mimecast-MFC-AGG-ID: 4qJ53-RhPAqZ110WXOEBYg_1749732532 To: devel@lists.libvirt.org Subject: [PATCH 01/15] log_cleaner: Use virFileCanonicalizePath() Date: Thu, 12 Jun 2025 14:48:33 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: E_ePAMqV0yySEIpTVhHQ3t2COrGDRnSUjPsiEhespMk_1749732532 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: J6T7VAS6QLSZHEIODAJKRP5QFQNCVT7O X-Message-ID-Hash: J6T7VAS6QLSZHEIODAJKRP5QFQNCVT7O X-MailFrom: mprivozn@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: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732614970116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik While use of realpath() is not forbidden, our some of our mocks already have a test friendly reimplementation of virFileCanonicalizePath(). Use the latter. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/logging/log_cleaner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logging/log_cleaner.c b/src/logging/log_cleaner.c index 4efcbc18e4..d247fdf829 100644 --- a/src/logging/log_cleaner.c +++ b/src/logging/log_cleaner.c @@ -66,7 +66,7 @@ virLogCleanerParseFilename(const char *path, g_autofree char *clear_path =3D NULL; char *chain_prefix =3D NULL; =20 - clear_path =3D realpath(path, NULL); + clear_path =3D virFileCanonicalizePath(path); if (!clear_path) { VIR_WARN("Failed to resolve path %s: %s", path, g_strerror(errno)); return NULL; --=20 2.49.0 From nobody Mon Sep 8 22:02:02 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=1749732586; cv=none; d=zohomail.com; s=zohoarc; b=OCIJY2aFdd8zyVjewyLUdUP1/LomSJlGw0v6L626MDgyJuaS9Am57aq2QFRkU3B5ObD17FLCm9BOwcs5TV8yEoM9yUsxw+Lj1BULJn/qvmrDPZI12S6LAlx2zVNuUPN1tqNQYgdRruFctbUt6n0W7b4/Fkt3EZ7qtwM0mWycfHI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732586; 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=XJF9RVBlAlfDefKOOJthQZx7IVCngyr+i4plr7800uQ=; b=Eq13uMl1wYRP4ivUA44d/R+WuncNJN2i8vGdiTVR0XwL/as/PVsbVVVc0TuSQeBxzU+ohtId0+BJu1314QJjOTR2BqrGAXpSlTqSazSY2sP/eEfHLAlFboWJs0Bd7wX4yzLqYvJVnOryHSOIOQz3iEvJl6AmK4wnMY2wC7L0HhI= 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 174973258668586.6220234644527; Thu, 12 Jun 2025 05:49:46 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id A3946E31; Thu, 12 Jun 2025 08:49:45 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id A05941284; Thu, 12 Jun 2025 08:49:00 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 92307D47; Thu, 12 Jun 2025 08:48:56 -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 E820FD44 for ; Thu, 12 Jun 2025 08:48:55 -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-677-_ZQ6ZQwBO4GRAQewSRBIGg-1; Thu, 12 Jun 2025 08:48:54 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 84FEB19560AA for ; Thu, 12 Jun 2025 12:48:53 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BF584195609D for ; Thu, 12 Jun 2025 12:48:52 +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=1749732535; 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=qJwShT9QD+qXyxt1kYMR63EdomEZ/clVLsf6ymiPTQg=; b=M7TaXvcUvoGIIAd/SXSMFahxPmV5H1KsvLDWWnyAVc+D5vcwxPGxlh/pOlgY5WNZQiMsIz DMKUz2bCOqHqFr5qvNb3YGPl77hULn91sCbkRtk7Q39eyccel/nsMr0uAZ/wrxsCD4m+Ny YotgBJmW7/QZ0FzfxJRkpul/rwkhY/I= X-MC-Unique: _ZQ6ZQwBO4GRAQewSRBIGg-1 X-Mimecast-MFC-AGG-ID: _ZQ6ZQwBO4GRAQewSRBIGg_1749732533 To: devel@lists.libvirt.org Subject: [PATCH 02/15] virt-aa-helper: Use virFileCanonicalizePath() Date: Thu, 12 Jun 2025 14:48:34 +0200 Message-ID: <9fbe46b31e5c455c9afe2bcbd4b50be30b4b7f16.1749732372.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: P4Ktt7WP8_hbZZMwNAU5HnmHExTrWAH23hJ-mDjW8YI_1749732533 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: CZLDVE3X565CE7VH5MRRR6RPEPVQYMS6 X-Message-ID-Hash: CZLDVE3X565CE7VH5MRRR6RPEPVQYMS6 X-MailFrom: mprivozn@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: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732588788116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik While use of realpath() is not forbidden, our some of our mocks already have a test friendly reimplementation of virFileCanonicalizePath(). Use the latter. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/security/virt-aa-helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index e3802c18be..d4358ebf9c 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -712,7 +712,7 @@ vah_add_path(virBuffer *buf, const char *path, const ch= ar *perms, bool recursive tmp =3D g_strdup(path); } else { pathtmp =3D g_strdup(path + strlen(pathdir)); - if ((pathreal =3D realpath(pathdir, NULL)) =3D=3D NULL) { + if (!(pathreal =3D virFileCanonicalizePath(pathdir))) { vah_error(NULL, 0, pathdir); vah_error(NULL, 0, _("could not find realpath")); return rc; --=20 2.49.0 From nobody Mon Sep 8 22:02:02 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=1749732636; cv=none; d=zohomail.com; s=zohoarc; b=jLGFYiwmxXd1191NoEgX0MkX6mxXE76RejS1hAy9p1bUw+YbaGpqRqIoOmLEXrxzhhVOIugaJgjuy2+ZBkl2+dkvy+VkaVckK7Os8Hte1BZBHG5WgAYUorlgz5i3P1nRyQbZWtttN2sX2IYlNUWRUxE+YOUPq6TCxza5jc6boYg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732636; 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=8Ev7hjddgGTE4BjIUL3aZ+KwwY/ou+4vAkOH4Gd1wsU=; b=iWiFqXZ5A7vuLk6X6PRemJSlqcWL+X5tLvupTX9EXmAbVmP/eq6aYDgbz3IugApUSSDAYbeZvoHRcWSXP/vaPvraPFs2qygbp1fPEIpcHOQLhFIq5QJrXA+SElRlDDR9nxd4uieaxY2CNG7hqj4qZMpTl6/+UfOhEpUZwCQ4PYY= 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 1749732636959225.91883773382813; Thu, 12 Jun 2025 05:50:36 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C12B112C7; Thu, 12 Jun 2025 08:50:35 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 4039912F0; Thu, 12 Jun 2025 08:49:04 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7E1BBD46; Thu, 12 Jun 2025 08:48:57 -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 08CC39CE for ; Thu, 12 Jun 2025 08:48:57 -0400 (EDT) Received: from mx-prod-mc-08.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-150-o5sSNjV-P4ubdOXTJubTBA-1; Thu, 12 Jun 2025 08:48:55 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 99F1918002EC for ; Thu, 12 Jun 2025 12:48:54 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E5341195609D for ; Thu, 12 Jun 2025 12:48:53 +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=1749732536; 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=Yl9ZpEdcupEVQfj/helVcM1m21dykcg7ijm6R3M+fGE=; b=E5ZtkHjvNH+ytnbNyqVF67P7jBLt2tom7DzsVugrveSsrUjR11Nw1AxlERk4jre61KwavY VdswMQA/VcKU7vGexdbqmPLsqWJSPJq/yil0JCA3iDnZahFeqhebSOetX2rGoFKnw8cTi4 HLB5XwHqN4Xc/PKb5kuoFmsRBj8UvHo= X-MC-Unique: o5sSNjV-P4ubdOXTJubTBA-1 X-Mimecast-MFC-AGG-ID: o5sSNjV-P4ubdOXTJubTBA_1749732534 To: devel@lists.libvirt.org Subject: [PATCH 03/15] virpcimock: Automatically invent fakerootdir, if not provided Date: Thu, 12 Jun 2025 14:48:35 +0200 Message-ID: <486337c9110893062bb2f3aae862133e68a292ea.1749732372.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: -M1_HL_-l1kIx9N0Bw_2ROhXGm4XMxYUvMNWesPQc-g_1749732534 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: OMBWJEQNUXSYKIEKWWVG5DEXIUWZ6GSF X-Message-ID-Hash: OMBWJEQNUXSYKIEKWWVG5DEXIUWZ6GSF X-MailFrom: mprivozn@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: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732637278116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik Currently, all users of virpcimock do set LIBVIRT_FAKE_ROOT_DIR envvar. But soon, virt-aa-helper will be run with it and basically right at the beginning of its main() it clears whole environment. So even if the envvar is provided the mock won't see that. Anyway, the solution is to just create a tempdir and then 'rm -rf' it in the desctructor. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tests/virpcimock.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 5b923c63ce..34128d5516 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -44,6 +44,7 @@ static DIR * (*real_opendir)(const char *name); static char *(*real_virFileCanonicalizePath)(const char *path); =20 static char *fakerootdir; +static bool fakerootClean; =20 /* To add a new mocked prefix in virpcimock: * - add the prefix here as a define to make it easier to track what we @@ -976,8 +977,16 @@ init_env(void) .vpd_len =3D G_N_ELEMENTS(fullVPDExampleData), }; =20 - if (!(fakerootdir =3D getenv("LIBVIRT_FAKE_ROOT_DIR"))) - ABORT("Missing LIBVIRT_FAKE_ROOT_DIR env variable\n"); + if (!(fakerootdir =3D getenv("LIBVIRT_FAKE_ROOT_DIR"))) { + GError *err =3D NULL; + + fakerootdir =3D g_dir_make_tmp(NULL, &err); + if (err !=3D NULL) { + ABORT("Unable to create a temporary dir: %s\n", err->message); + } + + fakerootClean =3D true; + } =20 tmp =3D g_strdup_printf("%s%s", fakerootdir, SYSFS_PCI_PREFIX); =20 @@ -1046,6 +1055,18 @@ init_env(void) } =20 =20 +static void __attribute__((destructor)) +deinit_env(void) +{ + if (!fakerootClean) + return; + + virFileDeleteTree(fakerootdir); + g_clear_pointer(&fakerootdir, g_free); + fakerootClean =3D false; +} + + /* * * Mocked functions --=20 2.49.0 From nobody Mon Sep 8 22:02:02 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=1749732656; cv=none; d=zohomail.com; s=zohoarc; b=Pd+qTjIcXB/7y7CjjPmllU+dcsdrD/tzM5Y8ByssIQh3EXF3bT9XTzcolYEd7gAt3/8N8pdX75SC5Gh1SysOFQit+gguT6DAhgrSsC+ZMTosbVfU58NUodmCRMaLe6ezYrYFAqqt6rlPBdoi2i8qug7PCe1TnDxFVyeBQ2ZFdJ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732656; 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=bE1O4Kv/1XuButdv6W+z0treaTGoEDDdBptw7mb4nUs=; b=AgKCh85hPCJgGNl3SwmutHNq8xTAduxXMSJb4GMADydF2e6Bi6o8qIZnj3G3B2MDQT79OUV4CRmERM8hGrO8XzQ2aT41XFftLoPZPO5dU252f7uucYvhNCC/XmoseE+Ifd/GHGtWnGCd4PghfYW+BadUKjASR5K7bhrmmgRsnBM= 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 1749732656919642.4161494226004; Thu, 12 Jun 2025 05:50:56 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E28D313AE; Thu, 12 Jun 2025 08:50:55 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 0A47B124D; Thu, 12 Jun 2025 08:49:10 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 179B5E77; Thu, 12 Jun 2025 08:49:05 -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 4FBB3D5B for ; Thu, 12 Jun 2025 08:48:58 -0400 (EDT) Received: from mx-prod-mc-08.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-204-OCMK71VXNAaEv3gebCl2bA-1; Thu, 12 Jun 2025 08:48:56 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B6E201801BD8 for ; Thu, 12 Jun 2025 12:48:55 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0D52D195609D for ; Thu, 12 Jun 2025 12:48:54 +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=1749732537; 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=VzwHPtXpgwQTbtBlbfVPKoz3aVwQdm3lBPAg48tT0gs=; b=E4C7RcerxyKJty4oV7cxE3tok8F6WDscR9mkJoE1KkXoUtWJM8aVIRVkonnK8A5Yb6aVDi UsvwQ1eCs+c+akF++P6ZaBYP23QYRj0LeUS5fcNkA6Hf747zHaTqCdmztIwFiFCbWdFURg bEITlFeLnaIRnzG0hBg4tbGd/qcY514= X-MC-Unique: OCMK71VXNAaEv3gebCl2bA-1 X-Mimecast-MFC-AGG-ID: OCMK71VXNAaEv3gebCl2bA_1749732535 To: devel@lists.libvirt.org Subject: [PATCH 04/15] virpcimock: Strip fakerootdir prefix in virFileCanonicalizePath() Date: Thu, 12 Jun 2025 14:48:36 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: uhNMMUy6wCzZjZV9sGt9ORWZpxr7-MqFf3_lD0t5jDg_1749732535 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: BPCQJLSDLT4ET2LHRLF6PZ7HPT3OGNGS X-Message-ID-Hash: BPCQJLSDLT4ET2LHRLF6PZ7HPT3OGNGS X-MailFrom: mprivozn@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: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732659496116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The mocked implementation of virFileCanonicalizePath() redirects accesses to few dirs into a temporary directory, where PCI related files live. See getrealpath() for more info on this. Anyway, in the end - real implementation of virFileCanonicalizePath() is called which then might contain the 'fakerootdir' prefix. Up until now this did not matter because none of our test really cared about actual value of resolved path. They usually cared about last component of the path or something. But this will soon change. TLDR - if the returned path has $fakerootdir prefix, strip it. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tests/virpcimock.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 34128d5516..4eff6d70e3 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -1184,13 +1184,23 @@ char * virFileCanonicalizePath(const char *path) { g_autofree char *newpath =3D NULL; + char *ret =3D NULL; =20 init_syms(); =20 if (getrealpath(&newpath, path) < 0) return NULL; =20 - return real_virFileCanonicalizePath(newpath); + ret =3D real_virFileCanonicalizePath(newpath); + + if (ret && fakerootdir && STRPREFIX(ret, fakerootdir)) { + size_t len =3D strlen(ret); + size_t preflen =3D strlen(fakerootdir); + + memmove(ret, ret + preflen, len - preflen + 1); + } + + return ret; } =20 # include "virmockstathelpers.c" --=20 2.49.0 From nobody Mon Sep 8 22:02:02 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=1749732934; cv=none; d=zohomail.com; s=zohoarc; b=VGA0rtJxELE8WyaFEyyQ01xKwMRcH6U8VhT2zXx4ADtvCHGu2bNOMDS651fgurDsGFw3GSZE7m2LwGH+DiD1/BIBq3ORmcRKal47CxOkjpbzmsuF+WuWMYW2+i3xuY8gRMtiXyffdqehEjc/Kh5lkxvovwYj7iidlR+AK+eq9yE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732934; 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=k9KoeGTJtAVB7Nlr39HUPylq0HwwQj+Xil6PibgTQk0=; b=U+38q6BkaWfCJ8HoIQ/v5nvLIsF7RIyTbgTSS1n4yDsa7NCVjTkIY4RFy/g5LEjnISkEJJgoY5syfMHsOGQj99SA5QQCx9asFt4mMEzKN8JCrsKlBxM+CLQhpkbvxDQkRUo6yAvO1JpgK+FDB3bWNDP1gVVrbZxGF0lRM3o6bUg= 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 174973293457398.04291409737982; Thu, 12 Jun 2025 05:55:34 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 860B3D5D; Thu, 12 Jun 2025 08:55:33 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9B66C14D2; Thu, 12 Jun 2025 08:53:36 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B3733E32; Thu, 12 Jun 2025 08:53:31 -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 C84A3110C for ; Thu, 12 Jun 2025 08:53:06 -0400 (EDT) Received: from mx-prod-mc-05.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-516-G-2kLnVdM2u523_QU1cGRQ-1; Thu, 12 Jun 2025 08:48:57 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DB93519560A2 for ; Thu, 12 Jun 2025 12:48:56 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 32C89195609D for ; Thu, 12 Jun 2025 12:48:55 +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=1749732786; 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=ZahWUR+aNRTpMDbxqRrMvIyeuKexmsCmrkKjIojcF+c=; b=gCjs8woTOybrV3DTNYdXwjJup0B3rkUfQKZXyHPQG3kvFkJtUJPFBcPTDjZN+a0LesKT9h +sXlgmNPd42Ee3ooqepjCN9E7ORiB3prCE2Zu4tHLv+pXMLXy44MCK/aNpLY8a85QnDm78 iC1wIO/uR/PLQzIZJWBh9XQkje1YE9Q= X-MC-Unique: G-2kLnVdM2u523_QU1cGRQ-1 X-Mimecast-MFC-AGG-ID: G-2kLnVdM2u523_QU1cGRQ_1749732537 To: devel@lists.libvirt.org Subject: [PATCH 05/15] tests: Fix mocking of open() Date: Thu, 12 Jun 2025 14:48:37 +0200 Message-ID: <47a72bf28c2f92ec93d36ef7f32905ad88380197.1749732372.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: RGqWkGjadYn0ZnkizpjCTi5UfMhn78V0A8cc1J15KFg_1749732537 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: BTFEENLIPAUH2DFE2GZMWNAT6LOWADH6 X-Message-ID-Hash: BTFEENLIPAUH2DFE2GZMWNAT6LOWADH6 X-MailFrom: mprivozn@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: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732935084116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik In some cases (well, majority), open() is either rewritten to open64(), either by plain '#define open open64') or at assembly level (using __REDIRECT macro). See for more info. This didn't really matter to us, because we do not chain load two mocks that would need to reimplement open() at the same time. But this is soon going to change. The problem is, that VIR_MOCK_REAL_INIT(open) glances over aforementioned rewrite and initializes real_open pointer to open() from the standard C library. But it needs to point to open() (well, open64()) from the next mock on the list. Therefore, init real_open to open64(). But of course, this is all glibc specific and for example musl does the oposite (#define open64 open). Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tests/nssmock.c | 4 ++++ tests/qemusecuritymock.c | 4 ++++ tests/vircgroupmock.c | 4 ++++ tests/virfilewrapper.c | 4 ++++ tests/virpcimock.c | 4 ++++ tests/virtestmock.c | 4 ++++ tests/virusbmock.c | 4 ++++ 7 files changed, 28 insertions(+) diff --git a/tests/nssmock.c b/tests/nssmock.c index 3493119f3b..d47fe7b10f 100644 --- a/tests/nssmock.c +++ b/tests/nssmock.c @@ -46,7 +46,11 @@ init_syms(void) if (real_open) return; =20 +# if defined(__GLIBC__) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS= =3D=3D 64 + VIR_MOCK_REAL_INIT_ALIASED(open, "open64"); +# else VIR_MOCK_REAL_INIT(open); +# endif # if WITH___OPEN_2 VIR_MOCK_REAL_INIT(__open_2); # endif diff --git a/tests/qemusecuritymock.c b/tests/qemusecuritymock.c index 2dfd6c33a0..d5c711b5d7 100644 --- a/tests/qemusecuritymock.c +++ b/tests/qemusecuritymock.c @@ -115,7 +115,11 @@ init_syms(void) return; =20 VIR_MOCK_REAL_INIT(chown); +#if defined(__GLIBC__) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS = =3D=3D 64 + VIR_MOCK_REAL_INIT_ALIASED(open, "open64"); +#else VIR_MOCK_REAL_INIT(open); +#endif #if WITH___OPEN_2 VIR_MOCK_REAL_INIT(__open_2); #endif diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c index d922f30f34..a5c18bd7b0 100644 --- a/tests/vircgroupmock.c +++ b/tests/vircgroupmock.c @@ -304,7 +304,11 @@ static void init_syms(void) VIR_MOCK_REAL_INIT(fopen); VIR_MOCK_REAL_INIT(access); VIR_MOCK_REAL_INIT(mkdir); +# if defined(__GLIBC__) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS= =3D=3D 64 + VIR_MOCK_REAL_INIT_ALIASED(open, "open64"); +# else VIR_MOCK_REAL_INIT(open); +# endif # if WITH___OPEN_2 VIR_MOCK_REAL_INIT(__open_2); # endif diff --git a/tests/virfilewrapper.c b/tests/virfilewrapper.c index 908f7142c2..3bccca9c11 100644 --- a/tests/virfilewrapper.c +++ b/tests/virfilewrapper.c @@ -56,7 +56,11 @@ static void init_syms(void) VIR_MOCK_REAL_INIT(fopen); VIR_MOCK_REAL_INIT(access); VIR_MOCK_REAL_INIT(mkdir); +# if defined(__GLIBC__) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS= =3D=3D 64 + VIR_MOCK_REAL_INIT_ALIASED(open, "open64"); +# else VIR_MOCK_REAL_INIT(open); +# endif # if WITH___OPEN_2 VIR_MOCK_REAL_INIT(__open_2); # endif diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 4eff6d70e3..ca345f37a3 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -945,7 +945,11 @@ init_syms(void) return; =20 VIR_MOCK_REAL_INIT(access); +# if defined(__GLIBC__) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS= =3D=3D 64 + VIR_MOCK_REAL_INIT_ALIASED(open, "open64"); +# else VIR_MOCK_REAL_INIT(open); +# endif # if WITH___OPEN_2 VIR_MOCK_REAL_INIT(__open_2); # endif /* WITH___OPEN_2 */ diff --git a/tests/virtestmock.c b/tests/virtestmock.c index 5b25b380e5..a5c3b29f39 100644 --- a/tests/virtestmock.c +++ b/tests/virtestmock.c @@ -46,7 +46,11 @@ static void init_syms(void) if (real_open) return; =20 +#if defined(__GLIBC__) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS = =3D=3D 64 + VIR_MOCK_REAL_INIT_ALIASED(open, "open64"); +#else VIR_MOCK_REAL_INIT(open); +#endif #if WITH___OPEN_2 VIR_MOCK_REAL_INIT(__open_2); #endif diff --git a/tests/virusbmock.c b/tests/virusbmock.c index e148296b7c..c23bed4528 100644 --- a/tests/virusbmock.c +++ b/tests/virusbmock.c @@ -40,7 +40,11 @@ static void init_syms(void) if (real_open) return; =20 +#if defined(__GLIBC__) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS = =3D=3D 64 + VIR_MOCK_REAL_INIT_ALIASED(open, "open64"); +#else VIR_MOCK_REAL_INIT(open); +#endif #if WITH___OPEN_2 VIR_MOCK_REAL_INIT(__open_2); #endif --=20 2.49.0 From nobody Mon Sep 8 22:02:02 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=1749732681; cv=none; d=zohomail.com; s=zohoarc; b=haDXfMe9xwbMkjxkgRdKCzqFlQ5o/aWSofrSbWEiVkbelpo92SOTF7DydBMD7Nsd7uSgT+xYoX9MDwQ3jFD9ictJHXBfjt6sboC7askCkVeUVlPSCkykKeLNp2bfYAj3s5qQ7GEIwBQvJqKLG/aojKeqG9gmRnZTF4DyL8pgRMc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732681; 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=E2EhfMduOxQgVPc9xmsnPeW1jzanjOVMipNaYr0D0Xg=; b=DLCzTpcqMUL3hhAG0arMRbyNw4HqyUqw7/oeqZcVnyPSaSDOZDXDUlhVvkdf/z+SSzmPz+Rwy5jqhAfwzFjGQ5YPHPKqSUZtdMHnJQly3mr+x2hQz4NJGUwYqJpISdKJrJ0uqksda1fklyGTP3pdCwsAfvK4jq9J1Z9XcXj/8ag= 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 1749732681823211.39221791937086; Thu, 12 Jun 2025 05:51:21 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id AEE06140B; Thu, 12 Jun 2025 08:51:20 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D6B3EE72; Thu, 12 Jun 2025 08:49:16 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 25652D90; Thu, 12 Jun 2025 08:49:10 -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 989D5127C for ; Thu, 12 Jun 2025 08:49:00 -0400 (EDT) Received: from mx-prod-mc-04.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-61-6lwcKB6EM-m8oX8xeL3Zew-1; Thu, 12 Jun 2025 08:48:58 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0E3F019560B6 for ; Thu, 12 Jun 2025 12:48:58 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5827F195609D for ; Thu, 12 Jun 2025 12:48:57 +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=1749732540; 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=j3Z6Uro/kN5fBWxbIb5sHaIa6l/hW1Hy5NP1No1CJmw=; b=AnaNrvoFsciAQjlfP9/aG22nZV78gbj+tPqOoNw1eA0blTk37sH25ksdfa8uUX2dM4ezu+ 0kM1rE1LW+9G2y3XUS0t4PoNLVELg/QT5lPn6M+zoArjTXo8a+OGy70t2PMsR0InKdCzig c8aYOo2pt/LVKvn35+XLUySnC6TC7tI= X-MC-Unique: 6lwcKB6EM-m8oX8xeL3Zew-1 X-Mimecast-MFC-AGG-ID: 6lwcKB6EM-m8oX8xeL3Zew_1749732538 To: devel@lists.libvirt.org Subject: [PATCH 06/15] virt-aa-helper-test: Print errors to stderr Date: Thu, 12 Jun 2025 14:48:38 +0200 Message-ID: <0d38f235607c989aaebe4a07e555247ebb3a4825.1749732372.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: dGEzyCO6opg0buRjqTW6LCdBZZeSHmTlAKhanR6jomg_1749732538 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 2WUAZRQVACFMAFQXLCXSRT2E7CZSB3KM X-Message-ID-Hash: 2WUAZRQVACFMAFQXLCXSRT2E7CZSB3KM X-MailFrom: mprivozn@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: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732683738116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik When a test case fails, there are two echo-s executed: the first one either prints the error message into /dev/null (default) or onto stdout (when the test script is executed with -d). Then, the second one prints the error message onto stdout. While this technically works, there's nothing ever printed onto stderr which is usually what's captured. Worse, if some command within the script fails, it prints something onto stderr but then looking at meson logs it's needlessly hard to match stderr and stdout lines. Just print error messages onto stderr. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tests/virt-aa-helper-test | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/virt-aa-helper-test b/tests/virt-aa-helper-test index 4c8d31c9d7..8259c2679f 100755 --- a/tests/virt-aa-helper-test +++ b/tests/virt-aa-helper-test @@ -116,7 +116,7 @@ testme() { input=3D"$4" if [ ! -e "$input" ]; then echo "FAIL: could not find $input" >$output - echo "FAIL: could not find $input" + echo "FAIL: could not find $input" >&2 echo " '$extra_args $args': " errors=3D$(($errors + 1)) fi @@ -141,6 +141,7 @@ testme() { if [ -n "$checkrule" ]; then if ! grep "$checkrule" "$tmpout" >/dev/null; then echo "FAIL: missing rule '$checkrule'" >"$output" + echo "FAIL: missing rule '$checkrule'" >&2 rule_missing=3D1 fi fi --=20 2.49.0 From nobody Mon Sep 8 22:02:02 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=1749732699; cv=none; d=zohomail.com; s=zohoarc; b=dFJTnHDf8a6VvUQNaYlTHXSrRre4/+QimF24G05w+brjr01u+R+s35aekgxECmz/IzcS6rAtGEbD8V0smbGyuRM4W/hTkDi+Q8uSfX4dwQvxx1Ut+kQNdyxjQHEde195Uf+3rUNmB0HLw5S8hMv5cEnAHPqUyqcBiSaD6F1KwxA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732699; 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=ec0bur1pCzOiGpF4LkZTzP2TPSGFY+PHfLQUde8nzHk=; b=Fo8F2JeFTKdE6PyOzD8W3LZg17TvwxmtnMjH+SJVWgk0e+h3PaFhwemfUwsf1utTLzcwo4PjUc6sJE4rHgZNke/7RqYepb++PrP8w/FdoZclC9d8x8B5rCi+5AIDZHGf+xnW2eeDhMgrGp0wn1qMtJS5y7ihPejxz15Gi0aqJGQ= 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 1749732699767460.4257750422072; Thu, 12 Jun 2025 05:51:39 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id CFC5A12FF; Thu, 12 Jun 2025 08:51:38 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C6F0611C4; Thu, 12 Jun 2025 08:49:18 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 87B0F1187; Thu, 12 Jun 2025 08:49:11 -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 BB585DAE for ; Thu, 12 Jun 2025 08:49:01 -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-175-BpxU3QETPXysvjixgZiz2Q-1; Thu, 12 Jun 2025 08:49:00 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 40EA01800288 for ; Thu, 12 Jun 2025 12:48:59 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7F301195609D for ; Thu, 12 Jun 2025 12:48:58 +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=1749732541; 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=uyeJYCTo5Ztkcf3HhD/ER5bO3QU36gi6vumiwVCXvng=; b=D+0iFMLdtpgEqqrehCOT4ZC/CDkJD2FC89mL8zILCY8RbplesrGANiTa5++cZayo3x4Ow4 9FnDrWZE/KB35sF3zt90sp8XRsJSL+gxBfmce1He+nGm1LARz6IcfZd+XH3OKKYiqQb4/j JJOMRXv1cz/QCB3Wt4lsRYsT3UJKb1o= X-MC-Unique: BpxU3QETPXysvjixgZiz2Q-1 X-Mimecast-MFC-AGG-ID: BpxU3QETPXysvjixgZiz2Q_1749732539 To: devel@lists.libvirt.org Subject: [PATCH 07/15] virt-aa-helper-test: Silence ls Date: Thu, 12 Jun 2025 14:48:39 +0200 Message-ID: <48d31790ead792d86f56596f7dad843918bcb81e.1749732372.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: TIGipFu0KWf41xwwiRHz_AMde6R_jBpNxeKkCRmHnBU_1749732539 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: UJG3TXUILTDMEALG436UPOKPXATZFTKB X-Message-ID-Hash: UJG3TXUILTDMEALG436UPOKPXATZFTKB X-MailFrom: mprivozn@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: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732702014116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik virt-aa-helper checks presence of files before it adds them into a profile. Because of that, test cases inside of virt-aa-helper-test that require presence of /boot/initrd* are guarded by a check. The check uses ls to find at least one initrd file. If there's none, then ls prints an error onto stderr. This is not helpful because the test script prints a message on its own right after. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tests/virt-aa-helper-test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/virt-aa-helper-test b/tests/virt-aa-helper-test index 8259c2679f..e462e46570 100755 --- a/tests/virt-aa-helper-test +++ b/tests/virt-aa-helper-test @@ -201,7 +201,7 @@ testme "1" "bad disk2" "-c -u $valid_uuid" "$test_xml" sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,,= ,g" "$template_xml" > "$test_xml" testme "1" "malformed xml" "-c -u $valid_uuid" "$test_xml" =20 -initrd=3D`ls -1 /boot/initrd* | head -1` +initrd=3D`ls -1 /boot/initrd* 2>/dev/null | head -1` if [ -z "$initrd" ]; then echo "Skipping /boot/initrd* tests. Could not find /boot/initrd*" else --=20 2.49.0 From nobody Mon Sep 8 22:02:02 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=1749732724; cv=none; d=zohomail.com; s=zohoarc; b=dZMeM41wy4cl89XazardrxY+UwslxeasNsa7a6YA/wz+8ClzjiiWSGAkhMuP9Er6oBTHdWekrj3yMBs8X1VZC+Qj8DHu2VNF0uy4bqbCwDQTJ44dIVOZZfmCiAeAIYvF4Esc7bVklOieIriNPO9M5bmkFl3Cd4cDtCTKCEnLLU0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732724; 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=ZMe+F/BV6SUKQdhvlYzbOQHu3L4U0JtErSEQNnb36QA=; b=bkxy3kAayp25YflmmG4y+vuh8aqn5VlDwY0PT7clzm1hy128FEpvYS6SKbEnFmmEicUHINpYbYwzdUJiYnBOfPVrryvWPLITNwCA7QZF9nZA73L2P+ZODcjnQK9Cq5Gq8ILj4AOgf/sBhYjboOP/+cglnkFYWC6Tu0oy6K1CxjA= 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 1749732724640529.7283004057454; Thu, 12 Jun 2025 05:52:04 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 9C4CC121D; Thu, 12 Jun 2025 08:52:03 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id AE1DA1185; Thu, 12 Jun 2025 08:49:21 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4B56810F3; Thu, 12 Jun 2025 08:49:16 -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 4503AE1E for ; Thu, 12 Jun 2025 08:49:03 -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-696-sEmZMX_7NfqeNR5VNRmGcQ-1; Thu, 12 Jun 2025 08:49:01 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 7D3F519560AD for ; Thu, 12 Jun 2025 12:49:00 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A58E3195609D for ; Thu, 12 Jun 2025 12:48:59 +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=1749732542; 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=W4c41mZ7tww4G5yJbl0NM9qleikxb9HkODXLzkgw5xQ=; b=UtTEMiFP+0wS8wHkyT8oXe5Xab9lgdioXsjCvkkYHf2C46K1CbSfSsT/TJvEEI2/d02L7/ rplOkiBuu11bUBAcA0Ag2LzKDl5ktCiwq8yZIXqNcb0jPoeqa2H44uTu3yP0uBT7WZkOkS /2uijlSyf1qYrKrPS5m4+oGbXW53NGE= X-MC-Unique: sEmZMX_7NfqeNR5VNRmGcQ-1 X-Mimecast-MFC-AGG-ID: sEmZMX_7NfqeNR5VNRmGcQ_1749732540 To: devel@lists.libvirt.org Subject: [PATCH 08/15] virt-aa-helper-test: Test hostdevs unconditionally Date: Thu, 12 Jun 2025 14:48:40 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: JaPLs1dzlAjxYDCibPRmEWFiPM05-9QWYi_EO7s1xTY_1749732540 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: L5QBPMFGNYD67SJQPJHY7353RGU5NW7H X-Message-ID-Hash: L5QBPMFGNYD67SJQPJHY7353RGU5NW7H X-MailFrom: mprivozn@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: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732726478116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik Our test suite is very feature rich. In particular, it has two mocks that implement sysfs close enough to create host-independent environment to work with PCI and USB devices. These mocks are called virpcimock and virusbmock, respectively. Inside of virt-aa-helper-test there is an attempt to test whether virt-aa-helper generates profiles for , once for USB and the other time for PCI. Use this mocks to run virt-aa-helper in an environment where certain PCI/USB devices always exist. There are two problem though: 1) those two test cases use hardcoded PCI/USB addresses, which makes them host environment dependant, 2) neither of the test cases checks whether corresponding rule was added into the profile. Using mocks we can get away with problem 1), and by passing the fifth argument to testme() we can list an expected rule in the profile. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tests/virt-aa-helper-test | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/tests/virt-aa-helper-test b/tests/virt-aa-helper-test index e462e46570..c0b8c1bafe 100755 --- a/tests/virt-aa-helper-test +++ b/tests/virt-aa-helper-test @@ -7,15 +7,9 @@ =20 set -e =20 -test_hostdev=3D"no" -if [ "$1" =3D "test_hostdev" ]; then - test_hostdev=3D"yes" - shift -fi - output=3D"/dev/null" use_valgrind=3D"" -ld_library_path=3D"$abs_top_builddir/src/" +ld_library_path=3D"$abs_top_builddir/tests/:$abs_top_builddir/src/" if [ ! -z "$1" ] && [ "$1" =3D "-d" ]; then output=3D"/dev/stdout" shift @@ -128,11 +122,12 @@ testme() { printf %s " < $input" >$output fi echo "': " >$output + ld_preload=3D"libvirusbmock.so:libvirpcimock.so" set +e if [ -n "$input" ]; then - LD_LIBRARY_PATH=3D"$ld_library_path" "${exe}" $extra_args $args < = $input >"$tmpout" 2>&1 + LD_PRELOAD=3D"$ld_preload" LD_LIBRARY_PATH=3D"$ld_library_path" ${= exe} $extra_args $args < $input >"$tmpout" 2>&1 else - LD_LIBRARY_PATH=3D"$ld_library_path" "${exe}" $extra_args $args >"= $tmpout" 2>&1 + LD_PRELOAD=3D"$ld_preload" LD_LIBRARY_PATH=3D"$ld_library_path" ${= exe} $extra_args $args >"$tmpout" 2>&1 fi rc=3D"$?" cat "$tmpout" >"$output" @@ -262,13 +257,11 @@ testme "0" "create multiple disks" "-c -u $valid_uuid= " "$test_xml" "$disk1.*rwk, sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###',${disk1}'/> "$test_xml" testme "0" "create (readonly)" "-c -u $valid_uuid" "$test_xml" "$disk1.*rk= ,$" =20 -if [ "$test_hostdev" =3D "yes" ]; then - sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,= ,
,g" "$template_xml" > "$test_xml" - testme "0" "create hostdev (USB)" "-c -u $valid_uuid" "$test_xml" +sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,,
,g" "$template_xml" > "$test_xml" +testme "0" "create hostdev (USB)" "-c -u $valid_uuid" "$test_xml" "/dev/bu= s/usb/001/020" =20 - sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,= ,
,g" "$template_xml" = > "$test_xml" - testme "0" "create hostdev (PCI)" "-c -u $valid_uuid" "$test_xml" -fi +sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,,
,g" "$template_xml" > "$t= est_xml" +testme "0" "create hostdev (PCI)" "-c -u $valid_uuid" "$test_xml" "/sys/de= vices/pci0000:00/0000:00:03.0/config" =20 sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$nonexistent,g" "$template_= xml" > "$test_xml" testme "0" "create (non-existent disk)" "-c -u $valid_uuid" "$test_xml" "$= nonexistent.*rwk,$" --=20 2.49.0 From nobody Mon Sep 8 22:02:02 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=1749732749; cv=none; d=zohomail.com; s=zohoarc; b=YV3GO/z3m62Un8AXiZU6dUvJNynGb/d+AHoEnF+Kt7OTCEqHCap2Q3uO0vIoIwEZl0e7ceS883QLZQSAcZTfVtlrl2fUtnjQ8tfCrL8MCimL2yFhQmSf+nKRxKmyOyOBxJLhHBBaLPzuN7ALvALnFIj9REREVPtTiZKijQLaPvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732749; 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=jdym9xEWUbwSQ6nMJWNX+3Lvc5fFEyJc932mbNw9NIE=; b=G0woNbb10wZo42N/1kmR4tOMuhLrhAMvKIb/P0rtd+5HUdEB2UNaPBYydcUNX6KocrtnMFCTPAoSPcDl5SJkaAX2zwAm6Ap9gP9miMBKY282m3Wuhtng8ghrbJxABFPaKQLsCiy18G8adqIT/uRWJvk7oH6PvmmgTSWM7oNKFfQ= 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 1749732749450701.3911914552667; Thu, 12 Jun 2025 05:52:29 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7CCD8D44; Thu, 12 Jun 2025 08:52:28 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D2B1113B1; Thu, 12 Jun 2025 08:49:23 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id EC57711B6; Thu, 12 Jun 2025 08:49:17 -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 A07D41300 for ; Thu, 12 Jun 2025 08:49:04 -0400 (EDT) Received: from mx-prod-mc-01.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-642-VrHQCFiHO7y7LPywaXfXcA-1; Thu, 12 Jun 2025 08:49:02 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 92D6B195608B for ; Thu, 12 Jun 2025 12:49:01 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C22B3195609D for ; Thu, 12 Jun 2025 12:49:00 +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=1749732544; 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=97lZ4XG8WJj0wQEALiTF/hTCtGMe9MwNQQgFnN8ZwsE=; b=Fx8tYpjTKC/cI6iL8DMStvWUihw3b8cKaRJI7/OZdxp9DH93Esk1IuUsrrH7NYSPH9y+9k mkDMuZiQocYvwRFgS0j78W5LnMnSrjrLG0pg1Fsxg8zF0LkeQGyZyFCwMTidOso2Hcf3/g AjNRe+krSA8VCoRYKrsiLCLz7Dri0Xk= X-MC-Unique: VrHQCFiHO7y7LPywaXfXcA-1 X-Mimecast-MFC-AGG-ID: VrHQCFiHO7y7LPywaXfXcA_1749732541 To: devel@lists.libvirt.org Subject: [PATCH 09/15] virt-aa-helper: Rework USB hostdev handling Date: Thu, 12 Jun 2025 14:48:41 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: VKKFCwYxupDOE7PyM_TMjj_gyepzXTN4fCu8EwTLI-g_1749732541 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 5E4UWIIGCN5DN4263MSEBMKKGLZ6TESC X-Message-ID-Hash: 5E4UWIIGCN5DN4263MSEBMKKGLZ6TESC X-MailFrom: mprivozn@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: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732750693116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik For an USB device, the virt-aa-helper must put that /dev/bus/usb/... path associated with given device. The way the code is currently written not only leads to a memleak (the @usb variable is allocated only to be overwritten right away), but is needlessly cumbersome. We can use virHostdevFindUSBDevice() to find the USB device, check if its missing and if not add the path associated with it into the profile. While at it, also use automatic memory freeing for the variable. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/security/virt-aa-helper.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index d4358ebf9c..a56d7e9062 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1040,24 +1040,21 @@ get_files(vahControl * ctl) for (i =3D 0; i < ctl->def->nhostdevs; i++) if (ctl->def->hostdevs[i]) { virDomainHostdevDef *dev =3D ctl->def->hostdevs[i]; - virDomainHostdevSubsysUSB *usbsrc =3D &dev->source.subsys.u.us= b; =20 if (dev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) continue; =20 switch (dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { - virUSBDevice *usb =3D - virUSBDeviceNew(usbsrc->bus, usbsrc->device, NULL); - - if (usb =3D=3D NULL) - continue; + g_autoptr(virUSBDevice) usb =3D NULL; =20 if (virHostdevFindUSBDevice(dev, true, &usb) < 0) continue; =20 + if (dev->missing) + continue; + rc =3D virUSBDeviceFileIterate(usb, file_iterate_hostdev_c= b, &buf); - virUSBDeviceFree(usb); if (rc !=3D 0) goto cleanup; break; --=20 2.49.0 From nobody Mon Sep 8 22:02:02 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=1749732830; cv=none; d=zohomail.com; s=zohoarc; b=F5OlqqMXXBjJf9gNPIMYZfAjGwvPgci/5F3z/V+vzfHd9diGOcuvsgkRhm/vjDSvFOkWsuN4yIcoOS9VnLDuCLcKQ0/DzX4UVp7TEY3du5yMQFmyvJrh54NtN2AQLyT3XSuc1e/ShdAOMf1KB6/VROeSMOjASc9emAPKAq/PVUU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732830; 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=iXHhJfURwP5WWy2BSh+S+DdgLsJbR2d0OoTKxIEqUgU=; b=Vd5XEzQAXseIwbDTbZXNdGx8aItzZxQ5jbAOcywiFJSm8JzDqLNBn67EmFUbw6RhF/smGrP8Wmum64k9/JPyeaqGWCcihSkO1clGTMkgGluSntpWsp6lWK8GhB3GV5h/qDyHDmrm0i2r96//VFPddiofhAK99XIOsSebSYeYi8c= 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 1749732830345397.9591283516952; Thu, 12 Jun 2025 05:53:50 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 31DFE149E; Thu, 12 Jun 2025 08:53:49 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 4435411F4; Thu, 12 Jun 2025 08:49:31 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 63DD2DEE; Thu, 12 Jun 2025 08:49:24 -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 556D41124 for ; Thu, 12 Jun 2025 08:49:07 -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-591-3pOCy_utNrm2dCSpC3mF0g-1; Thu, 12 Jun 2025 08:49:03 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 99E0A19560BA for ; Thu, 12 Jun 2025 12:49:02 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DEB9B195609D for ; Thu, 12 Jun 2025 12:49:01 +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=1749732547; 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=OROthnZuCo48zOWjsz/Q8oBZICLnidk7ZlZwQGVk0EQ=; b=hMFkPbIJvViF7PUrkOPEDQYXi1LXKY3PwhA/vJ+ZsdFO94AC5O/I7EN9cWxvGND1nf9Hwb bMHk8axAw/5lRvCGqeIPeoWKH7TN5sOQY0z8JlrDUFBVMPW8/GjE88uJc+32C18qaFXGQZ 0TXA+Wvs8G6Lc/ORba1W+Hus74wiYfc= X-MC-Unique: 3pOCy_utNrm2dCSpC3mF0g-1 X-Mimecast-MFC-AGG-ID: 3pOCy_utNrm2dCSpC3mF0g_1749732542 To: devel@lists.libvirt.org Subject: [PATCH 10/15] virt-aa-helper: Simplify paths collection Date: Thu, 12 Jun 2025 14:48:42 +0200 Message-ID: <7df3ab076aae048fc782e4b7f5bd07b89194c8c8.1749732372.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ZALu9hy3DTJF3lM3VmHFALdMf_jIkqELEwnT9HZs6HE_1749732542 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: CWCGO2GU77U672PGHSWEVPL4D2XXCKDF X-Message-ID-Hash: CWCGO2GU77U672PGHSWEVPL4D2XXCKDF X-MailFrom: mprivozn@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: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732831885116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The way virt-aa-helper works is the following: the apparmor secdriver formats domain XML, spawns virt-aa-helper process and feeds it with domain XML (through stdin). The helper process then parses the XML and iterates over devices, appending paths in each loop. These loops usually are in the following form: for (i =3D 0; i < ctl->def->nserials; i++) { if (ctl->def->serials[i] && ... } While we are probably honourable members of tautology club, those NULL checks are redundant. Our XML parses would never append NULL into def->devices array. If it did, we're in way bigger problems anyway. Then, constantly dereferencing ctl->def just to get to a path that's hidden a couple of structures deep gets hard to read. Just introduce temporary variables. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/security/virt-aa-helper.c | 329 ++++++++++++++++++---------------- 1 file changed, 173 insertions(+), 156 deletions(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index a56d7e9062..2fac65f108 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -904,63 +904,79 @@ get_files(vahControl * ctl) goto cleanup; } =20 - for (i =3D 0; i < ctl->def->nserials; i++) - if (ctl->def->serials[i] && - (ctl->def->serials[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYPE= _PTY || - ctl->def->serials[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYPE= _DEV || - ctl->def->serials[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYPE= _FILE || - ctl->def->serials[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYPE= _UNIX || - ctl->def->serials[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYPE= _PIPE) && - ctl->def->serials[i]->source->data.file.path && - ctl->def->serials[i]->source->data.file.path[0] !=3D '\0') + for (i =3D 0; i < ctl->def->nserials; i++) { + virDomainChrDef *chr =3D ctl->def->serials[i]; + + if ((chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_PTY || + chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_DEV || + chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_FILE || + chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_UNIX || + chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_PIPE) && + chr->source->data.file.path && + chr->source->data.file.path[0] !=3D '\0') { if (vah_add_file_chardev(&buf, - ctl->def->serials[i]->source->data.fi= le.path, + chr->source->data.file.path, "rw", - ctl->def->serials[i]->source->type) != =3D 0) + chr->source->type) !=3D 0) { goto cleanup; + } + } + } =20 - for (i =3D 0; i < ctl->def->nconsoles; i++) - if (ctl->def->consoles[i] && - (ctl->def->consoles[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYP= E_PTY || - ctl->def->consoles[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYP= E_DEV || - ctl->def->consoles[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYP= E_FILE || - ctl->def->consoles[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYP= E_UNIX || - ctl->def->consoles[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYP= E_PIPE) && - ctl->def->consoles[i]->source->data.file.path && - ctl->def->consoles[i]->source->data.file.path[0] !=3D '\0') + for (i =3D 0; i < ctl->def->nconsoles; i++) { + virDomainChrDef *chr =3D ctl->def->consoles[i]; + + if ((chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_PTY || + chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_DEV || + chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_FILE || + chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_UNIX || + chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_PIPE) && + chr->source->data.file.path && + chr->source->data.file.path[0] !=3D '\0') { if (vah_add_file(&buf, - ctl->def->consoles[i]->source->data.file.path= , "rw") !=3D 0) + chr->source->data.file.path, "rw") !=3D 0) { goto cleanup; + } + } + } =20 - for (i =3D 0; i < ctl->def->nparallels; i++) - if (ctl->def->parallels[i] && - (ctl->def->parallels[i]->source->type =3D=3D VIR_DOMAIN_CHR_TY= PE_PTY || - ctl->def->parallels[i]->source->type =3D=3D VIR_DOMAIN_CHR_TY= PE_DEV || - ctl->def->parallels[i]->source->type =3D=3D VIR_DOMAIN_CHR_TY= PE_FILE || - ctl->def->parallels[i]->source->type =3D=3D VIR_DOMAIN_CHR_TY= PE_UNIX || - ctl->def->parallels[i]->source->type =3D=3D VIR_DOMAIN_CHR_TY= PE_PIPE) && - ctl->def->parallels[i]->source->data.file.path && - ctl->def->parallels[i]->source->data.file.path[0] !=3D '\0') + for (i =3D 0; i < ctl->def->nparallels; i++) { + virDomainChrDef *chr =3D ctl->def->parallels[i]; + + if ((chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_PTY || + chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_DEV || + chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_FILE || + chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_UNIX || + chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_PIPE) && + chr->source->data.file.path && + chr->source->data.file.path[0] !=3D '\0') { if (vah_add_file_chardev(&buf, - ctl->def->parallels[i]->source->data.= file.path, + chr->source->data.file.path, "rw", - ctl->def->parallels[i]->source->type)= !=3D 0) + chr->source->type) !=3D 0) { goto cleanup; + } + } + } + + for (i =3D 0; i < ctl->def->nchannels; i++) { + virDomainChrDef *chr =3D ctl->def->channels[i]; =20 - for (i =3D 0; i < ctl->def->nchannels; i++) - if (ctl->def->channels[i] && - (ctl->def->channels[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYP= E_PTY || - ctl->def->channels[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYP= E_DEV || - ctl->def->channels[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYP= E_FILE || - ctl->def->channels[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYP= E_UNIX || - ctl->def->channels[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYP= E_PIPE) && - ctl->def->channels[i]->source->data.file.path && - ctl->def->channels[i]->source->data.file.path[0] !=3D '\0') + if ((chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_PTY || + chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_DEV || + chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_FILE || + chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_UNIX || + chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_PIPE) && + chr->source->data.file.path && + chr->source->data.file.path[0] !=3D '\0') { if (vah_add_file_chardev(&buf, - ctl->def->channels[i]->source->data.f= ile.path, + chr->source->data.file.path, "rw", - ctl->def->channels[i]->source->type) = !=3D 0) + chr->source->type) !=3D 0) { goto cleanup; + } + } + } =20 if (ctl->def->os.kernel) if (vah_add_file(&buf, ctl->def->os.kernel, "r") !=3D 0) @@ -1037,81 +1053,80 @@ get_files(vahControl * ctl) "r") !=3D 0) goto cleanup; =20 - for (i =3D 0; i < ctl->def->nhostdevs; i++) - if (ctl->def->hostdevs[i]) { - virDomainHostdevDef *dev =3D ctl->def->hostdevs[i]; + for (i =3D 0; i < ctl->def->nhostdevs; i++) { + virDomainHostdevDef *dev =3D ctl->def->hostdevs[i]; =20 - if (dev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) - continue; - - switch (dev->source.subsys.type) { - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { - g_autoptr(virUSBDevice) usb =3D NULL; - - if (virHostdevFindUSBDevice(dev, true, &usb) < 0) - continue; - - if (dev->missing) - continue; + if (dev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) + continue; =20 - rc =3D virUSBDeviceFileIterate(usb, file_iterate_hostdev_c= b, &buf); - if (rc !=3D 0) - goto cleanup; - break; - } - - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { - virDomainHostdevSubsysMediatedDev *mdevsrc =3D &dev->sourc= e.subsys.u.mdev; - switch (mdevsrc->model) { - case VIR_MDEV_MODEL_TYPE_VFIO_PCI: - case VIR_MDEV_MODEL_TYPE_VFIO_AP: - case VIR_MDEV_MODEL_TYPE_VFIO_CCW: - needsVfio =3D true; - break; - case VIR_MDEV_MODEL_TYPE_LAST: - default: - virReportEnumRangeError(virMediatedDeviceModelType, - mdevsrc->model); - break; - } - break; - } + switch (dev->source.subsys.type) { + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { + g_autoptr(virUSBDevice) usb =3D NULL; =20 - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - virPCIDevice *pci =3D virPCIDeviceNew(&dev->source.subsys.= u.pci.addr); - - virDeviceHostdevPCIDriverName driverName =3D dev->source.s= ubsys.u.pci.driver.name; - - if (driverName =3D=3D VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_V= FIO || - driverName =3D=3D VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_D= EFAULT) { - needsVfio =3D true; - } - - if (pci =3D=3D NULL) - continue; + if (virHostdevFindUSBDevice(dev, true, &usb) < 0) + continue; =20 - rc =3D virPCIDeviceFileIterate(pci, file_iterate_pci_cb, &= buf); - virPCIDeviceFree(pci); + if (dev->missing) + continue; =20 + rc =3D virUSBDeviceFileIterate(usb, file_iterate_hostdev_cb, &= buf); + if (rc !=3D 0) + goto cleanup; + break; + } + + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { + virDomainHostdevSubsysMediatedDev *mdevsrc =3D &dev->source.su= bsys.u.mdev; + switch (mdevsrc->model) { + case VIR_MDEV_MODEL_TYPE_VFIO_PCI: + case VIR_MDEV_MODEL_TYPE_VFIO_AP: + case VIR_MDEV_MODEL_TYPE_VFIO_CCW: + needsVfio =3D true; break; - } - - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: + case VIR_MDEV_MODEL_TYPE_LAST: default: - rc =3D 0; + virReportEnumRangeError(virMediatedDeviceModelType, + mdevsrc->model); break; - } /* switch */ + } + break; } =20 + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { + virPCIDevice *pci =3D virPCIDeviceNew(&dev->source.subsys.u.pc= i.addr); + + virDeviceHostdevPCIDriverName driverName =3D dev->source.subsy= s.u.pci.driver.name; + + if (driverName =3D=3D VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO = || + driverName =3D=3D VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAU= LT) { + needsVfio =3D true; + } + + if (pci =3D=3D NULL) + continue; + + rc =3D virPCIDeviceFileIterate(pci, file_iterate_pci_cb, &buf); + virPCIDeviceFree(pci); + + break; + } + + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: + default: + rc =3D 0; + break; + } /* switch */ + } + for (i =3D 0; i < ctl->def->nfss; i++) { - if (ctl->def->fss[i] && - ctl->def->fss[i]->type =3D=3D VIR_DOMAIN_FS_TYPE_MOUNT && - (ctl->def->fss[i]->fsdriver =3D=3D VIR_DOMAIN_FS_DRIVER_TY= PE_PATH || - ctl->def->fss[i]->fsdriver =3D=3D VIR_DOMAIN_FS_DRIVER_TY= PE_DEFAULT) && - ctl->def->fss[i]->src) { - virDomainFSDef *fs =3D ctl->def->fss[i]; + virDomainFSDef *fs =3D ctl->def->fss[i]; + + if (fs->type =3D=3D VIR_DOMAIN_FS_TYPE_MOUNT && + (fs->fsdriver =3D=3D VIR_DOMAIN_FS_DRIVER_TYPE_PATH || + fs->fsdriver =3D=3D VIR_DOMAIN_FS_DRIVER_TYPE_DEFAULT) && + fs->src) { =20 /* We don't need to add deny rw rules for readonly mounts, * this can only lead to troubles when mounting / readonly. @@ -1122,22 +1137,24 @@ get_files(vahControl * ctl) } =20 for (i =3D 0; i < ctl->def->ninputs; i++) { - if (ctl->def->inputs[i] && - (ctl->def->inputs[i]->type =3D=3D VIR_DOMAIN_INPUT_TYPE_PA= SSTHROUGH || - ctl->def->inputs[i]->type =3D=3D VIR_DOMAIN_INPUT_TYPE_EV= DEV)) { + virDomainInputDef *input =3D ctl->def->inputs[i]; + + if (input->type =3D=3D VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH || + input->type =3D=3D VIR_DOMAIN_INPUT_TYPE_EVDEV) { if (vah_add_file(&buf, ctl->def->inputs[i]->source.evdev, "rw"= ) !=3D 0) goto cleanup; } } =20 for (i =3D 0; i < ctl->def->nnets; i++) { - if (ctl->def->nets[i] && - ctl->def->nets[i]->type =3D=3D VIR_DOMAIN_NET_TYPE_VHOSTUS= ER && - ctl->def->nets[i]->data.vhostuser) { + virDomainNetDef *net =3D ctl->def->nets[i]; + + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_VHOSTUSER && + net->data.vhostuser) { virDomainChrSourceDef *vhu =3D ctl->def->nets[i]->data.vhostus= er; =20 if (vah_add_file_chardev(&buf, vhu->data.nix.path, "rw", - vhu->type) !=3D 0) + vhu->type) !=3D 0) goto cleanup; } } @@ -1170,10 +1187,11 @@ get_files(vahControl * ctl) } =20 for (i =3D 0; i < ctl->def->nsysinfo; i++) { + virSysinfoDef *sysinfo =3D ctl->def->sysinfo[i]; size_t j; =20 - for (j =3D 0; j < ctl->def->sysinfo[i]->nfw_cfgs; j++) { - virSysinfoFWCfgDef *f =3D &ctl->def->sysinfo[i]->fw_cfgs[j]; + for (j =3D 0; j < sysinfo->nfw_cfgs; j++) { + virSysinfoFWCfgDef *f =3D &sysinfo->fw_cfgs[j]; =20 if (f->file && vah_add_file(&buf, f->file, "r") !=3D 0) @@ -1216,50 +1234,49 @@ get_files(vahControl * ctl) } =20 =20 - if (ctl->def->ntpms > 0) { + for (i =3D 0; i < ctl->def->ntpms; i++) { + virDomainTPMDef *tpm =3D ctl->def->tpms[i]; char *shortName =3D NULL; const char *tpmpath =3D NULL; =20 - for (i =3D 0; i < ctl->def->ntpms; i++) { - if (ctl->def->tpms[i]->type !=3D VIR_DOMAIN_TPM_TYPE_EMULATOR) - continue; - - shortName =3D virDomainDefGetShortName(ctl->def); - - switch (ctl->def->tpms[i]->data.emulator.version) { - case VIR_DOMAIN_TPM_VERSION_1_2: - tpmpath =3D "tpm1.2"; - break; - case VIR_DOMAIN_TPM_VERSION_2_0: - tpmpath =3D "tpm2"; - break; - case VIR_DOMAIN_TPM_VERSION_DEFAULT: - case VIR_DOMAIN_TPM_VERSION_LAST: - break; - } - - /* Unix socket for QEMU and swtpm to use */ - virBufferAsprintf(&buf, - " \"%s/libvirt/qemu/swtpm/%s-swtpm.sock\" rw,\n", - RUNSTATEDIR, shortName); - /* Paths for swtpm to use: give it access to its state - * directory (state files and fsync on dir), log, and PID file= s. - */ - virBufferAsprintf(&buf, - " \"%s/lib/libvirt/swtpm/%s/%s/\" r,\n", - LOCALSTATEDIR, uuidstr, tpmpath); - virBufferAsprintf(&buf, - " \"%s/lib/libvirt/swtpm/%s/%s/**\" rwk,\n", - LOCALSTATEDIR, uuidstr, tpmpath); - virBufferAsprintf(&buf, - " \"%s/log/swtpm/libvirt/qemu/%s-swtpm.log\" w,\n", - LOCALSTATEDIR, ctl->def->name); - virBufferAsprintf(&buf, - " \"%s/libvirt/qemu/swtpm/%s-swtpm.pid\" rw,\n", - RUNSTATEDIR, shortName); - - VIR_FREE(shortName); + if (tpm->type !=3D VIR_DOMAIN_TPM_TYPE_EMULATOR) + continue; + + shortName =3D virDomainDefGetShortName(ctl->def); + + switch (tpm->data.emulator.version) { + case VIR_DOMAIN_TPM_VERSION_1_2: + tpmpath =3D "tpm1.2"; + break; + case VIR_DOMAIN_TPM_VERSION_2_0: + tpmpath =3D "tpm2"; + break; + case VIR_DOMAIN_TPM_VERSION_DEFAULT: + case VIR_DOMAIN_TPM_VERSION_LAST: + break; } + + /* Unix socket for QEMU and swtpm to use */ + virBufferAsprintf(&buf, + " \"%s/libvirt/qemu/swtpm/%s-swtpm.sock\" rw,\n= ", + RUNSTATEDIR, shortName); + /* Paths for swtpm to use: give it access to its state + * directory (state files and fsync on dir), log, and PID files. + */ + virBufferAsprintf(&buf, + " \"%s/lib/libvirt/swtpm/%s/%s/\" r,\n", + LOCALSTATEDIR, uuidstr, tpmpath); + virBufferAsprintf(&buf, + " \"%s/lib/libvirt/swtpm/%s/%s/**\" rwk,\n", + LOCALSTATEDIR, uuidstr, tpmpath); + virBufferAsprintf(&buf, + " \"%s/log/swtpm/libvirt/qemu/%s-swtpm.log\" w,= \n", + LOCALSTATEDIR, ctl->def->name); + virBufferAsprintf(&buf, + " \"%s/libvirt/qemu/swtpm/%s-swtpm.pid\" rw,\n", + RUNSTATEDIR, shortName); + + VIR_FREE(shortName); } =20 for (i =3D 0; i < ctl->def->nsmartcards; i++) { --=20 2.49.0 From nobody Mon Sep 8 22:02:02 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=1749732768; cv=none; d=zohomail.com; s=zohoarc; b=OKcExiPhCFpGwZXN0UL0I/5FvBuNaAy/fgIOsywjs3EiFSX6gbkGsWdr+83xQrdZAD8XSzym0mcBbM41qXHsPuNDW5Ncl1Q8Hl78zWpPAONRevMFf3y+XI+DLFaM3dXHICTM+NOWeqaqltvRLM6QiYEBbNABf8lVDZT0QsDAn6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732768; 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=u0qMjHeKJrn8DvtjXXN1qu2SB/5FR0AkeKoMJrRohaQ=; b=KcJLGIGsb0k0QXBvtFwHns1Nl2MkIgNxlO9RVuDofA72JzCLxXjndSymFaMoczYVOwr2oLAroxxyRazSz1aquAHKy7Kwm4Y9Kj2PfoelHlfdIRc8q9ezSTSBUzqIxOzMCAiI6KLM5/J8uYhn+HCY678AhW+1goEeC/51rkLRSQk= 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 1749732767984223.0275535790521; Thu, 12 Jun 2025 05:52:47 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 0F2C011FA; Thu, 12 Jun 2025 08:52:46 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id BB8F91207; Thu, 12 Jun 2025 08:49:27 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 905F8E6B; Thu, 12 Jun 2025 08:49:22 -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 21B541325 for ; Thu, 12 Jun 2025 08:49:06 -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-636-LvTsnKScPqaMM-dj5gfVaw-1; Thu, 12 Jun 2025 08:49:04 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 B2BF8180028F for ; Thu, 12 Jun 2025 12:49:03 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 07159195609D for ; Thu, 12 Jun 2025 12:49:02 +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=1749732545; 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=HWe7jbOV6qvzrSwjGqVhGfHnFAWMnhyrb3cLd5upck4=; b=WdgJWwuUDJwsYxoAoEAQnZXOBgjMN211qnCFJFlGx2jPKjsX5P3m9HFDZ4a8vubMJXrUxe csd2vr1NDXhviryeo2VXOPmP3YmXhYZQMw3VFiNgPSo62MRlwJl0YV2TuJapbnemKwYQGu JpZ/VpWoPJ5FTDQ0DxyRmgp2PV+I/kM= X-MC-Unique: LvTsnKScPqaMM-dj5gfVaw-1 X-Mimecast-MFC-AGG-ID: LvTsnKScPqaMM-dj5gfVaw_1749732543 To: devel@lists.libvirt.org Subject: [PATCH 11/15] virt-aa-helper: Decrease scope of @mem_path in get_files() Date: Thu, 12 Jun 2025 14:48:43 +0200 Message-ID: <21a38deb6eda2aad4941c7a761d8fdd87a4721c4.1749732372.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: sTW25jUldj2YRpAFW4BLeFg6H5cY6ZxUWJQgS_yBVsE_1749732543 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: EHIHO7QELWQ5HKLIDGHLDPCQRJ4ABJTL X-Message-ID-Hash: EHIHO7QELWQ5HKLIDGHLDPCQRJ4ABJTL X-MailFrom: mprivozn@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: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732770871116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The @mem_path variable inside of get_files() is used only within a single block. Move its declaration inside it. And also utilize automatic memory freeing. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/security/virt-aa-helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 2fac65f108..64cada3b3b 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -866,7 +866,6 @@ get_files(vahControl * ctl) int rc =3D -1; size_t i; char *uuid; - char *mem_path =3D NULL; char uuidstr[VIR_UUID_STRING_BUFLEN]; bool needsVfio =3D false, needsvhost =3D false, needsgl =3D false; =20 @@ -1210,6 +1209,8 @@ get_files(vahControl * ctl) "rw") !=3D 0) goto cleanup; } else { + g_autofree char *mem_path =3D NULL; + switch (shmem->model) { case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_PLAIN: /* until exposed, recreate qemuBuildShmemBackendMemProps */ @@ -1361,7 +1362,6 @@ get_files(vahControl * ctl) ctl->files =3D virBufferContentAndReset(&buf); =20 cleanup: - VIR_FREE(mem_path); VIR_FREE(uuid); return rc; } --=20 2.49.0 From nobody Mon Sep 8 22:02:02 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=1749732785; cv=none; d=zohomail.com; s=zohoarc; b=X1Ovw8WxbCmnWs380ymZ+gpR9sf7aUifAEJJFaz64mbgGn6X4EAvmZuCGfRqaFyOLG8IDWZZQ8/B6XqcnD79ZcF1J9tTah/Yn0OwSTg0x0/V4XwbWF9Xb8kc4PPZobuexzeSDIda7Olx1Wf1T0FwtcpfrVCXuOtUYh+7Wh3TmiE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732785; 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=xajBM2uKU3BmaHhxbbD8ciyvWMvas1HDlq0N1UNEPps=; b=fQ7olyAHSNYq8viBBIQMzo6v9FmGvinA/ytBYNCSTRj/p6fsdK88tE+7q9CCfctyrS9fHz4qkeywvnqp+0atGnT9yAhmso2jghX7zIPX7+e33TPgPQdY5Iiw0ZXGGQnUdRv9e0j3g/W7Y5hhCyguhiQXV2gZzTO2Y5DyLuYY3Y0= 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 1749732785726280.46968115761; Thu, 12 Jun 2025 05:53:05 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B73D614B5; Thu, 12 Jun 2025 08:53:04 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8DDF213D8; Thu, 12 Jun 2025 08:49:29 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D6E7411AA; Thu, 12 Jun 2025 08:49:22 -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 01FE1D95 for ; Thu, 12 Jun 2025 08:49:06 -0400 (EDT) Received: from mx-prod-mc-01.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-670-K_uBM-_AMsaAzMSkTNA8Tg-1; Thu, 12 Jun 2025 08:49:05 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CCAD41956096 for ; Thu, 12 Jun 2025 12:49:04 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 23D6C195609D for ; Thu, 12 Jun 2025 12:49:03 +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=1749732546; 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=vA2y6vdvINjppdmXztSHww9Gv/Ba9vqV6kziOu1HHnc=; b=GUIZkYoxSmfPUD9Xa8I/tPIlUakSLGXnvoE9+NFO95Z5mE62ecXncEB0Ilmr2n3rDhKrbM QdEOqORc+YBrIOp01xjPqTW2Bd9Wyf2osFJs245DjO2T1dt1FRnIDdpe6Hc5zA659ocBHw FOb5aiY70lnYj2kzGsBjRMqJEr3vkI0= X-MC-Unique: K_uBM-_AMsaAzMSkTNA8Tg-1 X-Mimecast-MFC-AGG-ID: K_uBM-_AMsaAzMSkTNA8Tg_1749732544 To: devel@lists.libvirt.org Subject: [PATCH 12/15] virt-aa-helper: Use automatic memory freeing Date: Thu, 12 Jun 2025 14:48:44 +0200 Message-ID: <0ed6ee7a0120a0d6cfd90dc060aa56b7ae7e267a.1749732372.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: pCFFSSNesFAzBr2e9QC5hSlUh8H1tpulG38NOog2Wxc_1749732544 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: HFGG4T2ERBADC6DRTBB5UEZA75FVVBAG X-Message-ID-Hash: HFGG4T2ERBADC6DRTBB5UEZA75FVVBAG X-MailFrom: mprivozn@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: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732787229116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/security/virt-aa-helper.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 64cada3b3b..2ea4b47fa5 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -865,7 +865,7 @@ get_files(vahControl * ctl) g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; int rc =3D -1; size_t i; - char *uuid; + g_autofree char *uuid =3D NULL; char uuidstr[VIR_UUID_STRING_BUFLEN]; bool needsVfio =3D false, needsvhost =3D false, needsgl =3D false; =20 @@ -1026,12 +1026,11 @@ get_files(vahControl * ctl) needsgl =3D true; } else { if (virDomainGraphicsNeedsAutoRenderNode(graphics)) { - char *defaultRenderNode =3D virHostGetDRMRenderNode(); + g_autofree char *defaultRenderNode =3D virHostGetDRMRender= Node(); needsgl =3D true; =20 if (defaultRenderNode) { vah_add_file(&buf, defaultRenderNode, "rw"); - VIR_FREE(defaultRenderNode); } } } @@ -1237,7 +1236,7 @@ get_files(vahControl * ctl) =20 for (i =3D 0; i < ctl->def->ntpms; i++) { virDomainTPMDef *tpm =3D ctl->def->tpms[i]; - char *shortName =3D NULL; + g_autofree char *shortName =3D NULL; const char *tpmpath =3D NULL; =20 if (tpm->type !=3D VIR_DOMAIN_TPM_TYPE_EMULATOR) @@ -1276,8 +1275,6 @@ get_files(vahControl * ctl) virBufferAsprintf(&buf, " \"%s/libvirt/qemu/swtpm/%s-swtpm.pid\" rw,\n", RUNSTATEDIR, shortName); - - VIR_FREE(shortName); } =20 for (i =3D 0; i < ctl->def->nsmartcards; i++) { @@ -1362,7 +1359,6 @@ get_files(vahControl * ctl) ctl->files =3D virBufferContentAndReset(&buf); =20 cleanup: - VIR_FREE(uuid); return rc; } =20 @@ -1438,15 +1434,13 @@ vahParseArgv(vahControl * ctl, int argc, char **arg= v) } =20 if (ctl->cmd =3D=3D 'c' || ctl->cmd =3D=3D 'r') { - char *xmlStr =3D NULL; + g_autofree char *xmlStr =3D NULL; if (virFileReadLimFD(STDIN_FILENO, MAX_FILE_LEN, &xmlStr) < 0) vah_error(ctl, 1, _("could not read xml file")); =20 if (get_definition(ctl, xmlStr) !=3D 0 || ctl->def =3D=3D NULL) { - VIR_FREE(xmlStr); vah_error(ctl, 1, _("could not get VM definition")); } - VIR_FREE(xmlStr); =20 if (get_files(ctl) !=3D 0) vah_error(ctl, 1, _("invalid VM definition")); --=20 2.49.0 From nobody Mon Sep 8 22:02:02 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=1749732852; cv=none; d=zohomail.com; s=zohoarc; b=A/uT1D6Etcld7gIN2oRGosuw5MPpIQ5Sk17bxVxFWnv6rPTKbRzQbXQgvwXE2U2P86CQiRSkT+qsWWgazb7wK1uaf1tnmxPk6QuRRjijiNW4DKYjyMXEZGuZRppFx6EOaGXt8l7t2oE2BJdhgHEvnaMzA7p/ftRz9ILxkRFuCiQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732852; 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=2i7Vndfduh806utcCGA5wBEXCS3Wf/oo9nnIIZOGIw0=; b=UCJaXgl3xNt5BlrpoWDIgHbExMsJvl39qDc/XcJ9StnLnlJI2uImZcoDOLEWUl/+KK0dPjqJ+2coPL9m1eh765aHp57t8Odko1Kp8GnYhQlQtXHI0gb1yM4u9/Kg2OsK2JOfPVWOF5gkpLVrbdw+b3KsTHk2a/HlvLNbHrMPNRo= 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 1749732852506529.6292449241279; Thu, 12 Jun 2025 05:54:12 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 69D801431; Thu, 12 Jun 2025 08:54:11 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D85D31401; Thu, 12 Jun 2025 08:49:33 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 6DAD8E3D; Thu, 12 Jun 2025 08:49:26 -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 86AB7D63 for ; Thu, 12 Jun 2025 08:49:08 -0400 (EDT) Received: from mx-prod-mc-04.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-626-CK2YIxYbNIqihXD8OB4F8A-1; Thu, 12 Jun 2025 08:49:06 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EA42319560AA for ; Thu, 12 Jun 2025 12:49:05 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4094B19560A3 for ; Thu, 12 Jun 2025 12:49:05 +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=1749732548; 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=yfgGEM0fhbAfW9w49tGDgQxK8PUb9p2b/E/UdS/1Xq8=; b=HAJYdc3D1JR0qa7RNY2v+L/FdOKbjIFYQJwe+IBN1ZLKD8shmO+F8E1l2cj24kRxKCMCIq IJvs0HudO3VvXbbGrr/CLaXBrHQPtFF/yBxIl7Aqc7l/9noJ1EzE2HNMytmvsopbx6fzS2 mdLbjIcL/GGrlWAWIGbZ8YYV3lMEYG8= X-MC-Unique: CK2YIxYbNIqihXD8OB4F8A-1 X-Mimecast-MFC-AGG-ID: CK2YIxYbNIqihXD8OB4F8A_1749732546 To: devel@lists.libvirt.org Subject: [PATCH 13/15] virt-aa-helper: Check retval of vah_add_file() Date: Thu, 12 Jun 2025 14:48:45 +0200 Message-ID: <3f0dfb3d3bf221d0f479549cad686e7ed621c390.1749732372.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: i3uNwYjIU6dytguG1CtIALUZy6fUeFu1Q3ARTV90aS4_1749732546 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: UJJS2HSLCVFNMQRMISRI6JR23ALVFIRP X-Message-ID-Hash: UJJS2HSLCVFNMQRMISRI6JR23ALVFIRP X-MailFrom: mprivozn@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: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732854248116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik Inside of get_files() there are two cases where vah_add_file() is not checked for its retval. This is possibly dangerous, because vah_add_file() might fail. Fix those places by introducing checks for the retval. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/security/virt-aa-helper.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 2ea4b47fa5..7748a0d19b 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1022,15 +1022,17 @@ get_files(vahControl * ctl) const char *rendernode =3D virDomainGraphicsGetRenderNode(graphics= ); =20 if (rendernode) { - vah_add_file(&buf, rendernode, "rw"); + if (vah_add_file(&buf, rendernode, "rw") !=3D 0) + goto cleanup; needsgl =3D true; } else { if (virDomainGraphicsNeedsAutoRenderNode(graphics)) { g_autofree char *defaultRenderNode =3D virHostGetDRMRender= Node(); needsgl =3D true; =20 - if (defaultRenderNode) { - vah_add_file(&buf, defaultRenderNode, "rw"); + if (defaultRenderNode && + vah_add_file(&buf, defaultRenderNode, "rw") !=3D 0) { + goto cleanup; } } } --=20 2.49.0 From nobody Mon Sep 8 22:02:02 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=1749732911; cv=none; d=zohomail.com; s=zohoarc; b=cqM6DpUUwNWpVQ0D9RdWbnoG2Ap5UQfeYjNXAixIDQRb7v4IfouZSqhieJUakHdUDGMPS9cXzMj9kx/jumcKfuyub1Ume5ip+S2k3vhz47ROAN/Mlp1JzD0/wRADuYUUdLKOpXEMUmLo1EPox1I9cALPSyBaaysCWwGQbmoqIyU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732911; 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=2fsncybPk9+KjL7+K8DXlUUOKC9meDNlDIPZMflhhZU=; b=A7IaSviL8fNiWGfTs0MR1Vbj5DUUXSWf2uTZjIm3hJCpciLalzEtiwqBLN0wdj8mVEzsV8BHFsHaj1q10r0qgLik/4NHdgB5655Qbs7I+z6/Y03EjpltYIu+QRSvXVMugEDfVMGGk09h+Mjcx5lVeQR+7ZtJBf5+mJ5K8Ky+TD0= 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 17497329112095.961650074639692; Thu, 12 Jun 2025 05:55:11 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 291C91281; Thu, 12 Jun 2025 08:55:10 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E962210F4; Thu, 12 Jun 2025 08:49:39 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C1E55E76; Thu, 12 Jun 2025 08:49:28 -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 AED60E76 for ; Thu, 12 Jun 2025 08:49:09 -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-209-H538btBXOs6kzeMuO2wsDA-1; Thu, 12 Jun 2025 08:49:07 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 14D7B180028E for ; Thu, 12 Jun 2025 12:49:07 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5D47719560A3 for ; Thu, 12 Jun 2025 12:49:06 +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=1749732549; 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=r74RNd3hS4OoZ8AmlnbVXWUZscxkipHGZ2akleFfTac=; b=Ka4Zcj4GrpeJfA51ZPP6Qs+5Hc89zgE8emAby648S1/LnidtXfnfV6937VgVSethUSco38 agb8zBcSG+Ih2bRm96lYiCwz7ONhMy7Ei37ehmhamyDqakgI0cA60/MNK/NBrXM9QuSQkC IkZ/V3Q+/bA97mWX0d3HbTRjvqkhomI= X-MC-Unique: H538btBXOs6kzeMuO2wsDA-1 X-Mimecast-MFC-AGG-ID: H538btBXOs6kzeMuO2wsDA_1749732547 To: devel@lists.libvirt.org Subject: [PATCH 14/15] virt-aa-helper: Drop cleanup label from get_files() Date: Thu, 12 Jun 2025 14:48:46 +0200 Message-ID: <3b3d8ce8a2b3c46098e1e2aa0485a77c66746325.1749732372.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: G_QnP0Uwd3CdPpEr7x2njQi7n9eWeFhE8z8V9oXXH8c_1749732547 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: TKIQVWTXNUCT2VTR5ZPFRT263L275TBA X-Message-ID-Hash: TKIQVWTXNUCT2VTR5ZPFRT263L275TBA X-MailFrom: mprivozn@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: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732912841116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik After previous cleanup the cleanup label is no longer necessary. Drop it. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/security/virt-aa-helper.c | 120 ++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 58 deletions(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 7748a0d19b..b662d971cb 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -863,7 +863,7 @@ static int get_files(vahControl * ctl) { g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - int rc =3D -1; + int rc; size_t i; g_autofree char *uuid =3D NULL; char uuidstr[VIR_UUID_STRING_BUFLEN]; @@ -875,7 +875,7 @@ get_files(vahControl * ctl) =20 if (STRNEQ(uuid, ctl->uuid)) { vah_error(ctl, 0, _("given uuid does not match XML uuid")); - goto cleanup; + return -1; } =20 /* load the storage driver so that backing store can be accessed */ @@ -900,7 +900,7 @@ get_files(vahControl * ctl) /* XXX should handle open errors more careful than just ignoring = them. */ if (storage_source_add_files(disk->src, &buf, 0) < 0) - goto cleanup; + return -1; } =20 for (i =3D 0; i < ctl->def->nserials; i++) { @@ -917,7 +917,7 @@ get_files(vahControl * ctl) chr->source->data.file.path, "rw", chr->source->type) !=3D 0) { - goto cleanup; + return -1; } } } @@ -934,7 +934,7 @@ get_files(vahControl * ctl) chr->source->data.file.path[0] !=3D '\0') { if (vah_add_file(&buf, chr->source->data.file.path, "rw") !=3D 0) { - goto cleanup; + return -1; } } } @@ -953,7 +953,7 @@ get_files(vahControl * ctl) chr->source->data.file.path, "rw", chr->source->type) !=3D 0) { - goto cleanup; + return -1; } } } @@ -972,48 +972,54 @@ get_files(vahControl * ctl) chr->source->data.file.path, "rw", chr->source->type) !=3D 0) { - goto cleanup; + return -1; } } } =20 - if (ctl->def->os.kernel) - if (vah_add_file(&buf, ctl->def->os.kernel, "r") !=3D 0) - goto cleanup; + if (ctl->def->os.kernel && + vah_add_file(&buf, ctl->def->os.kernel, "r") !=3D 0) { + return -1; + } =20 - if (ctl->def->os.initrd) - if (vah_add_file(&buf, ctl->def->os.initrd, "r") !=3D 0) - goto cleanup; + if (ctl->def->os.initrd && + vah_add_file(&buf, ctl->def->os.initrd, "r") !=3D 0) { + return -1; + } =20 - if (ctl->def->os.shim) - if (vah_add_file(&buf, ctl->def->os.shim, "r") !=3D 0) - goto cleanup; + if (ctl->def->os.shim && + vah_add_file(&buf, ctl->def->os.shim, "r") !=3D 0) { + return -1; + } =20 - if (ctl->def->os.dtb) - if (vah_add_file(&buf, ctl->def->os.dtb, "r") !=3D 0) - goto cleanup; + if (ctl->def->os.dtb && + vah_add_file(&buf, ctl->def->os.dtb, "r") !=3D 0) { + return -1; + } =20 for (i =3D 0; i < ctl->def->os.nacpiTables; i++) { if (vah_add_file(&buf, ctl->def->os.acpiTables[i]->path, "r") !=3D= 0) - goto cleanup; + return -1; } =20 - if (ctl->def->pstore) - if (vah_add_file(&buf, ctl->def->pstore->path, "rw") !=3D 0) - goto cleanup; + if (ctl->def->pstore && + vah_add_file(&buf, ctl->def->pstore->path, "rw") !=3D 0) { + return -1; + } =20 if (ctl->def->os.loader && ctl->def->os.loader->path) { bool readonly =3D false; virTristateBoolToBool(ctl->def->os.loader->readonly, &readonly); if (vah_add_file(&buf, ctl->def->os.loader->path, - readonly ? "rk" : "rwk") !=3D 0) - goto cleanup; + readonly ? "rk" : "rwk") !=3D 0) { + return -1; + } } =20 - if (ctl->def->os.loader && ctl->def->os.loader->nvram) { - if (storage_source_add_files(ctl->def->os.loader->nvram, &buf, 0) = < 0) - goto cleanup; + if (ctl->def->os.loader && ctl->def->os.loader->nvram && + storage_source_add_files(ctl->def->os.loader->nvram, &buf, 0) < 0)= { + return -1; } =20 for (i =3D 0; i < ctl->def->ngraphics; i++) { @@ -1023,7 +1029,7 @@ get_files(vahControl * ctl) =20 if (rendernode) { if (vah_add_file(&buf, rendernode, "rw") !=3D 0) - goto cleanup; + return -1; needsgl =3D true; } else { if (virDomainGraphicsNeedsAutoRenderNode(graphics)) { @@ -1032,7 +1038,7 @@ get_files(vahControl * ctl) =20 if (defaultRenderNode && vah_add_file(&buf, defaultRenderNode, "rw") !=3D 0) { - goto cleanup; + return -1; } } } @@ -1043,15 +1049,15 @@ get_files(vahControl * ctl) if (listenObj.type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCK= ET && listenObj.socket && vah_add_file(&buf, listenObj.socket, "rw")) - goto cleanup; + return -1; } } =20 if (ctl->def->ngraphics =3D=3D 1 && - ctl->def->graphics[0]->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_SDL) - if (vah_add_file(&buf, ctl->def->graphics[0]->data.sdl.xauth, - "r") !=3D 0) - goto cleanup; + ctl->def->graphics[0]->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_SDL && + vah_add_file(&buf, ctl->def->graphics[0]->data.sdl.xauth, "r") != =3D 0) { + return -1; + } =20 for (i =3D 0; i < ctl->def->nhostdevs; i++) { virDomainHostdevDef *dev =3D ctl->def->hostdevs[i]; @@ -1071,7 +1077,7 @@ get_files(vahControl * ctl) =20 rc =3D virUSBDeviceFileIterate(usb, file_iterate_hostdev_cb, &= buf); if (rc !=3D 0) - goto cleanup; + return -1; break; } =20 @@ -1132,7 +1138,7 @@ get_files(vahControl * ctl) * this can only lead to troubles when mounting / readonly. */ if (vah_add_path(&buf, fs->src->path, fs->readonly ? "R" : "rw= l", true) !=3D 0) - goto cleanup; + return -1; } } =20 @@ -1142,7 +1148,7 @@ get_files(vahControl * ctl) if (input->type =3D=3D VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH || input->type =3D=3D VIR_DOMAIN_INPUT_TYPE_EVDEV) { if (vah_add_file(&buf, ctl->def->inputs[i]->source.evdev, "rw"= ) !=3D 0) - goto cleanup; + return -1; } } =20 @@ -1155,7 +1161,7 @@ get_files(vahControl * ctl) =20 if (vah_add_file_chardev(&buf, vhu->data.nix.path, "rw", vhu->type) !=3D 0) - goto cleanup; + return -1; } } =20 @@ -1165,16 +1171,16 @@ get_files(vahControl * ctl) switch (mem->model) { case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: if (vah_add_file(&buf, mem->source.nvdimm.path, "rw") !=3D 0) - goto cleanup; + return -1; break; case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: if (vah_add_file(&buf, mem->source.virtio_pmem.path, "rw") != =3D 0) - goto cleanup; + return -1; break; case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC: if (vah_add_file(&buf, DEV_SGX_VEPC, "rw") !=3D 0 || vah_add_file(&buf, DEV_SGX_PROVISION, "r") !=3D 0) { - goto cleanup; + return -1; } break; =20 @@ -1195,7 +1201,7 @@ get_files(vahControl * ctl) =20 if (f->file && vah_add_file(&buf, f->file, "r") !=3D 0) - goto cleanup; + return -1; } } =20 @@ -1206,9 +1212,9 @@ get_files(vahControl * ctl) * model dependent defaults. */ if (shmem->server.enabled && shmem->server.chr->data.nix.path) { - if (vah_add_file(&buf, shmem->server.chr->data.nix.path, - "rw") !=3D 0) - goto cleanup; + if (vah_add_file(&buf, shmem->server.chr->data.nix.path, + "rw") !=3D 0) + return -1; } else { g_autofree char *mem_path =3D NULL; =20 @@ -1219,18 +1225,18 @@ get_files(vahControl * ctl) break; case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_DOORBELL: case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM: - /* until exposed, recreate qemuDomainPrepareShmemChardev = */ + /* until exposed, recreate qemuDomainPrepareShmemChardev */ mem_path =3D g_strdup_printf("/var/lib/libvirt/shmem-%s-so= ck", - shmem->name); + shmem->name); break; case VIR_DOMAIN_SHMEM_MODEL_LAST: virReportEnumRangeError(virDomainShmemModel, shmem->model); break; } - if (mem_path !=3D NULL) { - if (vah_add_file(&buf, mem_path, "rw") !=3D 0) - goto cleanup; + if (mem_path !=3D NULL && + vah_add_file(&buf, mem_path, "rw") !=3D 0) { + return -1; } } } @@ -1353,15 +1359,13 @@ get_files(vahControl * ctl) virBufferAddLit(&buf, " deny \"/var/lib/libvirt/.cache/\" w,\n"); } =20 - if (ctl->newfile) - if (vah_add_file(&buf, ctl->newfile, "rwk") !=3D 0) - goto cleanup; + if (ctl->newfile && + vah_add_file(&buf, ctl->newfile, "rwk") !=3D 0) { + return -1; + } =20 - rc =3D 0; ctl->files =3D virBufferContentAndReset(&buf); - - cleanup: - return rc; + return 0; } =20 static int --=20 2.49.0 From nobody Mon Sep 8 22:02:02 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=1749732880; cv=none; d=zohomail.com; s=zohoarc; b=cn9TtTmf9yZhIMRQrGXZXL7p7Bk2GsngOfrocAZ+iX5+u63JKYAQ7MLI3RyNAS5YbQxFdTwlLnH0oD/rpGMIfCm4kltdaNWnZTctV++JvkmHE6GCfJmL56HioYW0TRmds4xfL3k/bke+OAkezMxymTPlxgxXGTaH85ulaLgBdfw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732880; 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=x7D/s+M2U3Cu9J0kAZCyg8vaOdIsQtVEqha9XqsZuTM=; b=WL1nLLNvrfOwvhMfL5/GRCRGi9Tqjo9inn1JDZHcG4UFOgxeNuNoCNdSJfIutKaFP6Pe3cXRGZHr2DXRqGB2h3w2gXKIoAEMjKnyss4zfDs69pkGPBJO+80FM/fKWFK2+/AItkivJ4P0PC32/0nkITvsicIOgO4jrcpyLT0zTfA= 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 1749732880882503.4957826894489; Thu, 12 Jun 2025 05:54:40 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id CC41911EB; Thu, 12 Jun 2025 08:54:39 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id B3B1C139C; Thu, 12 Jun 2025 08:49:37 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 810DBE01; Thu, 12 Jun 2025 08:49:28 -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 7DA6E1388 for ; Thu, 12 Jun 2025 08:49:10 -0400 (EDT) Received: from mx-prod-mc-08.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-27-0OaKs0vlNqCXTB3TotwO5w-1; Thu, 12 Jun 2025 08:49:09 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2E708180047F for ; Thu, 12 Jun 2025 12:49:08 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 798AA195609D for ; Thu, 12 Jun 2025 12:49:07 +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=1749732550; 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=0xzYaehpxmURKTx/cJnm0NUPL15k1bLL0gJ+9/a0yfg=; b=Nr2hSpoF6YZKjB8ankM2Zbk6PWKNUt8EWb9lQeWv+Tmtqp3rNwt7/gArzE6gINs5sB99Bx VKzjokGAzj7F9BAPAMHPNyimpu8L/aOCaiY5PGs3wa2D8TzL2U+5HU8xxWMhVdK+qgz0I0 XCD94DFCC9Qg19b78ALGtbctCU73Jdw= X-MC-Unique: 0OaKs0vlNqCXTB3TotwO5w-1 X-Mimecast-MFC-AGG-ID: 0OaKs0vlNqCXTB3TotwO5w_1749732548 To: devel@lists.libvirt.org Subject: [PATCH 15/15] virt-aa-helper-test: Switch to getopts Date: Thu, 12 Jun 2025 14:48:47 +0200 Message-ID: <60d54b728efde27c0715743c4c82a4cb0f295a14.1749732372.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: wKtgSrs2kO2fG_Zz-vAxF0dV0gcMMfXd1BCQjltYeog_1749732548 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: EWLAAJLSQIA5GKPZSKTMXGWRRKQXHBDG X-Message-ID-Hash: EWLAAJLSQIA5GKPZSKTMXGWRRKQXHBDG X-MailFrom: mprivozn@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: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732882267116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik Instead of treating -d and -v arguments as positional, use getopts to parse cmd line arguments passed to virt-aa-helper-test script. While at it, introduce -h for printing basic help describing each argument. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tests/virt-aa-helper-test | 49 ++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/tests/virt-aa-helper-test b/tests/virt-aa-helper-test index c0b8c1bafe..f8df901d4f 100755 --- a/tests/virt-aa-helper-test +++ b/tests/virt-aa-helper-test @@ -10,21 +10,42 @@ set -e output=3D"/dev/null" use_valgrind=3D"" ld_library_path=3D"$abs_top_builddir/tests/:$abs_top_builddir/src/" -if [ ! -z "$1" ] && [ "$1" =3D "-d" ]; then - output=3D"/dev/stdout" - shift -fi - exe=3D"$abs_top_builddir/src/virt-aa-helper" -if [ ! -z "$1" ]; then - if [ "$1" =3D "-v" ]; then - use_valgrind=3D"yes" - shift - fi - if [ -n "$1" ]; then - exe=3D"$1" - shift - fi + +usage() { + script=3D`basename $1` + echo "$script: [OPTIONS] [EXE]" + echo " OPTIONS:" + echo " -d print debug onto stdout" + echo " -h print this help" + echo " -v to wrap virt-aa-helper invocation into valgrind" + echo " EXE use specified virt-aa-helper" +} + +while getopts "dhv" opt; do + case ${opt} in + d) + output=3D"/dev/stdout" + ;; + v) + use_valgrind=3D"yes" + ;; + h) + usage $0 + exit 0 + ;; + ?) + usage $0 + exit 1 + ;; + esac +done + + +shift $((OPTIND - 1)) +if [ -n "$1" ]; then + exe=3D"$1" + shift fi =20 if [ ! -x "$exe" ]; then --=20 2.49.0