From nobody Sat May 11 09:35:41 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=quarantine dis=quarantine) header.from=suse.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1709940575892377.09049292077304; Fri, 8 Mar 2024 15:29:35 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 1A0381C94; Fri, 8 Mar 2024 18:29:04 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 771F0178C; Fri, 8 Mar 2024 18:27:06 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0B0971997; Fri, 8 Mar 2024 18:26:59 -0500 (EST) Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (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 9ECFF1997 for ; Fri, 8 Mar 2024 18:26:57 -0500 (EST) Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2d28e465655so35090411fa.0 for ; Fri, 08 Mar 2024 15:26:57 -0800 (PST) Received: from localhost (75-169-5-227.slkc.qwest.net. [75.169.5.227]) by smtp.gmail.com with ESMTPSA id p7-20020a92d287000000b0036616cfacf4sm91732ilp.50.2024.03.08.15.26.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 15:26:55 -0800 (PST) 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=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709940416; x=1710545216; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5UgUTSXmEJyPKFCSJOJU5tpT5hqZRcek0a9SxlF3RI8=; b=XEhGZ3mB3BHf2gtJr9Nya6PB4UJ8E70qVJ7YZ8OzbHpfx2TKIm7Mc4rG5P9CiSqha6 B9EdLnq9wW29QNBYAZKBo3ER7cD1/ZUQdGbOjfYwTCRCzzDSpo1STKmfi4laR8aw/uCT NaQDQSu0E0mVpJwDObd9TqbkOxklM1i+QuhWpT7CpJPy6TNLe0hQJIbDshI8XARZnS26 fS/pmvbKPDuDu8JBP0lt/46gKCc65lUbxn0Kb/rdLRGO13w0YD/POxeOrao0/Xvfa5x8 tFi3Rm3KFSoQl4ggWhcyesW+pCyrdPNTvtVjJFK5xVsfWoXYfxy6cgkUqT+/ziv6Yv/G 4fCg== X-Gm-Message-State: AOJu0YxhqbywIte+SzE6eTvIoev80RVV3ylHZXl3Gm2xTeBgeLoIJfMv 3OKIE71T01/dpJeEABo5Dd3E6o+ZgCwBVd1Mb9DLL8W8YIEqLBjSRD5dOqvrbgjjGeCOrKOoBlO S X-Google-Smtp-Source: AGHT+IE1WWLDFkx1E2w/z9Oy6K6IVaMYFphxeSA9yM7MQWl412Ua6k8PNUevG1m/9qHHBZPzAkTu8g== X-Received: by 2002:a05:651c:211f:b0:2d4:1406:8653 with SMTP id a31-20020a05651c211f00b002d414068653mr453291ljq.43.1709940415904; Fri, 08 Mar 2024 15:26:55 -0800 (PST) From: Jim Fehlig To: devel@lists.libvirt.org Subject: [PATCH] security: Ensure kernel/initrd exist before restoring label Date: Fri, 8 Mar 2024 16:26:27 -0700 Message-ID: <20240308232654.26019-1-jfehlig@suse.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 Message-ID-Hash: JJOLUXOEI73KO6NTQAAX5A2ENSR6QSV4 X-Message-ID-Hash: JJOLUXOEI73KO6NTQAAX5A2ENSR6QSV4 X-MailFrom: jfehlig@suse.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: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1709940577788100001 When performing an install, it's common for tooling such as virt-install to remove the install kernel/initrd once they are successfully booted and the domain has been redefined to boot without them. After the installation is complete and the domain is rebooted/shutdown, the DAC and selinux security drivers attempt to restore labels on the now deleted files. It's harmles wrt functionality, but results in error messages such as Mar 08 12:40:37 virtqemud[5639]: internal error: child reported (status=3D1= 25): unable to stat: /var/lib/libvirt/boot/vir> Mar 08 12:40:37 virtqemud[5639]: unable to stat: /var/lib/libvirt/boot/virt= inst-yvp19moo-linux: No such file or directo> Mar 08 12:40:37 virtqemud[5639]: Unable to run security manager transaction Avoid the messages by checking if the kernel and initrd still exist before including them in the restore label transaction. Signed-off-by: Jim Fehlig Reviewed-by: Michal Privoznik --- src/security/security_dac.c | 4 ++-- src/security/security_selinux.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 4b8130630f..be606c6f33 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1993,11 +1993,11 @@ virSecurityDACRestoreAllLabel(virSecurityManager *m= gr, rc =3D -1; } =20 - if (def->os.kernel && + if (def->os.kernel && virFileExists(def->os.kernel) && virSecurityDACRestoreFileLabel(mgr, def->os.kernel) < 0) rc =3D -1; =20 - if (def->os.initrd && + if (def->os.initrd && virFileExists(def->os.initrd) && virSecurityDACRestoreFileLabel(mgr, def->os.initrd) < 0) rc =3D -1; =20 diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index ffad058d9a..b21986cb7e 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2915,11 +2915,11 @@ virSecuritySELinuxRestoreAllLabel(virSecurityManage= r *mgr, rc =3D -1; } =20 - if (def->os.kernel && + if (def->os.kernel && virFileExists(def->os.kernel) && virSecuritySELinuxRestoreFileLabel(mgr, def->os.kernel, true) < 0) rc =3D -1; =20 - if (def->os.initrd && + if (def->os.initrd && virFileExists(def->os.initrd) && virSecuritySELinuxRestoreFileLabel(mgr, def->os.initrd, true) < 0) rc =3D -1; =20 --=20 2.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org