public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v1] [edk2-platforms] Silicon/Intel/FitGen: Fix CheckOverlap would do incorrect split BiosModule action in corner case
@ 2022-05-26  7:40 jason1.lin
  0 siblings, 0 replies; 4+ messages in thread
From: jason1.lin @ 2022-05-26  7:40 UTC (permalink / raw)
  To: devel
  Cc: Jason1 Lin, Bob Feng, Liming Gao, Yuwei Chen, Dakota Chiang,
	Vanessa Chuang

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


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

* [PATCH v1] [edk2-platforms] Silicon/Intel/FitGen: Fix CheckOverlap would do incorrect split BiosModule action in corner case
@ 2022-05-26  8:51 jason1.lin
  2022-06-04  4:07 ` Bob Feng
  0 siblings, 1 reply; 4+ messages in thread
From: jason1.lin @ 2022-05-26  8:51 UTC (permalink / raw)
  To: devel
  Cc: Jason1 Lin, Bob Feng, Liming Gao, Yuwei Chen, Dakota Chiang,
	Vanessa Chuang

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


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

* Re: [PATCH v1] [edk2-platforms] Silicon/Intel/FitGen: Fix CheckOverlap would do incorrect split BiosModule action in corner case
  2022-05-26  8:51 jason1.lin
@ 2022-06-04  4:07 ` Bob Feng
  2022-06-07  3:33   ` jason1.lin
  0 siblings, 1 reply; 4+ messages in thread
From: Bob Feng @ 2022-06-04  4:07 UTC (permalink / raw)
  To: Lin, Jason1, devel@edk2.groups.io
  Cc: Gao, Liming, Chen, Christine, Chiang, Dakota, Chuang, Vanessa

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


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

* Re: [PATCH v1] [edk2-platforms] Silicon/Intel/FitGen: Fix CheckOverlap would do incorrect split BiosModule action in corner case
  2022-06-04  4:07 ` Bob Feng
@ 2022-06-07  3:33   ` jason1.lin
  0 siblings, 0 replies; 4+ messages in thread
From: jason1.lin @ 2022-06-07  3:33 UTC (permalink / raw)
  To: Feng, Bob C, devel@edk2.groups.io
  Cc: Gao, Liming, Chen, Christine, Chiang, Dakota, Chuang, Vanessa,
	Lin, Jason1

Hi Bob,

Agree.
Check the size first is more readable than do the type conversion.
That would be align with the address check.
I would send out patch v2 based on this change.

Thanks,
Jason.

-----Original Message-----
From: Feng, Bob C <bob.c.feng@intel.com> 
Sent: Saturday, June 4, 2022 12:08
To: Lin, Jason1 <jason1.lin@intel.com>; 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

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


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

end of thread, other threads:[~2022-06-07  3:33 UTC | newest]

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

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