]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c
If DataSize or VariableNameSize is near MAX_ADDRESS, this can cause the computed...
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / VariableSmmRuntimeDxe.c
index 2a59ac16f9cd08eac39ab1377eb0764e68bb11fd..2fca25981aaa1f1c945c330ac9d5fd1a6b51b491 100644 (file)
@@ -198,6 +198,16 @@ RuntimeServiceGetVariable (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  if (*DataSize >= mVariableBufferSize) {\r
+    //\r
+    // DataSize may be near MAX_ADDRESS incorrectly, this can cause the computed PayLoadSize to\r
+    // overflow to a small value and pass the check in InitCommunicateBuffer().\r
+    // To protect against this vulnerability, return EFI_INVALID_PARAMETER if DataSize is >= mVariableBufferSize.\r
+    // And there will be further check to ensure the total size is also not > mVariableBufferSize.\r
+    //\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r
 \r
   //\r
@@ -275,6 +285,16 @@ RuntimeServiceGetNextVariableName (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  if (*VariableNameSize >= mVariableBufferSize) {\r
+    //\r
+    // VariableNameSize may be near MAX_ADDRESS incorrectly, this can cause the computed PayLoadSize to\r
+    // overflow to a small value and pass the check in InitCommunicateBuffer().\r
+    // To protect against this vulnerability, return EFI_INVALID_PARAMETER if VariableNameSize is >= mVariableBufferSize.\r
+    // And there will be further check to ensure the total size is also not > mVariableBufferSize.\r
+    //\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r
 \r
   //\r
@@ -355,6 +375,16 @@ RuntimeServiceSetVariable (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  if (DataSize >= mVariableBufferSize) {\r
+    //\r
+    // DataSize may be near MAX_ADDRESS incorrectly, this can cause the computed PayLoadSize to\r
+    // overflow to a small value and pass the check in InitCommunicateBuffer().\r
+    // To protect against this vulnerability, return EFI_INVALID_PARAMETER if DataSize is >= mVariableBufferSize.\r
+    // And there will be further check to ensure the total size is also not > mVariableBufferSize.\r
+    //\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r
  \r
   //\r