From: "Michael Kubacki" <michael.kubacki@outlook.com>
To: devel@edk2.groups.io
Cc: Liming Gao <liming.gao@intel.com>,
Michael D Kinney <michael.d.kinney@intel.com>,
Guomin Jiang <guomin.jiang@intel.com>,
Wei6 Xu <wei6.xu@intel.com>
Subject: [PATCH v3 7/7] FmpDevicePkg/FmpDxe: Improve function parameter validation
Date: Thu, 6 Aug 2020 12:05:42 -0700 [thread overview]
Message-ID: <MWHPR07MB34401CAF917FDDF8E5CDEDF4E9480@MWHPR07MB3440.namprd07.prod.outlook.com> (raw)
In-Reply-To: <20200806190542.959-1-michael.kubacki@outlook.com>
From: Michael Kubacki <michael.kubacki@microsoft.com>
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2869
Makes some minor improvements to function parameter validation
in FmpDxe, in particular to externally exposed functions such
as those that back EFI_FIRMWARE_MANAGEMENT_PROTOCOL.
Cc: Liming Gao <liming.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Guomin Jiang <guomin.jiang@intel.com>
Cc: Wei6 Xu <wei6.xu@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Guomin Jiang <guomin.jiang@intel.com>
Reviewed-by: Wei6 Xu <wei6.xu@intel.com>
---
FmpDevicePkg/FmpDxe/FmpDxe.c | 51 ++++++++++++++++++--
1 file changed, 47 insertions(+), 4 deletions(-)
diff --git a/FmpDevicePkg/FmpDxe/FmpDxe.c b/FmpDevicePkg/FmpDxe/FmpDxe.c
index a3e342591936..854feec0a162 100644
--- a/FmpDevicePkg/FmpDxe/FmpDxe.c
+++ b/FmpDevicePkg/FmpDxe/FmpDxe.c
@@ -278,6 +278,11 @@ PopulateDescriptor (
EFI_STATUS Status;
UINT32 DependenciesSize;
+ if (Private == NULL) {
+ DEBUG ((DEBUG_ERROR, "FmpDxe(%s): PopulateDescriptor() - Private is NULL.\n", mImageIdName));
+ return;
+ }
+
if (Private->DescriptorPopulated) {
return;
}
@@ -451,6 +456,12 @@ GetTheImageInfo (
Status = EFI_SUCCESS;
+ if (This == NULL) {
+ DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetImageInfo() - This is NULL.\n", mImageIdName));
+ Status = EFI_INVALID_PARAMETER;
+ goto cleanup;
+ }
+
//
// Retrieve the private context structure
//
@@ -561,6 +572,12 @@ GetTheImage (
Status = EFI_SUCCESS;
+ if (This == NULL) {
+ DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetImage() - This is NULL.\n", mImageIdName));
+ Status = EFI_INVALID_PARAMETER;
+ goto cleanup;
+ }
+
//
// Retrieve the private context structure
//
@@ -615,7 +632,8 @@ GetTheImage (
@param[in] Image Pointer to the image.
@param[in] ImageSize Size of the image.
@param[in] AdditionalHeaderSize Size of any headers that cannot be calculated by this function.
- @param[out] PayloadSize
+ @param[out] PayloadSize An optional pointer to a UINTN that holds the size of the payload
+ (image size minus headers)
@retval !NULL Valid pointer to the header.
@retval NULL Structure is bad and pointer cannot be found.
@@ -626,7 +644,7 @@ GetFmpHeader (
IN CONST EFI_FIRMWARE_IMAGE_AUTHENTICATION *Image,
IN CONST UINTN ImageSize,
IN CONST UINTN AdditionalHeaderSize,
- OUT UINTN *PayloadSize
+ OUT UINTN *PayloadSize OPTIONAL
)
{
//
@@ -640,7 +658,10 @@ GetFmpHeader (
return NULL;
}
- *PayloadSize = ImageSize - (sizeof (Image->MonotonicCount) + Image->AuthInfo.Hdr.dwLength + AdditionalHeaderSize);
+ if (PayloadSize != NULL) {
+ *PayloadSize = ImageSize - (sizeof (Image->MonotonicCount) + Image->AuthInfo.Hdr.dwLength + AdditionalHeaderSize);
+ }
+
return (VOID *)((UINT8 *)Image + sizeof (Image->MonotonicCount) + Image->AuthInfo.Hdr.dwLength + AdditionalHeaderSize);
}
@@ -663,6 +684,11 @@ GetAllHeaderSize (
{
UINT32 CalculatedSize;
+ if (Image == NULL) {
+ DEBUG ((DEBUG_ERROR, "FmpDxe(%s): GetAllHeaderSize() - Image is NULL.\n", mImageIdName));
+ return 0;
+ }
+
CalculatedSize = sizeof (Image->MonotonicCount) +
AdditionalHeaderSize +
Image->AuthInfo.Hdr.dwLength;
@@ -743,6 +769,12 @@ CheckTheImage (
return EFI_UNSUPPORTED;
}
+ if (This == NULL) {
+ DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckImage() - This is NULL.\n", mImageIdName));
+ Status = EFI_INVALID_PARAMETER;
+ goto cleanup;
+ }
+
//
// Retrieve the private context structure
//
@@ -851,7 +883,7 @@ CheckTheImage (
if (ImageIndex != 1) {
DEBUG ((DEBUG_ERROR, "FmpDxe(%s): CheckImage() - Image Index Invalid.\n", mImageIdName));
*ImageUpdatable = IMAGE_UPDATABLE_INVALID_TYPE;
- Status = EFI_SUCCESS;
+ Status = EFI_INVALID_PARAMETER;
goto cleanup;
}
@@ -1026,6 +1058,12 @@ SetTheImage (
return EFI_UNSUPPORTED;
}
+ if (This == NULL) {
+ DEBUG ((DEBUG_ERROR, "FmpDxe(%s): SetTheImage() - This is NULL.\n", mImageIdName));
+ Status = EFI_INVALID_PARAMETER;
+ goto cleanup;
+ }
+
//
// Retrieve the private context structure
//
@@ -1382,6 +1420,11 @@ FmpDxeLockEventNotify (
EFI_STATUS Status;
FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private;
+ if (Context == NULL) {
+ ASSERT (Context != NULL);
+ return;
+ }
+
Private = (FIRMWARE_MANAGEMENT_PRIVATE_DATA *)Context;
if (!Private->FmpDeviceLocked) {
--
2.27.0.windows.1
prev parent reply other threads:[~2020-08-06 19:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200806190542.959-1-michael.kubacki@outlook.com>
2020-08-06 19:05 ` [PATCH v3 1/7] FmpDevicePkg/FmpDependencyLib: Correct ValidateDependency() documentation Michael Kubacki
2020-08-06 19:05 ` [PATCH v3 2/7] FmpDevicePkg/FmpDependencyLib: Fix "exression" typo Michael Kubacki
2020-08-06 19:05 ` [PATCH v3 3/7] FmpDevicePkg/FmpDependencyLib: Handle version string overflow Michael Kubacki
2020-08-06 19:05 ` [PATCH v3 4/7] FmpDevicePkg/FmpDependencyCheckLib: Return unsatisfied on handle failure Michael Kubacki
2020-08-06 19:05 ` [PATCH v3 5/7] FmpDevicePkg/FmpDxe: Better warn of potential ImageTypeId misconfig Michael Kubacki
2020-08-06 19:05 ` [PATCH v3 6/7] FmpDevicePkg/FmpDxe: Indicate ESRT GUID on invalid ImageIdName Michael Kubacki
2020-08-06 19:05 ` Michael Kubacki [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=MWHPR07MB34401CAF917FDDF8E5CDEDF4E9480@MWHPR07MB3440.namprd07.prod.outlook.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox