Patchwork [1/1] rng random backend: check for -EAGAIN errors on read

login
register
mail settings
Submitter Amit Shah
Date April 16, 2013, 10:28 a.m.
Message ID <eacda84dfaf2d99cf6d250b678be4e4d6c2088fb.1366108096.git.amit.shah@redhat.com>
Download mbox | patch
Permalink /patch/236920/
State New
Headers show

Comments

Amit Shah - April 16, 2013, 10:28 a.m.
Not handling EAGAIN triggers the assert

qemu/backends/rng-random.c:44:entropy_available: assertion failed: (len != -1)
Aborted (core dumped)

This happens when starting a guest with '-device virtio-rng-pci',
issuing a 'cat /dev/hwrng' in the guest, while also doing 'cat
/dev/random' on the host.

Reported-by: yunpingzheng <yunzheng@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
 backends/rng-random.c | 3 +++
 1 file changed, 3 insertions(+)
Andreas Färber - April 16, 2013, 1:51 p.m.
Am 16.04.2013 12:28, schrieb Amit Shah:
> Not handling EAGAIN triggers the assert
> 
> qemu/backends/rng-random.c:44:entropy_available: assertion failed: (len != -1)
> Aborted (core dumped)
> 
> This happens when starting a guest with '-device virtio-rng-pci',
> issuing a 'cat /dev/hwrng' in the guest, while also doing 'cat
> /dev/random' on the host.
> 
> Reported-by: yunpingzheng <yunzheng@redhat.com>
> Signed-off-by: Amit Shah <amit.shah@redhat.com>

Doesn't this apply to stable, too, then?

Regards,
Andreas

> ---
>  backends/rng-random.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/backends/rng-random.c b/backends/rng-random.c
> index d5761f2..830360c 100644
> --- a/backends/rng-random.c
> +++ b/backends/rng-random.c
> @@ -41,6 +41,9 @@ static void entropy_available(void *opaque)
>      ssize_t len;
>  
>      len = read(s->fd, buffer, s->size);
> +    if (len < 0 && errno == EAGAIN) {
> +        return;
> +    }
>      g_assert(len != -1);
>  
>      s->receive_func(s->opaque, buffer, len);
Amit Shah - April 16, 2013, 3:08 p.m.
On (Tue) 16 Apr 2013 [15:51:30], Andreas Färber wrote:
> Am 16.04.2013 12:28, schrieb Amit Shah:
> > Not handling EAGAIN triggers the assert
> > 
> > qemu/backends/rng-random.c:44:entropy_available: assertion failed: (len != -1)
> > Aborted (core dumped)
> > 
> > This happens when starting a guest with '-device virtio-rng-pci',
> > issuing a 'cat /dev/hwrng' in the guest, while also doing 'cat
> > /dev/random' on the host.
> > 
> > Reported-by: yunpingzheng <yunzheng@redhat.com>
> > Signed-off-by: Amit Shah <amit.shah@redhat.com>
> 
> Doesn't this apply to stable, too, then?

Ah, good point, it does.

Thanks for CC'ing stable.

		Amit
Anthony Liguori - April 22, 2013, 6:36 p.m.
Applied.  Thanks.

Regards,

Anthony Liguori

Patch

diff --git a/backends/rng-random.c b/backends/rng-random.c
index d5761f2..830360c 100644
--- a/backends/rng-random.c
+++ b/backends/rng-random.c
@@ -41,6 +41,9 @@  static void entropy_available(void *opaque)
     ssize_t len;
 
     len = read(s->fd, buffer, s->size);
+    if (len < 0 && errno == EAGAIN) {
+        return;
+    }
     g_assert(len != -1);
 
     s->receive_func(s->opaque, buffer, len);