summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRanbir Singh <rsingh@ventanamicro.com>2023-05-17 23:28:51 -0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-05-30 05:13:36 +0000
commit48c53994e649d51a388dc414944c9a9b717a1c3c (patch)
treef9134571670198656587515687f542084140f6cb
parent69e10f02111bf7e719237f05233abff4e50016fa (diff)
downloadedk2-48c53994e649d51a388dc414944c9a9b717a1c3c.tar.gz
edk2-48c53994e649d51a388dc414944c9a9b717a1c3c.tar.bz2
edk2-48c53994e649d51a388dc414944c9a9b717a1c3c.zip
IntelFsp2Pkg/Library/BaseFspCommonLib: Fix OVERRUN Coverity issue
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4200 FspData->PerfIdx is getting increased for every call unconditionally in the function SetFspMeasurePoint and hence memory access can happen for out of bound FspData->PerfData[] array entries also. Example - FspData->PerfData is an array of 32 UINT64 entries. Assume a call is made to SetFspMeasurePoint function when the FspData->PerfIdx last value is 31. It gets incremented to 32 at line 400. Any subsequent call to SetFspMeasurePoint functions leads to FspData->PerfData[32] getting accessed which is out of the PerfData array as well as the FSP_GLOBAL_DATA structure boundary. Hence keep array access and index increment inside if block only and return invalid performance timestamp when PerfIdx is invalid. Cc: Chasel Chiu <chasel.chiu@intel.com> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com> Cc: Star Zeng <star.zeng@intel.com> Signed-off-by: Ranbir Singh <rsingh@ventanamicro.com> Acked-by: Pedro Falcato <pedro.falcato@gmail.com> Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
-rw-r--r--IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c b/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
index a22b0e7825..6f6a086111 100644
--- a/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
+++ b/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
@@ -377,7 +377,8 @@ GetFspSiliconInitUpdDataPointer (
@param[in] Id Measurement point ID.
- @return performance timestamp.
+ @return performance timestamp if current PerfIdx is valid,
+ else return 0 as invalid performance timestamp
**/
UINT64
EFIAPI
@@ -395,9 +396,10 @@ SetFspMeasurePoint (
if (FspData->PerfIdx < sizeof (FspData->PerfData) / sizeof (FspData->PerfData[0])) {
FspData->PerfData[FspData->PerfIdx] = AsmReadTsc ();
((UINT8 *)(&FspData->PerfData[FspData->PerfIdx]))[7] = Id;
+ return FspData->PerfData[(FspData->PerfIdx)++];
}
- return FspData->PerfData[(FspData->PerfIdx)++];
+ return 0;
}
/**