From nobody Wed Mar 12 13:40:55 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 174057199954517.565743628049404; Wed, 26 Feb 2025 04:13:19 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4CDB51625; Wed, 26 Feb 2025 07:13:18 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id B942A1526; Wed, 26 Feb 2025 07:12:57 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id B871D151E; Wed, 26 Feb 2025 07:12:54 -0500 (EST) 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 1D4BC1521 for ; Wed, 26 Feb 2025 07:12:54 -0500 (EST) 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-551-5Ay1BPo6OFKFOOFzW2RQNA-1; Wed, 26 Feb 2025 07:12:52 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DD7B919373DC for ; Wed, 26 Feb 2025 12:12:51 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.3.236]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3808A300018D for ; Wed, 26 Feb 2025 12:12:50 +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, HEADER_FROM_DIFFERENT_DOMAINS,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=1740571973; 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; bh=vgcvaf9BLiQqZOixs19nCEkI9DrsBnqBKyiinhSnDG8=; b=XliaNtneUtPKfWchXpCn0hoCbA+mUbAUky09C26k/inrTm8+ysyjhFQY/s3NExEHB+OF7j iFd8IV4upW/ijXed7Wzq0l3OGcG2GW37GNXG1uxzYgEqKrnwhYlEy3BY1JulaN+1hFr4VR u401a0qfbKM7oB0og57Fox56Afz827s= X-MC-Unique: 5Ay1BPo6OFKFOOFzW2RQNA-1 X-Mimecast-MFC-AGG-ID: 5Ay1BPo6OFKFOOFzW2RQNA_1740571972 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH] virt-aa-helper: Avoid using RUNSTATEDIR Date: Wed, 26 Feb 2025 13:12:47 +0100 Message-ID: <9ff32eeb1cde0c760117e452c02b62cb81783fb8.1740571967.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: KXYNSw44gWvG7F6FH5PklLRWlYuNlbha6jSWdH4bdzY_1740571972 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: RTL4QWDH5PH2AQUSES32Y4AANCMSDHZR X-Message-ID-Hash: RTL4QWDH5PH2AQUSES32Y4AANCMSDHZR 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: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1740572001379019100 Content-Type: text/plain; charset="utf-8"; x-default="true" On some systems /run is mounted as: tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=3D348508k,= mode=3D755,inode64) and /var/run is then just a symlink: # ls -ld /var/run lrwxrwxrwx 1 root root 4 Apr 23 2024 /var/run -> /run But because we still think it's 2004 and FHS 2.3 is active we have a rule in our meson.build which constructs RUNSTATEDIR as the following: runstatedir =3D get_option('runstatedir') if runstatedir =3D=3D '' runstatedir =3D localstatedir / 'run' endif which (if unspecified on meson setup line) results in "/var/run". This in turn means, when when we're generating an AppArmor profile for a domain with allowed paths it contains stuff like: /var/run/libvirt/qemu/swtpm/2-guest-swtpm.sock But because of the aforementioned symlink the real path is: /run/libvirt/qemu/swtpm/2-guest-swtpm.sock and thus AppArmor denies access: audit: type=3D1400 audit(1740480419.348:415): apparmor=3D"DENIED" operati= on=3D"connect" class=3D"file" profile=3D"libvirt-126f2720-6f8e-45ab-a886-ec= 9277079a67" name=3D"/run/libvirt/qemu/swtpm/2-guest-swtpm.sock" pid=3D8080 = comm=3D"qemu-system-x86" requested_mask=3D"wr" denied_mask=3D"wr" fsuid=3D6= 4055 ouid=3D64055 Fortunately, there's a nice trick: AppArmor profile variables. We already use some of them (@{PROC}, @{HOME}, @{multiarch}) and instead of RUNSTATEDIR we can use @{run} which is declared as: # cat /etc/apparmor.d/tunables/run @{run}=3D/run/ /var/run/ and thus covers both scenarios. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/security/virt-aa-helper.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index c255b64f35..eabc29e9cf 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1238,8 +1238,8 @@ get_files(vahControl * ctl) =20 /* Unix socket for QEMU and swtpm to use */ virBufferAsprintf(&buf, - " \"%s/libvirt/qemu/swtpm/%s-swtpm.sock\" rw,\n", - RUNSTATEDIR, shortName); + " \"@{run}/libvirt/qemu/swtpm/%s-swtpm.sock\" rw,\n", + shortName); /* Paths for swtpm to use: give it access to its state * directory (state files and fsync on dir), log, and PID file= s. */ @@ -1253,8 +1253,8 @@ get_files(vahControl * ctl) " \"%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); + " \"@{run}/libvirt/qemu/swtpm/%s-swtpm.pid\" rw,\n", + shortName); =20 VIR_FREE(shortName); } @@ -1528,10 +1528,10 @@ main(int argc, char **argv) LOCALSTATEDIR, ctl->def->name); virBufferAsprintf(&buf, " \"%s/lib/libvirt/qemu/domain-%d= -%.*s/*\" rw,\n", LOCALSTATEDIR, ctl->def->id, 20, ctl->de= f->name); - virBufferAsprintf(&buf, " \"%s/libvirt/**/%s.pid\" rwk,\n= ", - RUNSTATEDIR, ctl->def->name); - virBufferAsprintf(&buf, " \"%s/libvirt/**/*.tunnelmigrate= .dest.%s\" rw,\n", - RUNSTATEDIR, ctl->def->name); + virBufferAsprintf(&buf, " \"@{run}/libvirt/**/%s.pid\" rw= k,\n", + ctl->def->name); + virBufferAsprintf(&buf, " \"@{run}/libvirt/**/*.tunnelmig= rate.dest.%s\" rw,\n", + ctl->def->name); } if (ctl->files) virBufferAdd(&buf, ctl->files, -1); --=20 2.45.3