rng: restrict passthrough names to known-good files

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.
This commit is contained in:
Eric Blake 2013-03-04 15:42:07 -07:00
parent 2631fe0420
commit 4932ef4502
5 changed files with 15 additions and 4 deletions

View File

@ -4310,7 +4310,8 @@ qemu-kvm -net nic,model=? /dev/null
<code>model</code> attribute. Supported source models are: <code>model</code> attribute. Supported source models are:
</p> </p>
<ul> <ul>
<li>'random' &mdash; /dev/random (default) or similar device as source</li> <li>'random' &mdash; /dev/random (default) or /dev/hwrng
device as source (for now, no other sources are permitted)</li>
<li>'egd' &mdash; a EGD protocol backend</li> <li>'egd' &mdash; a EGD protocol backend</li>
</ul> </ul>
</dd> </dd>

View File

@ -3511,7 +3511,10 @@
<attribute name="model"> <attribute name="model">
<value>random</value> <value>random</value>
</attribute> </attribute>
<ref name="filePath"/> <choice>
<value>/dev/random</value>
<value>/dev/hwrng</value>
</choice>
</group> </group>
<group> <group>
<attribute name="model"> <attribute name="model">

View File

@ -7423,6 +7423,13 @@ virDomainRNGDefParseXML(const xmlNodePtr node,
switch ((enum virDomainRNGBackend) def->backend) { switch ((enum virDomainRNGBackend) def->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM: case VIR_DOMAIN_RNG_BACKEND_RANDOM:
def->source.file = virXPathString("string(./backend)", ctxt); 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; break;
case VIR_DOMAIN_RNG_BACKEND_EGD: case VIR_DOMAIN_RNG_BACKEND_EGD:

View File

@ -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 \ -S -M pc -m 214 -smp 1 -nographic -nodefaults \
-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \ -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
-object 'rng-random,id=rng0,filename=/test/ph<ile' \ -object rng-random,id=rng0,filename=/dev/hwrng \
-device virtio-rng-pci,rng=rng0,bus=pci.0,addr=0x4 -device virtio-rng-pci,rng=rng0,bus=pci.0,addr=0x4

View File

@ -17,7 +17,7 @@
<controller type='usb' index='0'/> <controller type='usb' index='0'/>
<memballoon model='virtio'/> <memballoon model='virtio'/>
<rng model='virtio'> <rng model='virtio'>
<backend model='random'>/test/ph&lt;ile</backend> <backend model='random'>/dev/hwrng</backend>
</rng> </rng>
</devices> </devices>
</domain> </domain>