public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdeModulePkg/BDS: Fix a buffer overflow bug
@ 2017-05-17 11:39 Ruiyu Ni
  0 siblings, 0 replies; only message in thread
From: Ruiyu Ni @ 2017-05-17 11:39 UTC (permalink / raw)
  To: edk2-devel

KeyOption points to a buffer holding the content of Key####.
So its size is smaller than EFI_BOOT_MANAGER_KEY_OPTION.
Old code to assign value to KeyOption->OptionNumber modifies
the memory outside of the KeyOption buffer.

The patch fixes this bug.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Steven Shi <steven.shi@intel.com>
---
 MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
index 0f2e677c8a..431be0d8d6 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
@@ -167,7 +167,10 @@ BmCollectKeyOptions (
   if (BmIsKeyOptionVariable (Name, Guid, &OptionNumber)) {
     GetEfiGlobalVariable2 (Name, (VOID**) &KeyOption, &KeyOptionSize);
     ASSERT (KeyOption != NULL);
-    KeyOption->OptionNumber = OptionNumber;
+    //
+    // Be careful!! KeyOption points to a buffer smaller than EFI_BOOT_MANAGER_KEY_OPTION.
+    // Do not access KeyOption->OptionNumber.
+    //
     if (BmIsKeyOptionValid (KeyOption, KeyOptionSize)) {
       Param->KeyOptions = ReallocatePool (
                             Param->KeyOptionCount * sizeof (EFI_BOOT_MANAGER_KEY_OPTION),
@@ -179,12 +182,13 @@ BmCollectKeyOptions (
       // Insert the key option in order
       //
       for (Index = 0; Index < Param->KeyOptionCount; Index++) {
-        if (KeyOption->OptionNumber < Param->KeyOptions[Index].OptionNumber) {
+        if (OptionNumber < Param->KeyOptions[Index].OptionNumber) {
           break;
         }
       }
       CopyMem (&Param->KeyOptions[Index + 1], &Param->KeyOptions[Index], (Param->KeyOptionCount - Index) * sizeof (EFI_BOOT_MANAGER_KEY_OPTION));
       CopyMem (&Param->KeyOptions[Index], KeyOption, BmSizeOfKeyOption (KeyOption));
+      Param->KeyOptions[Index].OptionNumber = OptionNumber;
       Param->KeyOptionCount++;
     }
     FreePool (KeyOption);
-- 
2.12.2.windows.2



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2017-05-17 11:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-17 11:39 [PATCH] MdeModulePkg/BDS: Fix a buffer overflow bug Ruiyu Ni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox