From: Sebastian Alba Vives <sebasjosue84@gmail.com>
To: gregkh@linuxfoundation.org, yilun.xu@linux.intel.com
Cc: linux-fpga@vger.kernel.org, conor.dooley@microchip.com,
mdf@kernel.org, linux-kernel@vger.kernel.org,
Sebastian Alba Vives <sebasjosue84@gmail.com>
Subject: [PATCH v3 2/3] fpga: dfl-afu: validate DMA mapping length in afu_dma_map_region()
Date: Tue, 7 Apr 2026 08:17:35 -0600 [thread overview]
Message-ID: <20260407141735.17394-1-sebasjosue84@gmail.com> (raw)
In-Reply-To: <20260402125446.3776153-2-sebasjosue84@gmail.com>
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
next prev parent reply other threads:[~2026-04-07 14:18 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-02 12:54 [PATCH 1/3] fpga: dfl: add bounds check in dfh_get_param_size() Sebastian Alba Vives
2026-04-02 12:54 ` [PATCH 2/3] fpga: dfl-afu: fix integer truncation of npages in afu_dma_pin_pages() Sebastian Alba Vives
2026-04-02 16:07 ` Greg KH
[not found] ` <CAJD=UNc06upxLFo5eNrvy-UvP1Cu6CEBt-csCgECxAK94pa8mg@mail.gmail.com>
2026-04-03 11:16 ` Greg KH
2026-04-03 17:57 ` [PATCH v2] fpga: dfl-afu: validate DMA mapping length in afu_dma_map_region() Sebastian Alba Vives
2026-04-04 7:01 ` Greg KH
2026-04-07 14:17 ` Sebastian Alba Vives [this message]
2026-04-02 12:54 ` [PATCH 3/3] fpga: microchip-spi: add bounds checks in mpf_ops_parse_header() Sebastian Alba Vives
2026-04-02 15:03 ` Conor Dooley
2026-04-02 15:16 ` Conor Dooley
2026-04-02 15:37 ` [PATCH v2] " Sebastian Alba Vives
2026-04-02 16:03 ` Greg KH
2026-04-02 16:06 ` Greg KH
2026-04-02 16:16 ` Conor Dooley
2026-04-02 16:23 ` [PATCH v3] " Sebastian Alba Vives
2026-04-07 10:44 ` Xu Yilun
2026-04-07 8:51 ` [PATCH 1/3] fpga: dfl: add bounds check in dfh_get_param_size() Xu Yilun
2026-04-07 14:05 ` [PATCH v2 " Sebastian Alba Vives
2026-04-07 14:06 ` [PATCH v2 2/3] fpga: dfl-afu: fix integer truncation of npages in afu_dma_pin_pages() Sebastian Alba Vives
2026-04-07 14:06 ` [PATCH v2 3/3] fpga: microchip-spi: add bounds checks in mpf_ops_parse_header() Sebastian Alba Vives
2026-04-07 16:43 ` Conor Dooley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260407141735.17394-1-sebasjosue84@gmail.com \
--to=sebasjosue84@gmail.com \
--cc=conor.dooley@microchip.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-fpga@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mdf@kernel.org \
--cc=yilun.xu@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.