Skip to content

Commit fc3b071

Browse files
SebasteuoXu Yilun
authored andcommitted
fpga: dfl-afu: validate DMA mapping length in afu_dma_map_region()
afu_ioctl_dma_map() accepts a 64-bit length from userspace via DFL_FPGA_PORT_DMA_MAP ioctl without an upper bound check. The value is passed to afu_dma_pin_pages() where npages is derived as length >> PAGE_SHIFT and passed to pin_user_pages_fast() which takes int nr_pages, causing implicit truncation if length is very large. Validate map.length at the ioctl entry point before calling afu_dma_map_region(), rejecting values whose page count exceeds INT_MAX. Fixes: fa8dda1 ("fpga: dfl: afu: add DFL_FPGA_PORT_DMA_MAP/UNMAP ioctls support") Cc: stable@vger.kernel.org Signed-off-by: Sebastian Alba Vives <sebasjosue84@gmail.com> Reviewed-by: Xu Yilun <yilun.xu@intel.com> Link: https://lore.kernel.org/r/20260518190742.61426-3-sebasjosue84@gmail.com Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
1 parent 9e8bc49 commit fc3b071

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

drivers/fpga/dfl-afu-main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,9 @@ afu_ioctl_dma_map(struct dfl_feature_dev_data *fdata, void __user *arg)
723723
if (map.argsz < minsz || map.flags)
724724
return -EINVAL;
725725

726+
if (map.length >> PAGE_SHIFT > (u64)INT_MAX)
727+
return -EINVAL;
728+
726729
ret = afu_dma_map_region(fdata, map.user_addr, map.length, &map.iova);
727730
if (ret)
728731
return ret;

0 commit comments

Comments
 (0)