0009-fru-Fix-buffer-overflow-in-ipmi_spd_print_fru.patch 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. From 879f57c3b1ff17b1ca0dbdc8aac9c7a814e876fc Mon Sep 17 00:00:00 2001
  2. From: Chrostoper Ertl <chertl@microsoft.com>
  3. Date: Thu, 28 Nov 2019 16:44:18 +0000
  4. Subject: [PATCH] fru: Fix buffer overflow in ipmi_spd_print_fru
  5. Partial fix for CVE-2020-5208, see
  6. https://github.com/ipmitool/ipmitool/security/advisories/GHSA-g659-9qxw-p7cp
  7. The `ipmi_spd_print_fru` function has a similar issue as the one fixed
  8. by the previous commit in `read_fru_area_section`. An initial request is
  9. made to get the `fru.size`, which is used as the size for the allocation
  10. of `spd_data`. Inside a loop, further requests are performed to get the
  11. copy sizes which are not checked before being used as the size for a
  12. copy into the buffer.
  13. [Retrieve from:
  14. https://github.com/ipmitool/ipmitool/commit/840fb1cbb4fb365cb9797300e3374d4faefcdb10]
  15. Signed-off-by: Heiko Thiery <heiko.thiery@gmail.com>
  16. ---
  17. lib/dimm_spd.c | 9 ++++++++-
  18. 1 file changed, 8 insertions(+), 1 deletion(-)
  19. diff --git a/lib/dimm_spd.c b/lib/dimm_spd.c
  20. index 41e30db..68f3b4f 100644
  21. --- a/lib/dimm_spd.c
  22. +++ b/lib/dimm_spd.c
  23. @@ -1621,7 +1621,7 @@ ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id)
  24. struct ipmi_rq req;
  25. struct fru_info fru;
  26. uint8_t *spd_data, msg_data[4];
  27. - int len, offset;
  28. + uint32_t len, offset;
  29. msg_data[0] = id;
  30. @@ -1697,6 +1697,13 @@ ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id)
  31. }
  32. len = rsp->data[0];
  33. + if(rsp->data_len < 1
  34. + || len > rsp->data_len - 1
  35. + || len > fru.size - offset)
  36. + {
  37. + printf(" Not enough buffer size");
  38. + return -1;
  39. + }
  40. memcpy(&spd_data[offset], rsp->data + 1, len);
  41. offset += len;
  42. } while (offset < fru.size);
  43. --
  44. 2.20.1