From 4e8ef6147eea6065a4fa11bd4bae3c1dd405a665 Mon Sep 17 00:00:00 2001 From: Jeya R Date: Wed, 22 Jul 2020 16:53:49 +0530 Subject: [PATCH] msm: ADSPRPC: Size check before allocating memory from DMA For allocating memory from DMA we need to do a size check. This validation is required to avoid any improper paging request. We already have the range in which the size is expected to be. Change-Id: I72919a8807a7e3bacb7f8353a2aabb8cc6c19f0f Acked-by: Ekansh Gupta Signed-off-by: Jeya R --- drivers/char/adsprpc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/char/adsprpc.c b/drivers/char/adsprpc.c index 8ed94351e897..ada4f3a4c81c 100644 --- a/drivers/char/adsprpc.c +++ b/drivers/char/adsprpc.c @@ -648,12 +648,20 @@ static int fastrpc_mmap_find(struct fastrpc_file *fl, int fd, static int dma_alloc_memory(dma_addr_t *region_phys, void **vaddr, size_t size, unsigned long dma_attr) { + int err = 0; struct fastrpc_apps *me = &gfa; if (me->dev == NULL) { pr_err("device adsprpc-mem is not initialized\n"); return -ENODEV; } + VERIFY(err, size > 0 && size < MAX_SIZE_LIMIT); + if (err) { + err = -EFAULT; + pr_err("adsprpc: %s: invalid allocation size 0x%zx\n", + __func__, size); + return err; + } *vaddr = dma_alloc_attrs(me->dev, size, region_phys, GFP_KERNEL, dma_attr); if (IS_ERR_OR_NULL(*vaddr)) {