From: "Sami Mujawar" <sami.mujawar@arm.com>
To: "gua.guo@intel.com" <gua.guo@intel.com>,
"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: Marc Beatove <mbeatove@google.com>,
Ard Biesheuvel <ardb+tianocore@kernel.org>,
Ray Ni <ray.ni@intel.com>, John Mathew <john.mathews@intel.com>,
Gerd Hoffmann <kraxel@redhat.com>, nd <nd@arm.com>
Subject: Re: [edk2-devel] [PATCH v2 2/4] StandaloneMmPkg/Hob: Integer Overflow in CreateHob()
Date: Thu, 11 Jan 2024 14:06:25 +0000 [thread overview]
Message-ID: <B1FDDB41-7653-422D-8A86-F697EDBCC6DC@arm.com> (raw)
In-Reply-To: <20240111091439.1767-3-gua.guo@intel.com>
Hi Gua,
Thank you for this patch.
Please see my response inline marked [SAMI].
Regards,
Sami Mujawar
On 11/01/2024, 09:15, "gua.guo@intel.com <mailto:gua.guo@intel.com>" <gua.guo@intel.com <mailto:gua.guo@intel.com>> wrote:
From: Gua Guo <gua.guo@intel.com <mailto:gua.guo@intel.com>>
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4166 <https://bugzilla.tianocore.org/show_bug.cgi?id=4166>
Fix integer overflow in various CreateHob instances.
Fixes: CVE-2022-36765
The CreateHob() function aligns the requested size to 8
performing the following operation:
```
HobLength = (UINT16)((HobLength + 0x7) & (~0x7));
```
No checks are performed to ensure this value doesn't
overflow, and could lead to CreateHob() returning a smaller
HOB than requested, which could lead to OOB HOB accesses.
Reported-by: Marc Beatove <mbeatove@google.com <mailto:mbeatove@google.com>>
Reviewed-by: Ard Biesheuvel <ardb+tianocore@kernel.org <mailto:ardb+tianocore@kernel.org>>
Cc: Sami Mujawar <sami.mujawar@arm.com <mailto:sami.mujawar@arm.com>>
Cc: Ray Ni <ray.ni@intel.com <mailto:ray.ni@intel.com>>
Cc: John Mathew <john.mathews@intel.com <mailto:john.mathews@intel.com>>
Authored-by: Gerd Hoffmann <kraxel@redhat.com <mailto:kraxel@redhat.com>>
Signed-off-by: Gua Guo <gua.guo@intel.com <mailto:gua.guo@intel.com>>
---
.../StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c
index 1550e1babc..bb8426dc0a 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c
@@ -34,6 +34,13 @@ CreateHob (
HandOffHob = GetHobList ();
+ //
+ // Check Length to avoid data overflow.
+ //
+ if (HobLength > MAX_UINT16 - 0x7) {
+ return NULL;
[SAMI] Although this fix is correct, I think it shifts the problem somewhere else.
If the above condition occurs, a NULL is returned. A quick scan reveals that the calling functions do not check the returned value before use.
e.g. https://github.com/tianocore/edk2/blob/master/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c#L167-L170
There are multiple such places where the calling functions do not check the pointer returned by CreateHob().
I believe a similar situation can happen for the other patches in this series.
[/SAMI]
+ }
+
HobLength = (UINT16)((HobLength + 0x7) & (~0x7));
FreeMemory = HandOffHob->EfiFreeMemoryTop - HandOffHob->EfiFreeMemoryBottom;
--
2.39.2.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113619): https://edk2.groups.io/g/devel/message/113619
Mute This Topic: https://groups.io/mt/103658960/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2024-01-11 14:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-11 9:14 [edk2-devel] [PATCH v2 0/4] Bz4166: Integer Overflow in CreateHob() Guo, Gua
2024-01-11 9:14 ` [edk2-devel] [PATCH v2 1/4] UefiPayloadPkg/Hob: " Guo, Gua
2024-01-11 9:14 ` [edk2-devel] [PATCH v2 2/4] StandaloneMmPkg/Hob: " Guo, Gua
2024-01-11 14:06 ` Sami Mujawar [this message]
2024-01-11 14:18 ` Guo, Gua
2024-01-11 15:02 ` Sami Mujawar
2024-01-11 15:14 ` Guo, Gua
2024-01-11 16:11 ` Sami Mujawar
2024-01-11 9:14 ` [edk2-devel] [PATCH v2 3/4] EmbeddedPkg/Hob: " Guo, Gua
2024-01-11 9:14 ` [edk2-devel] [PATCH v2 4/4] MdeModulePkg/Hob: " Guo, Gua
2024-01-11 13:31 ` Guo, Gua
2024-01-11 10:28 ` [edk2-devel] [PATCH v2 0/4] Bz4166: " Gerd Hoffmann
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=B1FDDB41-7653-422D-8A86-F697EDBCC6DC@arm.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