From nobody Sat May 4 18:53:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599150145; cv=none; d=zohomail.com; s=zohoarc; b=CTpxdPu845aPLAwRSEZwxko+nMjBZJr3R13K40dUYHmG1wpmJIc/8ashXg/W8ds5YaZiGH/sgkM9ZUg6lYaZ6Ztv6PDx7DPhqYDMoT3hF7KDxvMsgSfeNbB0TmZ5936CXJ+52JIaBqZAJVhT+owz+KI0twxZhZMeZaqwd4g4f5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599150145; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=DkgWk8WcxV/FbAoBhUOfQEu2BMg3z9KEZxWiNSr/b0o=; b=He2C4WPHKCNzr7NA9n+OSLOgyMRoHubjLF4PNDe6NlojPFtOt8go8pM34pkEG3t18Yz/VsyQzA7cseP6x8hJibV+XHnkRapRhHHfC5CK8TktyezeLRo9G//vMMWwuB1v54Gyz8M5hnUzxGrr7fnamg962mxeUXoq329r48dVMUU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1599150145715867.3840522588101; Thu, 3 Sep 2020 09:22:25 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-511-e85O0YhnP1ycS3PCwXUVXg-1; Thu, 03 Sep 2020 12:22:22 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2EC3C2FD00; Thu, 3 Sep 2020 16:22:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0EA6C7C5B5; Thu, 3 Sep 2020 16:22:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CE6851826D2A; Thu, 3 Sep 2020 16:22:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 083GMELZ014653 for ; Thu, 3 Sep 2020 12:22:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0B8F91EA; Thu, 3 Sep 2020 16:22:14 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70B6359 for ; Thu, 3 Sep 2020 16:22:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599150144; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=DkgWk8WcxV/FbAoBhUOfQEu2BMg3z9KEZxWiNSr/b0o=; b=OFDsvrnrQ8YLNraCZka4cxPMprX+V0W+ANqC6u7WaoQ3t9TZJEjCGk2hZZLg5VbvL9uQ5e 7RlfHYnAnRpfTwd2aGH1gMI8DQ30gfy1gdpwjZqJoOhJmFeriW2mKTJs6vet+G0yU9aWpg ielW2fhDSCHB1Rcnd3JpMEaSQAm5bEc= X-MC-Unique: e85O0YhnP1ycS3PCwXUVXg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] qemu_namespace: Be tolerant to non-existent files when populating /dev Date: Thu, 3 Sep 2020 18:22:00 +0200 Message-Id: <48eff0469e51f6f5a3cd5b117deb8b1e5b26448d.1599150120.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) In 6.7.0 release I've changed how domain namespace is built and populated. Previously it used to be done from a pre-exec hook (ran in the forked off child, just before dropping all privileges and exec()-ing QEMU), which not only meant we had to have two different code paths for creating a node in domain's namespace (one for this pre-exec hook, the other for hotplug ran from the daemon), it also proved problematic because it was leaking FDs into QEMU process. To mitigate this problem, we've not only ditched libdevmapper from the NS population process, I've also dropped the pre-exec code and let the NS be populated from the daemon (using the hotplug code). But, I was not careful when doing so, because the pre-exec code was tolerant to files that doesn't exist, while this new code isn't. For instance, the very first thing that is done when the new NS is created is it's populated with @defaultDeviceACL which contain files like /dev/null, /dev/zero, /dev/random and /dev/kvm (and others). While the rest will probably exist every time, /dev/kvm might not and thus the new code I wrote has to be tolerant to that. Of course, users can override the @defaultDeviceACL (by setting cgroup_device_acl in qemu.conf) and remove /dev/kvm (which is acceptable workaround), but we definitely want libvirt to work out of the box even on hosts without KVM. Fixes: 9048dc4e627ddf33996084167bece7b5fb83b0bc Reported-by: Daniel P. Berrang=C3=A9 Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_namespace.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index 454d6a7b4d..87f4fd8d58 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -1094,6 +1094,9 @@ qemuNamespaceMknodItemInit(qemuNamespaceMknodItemPtr = item, item->file =3D file; =20 if (g_lstat(file, &item->sb) < 0) { + if (errno =3D=3D ENOENT) + return -2; + virReportSystemError(errno, _("Unable to access %s"), file); return -1; @@ -1168,9 +1171,16 @@ qemuNamespacePrepareOneItem(qemuNamespaceMknodDataPt= r data, =20 while (1) { qemuNamespaceMknodItem item =3D { 0 }; + int rc; =20 - if (qemuNamespaceMknodItemInit(&item, cfg, vm, next) < 0) + rc =3D qemuNamespaceMknodItemInit(&item, cfg, vm, next); + if (rc =3D=3D -2) { + /* @file doesn't exist. We can break here. */ + break; + } else if (rc < 0) { + /* Some other (critical) error. */ return -1; + } =20 if (STRPREFIX(next, QEMU_DEVPREFIX)) { for (i =3D 0; i < ndevMountsPath; i++) { --=20 2.26.2