public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 1/3] fpga: dfl: add bounds check in dfh_get_param_size()
@ 2026-04-07 17:22 Sebastian Alba Vives
  2026-04-07 17:22 ` [PATCH v4 2/3] fpga: dfl-afu: validate DMA mapping length in afu_dma_map_region() Sebastian Alba Vives
  2026-04-07 17:22 ` [PATCH v4 3/3] fpga: microchip-spi: fix OOB read in mpf_ops_parse_header() Sebastian Alba Vives
  0 siblings, 2 replies; 3+ messages in thread
From: Sebastian Alba Vives @ 2026-04-07 17:22 UTC (permalink / raw)
  To: yilun.xu, gregkh
  Cc: linux-fpga, conor.dooley, mdf, linux-kernel, stable,
	Sebastian Alba Vives

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: a80a4b2b2e4f ("fpga: dfl: add support for DFHv1")
Signed-off-by: Sebastian Alba Vives <sebasjosue84@gmail.com>
---
Changes in v4:
  - Resubmit as full series per maintainer request.
Changes in v2:
  - Use (size > max) instead of (size + DFHv1_PARAM_HDR > max).
    The previous check unnecessarily guarded against the next parameter
    header, which is not relevant at this point in the loop.
    Suggested by Xu Yilun.
---
 drivers/fpga/dfl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index 4087a36..81d7a68 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -1132,7 +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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-07 17:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07 17:22 [PATCH v4 1/3] fpga: dfl: add bounds check in dfh_get_param_size() Sebastian Alba Vives
2026-04-07 17:22 ` [PATCH v4 2/3] fpga: dfl-afu: validate DMA mapping length in afu_dma_map_region() Sebastian Alba Vives
2026-04-07 17:22 ` [PATCH v4 3/3] fpga: microchip-spi: fix OOB read in mpf_ops_parse_header() Sebastian Alba Vives

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox