0022-fdt-Fix-bounds-check-in-devfdt_get_addr_index.patch 1.0 KB

12345678910111213141516171819202122232425262728
  1. From 0e4edc3a01f179337bb0bd0d31855dbce338a23e Mon Sep 17 00:00:00 2001
  2. From: Samuel Holland <[email protected]>
  3. Date: Sun, 30 Oct 2022 14:53:45 -0500
  4. Subject: [PATCH 22/90] fdt: Fix bounds check in devfdt_get_addr_index
  5. reg must contain enough cells for the entire next address/size pair
  6. after skipping `index` pairs. The previous code allows an out-of-bounds
  7. read when na + ns > 1.
  8. Series-to: Simon Glass <[email protected]>
  9. Fixes: 69b41388ba45 ("dm: core: Add a new api to get indexed device address")
  10. Signed-off-by: Samuel Holland <[email protected]>
  11. ---
  12. drivers/core/fdtaddr.c | 2 +-
  13. 1 file changed, 1 insertion(+), 1 deletion(-)
  14. --- a/drivers/core/fdtaddr.c
  15. +++ b/drivers/core/fdtaddr.c
  16. @@ -43,7 +43,7 @@ fdt_addr_t devfdt_get_addr_index(const s
  17. }
  18. reg = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
  19. - if (!reg || (len <= (index * sizeof(fdt32_t) * (na + ns)))) {
  20. + if (!reg || (len < ((index + 1) * sizeof(fdt32_t) * (na + ns)))) {
  21. debug("Req index out of range\n");
  22. return FDT_ADDR_T_NONE;
  23. }