From patchwork Mon Mar 4 22:49:23 2013
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Eric Blake
X-Patchwork-Id: 224853
Return-Path:
X-Original-To: incoming@patchwork.ozlabs.org
Delivered-To: patchwork-incoming@bilbo.ozlabs.org
Received: from lists.gnu.org (lists.gnu.org [208.118.235.17])
(using TLSv1 with cipher AES256-SHA (256/256 bits))
(Client did not present a certificate)
by ozlabs.org (Postfix) with ESMTPS id 95B6D2C032E
for ;
Tue, 5 Mar 2013 09:49:50 +1100 (EST)
Received: from localhost ([::1]:53558 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.71) (envelope-from
)
id 1UCeCa-0001fL-Kn
for incoming@patchwork.ozlabs.org; Mon, 04 Mar 2013 17:49:48 -0500
Received: from eggs.gnu.org ([208.118.235.92]:49238)
by lists.gnu.org with esmtp (Exim 4.71)
(envelope-from ) id 1UCeCI-0001fG-Rb
for qemu-devel@nongnu.org; Mon, 04 Mar 2013 17:49:32 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
(envelope-from ) id 1UCeCH-0007u1-EY
for qemu-devel@nongnu.org; Mon, 04 Mar 2013 17:49:30 -0500
Received: from qmta10.emeryville.ca.mail.comcast.net ([76.96.30.17]:51522)
by eggs.gnu.org with esmtp (Exim 4.71)
(envelope-from ) id 1UCeCH-0007to-5C
for qemu-devel@nongnu.org; Mon, 04 Mar 2013 17:49:29 -0500
Received: from omta21.emeryville.ca.mail.comcast.net ([76.96.30.88])
by qmta10.emeryville.ca.mail.comcast.net with comcast
id 7XyP1l0021u4NiLAAapTwq; Mon, 04 Mar 2013 22:49:27 +0000
Received: from office.redhat.com ([24.10.251.25])
by omta21.emeryville.ca.mail.comcast.net with comcast
id 7apQ1l0010ZdyUg8hapSZo; Mon, 04 Mar 2013 22:49:27 +0000
From: Eric Blake
To: libvir-list@redhat.com
Date: Mon, 4 Mar 2013 15:49:23 -0700
Message-Id: <1362437363-27570-1-git-send-email-eblake@redhat.com>
X-Mailer: git-send-email 1.8.1.4
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net;
s=q20121106; t=1362437367;
bh=kzvcmIzlDS9RDomxzD1/Ojbrd8N2elqMfvTDvt+tN4E=;
h=Received:Received:From:To:Subject:Date:Message-Id;
b=pMRlbC1EtqzbAuO8Wb22KCi4BvqtlJXzkGA5XNjrJS9WkTiPeP87/rN/VYGFNBN0C
IwcAS+nUe/BtZSRaxYiZjjvu+NfKl95uefUxB1wLS6w2Cww+l7UZULOLV46kLbQZll
r/jIb1muQn1zPz5PIUIHdClZrCQ0Y9xrsDkFVVAjniA2Mb2c4e/xOTEex2toJWJnSL
IZtOuA/QrJhaOQSTCH3VPhOr3UQZnjjnWOWp7B6VNwQHgdwO5Q+wJ5T9tHZ1H1jUIQ
X2Ip9XFq5g8f+UIyyxVuGDc5W4dkzKUiLXa5O4GXScQlv0shOzVQ9bXjw/C0z0blPj
4gZ0cfC/9YQHw==
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
recognized.
X-Received-From: 76.96.30.17
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, anthony@codemonkey.ws
Subject: [Qemu-devel] [PATCH] rng: restrict passthrough names to known-good
files
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id:
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org
Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org
There is some controversy[1] on the qemu list on whether qemu should
have ever allowed arbitrary file name passthrough, or whether it
should be restricted to JUST /dev/random and /dev/hwrng. It is
always easier to add support for additional filenames than it is
to remove support for something once released, so this patch
restricts libvirt 1.0.3 (where the virtio-random backend was first
supported) to just the two uncontroversial names, letting us defer
to a later date any decision on whether supporting arbitrary files
makes sense. Additionally, since qemu 1.4 does NOT support
/dev/fdset/nnn fd passthrough for the backend, limiting to just
two known names means that we don't get tempted to try fd
passthrough where it won't work.
[1]https://lists.gnu.org/archive/html/qemu-devel/2013-03/threads.html#00023
* src/conf/domain_conf.c (virDomainRNGDefParseXML): Only allow
/dev/random and /dev/hwrng.
* docs/schemas/domaincommon.rng: Flag invalid files.
* docs/formatdomain.html.in (elementsRng): Document this.
* tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.args:
Update test to match.
* tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.xml:
Likewise.
Acked-by: Anthony Liguori
---
This needs to be acked before libvirt 1.0.3; otherwise we are
stuck supporting arbitrary name passthrough.
docs/formatdomain.html.in | 3 ++-
docs/schemas/domaincommon.rng | 5 ++++-
src/conf/domain_conf.c | 7 +++++++
tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.args | 2 +-
tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.xml | 2 +-
5 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 1835b39..4cafc92 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -4310,7 +4310,8 @@ qemu-kvm -net nic,model=? /dev/null
model
attribute. Supported source models are:
- - 'random' — /dev/random (default) or similar device as source
+ - 'random' — /dev/random (default) or /dev/hwrng
+ device as source (for now, no other sources are permitted)
- 'egd' — a EGD protocol backend
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index e7231cc..4b60885 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -3511,7 +3511,10 @@
random
-
+
+ /dev/random
+ /dev/hwrng
+
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 995cf0c..9c96cf1 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7423,6 +7423,13 @@ virDomainRNGDefParseXML(const xmlNodePtr node,
switch ((enum virDomainRNGBackend) def->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
def->source.file = virXPathString("string(./backend)", ctxt);
+ if (STRNEQ(def->source.file, "/dev/random") &&
+ STRNEQ(def->source.file, "/dev/hwrng")) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("file '%s' is not a supported random source"),
+ def->source.file);
+ goto error;
+ }
break;
case VIR_DOMAIN_RNG_BACKEND_EGD:
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.args b/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.args
index ad27132..7ab9dbc 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-random.args
@@ -2,5 +2,5 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu \
-S -M pc -m 214 -smp 1 -nographic -nodefaults \
-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
--object 'rng-random,id=rng0,filename=/test/ph
- /test/ph<ile
+ /dev/hwrng