Skip to content

Commit

Permalink
RDMA/umem: Fix potential addition overflow
Browse files Browse the repository at this point in the history
Given a large enough memory allocation, it is possible to wrap the
pinned_vm counter.  Check for addition overflow to prevent such
eventualities.

Fixes: 40ddacf ("RDMA/umem: Don't hold mmap_sem for too long")
Reported-by: Jason Gunthorpe <[email protected]>
Signed-off-by: Doug Ledford <[email protected]>
Reviewed-by: Leon Romanovsky <[email protected]>
Signed-off-by: Jason Gunthorpe <[email protected]>
  • Loading branch information
dledford authored and jgunthorpe committed Sep 25, 2018
1 parent 3312d1c commit c6ce580
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions drivers/infiniband/core/umem.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
struct page **page_list;
struct vm_area_struct **vma_list;
unsigned long lock_limit;
unsigned long new_pinned;
unsigned long cur_base;
struct mm_struct *mm;
unsigned long npages;
Expand Down Expand Up @@ -160,12 +161,13 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;

down_write(&mm->mmap_sem);
mm->pinned_vm += npages;
if ((mm->pinned_vm > lock_limit) && !capable(CAP_IPC_LOCK)) {
if (check_add_overflow(mm->pinned_vm, npages, &new_pinned) ||
(new_pinned > lock_limit && !capable(CAP_IPC_LOCK))) {
up_write(&mm->mmap_sem);
ret = -ENOMEM;
goto vma;
goto out;
}
mm->pinned_vm = new_pinned;
up_write(&mm->mmap_sem);

cur_base = addr & PAGE_MASK;
Expand Down

0 comments on commit c6ce580

Please sign in to comment.