* [PATCH 2/2] lguest: virtio-rng support
[not found] ` <200805161531.44725.rusty@rustcorp.com.au>
@ 2008-05-16 5:39 ` Rusty Russell
2008-05-16 5:39 ` Rusty Russell
` (2 subsequent siblings)
3 siblings, 0 replies; 26+ messages in thread
From: Rusty Russell @ 2008-05-16 5:39 UTC (permalink / raw)
To: virtualization
Cc: Christian Borntraeger, H. Anvin, Herbert Xu, Jeff Garzik, LKML
This is a simple patch to add support for the virtio "hardware random
generator" to lguest. It gets about 1.2 MB/sec reading from /dev/hwrng
in the guest.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
Documentation/lguest/lguest.c | 90 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
diff --git a/Documentation/lguest/lguest.c b/Documentation/lguest/lguest.c
--- a/Documentation/lguest/lguest.c
+++ b/Documentation/lguest/lguest.c
@@ -41,6 +41,7 @@
#include "linux/virtio_net.h"
#include "linux/virtio_blk.h"
#include "linux/virtio_console.h"
+#include "linux/virtio_rng.h"
#include "linux/virtio_ring.h"
#include "asm-x86/bootparam.h"
/*L:110 We can ignore the 39 include files we need for this program, but I do
@@ -195,6 +196,33 @@ static void *_convert(struct iovec *iov,
#define le16_to_cpu(v16) (v16)
#define le32_to_cpu(v32) (v32)
#define le64_to_cpu(v64) (v64)
+
+/* Is this iovec empty? */
+static bool iov_empty(const struct iovec iov[], unsigned int num_iov)
+{
+ unsigned int i;
+
+ for (i = 0; i < num_iov; i++)
+ if (iov[i].iov_len)
+ return false;
+ return true;
+}
+
+/* Take len bytes from the front of this iovec. */
+static void iov_consume(struct iovec iov[], unsigned num_iov, unsigned len)
+{
+ unsigned int i;
+
+ for (i = 0; i < num_iov; i++) {
+ unsigned int used;
+
+ used = iov[i].iov_len < len ? iov[i].iov_len : len;
+ iov[i].iov_base += used;
+ iov[i].iov_len -= used;
+ len -= used;
+ }
+ assert(len == 0);
+}
/* The device virtqueue descriptors are followed by feature bitmasks. */
static u8 *get_feature_bits(struct device *dev)
@@ -1613,6 +1641,64 @@ static void setup_block_file(const char
verbose("device %u: virtblock %llu sectors\n",
devices.device_num, le64_to_cpu(conf.capacity));
}
+
+/* Our random number generator device reads from /dev/urandom into the Guest's
+ * input buffers. The usual case is that the Guest doesn't want random numbers
+ * and so has no buffers although /dev/urandom is still readable, whereas
+ * console is the reverse.
+ *
+ * The same logic applies, however. */
+static bool handle_rng_input(int fd, struct device *dev)
+{
+ int len;
+ unsigned int head, in_num, out_num, totlen = 0;
+ struct iovec iov[dev->vq->vring.num];
+
+ /* First we need a buffer from the Guests's virtqueue. */
+ head = get_vq_desc(dev->vq, iov, &out_num, &in_num);
+
+ /* If they're not ready for input, stop listening to this file
+ * descriptor. We'll start again once they add an input buffer. */
+ if (head == dev->vq->vring.num)
+ return false;
+
+ if (out_num)
+ errx(1, "Output buffers in rng?");
+
+ /* This is why we convert to iovecs: the readv() call uses them, and so
+ * it reads straight into the Guest's buffer. We loop to make sure we
+ * fill it. */
+ while (!iov_empty(iov, in_num)) {
+ len = readv(dev->fd, iov, in_num);
+ if (len <= 0)
+ err(1, "Read from /dev/urandom gave %i", len);
+ iov_consume(iov, in_num, len);
+ totlen += len;
+ }
+
+ /* Tell the Guest about the new input. */
+ add_used_and_trigger(fd, dev->vq, head, totlen);
+
+ /* Everything went OK! */
+ return true;
+}
+
+/* And this creates a "hardware" random number device for the Guest. */
+static void setup_rng(void)
+{
+ struct device *dev;
+ int fd;
+
+ fd = open_or_die("/dev/urandom", O_RDONLY);
+
+ /* The device responds to return from I/O thread. */
+ dev = new_device("rng", VIRTIO_ID_RNG, fd, handle_rng_input);
+
+ /* The device has one virtqueue, where the Guest places inbufs. */
+ add_virtqueue(dev, VIRTQUEUE_NUM, enable_fd);
+
+ verbose("device %u: rng\n", devices.device_num++);
+}
/* That's the end of device setup. */
/*L:230 Reboot is pretty easy: clean up and exec() the Launcher afresh. */
@@ -1683,6 +1769,7 @@ static struct option opts[] = {
{ "verbose", 0, NULL, 'v' },
{ "tunnet", 1, NULL, 't' },
{ "block", 1, NULL, 'b' },
+ { "rng", 0, NULL, 'r' },
{ "initrd", 1, NULL, 'i' },
{ NULL },
};
@@ -1756,6 +1843,9 @@ int main(int argc, char *argv[])
break;
case 'b':
setup_block_file(optarg);
+ break;
+ case 'r':
+ setup_rng();
break;
case 'i':
initrd_name = optarg;
^ permalink raw reply [flat|nested] 26+ messages in thread* [PATCH 2/2] lguest: virtio-rng support
[not found] ` <200805161531.44725.rusty@rustcorp.com.au>
2008-05-16 5:39 ` [PATCH 2/2] lguest: virtio-rng support Rusty Russell
@ 2008-05-16 5:39 ` Rusty Russell
2008-05-16 7:31 ` [PATCH 1/2] virtio: hardware random device Christian Borntraeger
[not found] ` <200805161539.59739.rusty@rustcorp.com.au>
3 siblings, 0 replies; 26+ messages in thread
From: Rusty Russell @ 2008-05-16 5:39 UTC (permalink / raw)
To: virtualization
Cc: Christian Borntraeger, H. Anvin, Herbert Xu, Jeff Garzik, LKML
This is a simple patch to add support for the virtio "hardware random
generator" to lguest. It gets about 1.2 MB/sec reading from /dev/hwrng
in the guest.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
Documentation/lguest/lguest.c | 90 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
diff --git a/Documentation/lguest/lguest.c b/Documentation/lguest/lguest.c
--- a/Documentation/lguest/lguest.c
+++ b/Documentation/lguest/lguest.c
@@ -41,6 +41,7 @@
#include "linux/virtio_net.h"
#include "linux/virtio_blk.h"
#include "linux/virtio_console.h"
+#include "linux/virtio_rng.h"
#include "linux/virtio_ring.h"
#include "asm-x86/bootparam.h"
/*L:110 We can ignore the 39 include files we need for this program, but I do
@@ -195,6 +196,33 @@ static void *_convert(struct iovec *iov,
#define le16_to_cpu(v16) (v16)
#define le32_to_cpu(v32) (v32)
#define le64_to_cpu(v64) (v64)
+
+/* Is this iovec empty? */
+static bool iov_empty(const struct iovec iov[], unsigned int num_iov)
+{
+ unsigned int i;
+
+ for (i = 0; i < num_iov; i++)
+ if (iov[i].iov_len)
+ return false;
+ return true;
+}
+
+/* Take len bytes from the front of this iovec. */
+static void iov_consume(struct iovec iov[], unsigned num_iov, unsigned len)
+{
+ unsigned int i;
+
+ for (i = 0; i < num_iov; i++) {
+ unsigned int used;
+
+ used = iov[i].iov_len < len ? iov[i].iov_len : len;
+ iov[i].iov_base += used;
+ iov[i].iov_len -= used;
+ len -= used;
+ }
+ assert(len == 0);
+}
/* The device virtqueue descriptors are followed by feature bitmasks. */
static u8 *get_feature_bits(struct device *dev)
@@ -1613,6 +1641,64 @@ static void setup_block_file(const char
verbose("device %u: virtblock %llu sectors\n",
devices.device_num, le64_to_cpu(conf.capacity));
}
+
+/* Our random number generator device reads from /dev/urandom into the Guest's
+ * input buffers. The usual case is that the Guest doesn't want random numbers
+ * and so has no buffers although /dev/urandom is still readable, whereas
+ * console is the reverse.
+ *
+ * The same logic applies, however. */
+static bool handle_rng_input(int fd, struct device *dev)
+{
+ int len;
+ unsigned int head, in_num, out_num, totlen = 0;
+ struct iovec iov[dev->vq->vring.num];
+
+ /* First we need a buffer from the Guests's virtqueue. */
+ head = get_vq_desc(dev->vq, iov, &out_num, &in_num);
+
+ /* If they're not ready for input, stop listening to this file
+ * descriptor. We'll start again once they add an input buffer. */
+ if (head == dev->vq->vring.num)
+ return false;
+
+ if (out_num)
+ errx(1, "Output buffers in rng?");
+
+ /* This is why we convert to iovecs: the readv() call uses them, and so
+ * it reads straight into the Guest's buffer. We loop to make sure we
+ * fill it. */
+ while (!iov_empty(iov, in_num)) {
+ len = readv(dev->fd, iov, in_num);
+ if (len <= 0)
+ err(1, "Read from /dev/urandom gave %i", len);
+ iov_consume(iov, in_num, len);
+ totlen += len;
+ }
+
+ /* Tell the Guest about the new input. */
+ add_used_and_trigger(fd, dev->vq, head, totlen);
+
+ /* Everything went OK! */
+ return true;
+}
+
+/* And this creates a "hardware" random number device for the Guest. */
+static void setup_rng(void)
+{
+ struct device *dev;
+ int fd;
+
+ fd = open_or_die("/dev/urandom", O_RDONLY);
+
+ /* The device responds to return from I/O thread. */
+ dev = new_device("rng", VIRTIO_ID_RNG, fd, handle_rng_input);
+
+ /* The device has one virtqueue, where the Guest places inbufs. */
+ add_virtqueue(dev, VIRTQUEUE_NUM, enable_fd);
+
+ verbose("device %u: rng\n", devices.device_num++);
+}
/* That's the end of device setup. */
/*L:230 Reboot is pretty easy: clean up and exec() the Launcher afresh. */
@@ -1683,6 +1769,7 @@ static struct option opts[] = {
{ "verbose", 0, NULL, 'v' },
{ "tunnet", 1, NULL, 't' },
{ "block", 1, NULL, 'b' },
+ { "rng", 0, NULL, 'r' },
{ "initrd", 1, NULL, 'i' },
{ NULL },
};
@@ -1756,6 +1843,9 @@ int main(int argc, char *argv[])
break;
case 'b':
setup_block_file(optarg);
+ break;
+ case 'r':
+ setup_rng();
break;
case 'i':
initrd_name = optarg;
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 1/2] virtio: hardware random device
[not found] ` <200805161531.44725.rusty@rustcorp.com.au>
2008-05-16 5:39 ` [PATCH 2/2] lguest: virtio-rng support Rusty Russell
2008-05-16 5:39 ` Rusty Russell
@ 2008-05-16 7:31 ` Christian Borntraeger
[not found] ` <200805161539.59739.rusty@rustcorp.com.au>
3 siblings, 0 replies; 26+ messages in thread
From: Christian Borntraeger @ 2008-05-16 7:31 UTC (permalink / raw)
To: Rusty Russell; +Cc: LKML, H. Anvin, Herbert Xu, Jeff Garzik, virtualization
Am Freitag, 16. Mai 2008 schrieb Rusty Russell:
> virtio: An entropy device, as suggested by hpa.
>
> Note that by itself, having a "hardware" random generator does very
> little: you should probably run "rngd" in your guest to feed this into
> the kernel entropy pool.
>
> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
> ---
> drivers/char/hw_random/Kconfig | 10 ++
> drivers/char/hw_random/Makefile | 1
> drivers/char/hw_random/virtio-rng.c | 143 +++++++++++++++++++++++++++++++
> include/linux/virtio_rng.h | 8 ++
> 4 files changed, 162 insertions(+)
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
^ permalink raw reply [flat|nested] 26+ messages in thread[parent not found: <200805161539.59739.rusty@rustcorp.com.au>]
* Re: [PATCH 2/2] lguest: virtio-rng support
[not found] ` <200805161539.59739.rusty@rustcorp.com.au>
@ 2008-05-16 10:49 ` Johannes Berg
[not found] ` <1210934981.6381.1.camel@johannes.berg>
1 sibling, 0 replies; 26+ messages in thread
From: Johannes Berg @ 2008-05-16 10:49 UTC (permalink / raw)
To: Rusty Russell
Cc: Herbert Xu, Jeff Garzik, LKML, virtualization,
Christian Borntraeger, H. Anvin
[-- Attachment #1.1: Type: text/plain, Size: 386 bytes --]
> +
> +/* Our random number generator device reads from /dev/urandom into the Guest's
> + * input buffers. The usual case is that the Guest doesn't want random numbers
> + * and so has no buffers although /dev/urandom is still readable, whereas
> + * console is the reverse.
Is it really a good idea to use the hosts /dev/urandom to fill the
guests /dev/random?
johannes
[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
[-- Attachment #2: Type: text/plain, Size: 184 bytes --]
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 26+ messages in thread[parent not found: <1210934981.6381.1.camel@johannes.berg>]
* Re: [PATCH 2/2] lguest: virtio-rng support
[not found] ` <1210934981.6381.1.camel@johannes.berg>
@ 2008-05-16 20:25 ` H. Peter Anvin
2008-05-17 4:46 ` Rusty Russell
[not found] ` <200805171446.39814.rusty@rustcorp.com.au>
2 siblings, 0 replies; 26+ messages in thread
From: H. Peter Anvin @ 2008-05-16 20:25 UTC (permalink / raw)
To: Johannes Berg
Cc: Herbert Xu, Jeff Garzik, LKML, virtualization,
Christian Borntraeger
Johannes Berg wrote:
>> +
>> +/* Our random number generator device reads from /dev/urandom into the Guest's
>> + * input buffers. The usual case is that the Guest doesn't want random numbers
>> + * and so has no buffers although /dev/urandom is still readable, whereas
>> + * console is the reverse.
>
> Is it really a good idea to use the hosts /dev/urandom to fill the
> guests /dev/random?
Only if you have an entropy estimate to go with it. It's still dubious,
though: the guests own pool will do its own mixing, so you might as well
pull from /dev/random in the host as being a genuine entropy source and
only add what entropy is available.
-hpa
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 2/2] lguest: virtio-rng support
[not found] ` <1210934981.6381.1.camel@johannes.berg>
2008-05-16 20:25 ` H. Peter Anvin
@ 2008-05-17 4:46 ` Rusty Russell
[not found] ` <200805171446.39814.rusty@rustcorp.com.au>
2 siblings, 0 replies; 26+ messages in thread
From: Rusty Russell @ 2008-05-17 4:46 UTC (permalink / raw)
To: Johannes Berg
Cc: Theodore Tso, Herbert Xu, Jeff Garzik, Matt Mackall, LKML,
virtualization, Christian Borntraeger, H. Anvin
On Friday 16 May 2008 20:49:41 Johannes Berg wrote:
> > +
> > +/* Our random number generator device reads from /dev/urandom into the Guest's
> > + * input buffers. The usual case is that the Guest doesn't want random numbers
> > + * and so has no buffers although /dev/urandom is still readable, whereas
> > + * console is the reverse.
>
> Is it really a good idea to use the hosts /dev/urandom to fill the
> guests /dev/random?
Technically it's up to rngd in the guest to decide whether to feed entropy
or not (ie. /dev/urandom or /dev/random).
If we use /dev/random in the host, we risk a DoS. But since /dev/random
is 0666 on my system, perhaps noone actually cares?
Cheers,
Rusty.
^ permalink raw reply [flat|nested] 26+ messages in thread[parent not found: <200805171446.39814.rusty@rustcorp.com.au>]
* Re: [PATCH 2/2] lguest: virtio-rng support
[not found] ` <200805171446.39814.rusty@rustcorp.com.au>
@ 2008-05-17 4:50 ` H. Peter Anvin
2008-05-17 6:28 ` Rusty Russell
[not found] ` <200805171628.03801.rusty@rustcorp.com.au>
0 siblings, 2 replies; 26+ messages in thread
From: H. Peter Anvin @ 2008-05-17 4:50 UTC (permalink / raw)
To: Rusty Russell
Cc: Theodore Tso, Herbert Xu, Jeff Garzik, LKML, virtualization,
Christian Borntraeger, Matt Mackall, Johannes Berg
Rusty Russell wrote:
> On Friday 16 May 2008 20:49:41 Johannes Berg wrote:
>>> +
>>> +/* Our random number generator device reads from /dev/urandom into the Guest's
>>> + * input buffers. The usual case is that the Guest doesn't want random numbers
>>> + * and so has no buffers although /dev/urandom is still readable, whereas
>>> + * console is the reverse.
>> Is it really a good idea to use the hosts /dev/urandom to fill the
>> guests /dev/random?
>
> Technically it's up to rngd in the guest to decide whether to feed entropy
> or not (ie. /dev/urandom or /dev/random).
Uhm, no. It's not. Unless the host provides actual entropy
information, you have a security hole.
> If we use /dev/random in the host, we risk a DoS. But since /dev/random
> is 0666 on my system, perhaps noone actually cares?
/dev/random = give me actual entropy, if you have some.
/dev/urandom = give me what you have, regardless of quality.
There is no point in feeding the host /dev/urandom to the guest (except
for seeding, which can be handled through other means); it will do its
own mixing anyway. The reason to provide anything at all from the host
is to give it "golden" entropy bits.
-hpa
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 2/2] lguest: virtio-rng support
2008-05-17 4:50 ` H. Peter Anvin
@ 2008-05-17 6:28 ` Rusty Russell
[not found] ` <200805171628.03801.rusty@rustcorp.com.au>
1 sibling, 0 replies; 26+ messages in thread
From: Rusty Russell @ 2008-05-17 6:28 UTC (permalink / raw)
To: H. Peter Anvin
Cc: Theodore Tso, Herbert Xu, Jeff Garzik, LKML, virtualization,
Christian Borntraeger, Matt Mackall, Johannes Berg
On Saturday 17 May 2008 14:50:31 H. Peter Anvin wrote:
> Rusty Russell wrote:
> > On Friday 16 May 2008 20:49:41 Johannes Berg wrote:
> >>> +
> >>> +/* Our random number generator device reads from /dev/urandom into the
> >>> Guest's + * input buffers. The usual case is that the Guest doesn't
> >>> want random numbers + * and so has no buffers although /dev/urandom is
> >>> still readable, whereas + * console is the reverse.
> >>
> >> Is it really a good idea to use the hosts /dev/urandom to fill the
> >> guests /dev/random?
> >
> > Technically it's up to rngd in the guest to decide whether to feed
> > entropy or not (ie. /dev/urandom or /dev/random).
>
> Uhm, no. It's not. Unless the host provides actual entropy
> information, you have a security hole.
Huh? We just can't assume it adds entropy. AFAICT rngd -H0 is what we want
here.
> > If we use /dev/random in the host, we risk a DoS. But since /dev/random
> > is 0666 on my system, perhaps noone actually cares?
>
> There is no point in feeding the host /dev/urandom to the guest (except
> for seeding, which can be handled through other means); it will do its
> own mixing anyway.
Seeding is good, but unlikely to be done properly for first boot of some
standard virtualized container. In practice, feeding /dev/urandom from the
host will make /dev/urandom harder to predict in the guest.
> The reason to provide anything at all from the host
> is to give it "golden" entropy bits.
But you did not address the DoS question: can we ignore it? Or are we trading
off a DoS in the host against a potential security weakness in the guest?
If so, how do we resolve it?
Thanks,
Rusty.
^ permalink raw reply [flat|nested] 26+ messages in thread[parent not found: <200805171628.03801.rusty@rustcorp.com.au>]
* Re: [PATCH 2/2] lguest: virtio-rng support
[not found] ` <200805171628.03801.rusty@rustcorp.com.au>
@ 2008-05-17 6:43 ` Herbert Xu
2008-05-17 7:43 ` Christian Borntraeger
2008-05-17 7:47 ` Jeremy Fitzhardinge
` (2 subsequent siblings)
3 siblings, 1 reply; 26+ messages in thread
From: Herbert Xu @ 2008-05-17 6:43 UTC (permalink / raw)
To: Rusty Russell
Cc: Theodore Tso, Jeff Garzik, Matt Mackall, LKML, virtualization,
Christian Borntraeger, H. Peter Anvin, Johannes Berg
On Sat, May 17, 2008 at 04:28:03PM +1000, Rusty Russell wrote:
>
> But you did not address the DoS question: can we ignore it? Or are we trading
> off a DoS in the host against a potential security weakness in the guest?
Why not do both? Use the host's urandom to make the guest at least
unpredictable on start-up without increasing the guest's entropy,
and use the host's random to actually increase the guest's entropy.
Cheers,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 2/2] lguest: virtio-rng support
2008-05-17 6:43 ` Herbert Xu
@ 2008-05-17 7:43 ` Christian Borntraeger
2008-05-17 15:56 ` H. Peter Anvin
0 siblings, 1 reply; 26+ messages in thread
From: Christian Borntraeger @ 2008-05-17 7:43 UTC (permalink / raw)
To: Herbert Xu
Cc: Theodore Tso, Jeff Garzik, Matt Mackall, LKML, virtualization,
H. Peter Anvin, Johannes Berg
Am Samstag, 17. Mai 2008 schrieb Herbert Xu:
> On Sat, May 17, 2008 at 04:28:03PM +1000, Rusty Russell wrote:
> >
> > But you did not address the DoS question: can we ignore it? Or are we
trading
> > off a DoS in the host against a potential security weakness in the guest?
>
> Why not do both? Use the host's urandom to make the guest at least
> unpredictable on start-up without increasing the guest's entropy,
> and use the host's random to actually increase the guest's entropy.
I think the proper solution would be to use the hosts /dev/hw_rng - if
available.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH 2/2] lguest: virtio-rng support
[not found] ` <200805171628.03801.rusty@rustcorp.com.au>
2008-05-17 6:43 ` Herbert Xu
@ 2008-05-17 7:47 ` Jeremy Fitzhardinge
2008-05-17 15:57 ` H. Peter Anvin
[not found] ` <482E8D75.10606@goop.org>
3 siblings, 0 replies; 26+ messages in thread
From: Jeremy Fitzhardinge @ 2008-05-17 7:47 UTC (permalink / raw)
To: Rusty Russell
Cc: Theodore Tso, Herbert Xu, Jeff Garzik, Matt Mackall, LKML,
virtualization, Christian Borntraeger, H. Peter Anvin,
Johannes Berg
Rusty Russell wrote:
> On Saturday 17 May 2008 14:50:31 H. Peter Anvin wrote:
>
>> Rusty Russell wrote:
>>
>>> On Friday 16 May 2008 20:49:41 Johannes Berg wrote:
>>>
>>>>> +
>>>>> +/* Our random number generator device reads from /dev/urandom into the
>>>>> Guest's + * input buffers. The usual case is that the Guest doesn't
>>>>> want random numbers + * and so has no buffers although /dev/urandom is
>>>>> still readable, whereas + * console is the reverse.
>>>>>
>>>> Is it really a good idea to use the hosts /dev/urandom to fill the
>>>> guests /dev/random?
>>>>
>>> Technically it's up to rngd in the guest to decide whether to feed
>>> entropy or not (ie. /dev/urandom or /dev/random).
>>>
>> Uhm, no. It's not. Unless the host provides actual entropy
>> information, you have a security hole.
>>
>
> Huh? We just can't assume it adds entropy. AFAICT rngd -H0 is what we want
> here.
>
Hm, the Fedora manpage doesn't mention a -H option.
But the host->guest protocol should include the number of bits estimated
entropy along with the bits themselves.
>>> If we use /dev/random in the host, we risk a DoS. But since /dev/random
>>> is 0666 on my system, perhaps noone actually cares?
>>>
>> There is no point in feeding the host /dev/urandom to the guest (except
>> for seeding, which can be handled through other means); it will do its
>> own mixing anyway.
>>
>
> Seeding is good, but unlikely to be done properly for first boot of some
> standard virtualized container. In practice, feeding /dev/urandom from the
> host will make /dev/urandom harder to predict in the guest.
>
Yes, but only because the host /dev/urandom has some amount of real
entropy in it, in which case you may as well use some bits from
/dev/random. The guests are perfectly capable of implementing all the
/dev/urandom mixing algorithms for themselves; all they need is some
real entropy to start working with.
>> The reason to provide anything at all from the host
>> is to give it "golden" entropy bits.
>>
>
> But you did not address the DoS question: can we ignore it? Or are we trading
> off a DoS in the host against a potential security weakness in the guest?
>
> If so, how do we resolve it?
Entropy is a (typically) scarce resource which is generated at X
bits/second. If you're worried about an entropy-eating DoS, then you
deal with it like any other resource you're providing to guests: make
the host side rate-limit the guest entropy consumption to Y bits/sec (Y
<= X). And if you can estimate how much remaining entropy exists in the
host /dev/random, you can set a lower bound on what you provide to
guests so that the host always has something to work with.
Of course, there's no real reason that we need to provide guest entropy
from the host's /dev/random at all. If we're collecting entropy from
various entropy sources and feeding them all into a usermode daemon to
do all the whitening, etc, then we can just provide it directly from
that, leaving /dev/random available for purely host use. (There's
probably be some entropy exchange between the daemon and host
/dev/random, depending on what entropy sources are available to the host.)
J
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 2/2] lguest: virtio-rng support
[not found] ` <200805171628.03801.rusty@rustcorp.com.au>
2008-05-17 6:43 ` Herbert Xu
2008-05-17 7:47 ` Jeremy Fitzhardinge
@ 2008-05-17 15:57 ` H. Peter Anvin
[not found] ` <482E8D75.10606@goop.org>
3 siblings, 0 replies; 26+ messages in thread
From: H. Peter Anvin @ 2008-05-17 15:57 UTC (permalink / raw)
To: Rusty Russell
Cc: Theodore Tso, Herbert Xu, Jeff Garzik, LKML, virtualization,
Christian Borntraeger, Matt Mackall, Johannes Berg
Rusty Russell wrote:
>> Uhm, no. It's not. Unless the host provides actual entropy
>> information, you have a security hole.
>
> Huh? We just can't assume it adds entropy. AFAICT rngd -H0 is what we want
> here.
We can, if it comes from /dev/random.
>>> If we use /dev/random in the host, we risk a DoS. But since /dev/random
>>> is 0666 on my system, perhaps noone actually cares?
>> There is no point in feeding the host /dev/urandom to the guest (except
>> for seeding, which can be handled through other means); it will do its
>> own mixing anyway.
>
> Seeding is good, but unlikely to be done properly for first boot of some
> standard virtualized container. In practice, feeding /dev/urandom from the
> host will make /dev/urandom harder to predict in the guest.
Only up to a point.
>> The reason to provide anything at all from the host
>> is to give it "golden" entropy bits.
>
> But you did not address the DoS question: can we ignore it? Or are we trading
> off a DoS in the host against a potential security weakness in the guest?
>
> If so, how do we resolve it?
I don't think you have a DoS situation at all. The worst thing is that
you don't have any entropy available at all, at which point /dev/urandom
is as insecure as it ever is.
-hpa
^ permalink raw reply [flat|nested] 26+ messages in thread[parent not found: <482E8D75.10606@goop.org>]
* Re: [PATCH 2/2] lguest: virtio-rng support
[not found] ` <482E8D75.10606@goop.org>
@ 2008-05-19 9:05 ` Rusty Russell
[not found] ` <200805191905.11452.rusty@rustcorp.com.au>
1 sibling, 0 replies; 26+ messages in thread
From: Rusty Russell @ 2008-05-19 9:05 UTC (permalink / raw)
To: Jeremy Fitzhardinge
Cc: Theodore Tso, Herbert Xu, Jeff Garzik, Matt Mackall, LKML,
virtualization, Christian Borntraeger, H. Peter Anvin,
Johannes Berg
On Saturday 17 May 2008 17:47:01 Jeremy Fitzhardinge wrote:
> But the host->guest protocol should include the number of bits estimated
> entropy along with the bits themselves.
If we go down that path, we have to come up with a way of feeding that
information to guest userspace. Patches welcome. If we meanwhile assume
entropy == #bits, it fits the current /dev/hwrng model, and we can add an
entropy count later if we want to change that.
I'll change my lguest implementation to suck from /dev/random, since noone
else seems to consider its depletion to be a real issue. It's no worse than
what any other process can do.
Thanks,
Rusty.
^ permalink raw reply [flat|nested] 26+ messages in thread[parent not found: <200805191905.11452.rusty@rustcorp.com.au>]
* Re: [PATCH 2/2] lguest: virtio-rng support
[not found] ` <200805191905.11452.rusty@rustcorp.com.au>
@ 2008-05-19 9:10 ` Jeremy Fitzhardinge
[not found] ` <48314419.4080606@goop.org>
1 sibling, 0 replies; 26+ messages in thread
From: Jeremy Fitzhardinge @ 2008-05-19 9:10 UTC (permalink / raw)
To: Rusty Russell
Cc: Theodore Tso, Herbert Xu, Jeff Garzik, Matt Mackall, LKML,
virtualization, Christian Borntraeger, H. Peter Anvin,
Johannes Berg
Rusty Russell wrote:
> On Saturday 17 May 2008 17:47:01 Jeremy Fitzhardinge wrote:
>
>> But the host->guest protocol should include the number of bits estimated
>> entropy along with the bits themselves.
>>
>
> If we go down that path, we have to come up with a way of feeding that
> information to guest userspace. Patches welcome. If we meanwhile assume
> entropy == #bits, it fits the current /dev/hwrng model, and we can add an
> entropy count later if we want to change that.
>
Really? Wouldn't guest userspace just use /dev/random as usual, which I
think does have an ioctl to give that kind of information? And the
interfaces do allow things injecting entropy into the kernel pool to
provide entropy estimates along with the actual bits themselves.
> I'll change my lguest implementation to suck from /dev/random, since noone
> else seems to consider its depletion to be a real issue. It's no worse than
> what any other process can do.
>
Well, I think having some rate-limiting controls would be nice to have,
but certainly not a show-stopper for a first implementation.
J
^ permalink raw reply [flat|nested] 26+ messages in thread[parent not found: <48314419.4080606@goop.org>]
* Re: [PATCH 2/2] lguest: virtio-rng support
[not found] ` <48314419.4080606@goop.org>
@ 2008-05-19 9:28 ` Rusty Russell
[not found] ` <200805191928.13043.rusty@rustcorp.com.au>
1 sibling, 0 replies; 26+ messages in thread
From: Rusty Russell @ 2008-05-19 9:28 UTC (permalink / raw)
To: Jeremy Fitzhardinge
Cc: Theodore Tso, Herbert Xu, Jeff Garzik, Matt Mackall, LKML,
virtualization, Christian Borntraeger, H. Peter Anvin,
Johannes Berg
On Monday 19 May 2008 19:10:49 Jeremy Fitzhardinge wrote:
> Rusty Russell wrote:
> > On Saturday 17 May 2008 17:47:01 Jeremy Fitzhardinge wrote:
> >> But the host->guest protocol should include the number of bits estimated
> >> entropy along with the bits themselves.
> >
> > If we go down that path, we have to come up with a way of feeding that
> > information to guest userspace. Patches welcome. If we meanwhile assume
> > entropy == #bits, it fits the current /dev/hwrng model, and we can add an
> > entropy count later if we want to change that.
>
> Really? Wouldn't guest userspace just use /dev/random as usual, which I
> think does have an ioctl to give that kind of information? And the
> interfaces do allow things injecting entropy into the kernel pool to
> provide entropy estimates along with the actual bits themselves.
Unfortunately not. Hardware randomness devices export /dev/hwrng, and it's up
to userspace to feed that into /dev/random (or not). That's usually done by
rngd, which at least on my system, assumes 1 bit of entropy per bit of data
from /dev/hwrng by default.
I was a little surprised that this decision was exported to userspace, but if
you're not prepared to unconditionally trust hw rngs, it makes sense to palm
it off. We could write a boutique device for virtualization which *did* feed
directly, but that would be a little gauche.
Cheers,
Rusty.
^ permalink raw reply [flat|nested] 26+ messages in thread[parent not found: <200805191928.13043.rusty@rustcorp.com.au>]
* Re: [PATCH 2/2] lguest: virtio-rng support
[not found] ` <200805191928.13043.rusty@rustcorp.com.au>
@ 2008-05-19 9:45 ` Jeremy Fitzhardinge
0 siblings, 0 replies; 26+ messages in thread
From: Jeremy Fitzhardinge @ 2008-05-19 9:45 UTC (permalink / raw)
To: Rusty Russell
Cc: Theodore Tso, Herbert Xu, Jeff Garzik, Matt Mackall, LKML,
virtualization, Christian Borntraeger, H. Peter Anvin,
Johannes Berg
Rusty Russell wrote:
> Unfortunately not. Hardware randomness devices export /dev/hwrng, and it's up
> to userspace to feed that into /dev/random (or not). That's usually done by
> rngd, which at least on my system, assumes 1 bit of entropy per bit of data
> from /dev/hwrng by default.
>
> I was a little surprised that this decision was exported to userspace, but if
> you're not prepared to unconditionally trust hw rngs, it makes sense to palm
> it off.
Yeah, that's a bit of a pity. Hardware rngs can often generate really
crappy randomness, which needs tons of processing to remove noise like
50/60hz hum, etc.
> We could write a boutique device for virtualization which *did* feed
> directly, but that would be a little gauche.
>
Well, yes, we can certainly do any amount of processing we like to the
stuff provided to guests, so that the 1:1 bits/entropy ratio is as true
as we can make it.
J
^ permalink raw reply [flat|nested] 26+ messages in thread