[edk2-devel] [PATCH 1/1] IntelFsp2Pkg/Library/BaseFspCommonLib: Fix OVERRUN Coverity issue
Pedro Falcato
pedro.falcato at gmail.com
Fri May 19 12:29:21 UTC 2023
On Thu, May 18, 2023 at 4:16 PM Ranbir Singh <rsingh at ventanamicro.com> wrote:
>
> 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 at intel.com>
> Cc: Nate DeSimone <nathaniel.l.desimone at intel.com>
> Cc: Star Zeng <star.zeng at intel.com>
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4200
> Signed-off-by: Ranbir Singh <Ranbir.Singh3 at Dell.com>
> Signed-off-by: Ranbir Singh <rsingh at ventanamicro.com>
> ---
> IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c b/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
> index a22b0e7825ad..cda2a7b2478e 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 (UINT64)0x0000000000000000;
return 0;
Works just as well. You also don't need a cast.
https://godbolt.org/z/e5vvGcWWo
--
Pedro
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#105074): https://edk2.groups.io/g/devel/message/105074
Mute This Topic: https://groups.io/mt/98993286/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-
More information about the edk2-devel-archive
mailing list