[PATCH v8 1/3] fpga: dfl: add bounds check in dfh_get_param_size()

From: Sebastian Alba Vives

Date: Mon May 18 2026 - 15:09:00 EST


dfh_get_param_size() can return a parameter size larger than the feature
region because the loop bounds check is evaluated before incrementing
size. If the EOP (End of Parameters) bit is set in the same iteration,
the inflated size is returned without re-validation against max.

This can cause create_feature_instance() to call memcpy_fromio() with a
size exceeding the ioremap'd region when a malicious FPGA device provides
crafted DFHv1 parameter headers.

Add a bounds check after the size increment to ensure the accumulated
size never exceeds the feature boundary.

Fixes: 4747ab89b4a6 ("fpga: dfl: add basic support for DFHv1")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Sebastian Alba Vives <sebasjosue84@xxxxxxxxx>
---
Changes in v8:
- Add Cc: stable tag.
Reported by Greg Kroah-Hartman.
Changes in v7:
- Correct the Fixes: tag commit hash (checkpatch).
Reported by Xu Yilun.
Changes in v6:
- Rebase onto linux-next. Add cover letter.
Suggested by Xu Yilun.
Changes in v5:
- Add blank line after the new bounds check.
Suggested by Xu Yilun.
---
drivers/fpga/dfl.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index 4087a36a0..4c63c7c85 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -1132,6 +1132,8 @@ static int dfh_get_param_size(void __iomem *dfh_base, resource_size_t max)
return -EINVAL;

size += next * sizeof(u64);
+ if (size > max)
+ return -EINVAL;

if (FIELD_GET(DFHv1_PARAM_HDR_NEXT_EOP, v))
return size;
--
2.43.0