Re: [PATCH] hwrng: virtio - fix copy_data() handling of partial reads
From: Herbert Xu
Date: Fri Nov 13 2026 - 12:44:06 EST
On Thu, Nov 05, 2026 at 03:17:33PM +0800, Xiang Lei wrote:
> vi->data_avail is decremented on each read, so it holds the remaining
> bytes rather than the total length. Subtracting vi->data_idx from it
> again in commit e3046eeada29 ("hwrng: virtio: clamp device-reported
> used.len at copy_data()") undercounts the bytes left after a partial
> read. This can leave vi->data_avail nonzero without queuing a new
> request, causing virtio_read() to hang on have_data.
>
> Clamp vi->data_avail to sizeof(vi->data) - vi->data_idx instead.
>
> Fixes: e3046eeada29 ("hwrng: virtio: clamp device-reported used.len at copy_data()")
> Tested-by: Wei Liu <liuwei@xxxxxxxxxx>
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Xiang Lei <leixiang@xxxxxxxxxx>
> ---
> drivers/char/hw_random/virtio-rng.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt