public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Bob Feng" <bob.c.feng@intel.com>
To: "Lin, Jason1" <jason1.lin@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Gao, Liming" <gaoliming@byosoft.com.cn>,
	"Chen, Christine" <yuwei.chen@intel.com>,
	"Chiang, Dakota" <dakota.chiang@intel.com>,
	"Chuang, Vanessa" <vanessa.chuang@intel.com>
Subject: Re: [PATCH v1] [edk2-platforms] Silicon/Intel/FitGen: Fix CheckOverlap would do incorrect split BiosModule action in corner case
Date: Sat, 4 Jun 2022 04:07:55 +0000	[thread overview]
Message-ID: <PH7PR11MB58634AD3FCA77EA5364DF62AC9A09@PH7PR11MB5863.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20220526085148.423-1-jason1.lin@intel.com>

Hi Jason,

Do you think the code could be more understandable if adding a check for the size? 

if ((gFitTableContext.BiosModule[Index].Address <= Address) && (gFitTableContext.BiosModule[Index].Size >= Size) &&
        ((gFitTableContext.BiosModule[Index].Size - Size) >= (Address - gFitTableContext.BiosModule[Index].Address)))


Thanks,
Bob

-----Original Message-----
From: Lin, Jason1 <jason1.lin@intel.com> 
Sent: Thursday, May 26, 2022 4:52 PM
To: devel@edk2.groups.io
Cc: Lin, Jason1 <jason1.lin@intel.com>; Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Chen, Christine <yuwei.chen@intel.com>; Chiang, Dakota <dakota.chiang@intel.com>; Chuang, Vanessa <vanessa.chuang@intel.com>
Subject: [PATCH v1] [edk2-platforms] Silicon/Intel/FitGen: Fix CheckOverlap would do incorrect split BiosModule action in corner case

From: Jason1 Lin <jason1.lin@intel.com>

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

[Description]
CheckOverlap function would do incorrect split on the BiosModule which not happen overlap. This would cause incorrect value locate in FIT entry record.

[Condition]
- This BiosModule base address is lower than input address.
- This BiosModule size is smaller than input size.

[Resolution]
- Do the type coversion to UINT64 to prevent overflow when the value shuld be nagative.
- Do the type coversion from UINT64 to INT64 to do the comparsion with possible nagative value.

Signed-off-by: Jason1 Lin <jason1.lin@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Cc: Dakota Chiang <dakota.chiang@intel.com>
Cc: Vanessa Chuang <vanessa.chuang@intel.com>
---
 Silicon/Intel/Tools/FitGen/FitGen.c | 30 +++++++++++++++++++-  Silicon/Intel/Tools/FitGen/FitGen.h |  2 +-
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/Silicon/Intel/Tools/FitGen/FitGen.c b/Silicon/Intel/Tools/FitGen/FitGen.c
index 290e688f6e..9d7185dc55 100644
--- a/Silicon/Intel/Tools/FitGen/FitGen.c
+++ b/Silicon/Intel/Tools/FitGen/FitGen.c
@@ -755,12 +755,40 @@ CheckOverlap (
   IN UINT32 Address,   IN UINT32 Size   )+/*+++Routine Description:++  Check wheather the input address and size is overlap with any BiosModule.+  If happen overlap, need to be deal with this case.+      ---      +--------------+ <------ BiosModule A Base           +--------------++       |       |              |                                     |              |+               |              |                                     |  BiosModule  |+               |              |                                     |      A       |+               |              |                                     |              |+  BiosModule A +--------------+ <------ [Input] Address     ====>   +--------------++      Size     |              |    |+               |              |    |    [Input] Size+               +--------------+  ------                             +--------------++               |              |                                     |  BiosModule  |+       |       |              |                                     |      B       |+      ---      +--------------+                                     +--------------+++Arguments:++  Address     - The address of the buffer that required to check.+  Size        - The size of the buffer that required to check.++Returns:++  None++--*/ {   INTN  Index;    for (Index = 0; Index < (INTN)gFitTableContext.BiosModuleNumber; Index ++) {     if ((gFitTableContext.BiosModule[Index].Address <= Address) &&-        ((gFitTableContext.BiosModule[Index].Size - Size) >= (Address - gFitTableContext.BiosModule[Index].Address))) {+        ((INT64)((UINT64)gFitTableContext.BiosModule[Index].Size - (UINT64)Size) >= (INT64)((UINT64)Address - (UINT64)gFitTableContext.BiosModule[Index].Address))) {       UINT32  TempSize;       INT32   SubIndex; diff --git a/Silicon/Intel/Tools/FitGen/FitGen.h b/Silicon/Intel/Tools/FitGen/FitGen.h
index 5add6a8870..4943ee259c 100644
--- a/Silicon/Intel/Tools/FitGen/FitGen.h
+++ b/Silicon/Intel/Tools/FitGen/FitGen.h
@@ -31,7 +31,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 // Utility version information // #define UTILITY_MAJOR_VERSION 0-#define UTILITY_MINOR_VERSION 64+#define UTILITY_MINOR_VERSION 65 #define UTILITY_DATE          __DATE__  //-- 
2.36.1.windows.1


  reply	other threads:[~2022-06-04  4:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-26  8:51 [PATCH v1] [edk2-platforms] Silicon/Intel/FitGen: Fix CheckOverlap would do incorrect split BiosModule action in corner case jason1.lin
2022-06-04  4:07 ` Bob Feng [this message]
2022-06-07  3:33   ` jason1.lin
  -- strict thread matches above, loose matches on Subject: below --
2022-05-26  7:40 jason1.lin

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=PH7PR11MB58634AD3FCA77EA5364DF62AC9A09@PH7PR11MB5863.namprd11.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