]> git.baikalelectronics.ru Git - kernel.git/commitdiff
udmabuf: add back sanity check
authorGerd Hoffmann <kraxel@redhat.com>
Mon, 20 Jun 2022 07:15:47 +0000 (09:15 +0200)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 20 Jun 2022 13:38:29 +0000 (08:38 -0500)
Check vm_fault->pgoff before using it.  When we removed the warning, we
also removed the check.

Fixes: b4f2e096eaa6 ("udmabuf: drop WARN_ON() check.")
Reported-by: zdi-disclosures@trendmicro.com
Suggested-by: Linus Torvalds <torvalds@linuxfoundation.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/dma-buf/udmabuf.c

index e7330684d3b8247d3cfbdcbd80bfefb596460aab..9631f2fd2faf7f2d575c2fae4872e7eccecad722 100644 (file)
@@ -32,8 +32,11 @@ static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf)
 {
        struct vm_area_struct *vma = vmf->vma;
        struct udmabuf *ubuf = vma->vm_private_data;
+       pgoff_t pgoff = vmf->pgoff;
 
-       vmf->page = ubuf->pages[vmf->pgoff];
+       if (pgoff >= ubuf->pagecount)
+               return VM_FAULT_SIGBUS;
+       vmf->page = ubuf->pages[pgoff];
        get_page(vmf->page);
        return 0;
 }