From nobody Mon Sep 8 17:08:19 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 1740405028231284.46206540873254; Mon, 24 Feb 2025 05:50:28 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 1738F14D0; Mon, 24 Feb 2025 08:50:27 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C17431B2C; Mon, 24 Feb 2025 08:50:09 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 26CEB1A61; Mon, 24 Feb 2025 08:50:06 -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 0E59914D0 for ; Mon, 24 Feb 2025 08:50:05 -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-587-XQMd_3ezNaWjiqZooZ2iNg-1; Mon, 24 Feb 2025 08:50:03 -0500 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7B2BF19783BC for ; Mon, 24 Feb 2025 13:50:02 +0000 (UTC) Received: from orkuz (unknown [10.43.3.115]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0A98119560AA for ; Mon, 24 Feb 2025 13:50: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, 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=1740405004; 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=WmvS+BadfbfXiP8yDdJ6MLBkaEjsxTngOPIWK7+lCpo=; b=EtyCwxlsC5QyVtgyFFP3f9UKmX3w6Jxl7iWjuzzt1tMHK4SBQBSpEqwvA+WqFtF4fTDrCt x6tM7UkyL04ou+PGgObvCVvSuF47JGMc9ZzpTd4mS9EEJ36ovAqHviddPBceVlO4mm5mEP J/DSKEIJTXT9vHEYkzpBfkh5DakkYBk= X-MC-Unique: XQMd_3ezNaWjiqZooZ2iNg-1 X-Mimecast-MFC-AGG-ID: XQMd_3ezNaWjiqZooZ2iNg_1740405002 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [PATCH] run: Use correct SELinux context for modular daemons Date: Mon, 24 Feb 2025 14:49:59 +0100 Message-ID: <211b760d6b4fd904f9e1f8643dfbb655589a0194.1740404999.git.jdenemar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Cpkc898AClgfrYcZ8BEQAVBXZFXKi5WZXHEWvNKxn18_1740405002 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: CH73MBC6WVAUYCSBWYW4GYVFT7OLQJ4F X-Message-ID-Hash: CH73MBC6WVAUYCSBWYW4GYVFT7OLQJ4F X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1740405030394019100 Content-Type: text/plain; charset="utf-8" Only libvirtd uses virtd_t/virt_exec_t context, modular daemons use their specific context each. Signed-off-by: Jiri Denemark Reviewed-by: Michal Privoznik --- run.in | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/run.in b/run.in index 2821b71230..d8db7cf697 100644 --- a/run.in +++ b/run.in @@ -202,10 +202,11 @@ else: stopped_units.append(unit) =20 if opts.selinux: + progname =3D os.path.basename(prog) # if using a wrapper command like 'gdb', setting the selinux # context won't work because the wrapper command will not be a # valid entrypoint for the virtd_t context - if os.path.basename(prog) not in ["libvirtd", *modular_daemons= ]: + if progname not in ["libvirtd", *modular_daemons]: raise Exception("'{}' is not recognized as a valid daemon.= " "Selinux process context can only be set w= hen " "executing a daemon directly without wrapp= er " @@ -216,17 +217,22 @@ else: "'{}' outside build directory" .format(progpath)) =20 + if progname =3D=3D "libvirtd": + context =3D "virtd" + else: + context =3D progname + # selinux won't allow us to transition to the virtd_t context = from # e.g. the user_home_t context (the likely label of the local # executable file) - if not chcon(progpath, "system_u", "object_r", "virtd_exec_t"): + if not chcon(progpath, "system_u", "object_r", f"{context}_exe= c_t"): raise Exception("Failed to change selinux context of binar= y") dorestorecon =3D True =20 args =3D ['runcon', '-u', 'system_u', '-r', 'system_r', - '-t', 'virtd_t', *args] + '-t', f'{context}_t', *args] =20 print("Running '%s'..." % str(" ".join(args))) ret =3D subprocess.call(args, env=3Denv) --=20 2.48.1