IB/mlx5: Fix possible array overflow
authorEli Cohen <eli@dev.mellanox.co.il>
Sun, 14 Sep 2014 13:47:53 +0000 (16:47 +0300)
committerRoland Dreier <roland@purestorage.com>
Thu, 9 Oct 2014 07:08:40 +0000 (00:08 -0700)
The check to verify that userspace does not provide an invalid index to the
micro UAR was placed too late. Fix this by moving the check before using the
index.

Reported by: Shachar Raindel <raindel@mellanox.com>
Signed-off-by: Eli Cohen <eli@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
drivers/infiniband/hw/mlx5/main.c

index ecd3aeb..a244317 100644 (file)
@@ -650,13 +650,13 @@ static int mlx5_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vm
                        return -EINVAL;
 
                idx = get_index(vma->vm_pgoff);
+               if (idx >= uuari->num_uars)
+                       return -EINVAL;
+
                pfn = uar_index2pfn(dev, uuari->uars[idx].index);
                mlx5_ib_dbg(dev, "uar idx 0x%lx, pfn 0x%llx\n", idx,
                            (unsigned long long)pfn);
 
-               if (idx >= uuari->num_uars)
-                       return -EINVAL;
-
                vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
                if (io_remap_pfn_range(vma, vma->vm_start, pfn,
                                       PAGE_SIZE, vma->vm_page_prot))