Re: [PATCH] vhost: fix end of range for access_ok
From: Koichiro Den
Date: Tue Aug 22 2017 - 10:49:52 EST
On Mon, 2017-08-21 at 22:45 +0300, Michael S. Tsirkin wrote:
> During access_ok checks, addr increases as we iterate over the data
> structure, thus addr + len - 1 will point beyond the end of region we
> are translating.ÂÂHarmless since we then verify that the region covers
> addr, but let's not waste cpu cycles.
>
> Reported-by: Koichiro Den <den@xxxxxxxxxxxxx>
> Signed-off-by: Michael S. Tsirkin <mst@xxxxxxxxxx>
> ---
>
> Lightly tested, would appreciate an ack from reporter.
>
> Âdrivers/vhost/vhost.c | 4 ++--
> Â1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index e4613a3..ecd70e4 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -1176,7 +1176,7 @@ static int iotlb_access_ok(struct vhost_virtqueue *vq,
> Â{
> Â const struct vhost_umem_node *node;
> Â struct vhost_umem *umem = vq->iotlb;
> - u64 s = 0, size, orig_addr = addr;
> + u64 s = 0, size, orig_addr = addr, last = addr + len - 1;
> Â
> Â if (vhost_vq_meta_fetch(vq, addr, len, type))
> Â return true;
> @@ -1184,7 +1184,7 @@ static int iotlb_access_ok(struct vhost_virtqueue *vq,
> Â while (len > s) {
> Â node = vhost_umem_interval_tree_iter_first(&umem->umem_tree,
> Â ÂÂÂaddr,
> - ÂÂÂaddr + len - 1);
> + ÂÂÂlast);
> Â if (node == NULL || node->start > addr) {
> Â vhost_iotlb_miss(vq, addr, access);
> Â return false;
Michael, Thank you for this one.
Acked-by: Koichiro Den <den@xxxxxxxxxxxxx>