public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-platforms][PATCH V1 1/1] MinPlatformPkg/MultiBoardInitSupportLib: Fix NULL pointer dereferences
@ 2019-08-23 23:24 Kubacki, Michael A
  2019-08-23 23:44 ` Nate DeSimone
  2019-08-26  7:28 ` [edk2-devel] " Chiu, Chasel
  0 siblings, 2 replies; 3+ messages in thread
From: Kubacki, Michael A @ 2019-08-23 23:24 UTC (permalink / raw)
  To: devel; +Cc: Chasel Chiu, Nate DeSimone, Liming Gao

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2114

Removes potential NULL pointer de-references in the library and
validates NULL pointers are not passed to library functions.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>
---
 Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.h                                  | 84 ++++++++++++++++-
 Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.c | 24 ++++-
 Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.c | 97 +++++++++++++++++---
 3 files changed, 188 insertions(+), 17 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.h b/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.h
index 6c14b5677d..a854f61e27 100644
--- a/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.h
+++ b/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.h
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -10,18 +10,39 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #include <Library/BoardInitLib.h>
 
+/**
+  This board service detects the board type.
+
+  @retval EFI_SUCCESS   The board was detected successfully.
+  @retval EFI_NOT_FOUND The board could not be detected.
+
+**/
 typedef
 EFI_STATUS
 (EFIAPI *BOARD_DETECT) (
   VOID
   );
 
+/**
+  This board service performs board-specific initialization.
+
+  @retval EFI_SUCCESS   Board-specific initialization was successful.
+  @retval EFI_NOT_READY The board has not been detected yet.
+
+**/
 typedef
 EFI_STATUS
 (EFIAPI *BOARD_INIT) (
   VOID
   );
 
+/**
+  This board service detects the boot mode.
+
+  @retval EFI_BOOT_MODE The boot mode.
+  @retval EFI_NOT_READY The board has not been detected yet.
+
+**/
 typedef
 EFI_BOOT_MODE
 (EFIAPI *BOARD_BOOT_MODE_DETECT) (
@@ -52,24 +73,85 @@ typedef struct {
   BOARD_INIT              BoardInitEndOfFirmware;
 } BOARD_NOTIFICATION_INIT_FUNC;
 
+/**
+  Registers the given function for callback during board detection.
+
+  When this function is called the given function pointer is added to an internal list. When board detection is
+  performed within the BoardDetect() API, the function pointers in the list will be invoked until a board
+  detection function reports it has successfully detected the board.
+
+  @param[in]    BoardDetect             A pointer to a function of type BOARD_DETECT_FUNC that is called during
+                                        board detection.
+
+  @retval       EFI_SUCCESS             The function was successfully registered.
+  @retval       EFI_INVALID_PARAMETER   The function pointer given is NULL.
+  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to add a new board detection callback.
+
+**/
 EFI_STATUS
 EFIAPI
 RegisterBoardDetect (
   IN BOARD_DETECT_FUNC  *BoardDetect
   );
 
+/**
+  Registers the given set of board functions for callback to perform pre-memory board initialization tasks.
+
+  When this function is called, the given structure of function pointers are stored for future invocation. When
+  board pre-memory initialization tasks are required, the corresponding pre-memory function in this structure
+  will be called. Typically, RegisterBoardPreMemInit() is called during board detection with the successfully
+  detected board providing its set of board-specific pre-memory initialization functions.
+
+  @param[in]    BoardPreMemInit         A pointer to a structure of function pointers described in the type
+                                        BOARD_PRE_MEM_INIT_FUNC.
+
+  @retval       EFI_SUCCESS             The board pre-memory functions were successfully registered.
+  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
+  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to register the callback functions.
+
+**/
 EFI_STATUS
 EFIAPI
 RegisterBoardPreMemInit (
   IN BOARD_PRE_MEM_INIT_FUNC  *BoardPreMemInit
   );
 
+/**
+  Registers the given set of board functions for callback to perform post-memory board initialization tasks.
+
+  When this function is called, the given structure of function pointers are stored for future invocation. When
+  board post-memory initialization tasks are required, the corresponding post-memory function in this structure
+  will be called. Typically, RegisterBoardPostMemInit() is called during board detection with the successfuly
+  detected board providing its set of board-specific post-memory initialization functions.
+
+  @param[in]    BoardPostMemInit        A pointer to a structure of function pointers described in the type
+                                        BOARD_POST_MEM_INIT_FUNC.
+
+  @retval       EFI_SUCCESS             The board post-memory functions were successfully registered.
+  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
+  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to register the callback functions.
+
+**/
 EFI_STATUS
 EFIAPI
 RegisterBoardPostMemInit (
   IN BOARD_POST_MEM_INIT_FUNC  *BoardPostMemInit
   );
 
+/**
+  Registers the given set of board functions for callback to perform board initialization tasks.
+
+  When this function is called, the given structure of function pointers are stored for future invocation. When
+  board initialization tasks are required, the corresponding functions in this structure will be called.
+
+  @param[in]    BoardNotificationInit   A pointer to a structure of function pointers described in the type
+                                        BOARD_NOTIFICATION_INIT_FUNC.
+
+  @retval       EFI_SUCCESS             The board notification functions were successfully registered.
+  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
+  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to register the callback functions.
+
+**/
 EFI_STATUS
 EFIAPI
 RegisterBoardNotificationInit (
diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.c b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.c
index 90aabdbbc7..3eb3a1adc7 100644
--- a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.c
+++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.c
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -11,6 +11,20 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/DebugLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 
+/**
+  Registers the given set of board functions for callback to perform board initialization tasks.
+
+  When this function is called, the given structure of function pointers are stored for future invocation. When
+  board initialization tasks are required, the corresponding functions in this structure will be called.
+
+  @param[in]    BoardNotificationInit   A pointer to a structure of function pointers described in the type
+                                        BOARD_NOTIFICATION_INIT_FUNC.
+
+  @retval       EFI_SUCCESS             The board notification functions were successfully registered.
+  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
+  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to register the callback functions.
+
+**/
 EFI_STATUS
 EFIAPI
 RegisterBoardNotificationInit (
@@ -20,6 +34,10 @@ RegisterBoardNotificationInit (
   EFI_HANDLE  Handle;
   EFI_STATUS  Status;
 
+  if (BoardNotificationInit == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
   Handle = NULL;
   Status = gBS->InstallProtocolInterface (
                   &Handle,
@@ -27,7 +45,7 @@ RegisterBoardNotificationInit (
                   EFI_NATIVE_INTERFACE,
                   BoardNotificationInit
                   );
-  ASSERT_EFI_ERROR(Status);
+  ASSERT_EFI_ERROR (Status);
 
-  return EFI_SUCCESS;
+  return Status;
 }
diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.c b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.c
index f1cd735e41..6f5b90d9b1 100644
--- a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.c
+++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.c
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -12,6 +12,21 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/MemoryAllocationLib.h>
 #include <Library/PeiServicesLib.h>
 
+/**
+  Registers the given function for callback during board detection.
+
+  When this function is called the given function pointer is added to an internal list. When board detection is
+  performed within the BoardDetect() API, the function pointers in the list will be invoked until a board
+  detection function reports it has successfully detected the board.
+
+  @param[in]    BoardDetect             A pointer to a function of type BOARD_DETECT_FUNC that is called during
+                                        board detection.
+
+  @retval       EFI_SUCCESS             The function was successfully registered.
+  @retval       EFI_INVALID_PARAMETER   The function pointer given is NULL.
+  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to add a new board detection callback.
+
+**/
 EFI_STATUS
 EFIAPI
 RegisterBoardDetect (
@@ -21,18 +36,42 @@ RegisterBoardDetect (
   EFI_STATUS                 Status;
   EFI_PEI_PPI_DESCRIPTOR     *PpiListBoardDetect;
 
-  PpiListBoardDetect = AllocatePool (sizeof(EFI_PEI_PPI_DESCRIPTOR));
-  ASSERT (PpiListBoardDetect != NULL);
+  if (BoardDetect == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  PpiListBoardDetect = AllocatePool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
+  if (PpiListBoardDetect == NULL) {
+    ASSERT (PpiListBoardDetect != NULL);
+    return EFI_OUT_OF_RESOURCES;
+  }
 
   PpiListBoardDetect->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
   PpiListBoardDetect->Guid  = &gBoardDetectGuid;
   PpiListBoardDetect->Ppi   = BoardDetect;
 
   Status = PeiServicesInstallPpi (PpiListBoardDetect);
-  ASSERT_EFI_ERROR(Status);
-  return EFI_SUCCESS;
+  ASSERT_EFI_ERROR (Status);
+
+  return Status;
 }
 
+/**
+  Registers the given set of board functions for callback to perform pre-memory board initialization tasks.
+
+  When this function is called, the given structure of function pointers are stored for future invocation. When
+  board pre-memory initialization tasks are required, the corresponding pre-memory function in this structure
+  will be called. Typically, RegisterBoardPreMemInit() is called during board detection with the successfully
+  detected board providing its set of board-specific pre-memory initialization functions.
+
+  @param[in]    BoardPreMemInit         A pointer to a structure of function pointers described in the type
+                                        BOARD_PRE_MEM_INIT_FUNC.
+
+  @retval       EFI_SUCCESS             The board pre-memory functions were successfully registered.
+  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
+  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to register the callback functions.
+
+**/
 EFI_STATUS
 EFIAPI
 RegisterBoardPreMemInit (
@@ -42,18 +81,42 @@ RegisterBoardPreMemInit (
   EFI_STATUS                 Status;
   EFI_PEI_PPI_DESCRIPTOR     *PpiListBoardInitPreMem;
 
-  PpiListBoardInitPreMem = AllocatePool (sizeof(EFI_PEI_PPI_DESCRIPTOR));
-  ASSERT (PpiListBoardInitPreMem != NULL);
+  if (BoardPreMemInit == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  PpiListBoardInitPreMem = AllocatePool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
+  if (PpiListBoardInitPreMem == NULL) {
+    ASSERT (PpiListBoardInitPreMem != NULL);
+    return EFI_OUT_OF_RESOURCES;
+  }
 
   PpiListBoardInitPreMem->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
   PpiListBoardInitPreMem->Guid  = &gBoardPreMemInitGuid;
   PpiListBoardInitPreMem->Ppi   = BoardPreMemInit;
 
   Status = PeiServicesInstallPpi (PpiListBoardInitPreMem);
-  ASSERT_EFI_ERROR(Status);
-  return EFI_SUCCESS;
+  ASSERT_EFI_ERROR (Status);
+
+  return Status;
 }
 
+/**
+  Registers the given set of board functions for callback to perform post-memory board initialization tasks.
+
+  When this function is called, the given structure of function pointers are stored for future invocation. When
+  board post-memory initialization tasks are required, the corresponding post-memory function in this structure
+  will be called. Typically, RegisterBoardPostMemInit() is called during board detection with the successfuly
+  detected board providing its set of board-specific post-memory initialization functions.
+
+  @param[in]    BoardPostMemInit        A pointer to a structure of function pointers described in the type
+                                        BOARD_POST_MEM_INIT_FUNC.
+
+  @retval       EFI_SUCCESS             The board post-memory functions were successfully registered.
+  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
+  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to register the callback functions.
+
+**/
 EFI_STATUS
 EFIAPI
 RegisterBoardPostMemInit (
@@ -63,14 +126,22 @@ RegisterBoardPostMemInit (
   EFI_STATUS                 Status;
   EFI_PEI_PPI_DESCRIPTOR     *PpiListBoardInitPostMem;
 
-  PpiListBoardInitPostMem = AllocatePool (sizeof(EFI_PEI_PPI_DESCRIPTOR));
-  ASSERT (PpiListBoardInitPostMem != NULL);
+  if (BoardPostMemInit == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  PpiListBoardInitPostMem = AllocatePool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
+  if (PpiListBoardInitPostMem == NULL) {
+    ASSERT (PpiListBoardInitPostMem != NULL);
+    return EFI_OUT_OF_RESOURCES;
+  }
 
   PpiListBoardInitPostMem->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
   PpiListBoardInitPostMem->Guid  = &gBoardPostMemInitGuid;
   PpiListBoardInitPostMem->Ppi   = BoardPostMemInit;
 
   Status = PeiServicesInstallPpi (PpiListBoardInitPostMem);
-  ASSERT_EFI_ERROR(Status);
-  return EFI_SUCCESS;
+  ASSERT_EFI_ERROR (Status);
+
+  return Status;
 }
-- 
2.16.2.windows.1


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

* Re: [edk2-platforms][PATCH V1 1/1] MinPlatformPkg/MultiBoardInitSupportLib: Fix NULL pointer dereferences
  2019-08-23 23:24 [edk2-platforms][PATCH V1 1/1] MinPlatformPkg/MultiBoardInitSupportLib: Fix NULL pointer dereferences Kubacki, Michael A
@ 2019-08-23 23:44 ` Nate DeSimone
  2019-08-26  7:28 ` [edk2-devel] " Chiu, Chasel
  1 sibling, 0 replies; 3+ messages in thread
From: Nate DeSimone @ 2019-08-23 23:44 UTC (permalink / raw)
  To: Kubacki, Michael A, devel@edk2.groups.io; +Cc: Chiu, Chasel, Gao, Liming

Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>

-----Original Message-----
From: Kubacki, Michael A 
Sent: Friday, August 23, 2019 4:24 PM
To: devel@edk2.groups.io
Cc: Chiu, Chasel <chasel.chiu@intel.com>; Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [edk2-platforms][PATCH V1 1/1] MinPlatformPkg/MultiBoardInitSupportLib: Fix NULL pointer dereferences

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2114

Removes potential NULL pointer de-references in the library and validates NULL pointers are not passed to library functions.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>
---
 Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.h                                  | 84 ++++++++++++++++-
 Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.c | 24 ++++-  Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.c | 97 +++++++++++++++++---
 3 files changed, 188 insertions(+), 17 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.h b/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.h
index 6c14b5677d..a854f61e27 100644
--- a/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.h
+++ b/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSuppor
+++ tLib.h
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -10,18 +10,39 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #include <Library/BoardInitLib.h>
 
+/**
+  This board service detects the board type.
+
+  @retval EFI_SUCCESS   The board was detected successfully.
+  @retval EFI_NOT_FOUND The board could not be detected.
+
+**/
 typedef
 EFI_STATUS
 (EFIAPI *BOARD_DETECT) (
   VOID
   );
 
+/**
+  This board service performs board-specific initialization.
+
+  @retval EFI_SUCCESS   Board-specific initialization was successful.
+  @retval EFI_NOT_READY The board has not been detected yet.
+
+**/
 typedef
 EFI_STATUS
 (EFIAPI *BOARD_INIT) (
   VOID
   );
 
+/**
+  This board service detects the boot mode.
+
+  @retval EFI_BOOT_MODE The boot mode.
+  @retval EFI_NOT_READY The board has not been detected yet.
+
+**/
 typedef
 EFI_BOOT_MODE
 (EFIAPI *BOARD_BOOT_MODE_DETECT) (
@@ -52,24 +73,85 @@ typedef struct {
   BOARD_INIT              BoardInitEndOfFirmware;
 } BOARD_NOTIFICATION_INIT_FUNC;
 
+/**
+  Registers the given function for callback during board detection.
+
+  When this function is called the given function pointer is added to 
+ an internal list. When board detection is  performed within the 
+ BoardDetect() API, the function pointers in the list will be invoked until a board  detection function reports it has successfully detected the board.
+
+  @param[in]    BoardDetect             A pointer to a function of type BOARD_DETECT_FUNC that is called during
+                                        board detection.
+
+  @retval       EFI_SUCCESS             The function was successfully registered.
+  @retval       EFI_INVALID_PARAMETER   The function pointer given is NULL.
+  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to add a new board detection callback.
+
+**/
 EFI_STATUS
 EFIAPI
 RegisterBoardDetect (
   IN BOARD_DETECT_FUNC  *BoardDetect
   );
 
+/**
+  Registers the given set of board functions for callback to perform pre-memory board initialization tasks.
+
+  When this function is called, the given structure of function 
+ pointers are stored for future invocation. When  board pre-memory 
+ initialization tasks are required, the corresponding pre-memory 
+ function in this structure  will be called. Typically, RegisterBoardPreMemInit() is called during board detection with the successfully  detected board providing its set of board-specific pre-memory initialization functions.
+
+  @param[in]    BoardPreMemInit         A pointer to a structure of function pointers described in the type
+                                        BOARD_PRE_MEM_INIT_FUNC.
+
+  @retval       EFI_SUCCESS             The board pre-memory functions were successfully registered.
+  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
+  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to register the callback functions.
+
+**/
 EFI_STATUS
 EFIAPI
 RegisterBoardPreMemInit (
   IN BOARD_PRE_MEM_INIT_FUNC  *BoardPreMemInit
   );
 
+/**
+  Registers the given set of board functions for callback to perform post-memory board initialization tasks.
+
+  When this function is called, the given structure of function 
+ pointers are stored for future invocation. When  board post-memory 
+ initialization tasks are required, the corresponding post-memory 
+ function in this structure  will be called. Typically, RegisterBoardPostMemInit() is called during board detection with the successfuly  detected board providing its set of board-specific post-memory initialization functions.
+
+  @param[in]    BoardPostMemInit        A pointer to a structure of function pointers described in the type
+                                        BOARD_POST_MEM_INIT_FUNC.
+
+  @retval       EFI_SUCCESS             The board post-memory functions were successfully registered.
+  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
+  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to register the callback functions.
+
+**/
 EFI_STATUS
 EFIAPI
 RegisterBoardPostMemInit (
   IN BOARD_POST_MEM_INIT_FUNC  *BoardPostMemInit
   );
 
+/**
+  Registers the given set of board functions for callback to perform board initialization tasks.
+
+  When this function is called, the given structure of function 
+ pointers are stored for future invocation. When  board initialization tasks are required, the corresponding functions in this structure will be called.
+
+  @param[in]    BoardNotificationInit   A pointer to a structure of function pointers described in the type
+                                        BOARD_NOTIFICATION_INIT_FUNC.
+
+  @retval       EFI_SUCCESS             The board notification functions were successfully registered.
+  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
+  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to register the callback functions.
+
+**/
 EFI_STATUS
 EFIAPI
 RegisterBoardNotificationInit (
diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.c b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.c
index 90aabdbbc7..3eb3a1adc7 100644
--- a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/DxeMultiBoardInitSupportLib.c
+++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitS
+++ upportLib/DxeMultiBoardInitSupportLib.c
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -11,6 +11,20 @@ SPDX-License-Identifier: BSD-2-Clause-Patent  #include <Library/DebugLib.h>  #include <Library/UefiBootServicesTableLib.h>
 
+/**
+  Registers the given set of board functions for callback to perform board initialization tasks.
+
+  When this function is called, the given structure of function 
+ pointers are stored for future invocation. When  board initialization tasks are required, the corresponding functions in this structure will be called.
+
+  @param[in]    BoardNotificationInit   A pointer to a structure of function pointers described in the type
+                                        BOARD_NOTIFICATION_INIT_FUNC.
+
+  @retval       EFI_SUCCESS             The board notification functions were successfully registered.
+  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
+  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to register the callback functions.
+
+**/
 EFI_STATUS
 EFIAPI
 RegisterBoardNotificationInit (
@@ -20,6 +34,10 @@ RegisterBoardNotificationInit (
   EFI_HANDLE  Handle;
   EFI_STATUS  Status;
 
+  if (BoardNotificationInit == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
   Handle = NULL;
   Status = gBS->InstallProtocolInterface (
                   &Handle,
@@ -27,7 +45,7 @@ RegisterBoardNotificationInit (
                   EFI_NATIVE_INTERFACE,
                   BoardNotificationInit
                   );
-  ASSERT_EFI_ERROR(Status);
+  ASSERT_EFI_ERROR (Status);
 
-  return EFI_SUCCESS;
+  return Status;
 }
diff --git a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.c b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.c
index f1cd735e41..6f5b90d9b1 100644
--- a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportLib/PeiMultiBoardInitSupportLib.c
+++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitS
+++ upportLib/PeiMultiBoardInitSupportLib.c
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -12,6 +12,21 @@ SPDX-License-Identifier: BSD-2-Clause-Patent  #include <Library/MemoryAllocationLib.h>  #include <Library/PeiServicesLib.h>
 
+/**
+  Registers the given function for callback during board detection.
+
+  When this function is called the given function pointer is added to 
+ an internal list. When board detection is  performed within the 
+ BoardDetect() API, the function pointers in the list will be invoked until a board  detection function reports it has successfully detected the board.
+
+  @param[in]    BoardDetect             A pointer to a function of type BOARD_DETECT_FUNC that is called during
+                                        board detection.
+
+  @retval       EFI_SUCCESS             The function was successfully registered.
+  @retval       EFI_INVALID_PARAMETER   The function pointer given is NULL.
+  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to add a new board detection callback.
+
+**/
 EFI_STATUS
 EFIAPI
 RegisterBoardDetect (
@@ -21,18 +36,42 @@ RegisterBoardDetect (
   EFI_STATUS                 Status;
   EFI_PEI_PPI_DESCRIPTOR     *PpiListBoardDetect;
 
-  PpiListBoardDetect = AllocatePool (sizeof(EFI_PEI_PPI_DESCRIPTOR));
-  ASSERT (PpiListBoardDetect != NULL);
+  if (BoardDetect == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  PpiListBoardDetect = AllocatePool (sizeof (EFI_PEI_PPI_DESCRIPTOR));  
+ if (PpiListBoardDetect == NULL) {
+    ASSERT (PpiListBoardDetect != NULL);
+    return EFI_OUT_OF_RESOURCES;
+  }
 
   PpiListBoardDetect->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
   PpiListBoardDetect->Guid  = &gBoardDetectGuid;
   PpiListBoardDetect->Ppi   = BoardDetect;
 
   Status = PeiServicesInstallPpi (PpiListBoardDetect);
-  ASSERT_EFI_ERROR(Status);
-  return EFI_SUCCESS;
+  ASSERT_EFI_ERROR (Status);
+
+  return Status;
 }
 
+/**
+  Registers the given set of board functions for callback to perform pre-memory board initialization tasks.
+
+  When this function is called, the given structure of function 
+ pointers are stored for future invocation. When  board pre-memory 
+ initialization tasks are required, the corresponding pre-memory 
+ function in this structure  will be called. Typically, RegisterBoardPreMemInit() is called during board detection with the successfully  detected board providing its set of board-specific pre-memory initialization functions.
+
+  @param[in]    BoardPreMemInit         A pointer to a structure of function pointers described in the type
+                                        BOARD_PRE_MEM_INIT_FUNC.
+
+  @retval       EFI_SUCCESS             The board pre-memory functions were successfully registered.
+  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
+  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to register the callback functions.
+
+**/
 EFI_STATUS
 EFIAPI
 RegisterBoardPreMemInit (
@@ -42,18 +81,42 @@ RegisterBoardPreMemInit (
   EFI_STATUS                 Status;
   EFI_PEI_PPI_DESCRIPTOR     *PpiListBoardInitPreMem;
 
-  PpiListBoardInitPreMem = AllocatePool (sizeof(EFI_PEI_PPI_DESCRIPTOR));
-  ASSERT (PpiListBoardInitPreMem != NULL);
+  if (BoardPreMemInit == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  PpiListBoardInitPreMem = AllocatePool (sizeof 
+ (EFI_PEI_PPI_DESCRIPTOR));  if (PpiListBoardInitPreMem == NULL) {
+    ASSERT (PpiListBoardInitPreMem != NULL);
+    return EFI_OUT_OF_RESOURCES;
+  }
 
   PpiListBoardInitPreMem->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
   PpiListBoardInitPreMem->Guid  = &gBoardPreMemInitGuid;
   PpiListBoardInitPreMem->Ppi   = BoardPreMemInit;
 
   Status = PeiServicesInstallPpi (PpiListBoardInitPreMem);
-  ASSERT_EFI_ERROR(Status);
-  return EFI_SUCCESS;
+  ASSERT_EFI_ERROR (Status);
+
+  return Status;
 }
 
+/**
+  Registers the given set of board functions for callback to perform post-memory board initialization tasks.
+
+  When this function is called, the given structure of function 
+ pointers are stored for future invocation. When  board post-memory 
+ initialization tasks are required, the corresponding post-memory 
+ function in this structure  will be called. Typically, RegisterBoardPostMemInit() is called during board detection with the successfuly  detected board providing its set of board-specific post-memory initialization functions.
+
+  @param[in]    BoardPostMemInit        A pointer to a structure of function pointers described in the type
+                                        BOARD_POST_MEM_INIT_FUNC.
+
+  @retval       EFI_SUCCESS             The board post-memory functions were successfully registered.
+  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
+  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to register the callback functions.
+
+**/
 EFI_STATUS
 EFIAPI
 RegisterBoardPostMemInit (
@@ -63,14 +126,22 @@ RegisterBoardPostMemInit (
   EFI_STATUS                 Status;
   EFI_PEI_PPI_DESCRIPTOR     *PpiListBoardInitPostMem;
 
-  PpiListBoardInitPostMem = AllocatePool (sizeof(EFI_PEI_PPI_DESCRIPTOR));
-  ASSERT (PpiListBoardInitPostMem != NULL);
+  if (BoardPostMemInit == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  PpiListBoardInitPostMem = AllocatePool (sizeof 
+ (EFI_PEI_PPI_DESCRIPTOR));  if (PpiListBoardInitPostMem == NULL) {
+    ASSERT (PpiListBoardInitPostMem != NULL);
+    return EFI_OUT_OF_RESOURCES;
+  }
 
   PpiListBoardInitPostMem->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
   PpiListBoardInitPostMem->Guid  = &gBoardPostMemInitGuid;
   PpiListBoardInitPostMem->Ppi   = BoardPostMemInit;
 
   Status = PeiServicesInstallPpi (PpiListBoardInitPostMem);
-  ASSERT_EFI_ERROR(Status);
-  return EFI_SUCCESS;
+  ASSERT_EFI_ERROR (Status);
+
+  return Status;
 }
--
2.16.2.windows.1


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

* Re: [edk2-devel] [edk2-platforms][PATCH V1 1/1] MinPlatformPkg/MultiBoardInitSupportLib: Fix NULL pointer dereferences
  2019-08-23 23:24 [edk2-platforms][PATCH V1 1/1] MinPlatformPkg/MultiBoardInitSupportLib: Fix NULL pointer dereferences Kubacki, Michael A
  2019-08-23 23:44 ` Nate DeSimone
@ 2019-08-26  7:28 ` Chiu, Chasel
  1 sibling, 0 replies; 3+ messages in thread
From: Chiu, Chasel @ 2019-08-26  7:28 UTC (permalink / raw)
  To: devel@edk2.groups.io, Kubacki, Michael A
  Cc: Desimone, Nathaniel L, Gao, Liming


Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>


> -----Original Message-----
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> Kubacki, Michael A
> Sent: Saturday, August 24, 2019 7:24 AM
> To: devel@edk2.groups.io
> Cc: Chiu, Chasel <chasel.chiu@intel.com>; Desimone, Nathaniel L
> <nathaniel.l.desimone@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: [edk2-devel] [edk2-platforms][PATCH V1 1/1]
> MinPlatformPkg/MultiBoardInitSupportLib: Fix NULL pointer dereferences
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2114
> 
> Removes potential NULL pointer de-references in the library and validates
> NULL pointers are not passed to library functions.
> 
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Signed-off-by: Michael Kubacki <michael.a.kubacki@intel.com>
> ---
>  Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.h
> | 84 ++++++++++++++++-
> 
> Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportL
> ib/DxeMultiBoardInitSupportLib.c | 24 ++++-
> Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSupportL
> ib/PeiMultiBoardInitSupportLib.c | 97 +++++++++++++++++---
>  3 files changed, 188 insertions(+), 17 deletions(-)
> 
> diff --git
> a/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.
> h
> b/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.
> h
> index 6c14b5677d..a854f61e27 100644
> ---
> a/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSupportLib.
> h
> +++ b/Platform/Intel/MinPlatformPkg/Include/Library/MultiBoardInitSuppor
> +++ tLib.h
> @@ -1,6 +1,6 @@
>  /** @file
> 
> -Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -10,18 +10,39 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  #include <Library/BoardInitLib.h>
> 
> +/**
> +  This board service detects the board type.
> +
> +  @retval EFI_SUCCESS   The board was detected successfully.
> +  @retval EFI_NOT_FOUND The board could not be detected.
> +
> +**/
>  typedef
>  EFI_STATUS
>  (EFIAPI *BOARD_DETECT) (
>    VOID
>    );
> 
> +/**
> +  This board service performs board-specific initialization.
> +
> +  @retval EFI_SUCCESS   Board-specific initialization was successful.
> +  @retval EFI_NOT_READY The board has not been detected yet.
> +
> +**/
>  typedef
>  EFI_STATUS
>  (EFIAPI *BOARD_INIT) (
>    VOID
>    );
> 
> +/**
> +  This board service detects the boot mode.
> +
> +  @retval EFI_BOOT_MODE The boot mode.
> +  @retval EFI_NOT_READY The board has not been detected yet.
> +
> +**/
>  typedef
>  EFI_BOOT_MODE
>  (EFIAPI *BOARD_BOOT_MODE_DETECT) (
> @@ -52,24 +73,85 @@ typedef struct {
>    BOARD_INIT              BoardInitEndOfFirmware;
>  } BOARD_NOTIFICATION_INIT_FUNC;
> 
> +/**
> +  Registers the given function for callback during board detection.
> +
> +  When this function is called the given function pointer is added to
> + an internal list. When board detection is  performed within the
> + BoardDetect() API, the function pointers in the list will be invoked until a
> board  detection function reports it has successfully detected the board.
> +
> +  @param[in]    BoardDetect             A pointer to a function of type
> BOARD_DETECT_FUNC that is called during
> +                                        board detection.
> +
> +  @retval       EFI_SUCCESS             The function was successfully
> registered.
> +  @retval       EFI_INVALID_PARAMETER   The function pointer given is NULL.
> +  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources
> exist to add a new board detection callback.
> +
> +**/
>  EFI_STATUS
>  EFIAPI
>  RegisterBoardDetect (
>    IN BOARD_DETECT_FUNC  *BoardDetect
>    );
> 
> +/**
> +  Registers the given set of board functions for callback to perform
> pre-memory board initialization tasks.
> +
> +  When this function is called, the given structure of function
> + pointers are stored for future invocation. When  board pre-memory
> + initialization tasks are required, the corresponding pre-memory
> + function in this structure  will be called. Typically, RegisterBoardPreMemInit()
> is called during board detection with the successfully  detected board
> providing its set of board-specific pre-memory initialization functions.
> +
> +  @param[in]    BoardPreMemInit         A pointer to a structure of function
> pointers described in the type
> +                                        BOARD_PRE_MEM_INIT_FUNC.
> +
> +  @retval       EFI_SUCCESS             The board pre-memory functions were
> successfully registered.
> +  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
> +  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources
> exist to register the callback functions.
> +
> +**/
>  EFI_STATUS
>  EFIAPI
>  RegisterBoardPreMemInit (
>    IN BOARD_PRE_MEM_INIT_FUNC  *BoardPreMemInit
>    );
> 
> +/**
> +  Registers the given set of board functions for callback to perform
> post-memory board initialization tasks.
> +
> +  When this function is called, the given structure of function
> + pointers are stored for future invocation. When  board post-memory
> + initialization tasks are required, the corresponding post-memory
> + function in this structure  will be called. Typically,
> RegisterBoardPostMemInit() is called during board detection with the
> successfuly  detected board providing its set of board-specific post-memory
> initialization functions.
> +
> +  @param[in]    BoardPostMemInit        A pointer to a structure of function
> pointers described in the type
> +                                        BOARD_POST_MEM_INIT_FUNC.
> +
> +  @retval       EFI_SUCCESS             The board post-memory functions were
> successfully registered.
> +  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
> +  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources
> exist to register the callback functions.
> +
> +**/
>  EFI_STATUS
>  EFIAPI
>  RegisterBoardPostMemInit (
>    IN BOARD_POST_MEM_INIT_FUNC  *BoardPostMemInit
>    );
> 
> +/**
> +  Registers the given set of board functions for callback to perform board
> initialization tasks.
> +
> +  When this function is called, the given structure of function
> + pointers are stored for future invocation. When  board initialization tasks
> are required, the corresponding functions in this structure will be called.
> +
> +  @param[in]    BoardNotificationInit   A pointer to a structure of function
> pointers described in the type
> +                                        BOARD_NOTIFICATION_INIT_FUNC.
> +
> +  @retval       EFI_SUCCESS             The board notification functions were
> successfully registered.
> +  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
> +  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources
> exist to register the callback functions.
> +
> +**/
>  EFI_STATUS
>  EFIAPI
>  RegisterBoardNotificationInit (
> diff --git
> a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSuppo
> rtLib/DxeMultiBoardInitSupportLib.c
> b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSuppo
> rtLib/DxeMultiBoardInitSupportLib.c
> index 90aabdbbc7..3eb3a1adc7 100644
> ---
> a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSuppo
> rtLib/DxeMultiBoardInitSupportLib.c
> +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitS
> +++ upportLib/DxeMultiBoardInitSupportLib.c
> @@ -1,6 +1,6 @@
>  /** @file
> 
> -Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -11,6 +11,20 @@ SPDX-License-Identifier: BSD-2-Clause-Patent  #include
> <Library/DebugLib.h>  #include <Library/UefiBootServicesTableLib.h>
> 
> +/**
> +  Registers the given set of board functions for callback to perform board
> initialization tasks.
> +
> +  When this function is called, the given structure of function
> + pointers are stored for future invocation. When  board initialization tasks
> are required, the corresponding functions in this structure will be called.
> +
> +  @param[in]    BoardNotificationInit   A pointer to a structure of function
> pointers described in the type
> +                                        BOARD_NOTIFICATION_INIT_FUNC.
> +
> +  @retval       EFI_SUCCESS             The board notification functions were
> successfully registered.
> +  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
> +  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources
> exist to register the callback functions.
> +
> +**/
>  EFI_STATUS
>  EFIAPI
>  RegisterBoardNotificationInit (
> @@ -20,6 +34,10 @@ RegisterBoardNotificationInit (
>    EFI_HANDLE  Handle;
>    EFI_STATUS  Status;
> 
> +  if (BoardNotificationInit == NULL) {
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
>    Handle = NULL;
>    Status = gBS->InstallProtocolInterface (
>                    &Handle,
> @@ -27,7 +45,7 @@ RegisterBoardNotificationInit (
>                    EFI_NATIVE_INTERFACE,
>                    BoardNotificationInit
>                    );
> -  ASSERT_EFI_ERROR(Status);
> +  ASSERT_EFI_ERROR (Status);
> 
> -  return EFI_SUCCESS;
> +  return Status;
>  }
> diff --git
> a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSuppo
> rtLib/PeiMultiBoardInitSupportLib.c
> b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSuppo
> rtLib/PeiMultiBoardInitSupportLib.c
> index f1cd735e41..6f5b90d9b1 100644
> ---
> a/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitSuppo
> rtLib/PeiMultiBoardInitSupportLib.c
> +++ b/Platform/Intel/MinPlatformPkg/PlatformInit/Library/MultiBoardInitS
> +++ upportLib/PeiMultiBoardInitSupportLib.c
> @@ -1,6 +1,6 @@
>  /** @file
> 
> -Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -12,6 +12,21 @@ SPDX-License-Identifier: BSD-2-Clause-Patent  #include
> <Library/MemoryAllocationLib.h>  #include <Library/PeiServicesLib.h>
> 
> +/**
> +  Registers the given function for callback during board detection.
> +
> +  When this function is called the given function pointer is added to
> + an internal list. When board detection is  performed within the
> + BoardDetect() API, the function pointers in the list will be invoked until a
> board  detection function reports it has successfully detected the board.
> +
> +  @param[in]    BoardDetect             A pointer to a function of type
> BOARD_DETECT_FUNC that is called during
> +                                        board detection.
> +
> +  @retval       EFI_SUCCESS             The function was successfully
> registered.
> +  @retval       EFI_INVALID_PARAMETER   The function pointer given is NULL.
> +  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources
> exist to add a new board detection callback.
> +
> +**/
>  EFI_STATUS
>  EFIAPI
>  RegisterBoardDetect (
> @@ -21,18 +36,42 @@ RegisterBoardDetect (
>    EFI_STATUS                 Status;
>    EFI_PEI_PPI_DESCRIPTOR     *PpiListBoardDetect;
> 
> -  PpiListBoardDetect = AllocatePool (sizeof(EFI_PEI_PPI_DESCRIPTOR));
> -  ASSERT (PpiListBoardDetect != NULL);
> +  if (BoardDetect == NULL) {
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  PpiListBoardDetect = AllocatePool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
> + if (PpiListBoardDetect == NULL) {
> +    ASSERT (PpiListBoardDetect != NULL);
> +    return EFI_OUT_OF_RESOURCES;
> +  }
> 
>    PpiListBoardDetect->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI |
> EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
>    PpiListBoardDetect->Guid  = &gBoardDetectGuid;
>    PpiListBoardDetect->Ppi   = BoardDetect;
> 
>    Status = PeiServicesInstallPpi (PpiListBoardDetect);
> -  ASSERT_EFI_ERROR(Status);
> -  return EFI_SUCCESS;
> +  ASSERT_EFI_ERROR (Status);
> +
> +  return Status;
>  }
> 
> +/**
> +  Registers the given set of board functions for callback to perform
> pre-memory board initialization tasks.
> +
> +  When this function is called, the given structure of function
> + pointers are stored for future invocation. When  board pre-memory
> + initialization tasks are required, the corresponding pre-memory
> + function in this structure  will be called. Typically, RegisterBoardPreMemInit()
> is called during board detection with the successfully  detected board
> providing its set of board-specific pre-memory initialization functions.
> +
> +  @param[in]    BoardPreMemInit         A pointer to a structure of function
> pointers described in the type
> +                                        BOARD_PRE_MEM_INIT_FUNC.
> +
> +  @retval       EFI_SUCCESS             The board pre-memory functions were
> successfully registered.
> +  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
> +  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources
> exist to register the callback functions.
> +
> +**/
>  EFI_STATUS
>  EFIAPI
>  RegisterBoardPreMemInit (
> @@ -42,18 +81,42 @@ RegisterBoardPreMemInit (
>    EFI_STATUS                 Status;
>    EFI_PEI_PPI_DESCRIPTOR     *PpiListBoardInitPreMem;
> 
> -  PpiListBoardInitPreMem = AllocatePool (sizeof(EFI_PEI_PPI_DESCRIPTOR));
> -  ASSERT (PpiListBoardInitPreMem != NULL);
> +  if (BoardPreMemInit == NULL) {
> +    return EFI_OUT_OF_RESOURCES;
> +  }
> +
> +  PpiListBoardInitPreMem = AllocatePool (sizeof
> + (EFI_PEI_PPI_DESCRIPTOR));  if (PpiListBoardInitPreMem == NULL) {
> +    ASSERT (PpiListBoardInitPreMem != NULL);
> +    return EFI_OUT_OF_RESOURCES;
> +  }
> 
>    PpiListBoardInitPreMem->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI |
> EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
>    PpiListBoardInitPreMem->Guid  = &gBoardPreMemInitGuid;
>    PpiListBoardInitPreMem->Ppi   = BoardPreMemInit;
> 
>    Status = PeiServicesInstallPpi (PpiListBoardInitPreMem);
> -  ASSERT_EFI_ERROR(Status);
> -  return EFI_SUCCESS;
> +  ASSERT_EFI_ERROR (Status);
> +
> +  return Status;
>  }
> 
> +/**
> +  Registers the given set of board functions for callback to perform
> post-memory board initialization tasks.
> +
> +  When this function is called, the given structure of function
> + pointers are stored for future invocation. When  board post-memory
> + initialization tasks are required, the corresponding post-memory
> + function in this structure  will be called. Typically,
> RegisterBoardPostMemInit() is called during board detection with the
> successfuly  detected board providing its set of board-specific post-memory
> initialization functions.
> +
> +  @param[in]    BoardPostMemInit        A pointer to a structure of function
> pointers described in the type
> +                                        BOARD_POST_MEM_INIT_FUNC.
> +
> +  @retval       EFI_SUCCESS             The board post-memory functions were
> successfully registered.
> +  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
> +  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources
> exist to register the callback functions.
> +
> +**/
>  EFI_STATUS
>  EFIAPI
>  RegisterBoardPostMemInit (
> @@ -63,14 +126,22 @@ RegisterBoardPostMemInit (
>    EFI_STATUS                 Status;
>    EFI_PEI_PPI_DESCRIPTOR     *PpiListBoardInitPostMem;
> 
> -  PpiListBoardInitPostMem = AllocatePool (sizeof(EFI_PEI_PPI_DESCRIPTOR));
> -  ASSERT (PpiListBoardInitPostMem != NULL);
> +  if (BoardPostMemInit == NULL) {
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  PpiListBoardInitPostMem = AllocatePool (sizeof
> + (EFI_PEI_PPI_DESCRIPTOR));  if (PpiListBoardInitPostMem == NULL) {
> +    ASSERT (PpiListBoardInitPostMem != NULL);
> +    return EFI_OUT_OF_RESOURCES;
> +  }
> 
>    PpiListBoardInitPostMem->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI |
> EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
>    PpiListBoardInitPostMem->Guid  = &gBoardPostMemInitGuid;
>    PpiListBoardInitPostMem->Ppi   = BoardPostMemInit;
> 
>    Status = PeiServicesInstallPpi (PpiListBoardInitPostMem);
> -  ASSERT_EFI_ERROR(Status);
> -  return EFI_SUCCESS;
> +  ASSERT_EFI_ERROR (Status);
> +
> +  return Status;
>  }
> --
> 2.16.2.windows.1
> 
> 
> 


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

end of thread, other threads:[~2019-08-26  7:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-23 23:24 [edk2-platforms][PATCH V1 1/1] MinPlatformPkg/MultiBoardInitSupportLib: Fix NULL pointer dereferences Kubacki, Michael A
2019-08-23 23:44 ` Nate DeSimone
2019-08-26  7:28 ` [edk2-devel] " Chiu, Chasel

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