]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fpga: dfl: add bounds check in dfh_get_param_size()
authorSebastian Alba Vives <sebasjosue84@gmail.com>
Mon, 18 May 2026 19:07:40 +0000 (13:07 -0600)
committerXu Yilun <yilun.xu@linux.intel.com>
Mon, 1 Jun 2026 04:28:33 +0000 (12:28 +0800)
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@vger.kernel.org
Signed-off-by: Sebastian Alba Vives <sebasjosue84@gmail.com>
Reviewed-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20260518190742.61426-2-sebasjosue84@gmail.com
Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
drivers/fpga/dfl.c

index 4087a36a0571a0430e5a90849e320174f747a426..4c63c7c8579bb709ad4152a53ea137bd3c1690c5 100644 (file)
@@ -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;