]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
virtio: rng: Check length before copying
authorAndrew Scull <ascull@google.com>
Mon, 16 May 2022 10:41:39 +0000 (10:41 +0000)
committerTom Rini <trini@konsulko.com>
Wed, 8 Jun 2022 13:24:04 +0000 (09:24 -0400)
Check the length of data written by the device is consistent with the
size of the buffers to avoid out-of-bounds memory accesses in case
values aren't consistent.

Signed-off-by: Andrew Scull <ascull@google.com>
Cc: Sughosh Ganu <sughosh.ganu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/virtio/virtio_rng.c

index 9314c0a03ed70412851863db2a357a31020a9aad..b85545c2ee5c1b74679b4e0f27ba6353704f276c 100644 (file)
@@ -41,6 +41,9 @@ static int virtio_rng_read(struct udevice *dev, void *data, size_t len)
                while (!virtqueue_get_buf(priv->rng_vq, &rsize))
                        ;
 
+               if (rsize > sg.length)
+                       return -EIO;
+
                memcpy(ptr, buf, rsize);
                len -= rsize;
                ptr += rsize;