From nobody Fri May 17 11:28:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1618486824; cv=none; d=zohomail.com; s=zohoarc; b=FEwPjcv9vhLpG4YAe+7zVoSA1RqLyD7ArrCWuPT+IFh1639Vs/8tJtbQRcDCIzrznkTZI9Hi76+S7Y0iwBUmQk7anYW0niVGR28WoJjok4aLogTAUZ2TuWKWjCj6A+6iJafIhqOX84tx9qzgkcHKGDnNQH7tNAMDgmvkaopYu8I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618486824; 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=gfA7PegoKdgYzRp4x89IzhaAsuUi7CBi0XT7H07TjkY=; b=PQ3iwXIEMYBh+oukG6FN7CtpE3nmGCmRBNb0D3k/csV2toj+l9K1cdUN5AFPfJOPdFp7xUXVIFfdT48pRjim3kFnGZxV0PYTcLoxCa1rLVhivRuzGbT7s0ojpbezxb0kG0vQrmzz7WGAoMC71lQunqcIOZbnPP/DF4Q/4PTCAoo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 161848682493161.54835887673971; Thu, 15 Apr 2021 04:40:24 -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-286-9PWM6Y8aPUuPXYjcL6Uj3w-1; Thu, 15 Apr 2021 07:40:21 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 17D02100806B; Thu, 15 Apr 2021 11:40:17 +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 CCAB210016F4; Thu, 15 Apr 2021 11:40: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 C996B1806D15; Thu, 15 Apr 2021 11:40:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13FBeF13006363 for ; Thu, 15 Apr 2021 07:40:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1269C5D71F; Thu, 15 Apr 2021 11:40:15 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DEA06267F for ; Thu, 15 Apr 2021 11:40:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618486824; 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=gfA7PegoKdgYzRp4x89IzhaAsuUi7CBi0XT7H07TjkY=; b=ZWiZotr3WMFJChpDSlh0HYqjW4onL0+a278ceFI34YefXDX87CJqypXIjIiZBM/FuqffM8 GoYM6cwt1Ao45jbPF8yqCsu3YwgHIcfsNhM49PsYpvzWGOTuYNqpTaC/zQKTl298v+JfuS YOuH4vx5eszkw6uqGbXud5gyX/iBxL4= X-MC-Unique: 9PWM6Y8aPUuPXYjcL6Uj3w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH] virsh: snapshot: Don't validate schema of XML generated by 'virsh snapshot-create-as' Date: Thu, 15 Apr 2021 13:40:09 +0200 Message-Id: <823a459c5acd8196cd5d92b114d01712906177f8.1618486809.git.pkrempa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Commit 95f8e3237e5486f487324c6 which introduced XML schema validation for snapshot XMLs always asserted the validation for the XML generated by 'virsh snapshot-create-as' on the basis that it's libvirt-generated, thus valid. This unfortunately isn't true as users can influence certain bits of the XML such as the disk image path which must be a full path. Thus if a user tries to invoke virsh as: $ virsh snapshot-create-as upstream --diskspec vda,file=3Drelative.qcow2 error: XML document failed to validate against schema: Unable to validate = doc against /path/to/domainsnapshot.rng Extra element disks in interleave Element domainsnapshot failed to validate content They get a rather useless error from the libxml2 RNG validator. With this fix applied, we get to the XML parser in libvirtd which has a more reasonable error: $ virsh snapshot-create-as upstream --diskspec vda,file=3Drelative.qcow2 error: XML error: disk snapshot image path 'relative.qcow2' must be absolu= te Instead users can force validation of the XML generated by 'virsh snapshot-create-as' by passing the '--validate' flag. Signed-off-by: Peter Krempa --- docs/manpages/virsh.rst | 4 +++- tools/virsh-snapshot.c | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index bccda292a2..ad91cd6356 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -6916,7 +6916,7 @@ snapshot-create-as snapshot-create-as domain {[--print-xml] [--no-metadata] [--halt] [--reuse-external]} [name] - [description] [--disk-only [--quiesce]] [--atomic] + [description] [--disk-only [--quiesce]] [--atomic] [--validate] [[--live] [--memspec memspec]] [--diskspec] diskspec]... Create a snapshot for domain *domain* with the given and @@ -6988,6 +6988,8 @@ For now, it is not possible to create snapshots in a = domain that has checkpoints, although this restriction will be lifted in a future release. +Optionally, the *--validate* option can be passed to validate XML document +which is internally generated by this command against the internal RNG sch= ema. snapshot-current ---------------- diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 2bc2cb7e23..2bec722c61 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -372,6 +372,10 @@ static const vshCmdOptDef opts_snapshot_create_as[] = =3D { .help =3D N_("require atomic operation") }, VIRSH_COMMON_OPT_LIVE(N_("take a live snapshot")), + {.name =3D "validate", + .type =3D VSH_OT_BOOL, + .help =3D N_("validate the XML against the schema"), + }, {.name =3D "memspec", .type =3D VSH_OT_STRING, .flags =3D VSH_OFLAG_REQ_OPT, @@ -394,7 +398,7 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) const char *desc =3D NULL; const char *memspec =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - unsigned int flags =3D VIR_DOMAIN_SNAPSHOT_CREATE_VALIDATE; + unsigned int flags =3D 0; const vshCmdOpt *opt =3D NULL; if (vshCommandOptBool(cmd, "no-metadata")) @@ -411,6 +415,8 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) flags |=3D VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC; if (vshCommandOptBool(cmd, "live")) flags |=3D VIR_DOMAIN_SNAPSHOT_CREATE_LIVE; + if (vshCommandOptBool(cmd, "validate")) + flags |=3D VIR_DOMAIN_SNAPSHOT_CREATE_VALIDATE; if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; --=20 2.30.2