public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] fpga: dfl: add bounds check in dfh_get_param_size()
@ 2026-04-02 12:54 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
                   ` (3 more replies)
  0 siblings, 4 replies; 21+ messages in thread
From: Sebastian Alba Vives @ 2026-04-02 12:54 UTC (permalink / raw)
  To: linux-fpga
  Cc: yilun.xu, conor.dooley, mdf, linux-kernel,
	Sebastian Josue Alba Vives

From: Sebastian Josue Alba Vives <sebasjosue84@gmail.com>

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 re-check after the size increment to ensure the returned
size never exceeds the feature boundary.

Fixes: a80a4b2b2e4f ("fpga: dfl: add support for DFHv1")
Signed-off-by: Sebastian Alba Vives <sebasjosue84@gmail.com>
---
 drivers/fpga/dfl.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index 4087a36..0f0889a 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -1133,6 +1133,9 @@ static int dfh_get_param_size(void __iomem *dfh_base, resource_size_t max)
 
 		size += next * sizeof(u64);
 
+		if (size + DFHv1_PARAM_HDR > max)
+			return -EINVAL;
+
 		if (FIELD_GET(DFHv1_PARAM_HDR_NEXT_EOP, v))
 			return size;
 	}
-- 
2.43.0


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

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

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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   ` [PATCH v3 2/3] " Sebastian Alba Vives
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

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