From nobody Wed Nov 13 13:04:15 2024 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 1722605393961446.2263921873914; Fri, 2 Aug 2024 06:29:53 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D9F0DAE4; Fri, 2 Aug 2024 09:29:52 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E1A751524; Fri, 2 Aug 2024 09:24:26 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id BD5E31467; Fri, 2 Aug 2024 09:24:20 -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 CE6701459 for ; Fri, 2 Aug 2024 09:24:04 -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-692-g2srHEvwPH-I1LnTtuFARQ-1; Fri, 02 Aug 2024 09:24:03 -0400 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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5439C1944B2C for ; Fri, 2 Aug 2024 13:24:02 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7CF0C19560AA for ; Fri, 2 Aug 2024 13:24: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_H4,RCVD_IN_MSPIKE_WL,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=1722605044; 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=AVb0n3JOJ1q2LvqReWer7lXFgNQnLvbCHX6rRRD7Wdc=; b=WLCDGeHw58fnZn7sMgJLGRKp6Mad+yoRgivcy3n5iYAcGcNNFKcXPdbH2gxxgkOrb2nB7Y rnxa+waY1vNyAL38albBsZcW9xjmW7gLoa0LXc/nxQJpxBcQVZPEFLM29L89w3ikfIKpj9 li+n0vrz6Jh2nOOFxTzvYSTsKXZc35E= X-MC-Unique: g2srHEvwPH-I1LnTtuFARQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH v5 11/11] qemu: migration: Don't remember seclabel for images shared from current host Date: Fri, 2 Aug 2024 15:23:44 +0200 Message-ID: <5e52897f7d5b67ec2154f78de9316f207fa8efc0.1722604627.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: GQPESHYZ2VIMSBQVC4AQ7IY2RHZIR2EY X-Message-ID-Hash: GQPESHYZ2VIMSBQVC4AQ7IY2RHZIR2EY X-MailFrom: pkrempa@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: 1722605394954116600 Content-Type: text/plain; charset="utf-8" In case when the user exports images from current host and there is an incoming migration from a remote host, security label remembering would be possible but would attempt to remember the label allowing access to the image as the image is already used by a VM on remote host. To prevent remembering the wrong label, we'll skip the remembering of the label for any shared resource, so that the code behaves identically regardless of how the image is accessed. Signed-off-by: Peter Krempa --- src/qemu/qemu_migration.c | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 2c462fd5f5..c0231d17f0 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -533,6 +533,67 @@ qemuMigrationDstPrepareStorage(virDomainObj *vm, } +static void +qemuMigrationDstPrepareDiskSeclabelOne(virStorageSource *src, + char *const *sharedFilesystems) +{ + if (!virStorageSourceIsLocalStorage(src)) + return; + + /* We care only about existing local storage */ + if (virStorageSourceIsEmpty(src)) + return; + + /* Only paths which are on local filesystem but shared elsewhere are r= elevant */ + if (!virFileIsSharedFSOverride(src->path, sharedFilesystems)) + return; + + src->seclabelSkipRemeber =3D true; +} + + +static void +qemuMigrationDstPrepareDiskSeclabels(virDomainObj *vm, + size_t nmigrate_disks, + const char **migrate_disks, + unsigned int flags) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(priv->dr= iver); + size_t i; + + /* In case when storage is exported from this host, security label + * remembering would behave differently compared to the host which mou= nts + * the exported filesystem. Specifically for incoming migration rememb= ering + * a seclabel would remember a seclabel already allowing access to the= image, + * which is not desired. Thus we skip remembering of seclabels for ima= ges + * which are local to this host but accessed in a shared way from anot= her + * host. + */ + if (!cfg->sharedFilesystems || + cfg->sharedFilesystems[0] =3D=3D NULL) + return; + + for (i =3D 0; i < vm->def->ndisks; i++) { + virDomainDiskDef *disk =3D vm->def->disks[i]; + + /* Any storage that was migrated via NBD is technically fully loca= l so + * we want seclabels remembered */ + if (flags & (VIR_MIGRATE_NON_SHARED_DISK | VIR_MIGRATE_NON_SHARED_= INC)) { + if (qemuMigrationAnyCopyDisk(disk, nmigrate_disks, migrate_dis= ks)) + continue; + } + + qemuMigrationDstPrepareDiskSeclabelOne(disk->src, cfg->sharedFiles= ystems); + } + + if (vm->def->os.loader && vm->def->os.loader->nvram) { + qemuMigrationDstPrepareDiskSeclabelOne(vm->def->os.loader->nvram, + cfg->sharedFilesystems); + } +} + + /** * qemuMigrationDstStartNBDServer: * @driver: qemu driver @@ -3154,6 +3215,8 @@ qemuMigrationDstPrepareActive(virQEMUDriver *driver, dataFD[0]))) goto error; + qemuMigrationDstPrepareDiskSeclabels(vm, nmigrate_disks, migrate_disks= , flags); + if (qemuProcessPrepareDomain(driver, vm, startFlags) < 0) goto error; --=20 2.45.2