You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.7 KiB

  1. From 960dbb956d9f9cb05b719087faed53c88dc80956 Mon Sep 17 00:00:00 2001
  2. From: Chrostoper Ertl <chertl@microsoft.com>
  3. Date: Thu, 28 Nov 2019 16:33:59 +0000
  4. Subject: [PATCH 06/11] fru: Fix buffer overflow vulnerabilities
  5. Partial fix for CVE-2020-5208, see
  6. https://github.com/ipmitool/ipmitool/security/advisories/GHSA-g659-9qxw-p7cp
  7. The `read_fru_area_section` function only performs size validation of
  8. requested read size, and falsely assumes that the IPMI message will not
  9. respond with more than the requested amount of data; it uses the
  10. unvalidated response size to copy into `frubuf`. If the response is
  11. larger than the request, this can result in overflowing the buffer.
  12. The same issue affects the `read_fru_area` function.
  13. ---
  14. lib/ipmi_fru.c | 33 +++++++++++++++++++++++++++++++--
  15. 1 file changed, 31 insertions(+), 2 deletions(-)
  16. --- a/lib/ipmi_fru.c
  17. +++ b/lib/ipmi_fru.c
  18. @@ -615,7 +615,10 @@ int
  19. read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
  20. uint32_t offset, uint32_t length, uint8_t *frubuf)
  21. {
  22. - uint32_t off = offset, tmp, finish;
  23. + uint32_t off = offset;
  24. + uint32_t tmp;
  25. + uint32_t finish;
  26. + uint32_t size_left_in_buffer;
  27. struct ipmi_rs * rsp;
  28. struct ipmi_rq req;
  29. uint8_t msg_data[4];
  30. @@ -628,10 +631,12 @@ read_fru_area(struct ipmi_intf * intf, s
  31. finish = offset + length;
  32. if (finish > fru->size) {
  33. + memset(frubuf + fru->size, 0, length - fru->size);
  34. finish = fru->size;
  35. lprintf(LOG_NOTICE, "Read FRU Area length %d too large, "
  36. "Adjusting to %d",
  37. offset + length, finish - offset);
  38. + length = finish - offset;
  39. }
  40. memset(&req, 0, sizeof(req));
  41. @@ -667,6 +672,7 @@ read_fru_area(struct ipmi_intf * intf, s
  42. }
  43. }
  44. + size_left_in_buffer = length;
  45. do {
  46. tmp = fru->access ? off >> 1 : off;
  47. msg_data[0] = id;
  48. @@ -707,9 +713,18 @@ read_fru_area(struct ipmi_intf * intf, s
  49. }
  50. tmp = fru->access ? rsp->data[0] << 1 : rsp->data[0];
  51. + if(rsp->data_len < 1
  52. + || tmp > rsp->data_len - 1
  53. + || tmp > size_left_in_buffer)
  54. + {
  55. + printf(" Not enough buffer size");
  56. + return -1;
  57. + }
  58. +
  59. memcpy(frubuf, rsp->data + 1, tmp);
  60. off += tmp;
  61. frubuf += tmp;
  62. + size_left_in_buffer -= tmp;
  63. /* sometimes the size returned in the Info command
  64. * is too large. return 0 so higher level function
  65. * still attempts to parse what was returned */
  66. @@ -742,7 +757,9 @@ read_fru_area_section(struct ipmi_intf *
  67. uint32_t offset, uint32_t length, uint8_t *frubuf)
  68. {
  69. static uint32_t fru_data_rqst_size = 20;
  70. - uint32_t off = offset, tmp, finish;
  71. + uint32_t off = offset;
  72. + uint32_t tmp, finish;
  73. + uint32_t size_left_in_buffer;
  74. struct ipmi_rs * rsp;
  75. struct ipmi_rq req;
  76. uint8_t msg_data[4];
  77. @@ -755,10 +772,12 @@ read_fru_area_section(struct ipmi_intf *
  78. finish = offset + length;
  79. if (finish > fru->size) {
  80. + memset(frubuf + fru->size, 0, length - fru->size);
  81. finish = fru->size;
  82. lprintf(LOG_NOTICE, "Read FRU Area length %d too large, "
  83. "Adjusting to %d",
  84. offset + length, finish - offset);
  85. + length = finish - offset;
  86. }
  87. memset(&req, 0, sizeof(req));
  88. @@ -773,6 +792,8 @@ read_fru_area_section(struct ipmi_intf *
  89. if (fru->access && fru_data_rqst_size > 16)
  90. #endif
  91. fru_data_rqst_size = 16;
  92. +
  93. + size_left_in_buffer = length;
  94. do {
  95. tmp = fru->access ? off >> 1 : off;
  96. msg_data[0] = id;
  97. @@ -804,8 +825,16 @@ read_fru_area_section(struct ipmi_intf *
  98. }
  99. tmp = fru->access ? rsp->data[0] << 1 : rsp->data[0];
  100. + if(rsp->data_len < 1
  101. + || tmp > rsp->data_len - 1
  102. + || tmp > size_left_in_buffer)
  103. + {
  104. + printf(" Not enough buffer size");
  105. + return -1;
  106. + }
  107. memcpy((frubuf + off)-offset, rsp->data + 1, tmp);
  108. off += tmp;
  109. + size_left_in_buffer -= tmp;
  110. /* sometimes the size returned in the Info command
  111. * is too large. return 0 so higher level function