public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2] MdeModulePkg/BDS: Fix a buffer overflow bug
@ 2017-05-19  7:25 Ruiyu Ni
  2017-05-19  7:31 ` Fan, Jeff
  0 siblings, 1 reply; 3+ messages in thread
From: Ruiyu Ni @ 2017-05-19  7:25 UTC (permalink / raw)
  To: edk2-devel; +Cc: Steven Shi, Star Zeng, Jeff Fan

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>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Jeff Fan <jeff.fan@intel.com>
---
 MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
index 0f2e677c8a..efad073880 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
@@ -42,7 +42,7 @@ VOID                         *mBmTxtInExRegistration  = NULL;
 **/
 UINTN
 BmSizeOfKeyOption (
-  EFI_BOOT_MANAGER_KEY_OPTION  *KeyOption
+  IN CONST EFI_BOOT_MANAGER_KEY_OPTION  *KeyOption
   )
 {
   return OFFSET_OF (EFI_BOOT_MANAGER_KEY_OPTION, Keys)
@@ -61,8 +61,8 @@ BmSizeOfKeyOption (
 **/
 BOOLEAN
 BmIsKeyOptionValid (
-  IN EFI_BOOT_MANAGER_KEY_OPTION     *KeyOption,
-  IN UINTN                           KeyOptionSize
+  IN CONST EFI_BOOT_MANAGER_KEY_OPTION *KeyOption,
+  IN       UINTN                       KeyOptionSize
 )
 {
   UINT16   OptionName[BM_OPTION_NAME_LEN];
@@ -158,16 +158,15 @@ BmCollectKeyOptions (
 {
   UINTN                        Index;
   BM_COLLECT_KEY_OPTIONS_PARAM *Param;
-  EFI_BOOT_MANAGER_KEY_OPTION  *KeyOption;
+  VOID                         *KeyOption;
   UINT16                       OptionNumber;
   UINTN                        KeyOptionSize;
 
   Param = (BM_COLLECT_KEY_OPTIONS_PARAM *) Context;
 
   if (BmIsKeyOptionVariable (Name, Guid, &OptionNumber)) {
-    GetEfiGlobalVariable2 (Name, (VOID**) &KeyOption, &KeyOptionSize);
+    GetEfiGlobalVariable2 (Name, &KeyOption, &KeyOptionSize);
     ASSERT (KeyOption != NULL);
-    KeyOption->OptionNumber = OptionNumber;
     if (BmIsKeyOptionValid (KeyOption, KeyOptionSize)) {
       Param->KeyOptions = ReallocatePool (
                             Param->KeyOptionCount * sizeof (EFI_BOOT_MANAGER_KEY_OPTION),
@@ -179,12 +178,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));
+      CopyMem (&Param->KeyOptions[Index], KeyOption, KeyOptionSize);
+      Param->KeyOptions[Index].OptionNumber = OptionNumber;
       Param->KeyOptionCount++;
     }
     FreePool (KeyOption);
-- 
2.12.2.windows.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] MdeModulePkg/BDS: Fix a buffer overflow bug
  2017-05-19  7:25 [PATCH v2] MdeModulePkg/BDS: Fix a buffer overflow bug Ruiyu Ni
@ 2017-05-19  7:31 ` Fan, Jeff
  2017-05-19  7:33   ` Zeng, Star
  0 siblings, 1 reply; 3+ messages in thread
From: Fan, Jeff @ 2017-05-19  7:31 UTC (permalink / raw)
  To: Ni, Ruiyu, edk2-devel@lists.01.org; +Cc: Shi, Steven, Zeng, Star

Reviewed-by: Jeff Fan <jeff.fan@intel.com>

-----Original Message-----
From: Ni, Ruiyu 
Sent: Friday, May 19, 2017 3:26 PM
To: edk2-devel@lists.01.org
Cc: Shi, Steven; Zeng, Star; Fan, Jeff
Subject: [PATCH v2] MdeModulePkg/BDS: Fix a buffer overflow bug

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>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Jeff Fan <jeff.fan@intel.com>
---
 MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
index 0f2e677c8a..efad073880 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
@@ -42,7 +42,7 @@ VOID                         *mBmTxtInExRegistration  = NULL;
 **/
 UINTN
 BmSizeOfKeyOption (
-  EFI_BOOT_MANAGER_KEY_OPTION  *KeyOption
+  IN CONST EFI_BOOT_MANAGER_KEY_OPTION  *KeyOption
   )
 {
   return OFFSET_OF (EFI_BOOT_MANAGER_KEY_OPTION, Keys) @@ -61,8 +61,8 @@ BmSizeOfKeyOption (  **/  BOOLEAN  BmIsKeyOptionValid (
-  IN EFI_BOOT_MANAGER_KEY_OPTION     *KeyOption,
-  IN UINTN                           KeyOptionSize
+  IN CONST EFI_BOOT_MANAGER_KEY_OPTION *KeyOption,
+  IN       UINTN                       KeyOptionSize
 )
 {
   UINT16   OptionName[BM_OPTION_NAME_LEN];
@@ -158,16 +158,15 @@ BmCollectKeyOptions (  {
   UINTN                        Index;
   BM_COLLECT_KEY_OPTIONS_PARAM *Param;
-  EFI_BOOT_MANAGER_KEY_OPTION  *KeyOption;
+  VOID                         *KeyOption;
   UINT16                       OptionNumber;
   UINTN                        KeyOptionSize;
 
   Param = (BM_COLLECT_KEY_OPTIONS_PARAM *) Context;
 
   if (BmIsKeyOptionVariable (Name, Guid, &OptionNumber)) {
-    GetEfiGlobalVariable2 (Name, (VOID**) &KeyOption, &KeyOptionSize);
+    GetEfiGlobalVariable2 (Name, &KeyOption, &KeyOptionSize);
     ASSERT (KeyOption != NULL);
-    KeyOption->OptionNumber = OptionNumber;
     if (BmIsKeyOptionValid (KeyOption, KeyOptionSize)) {
       Param->KeyOptions = ReallocatePool (
                             Param->KeyOptionCount * sizeof (EFI_BOOT_MANAGER_KEY_OPTION), @@ -179,12 +178,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));
+      CopyMem (&Param->KeyOptions[Index], KeyOption, KeyOptionSize);
+      Param->KeyOptions[Index].OptionNumber = OptionNumber;
       Param->KeyOptionCount++;
     }
     FreePool (KeyOption);
--
2.12.2.windows.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] MdeModulePkg/BDS: Fix a buffer overflow bug
  2017-05-19  7:31 ` Fan, Jeff
@ 2017-05-19  7:33   ` Zeng, Star
  0 siblings, 0 replies; 3+ messages in thread
From: Zeng, Star @ 2017-05-19  7:33 UTC (permalink / raw)
  To: Fan, Jeff, Ni, Ruiyu, edk2-devel@lists.01.org; +Cc: Shi, Steven, Zeng, Star

Reviewed-by: Star Zeng <star.zeng@intel.com>

-----Original Message-----
From: Fan, Jeff 
Sent: Friday, May 19, 2017 3:31 PM
To: Ni, Ruiyu <ruiyu.ni@intel.com>; edk2-devel@lists.01.org
Cc: Shi, Steven <steven.shi@intel.com>; Zeng, Star <star.zeng@intel.com>
Subject: RE: [PATCH v2] MdeModulePkg/BDS: Fix a buffer overflow bug

Reviewed-by: Jeff Fan <jeff.fan@intel.com>

-----Original Message-----
From: Ni, Ruiyu 
Sent: Friday, May 19, 2017 3:26 PM
To: edk2-devel@lists.01.org
Cc: Shi, Steven; Zeng, Star; Fan, Jeff
Subject: [PATCH v2] MdeModulePkg/BDS: Fix a buffer overflow bug

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>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Jeff Fan <jeff.fan@intel.com>
---
 MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
index 0f2e677c8a..efad073880 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c
@@ -42,7 +42,7 @@ VOID                         *mBmTxtInExRegistration  = NULL;
 **/
 UINTN
 BmSizeOfKeyOption (
-  EFI_BOOT_MANAGER_KEY_OPTION  *KeyOption
+  IN CONST EFI_BOOT_MANAGER_KEY_OPTION  *KeyOption
   )
 {
   return OFFSET_OF (EFI_BOOT_MANAGER_KEY_OPTION, Keys) @@ -61,8 +61,8 @@ BmSizeOfKeyOption (  **/  BOOLEAN  BmIsKeyOptionValid (
-  IN EFI_BOOT_MANAGER_KEY_OPTION     *KeyOption,
-  IN UINTN                           KeyOptionSize
+  IN CONST EFI_BOOT_MANAGER_KEY_OPTION *KeyOption,
+  IN       UINTN                       KeyOptionSize
 )
 {
   UINT16   OptionName[BM_OPTION_NAME_LEN];
@@ -158,16 +158,15 @@ BmCollectKeyOptions (  {
   UINTN                        Index;
   BM_COLLECT_KEY_OPTIONS_PARAM *Param;
-  EFI_BOOT_MANAGER_KEY_OPTION  *KeyOption;
+  VOID                         *KeyOption;
   UINT16                       OptionNumber;
   UINTN                        KeyOptionSize;
 
   Param = (BM_COLLECT_KEY_OPTIONS_PARAM *) Context;
 
   if (BmIsKeyOptionVariable (Name, Guid, &OptionNumber)) {
-    GetEfiGlobalVariable2 (Name, (VOID**) &KeyOption, &KeyOptionSize);
+    GetEfiGlobalVariable2 (Name, &KeyOption, &KeyOptionSize);
     ASSERT (KeyOption != NULL);
-    KeyOption->OptionNumber = OptionNumber;
     if (BmIsKeyOptionValid (KeyOption, KeyOptionSize)) {
       Param->KeyOptions = ReallocatePool (
                             Param->KeyOptionCount * sizeof (EFI_BOOT_MANAGER_KEY_OPTION), @@ -179,12 +178,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));
+      CopyMem (&Param->KeyOptions[Index], KeyOption, KeyOptionSize);
+      Param->KeyOptions[Index].OptionNumber = OptionNumber;
       Param->KeyOptionCount++;
     }
     FreePool (KeyOption);
--
2.12.2.windows.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-05-19  7:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-19  7:25 [PATCH v2] MdeModulePkg/BDS: Fix a buffer overflow bug Ruiyu Ni
2017-05-19  7:31 ` Fan, Jeff
2017-05-19  7:33   ` Zeng, Star

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