From 042e458813aad3465e27cf53c00afe80a272dffb Mon Sep 17 00:00:00 2001 From: Mike Maslenkin Date: Sun, 27 Aug 2023 01:51:31 +0300 Subject: [PATCH 1/6] RedfishClientPkg: fix crash on access to uninitialized list variable. Signed-off-by: Mike Maslenkin Reviewed-by: Nickle Wang Reviewed-by: Igor Kulchytskyy --- RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c b/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c index b9c799e07..a1738de46 100644 --- a/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c @@ -97,6 +97,8 @@ RedfishConsumeResourceCommon ( if (BiosCs->Attributes == NULL) { BiosCs->Attributes = AllocateZeroPool (sizeof (RedfishBios_V1_0_9_Attributes_CS)); ASSERT (BiosCs->Attributes != NULL); + // initialize list + BiosCs->Attributes->Prop.ForwardLink = &BiosCs->Attributes->Prop; } // From 19995d90257c70a22856d92637da2959c0d31ee6 Mon Sep 17 00:00:00 2001 From: Mike Maslenkin Date: Sun, 27 Aug 2023 02:01:24 +0300 Subject: [PATCH 2/6] RedfishClientPkg: fix access to uninitialized variable This patch fixes access to uninitialized variable, causing ASSERT from FreePool at least. Before this patch RedfishSettingsResponse was initialized by GetResourceByUri under 'if (JsonValue != NULL)' condition. But freed under 'if (Private->Payload != NULL)' condition. Thus uninitialized pointers caused ASSERT on attempt to free memory. Signed-off-by: Mike Maslenkin Reviewed-by: Nickle Wang Reviewed-by: Igor Kulchytskyy --- RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c index e7ac87795..f5562fb49 100644 --- a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c @@ -128,6 +128,8 @@ RedfishResourceConsumeResource ( return Status; } + ZeroMem (&RedfishSettingsResponse, sizeof (REDFISH_RESPONSE)); + ExpectedResponse = &Response; RedfishSettingsUri = NULL; JsonValue = RedfishJsonInPayload (Response.Payload); From a4decf47c31d2f1b9612a905a860c37f57928b9b Mon Sep 17 00:00:00 2001 From: Mike Maslenkin Date: Sun, 27 Aug 2023 02:02:14 +0300 Subject: [PATCH 3/6] RedfishClientPkg: fix leak of allocated Etag data Signed-off-by: Mike Maslenkin Reviewed-by: Nickle Wang Reviewed-by: Igor Kulchytskyy --- RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c | 4 ++++ .../Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c | 4 ++++ RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c index f5562fb49..32dca964a 100644 --- a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c @@ -220,6 +220,10 @@ RedfishResourceConsumeResource ( Private->Json = NULL; } + if (Etag != NULL) { + FreePool (Etag); + } + return Status; } diff --git a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c index 91968dbe4..5c2a4eadf 100644 --- a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c +++ b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c @@ -164,6 +164,10 @@ RedfishResourceConsumeResource ( Private->Json = NULL; } + if (Etag != NULL) { + FreePool (Etag); + } + return Status; } diff --git a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c index c55a6848c..f34f3266f 100644 --- a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c +++ b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c @@ -164,6 +164,10 @@ RedfishResourceConsumeResource ( Private->Json = NULL; } + if (Etag != NULL) { + FreePool (Etag); + } + return Status; } From 0db39ff6cada7e734ce5d3c307c99037b8ac7098 Mon Sep 17 00:00:00 2001 From: Mike Maslenkin Date: Sun, 27 Aug 2023 02:02:55 +0300 Subject: [PATCH 4/6] RedfishClientPkg: fix memory leak during EFI variables write. Signed-off-by: Mike Maslenkin Reviewed-by: Nickle Wang Reviewed-by: Igor Kulchytskyy --- .../RedfishConfigLangMapDxe/RedfishConfigLangMapDxe.c | 6 +++++- RedfishClientPkg/RedfishETagDxe/RedfishETagDxe.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/RedfishClientPkg/RedfishConfigLangMapDxe/RedfishConfigLangMapDxe.c b/RedfishClientPkg/RedfishConfigLangMapDxe/RedfishConfigLangMapDxe.c index 86684cc72..6a72afed8 100644 --- a/RedfishClientPkg/RedfishConfigLangMapDxe/RedfishConfigLangMapDxe.c +++ b/RedfishClientPkg/RedfishConfigLangMapDxe/RedfishConfigLangMapDxe.c @@ -424,7 +424,11 @@ SaveConfigLangMapList ( gRT->SetVariable (VariableName, &gEfiRedfishClientVariableGuid, VARIABLE_ATTRIBUTE_NV_BS, 0, NULL); } - return gRT->SetVariable (VariableName, &gEfiRedfishClientVariableGuid, VARIABLE_ATTRIBUTE_NV_BS, VarSize, (VOID *)VarData); + Status = gRT->SetVariable (VariableName, &gEfiRedfishClientVariableGuid, VARIABLE_ATTRIBUTE_NV_BS, VarSize, (VOID *)VarData); + + FreePool (VarData); + + return Status; } /** diff --git a/RedfishClientPkg/RedfishETagDxe/RedfishETagDxe.c b/RedfishClientPkg/RedfishETagDxe/RedfishETagDxe.c index 7ac6e885d..a892ced98 100644 --- a/RedfishClientPkg/RedfishETagDxe/RedfishETagDxe.c +++ b/RedfishClientPkg/RedfishETagDxe/RedfishETagDxe.c @@ -411,7 +411,11 @@ SaveETagList ( gRT->SetVariable (VariableName, &gEfiRedfishClientVariableGuid, VARIABLE_ATTRIBUTE_NV_BS, 0, NULL); } - return gRT->SetVariable (VariableName, &gEfiRedfishClientVariableGuid, VARIABLE_ATTRIBUTE_NV_BS, VarSize, (VOID *)VarData); + Status = gRT->SetVariable (VariableName, &gEfiRedfishClientVariableGuid, VARIABLE_ATTRIBUTE_NV_BS, VarSize, (VOID *)VarData); + + FreePool (VarData); + + return Status; } /** From cbbbd836aca7f6c6578c34a45bd05aef7b14e8db Mon Sep 17 00:00:00 2001 From: Mike Maslenkin Date: Sun, 27 Aug 2023 02:15:02 +0300 Subject: [PATCH 5/6] RedfishClientPkg: fix misprints in Readme.md Signed-off-by: Mike Maslenkin Reviewed-by: Nickle Wang Reviewed-by: Igor Kulchytskyy --- RedfishClientPkg/Readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RedfishClientPkg/Readme.md b/RedfishClientPkg/Readme.md index 18a27633c..0aec0580a 100644 --- a/RedfishClientPkg/Readme.md +++ b/RedfishClientPkg/Readme.md @@ -40,7 +40,7 @@ Below are the block diagrams of UEFI Redfish Client EDK2 Implementation. ![UEFI Redfish Client Implementation](https://github.com/changab/edk2-staging/blob/edk2-redfish-client/RedfishClientPkg/Documents/Media/RedfishClientDriverStack.svg?raw=true) ## EFI EDK2 Redfish Client Framework -The functionality of each block in the diagrams are described in belwo sections, +The functionality of each block in the diagrams are described in below sections, ### EDK2 Redfish Foundation ***[[1]](#[0])*** EDK2 Redfish Redfish Foundation provides the facilities of communicating with @@ -68,7 +68,7 @@ project. ### EDK2 Redfish JSON Schema to C Structure Convertor ***[[3]](#[0])*** This is the script auto-generated EDK2 drivers and libraries that provide the -Redfish schema naming based JSON to C structure and vise versa converters. C +Redfish schema naming based JSON to C structure and vice versa converters. C structure is another representation of Redfish properties other than JSON and CSDL(XML). The higher layer Redfish client application can deal with C structure instead of using JSON library to manipulate Redfish properties. The script @@ -85,7 +85,7 @@ sits between **JSON Schema to C Structure converters** and **EFI Platform Configuration to Redfish Protocol**. The Redfish feature driver gets and sets the platform configuration and incorporates it with Redfish JSON schema C structure to manipulate Redfish JSON resources. Then applies the settings from -Redfish service to platform configurations, or vise versa to update platform +Redfish service to platform configurations, or vice versa to update platform configurations to Redfish service. Both EDK2 Redfish Non-Collection and Collection Feature drivers are script auto-generated base on Redfish schema naming. The EDK2 Redfish Non-Collection feature driver manages the resource of From d461404aa491c2f110da5bf938681650670f00b6 Mon Sep 17 00:00:00 2001 From: Mike Maslenkin Date: Tue, 29 Aug 2023 01:40:36 +0300 Subject: [PATCH 6/6] RedfishClientPkg: spelling fixes Signed-off-by: Mike Maslenkin Reviewed-by: Nickle Wang Reviewed-by: Igor Kulchytskyy --- RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c | 4 ++-- .../ComputerSystemCollectionDxe.c | 6 +++--- .../Features/MemoryCollectionDxe/MemoryCollectionDxe.c | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c b/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c index a1738de46..a969557dd 100644 --- a/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c @@ -831,7 +831,7 @@ HandleResource ( DEBUG ((REDFISH_DEBUG_TRACE, "%a consume for %s\n", __func__, Uri)); Status = EdkIIRedfishResourceConfigConsume (&SchemaInfo, Uri); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a, failed to consume resoruce for: %s: %r\n", __func__, Uri, Status)); + DEBUG ((DEBUG_ERROR, "%a, failed to consume resource for: %s: %r\n", __func__, Uri, Status)); } // @@ -840,7 +840,7 @@ HandleResource ( DEBUG ((REDFISH_DEBUG_TRACE, "%a update for %s\n", __func__, Uri)); Status = EdkIIRedfishResourceConfigUpdate (&SchemaInfo, Uri); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a, failed to update resoruce for: %s: %r\n", __func__, Uri, Status)); + DEBUG ((DEBUG_ERROR, "%a, failed to update resource for: %s: %r\n", __func__, Uri, Status)); } return Status; diff --git a/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.c b/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.c index 8f2054e1e..1e362d49c 100644 --- a/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.c +++ b/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.c @@ -109,7 +109,7 @@ HandleResource ( DEBUG ((REDFISH_DEBUG_TRACE, "%a consume for %s\n", __func__, Uri)); Status = EdkIIRedfishResourceConfigConsume (&SchemaInfo, Uri); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a, failed to consume resoruce for: %s: %r\n", __func__, Uri, Status)); + DEBUG ((DEBUG_ERROR, "%a, failed to consume resource for: %s: %r\n", __func__, Uri, Status)); } // @@ -118,7 +118,7 @@ HandleResource ( DEBUG ((REDFISH_DEBUG_TRACE, "%a update for %s\n", __func__, Uri)); Status = EdkIIRedfishResourceConfigUpdate (&SchemaInfo, Uri); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a, failed to update resoruce for: %s: %r\n", __func__, Uri, Status)); + DEBUG ((DEBUG_ERROR, "%a, failed to update resource for: %s: %r\n", __func__, Uri, Status)); } return Status; @@ -228,7 +228,7 @@ CreateCollectionResource ( Status = EdkIIRedfishResourceConfigProvisionging (&SchemaInfo, Private->CollectionUri, Private->InformationExchange, TRUE); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a, failed to create resoruce for: %s: %r\n", __func__, Private->CollectionUri, Status)); + DEBUG ((DEBUG_ERROR, "%a, failed to create resource for: %s: %r\n", __func__, Private->CollectionUri, Status)); } return Status; diff --git a/RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.c b/RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.c index b94ff2e86..1b755cde0 100644 --- a/RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.c +++ b/RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.c @@ -109,7 +109,7 @@ HandleResource ( DEBUG ((REDFISH_DEBUG_TRACE, "%a consume for %s\n", __func__, Uri)); Status = EdkIIRedfishResourceConfigConsume (&SchemaInfo, Uri); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a, failed to consume resoruce for: %s: %r\n", __func__, Uri, Status)); + DEBUG ((DEBUG_ERROR, "%a, failed to consume resource for: %s: %r\n", __func__, Uri, Status)); } // @@ -118,7 +118,7 @@ HandleResource ( DEBUG ((REDFISH_DEBUG_TRACE, "%a update for %s\n", __func__, Uri)); Status = EdkIIRedfishResourceConfigUpdate (&SchemaInfo, Uri); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a, failed to update resoruce for: %s: %r\n", __func__, Uri, Status)); + DEBUG ((DEBUG_ERROR, "%a, failed to update resource for: %s: %r\n", __func__, Uri, Status)); } return Status; @@ -228,7 +228,7 @@ CreateCollectionResource ( Status = EdkIIRedfishResourceConfigProvisionging (&SchemaInfo, Private->CollectionUri, Private->InformationExchange, TRUE); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a, failed to create resoruce for: %s: %r\n", __func__, Private->CollectionUri, Status)); + DEBUG ((DEBUG_ERROR, "%a, failed to create resource for: %s: %r\n", __func__, Private->CollectionUri, Status)); } return Status;