lkml.org 
[lkml]   [2026]   [Apr]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v3 2/3] fpga: dfl-afu: validate DMA mapping length in afu_dma_map_region()
Date
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.

Signed-off-by: Sebastian Alba Vives <sebasjosue84@gmail.com>
---
Changes in v3:
- Move the upper-bound check on map.length to afu_ioctl_dma_map()
at the ioctl entry point, before crossing the userspace/kernel
boundary, instead of deep in afu_dma_pin_pages(). Revert changes
to dfl-afu-dma-region.c from v1/v2.
Suggested by Greg Kroah-Hartman.
Changes in v2:
- Added cap at INT_MAX in afu_dma_pin_pages() (superseded by v3).
---
drivers/fpga/dfl-afu-main.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/fpga/dfl-afu-main.c b/drivers/fpga/dfl-afu-main.c
index 3bf8e73..097a97e 100644
--- a/drivers/fpga/dfl-afu-main.c
+++ b/drivers/fpga/dfl-afu-main.c
@@ -723,6 +723,9 @@ afu_ioctl_dma_map(struct dfl_feature_dev_data *fdata, void __user *arg)
if (map.argsz < minsz || map.flags)
return -EINVAL;

+ if (map.length >> PAGE_SHIFT > (u64)INT_MAX)
+ return -EINVAL;
+
ret = afu_dma_map_region(fdata, map.user_addr, map.length, &map.iova);
if (ret)
return ret;
--
2.43.0

\
 
 \ /
  Last update: 2026-04-07 16:18    [W:0.202 / U:19.191 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and my Meterkast|Read the blog