0001-NetworkPkg-IScsiDxe-Fix-for-out-of-bound-memory-acce.patch 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. From 0a3b2a29b96b11fb858974044359c806c6b0a111 Mon Sep 17 00:00:00 2001
  2. From: Santhosh Kumar V <santhoshkumarv@ami.com>
  3. Date: Wed, 7 May 2025 18:53:30 +0530
  4. Subject: [PATCH] NetworkPkg/IScsiDxe:Fix for out of bound memory access for
  5. bz4207 (CVE-2024-38805)
  6. In IScsiBuildKeyValueList, check if we have any data left (Len > 0) before advancing the Data pointer and reducing Len.
  7. Avoids wrapping Len. Also Used SafeUint32SubSafeUint32Sub call to reduce the Len .
  8. Upstream: https://github.com/tianocore/edk2/commit/b3a2f7ff24e156e8c4d694fffff01e95a048c536
  9. Signed-off-by: santhosh kumar V <santhoshkumarv@ami.com>
  10. Signed-off-by: Julien Olivain <ju.o@free.fr>
  11. ---
  12. NetworkPkg/IScsiDxe/IScsiProto.c | 29 ++++++++++++++++++++++++-----
  13. 1 file changed, 24 insertions(+), 5 deletions(-)
  14. diff --git a/NetworkPkg/IScsiDxe/IScsiProto.c b/NetworkPkg/IScsiDxe/IScsiProto.c
  15. index ef587649a0..53a0ff801d 100644
  16. --- a/NetworkPkg/IScsiDxe/IScsiProto.c
  17. +++ b/NetworkPkg/IScsiDxe/IScsiProto.c
  18. @@ -1880,6 +1880,8 @@ IScsiBuildKeyValueList (
  19. {
  20. LIST_ENTRY *ListHead;
  21. ISCSI_KEY_VALUE_PAIR *KeyValuePair;
  22. + EFI_STATUS Status;
  23. + UINT32 Result;
  24. ListHead = AllocatePool (sizeof (LIST_ENTRY));
  25. if (ListHead == NULL) {
  26. @@ -1903,9 +1905,14 @@ IScsiBuildKeyValueList (
  27. Data++;
  28. }
  29. - if (*Data == '=') {
  30. + // Here Len must not be zero.
  31. + // The value of Len is size of data buffer. Actually, Data is make up of strings.
  32. + // AuthMethod=None\0TargetAlias=LIO Target\0 TargetPortalGroupTag=1\0
  33. + // (1) Len == 0, *Data != '=' goto ON_ERROR
  34. + // (2) *Data == '=', Len != 0 normal case.
  35. + // (3) *Data == '=', Len == 0, Between Data and Len are mismatch, Len isn't all size of data, as error.
  36. + if ((Len > 0) && (*Data == '=')) {
  37. *Data = '\0';
  38. -
  39. Data++;
  40. Len--;
  41. } else {
  42. @@ -1915,10 +1922,22 @@ IScsiBuildKeyValueList (
  43. KeyValuePair->Value = Data;
  44. - InsertTailList (ListHead, &KeyValuePair->List);
  45. + Status = SafeUint32Add ((UINT32)AsciiStrLen (KeyValuePair->Value), 1, &Result);
  46. + if (EFI_ERROR (Status)) {
  47. + DEBUG ((DEBUG_ERROR, "%a Memory Overflow is Detected.\n", __func__));
  48. + FreePool (KeyValuePair);
  49. + goto ON_ERROR;
  50. + }
  51. - Data += AsciiStrLen (KeyValuePair->Value) + 1;
  52. - Len -= (UINT32)AsciiStrLen (KeyValuePair->Value) + 1;
  53. + Status = SafeUint32Sub (Len, Result, &Len);
  54. + if (EFI_ERROR (Status)) {
  55. + DEBUG ((DEBUG_ERROR, "%a Out of bound memory access Detected.\n", __func__));
  56. + FreePool (KeyValuePair);
  57. + goto ON_ERROR;
  58. + }
  59. +
  60. + InsertTailList (ListHead, &KeyValuePair->List);
  61. + Data += Result;
  62. }
  63. return ListHead;
  64. --
  65. 2.49.0