[edk2-devel] [PATCH] UefiCpuPkg RegisterCpuFeaturesLib: NumberOfCpus may be uninitialized

Zeng, Star posted 1 patch 3 years, 2 months ago
Failed in applying to current master (apply log)
.../Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c      | 1 +
1 file changed, 1 insertion(+)
[edk2-devel] [PATCH] UefiCpuPkg RegisterCpuFeaturesLib: NumberOfCpus may be uninitialized
Posted by Zeng, Star 3 years, 2 months ago
NumberOfCpus local variable in GetAcpiCpuData will be uninitialized
when CpuS3DataDxe runs before DxeRegisterCpuFeaturesLib (linked by
CpuFeaturesDxe) because there is no code to initialize it at
(AcpiCpuData != NULL) execution path.

The issue is exposed after cefad282fb31aff3e1a6dcbd368cbbffc3fce900
and 38ee7bafa72f58982f99ac6f61eef160f80bad69.
There was negligence in that code review.
One further topic may be "Could EDK2 CI be enhanced to catch this kind
of uninitialized local variable case?". :)

This patch fixes this regression issue.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
 .../Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c      | 1 +
 1 file changed, 1 insertion(+)

diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c
index 7bb92404027f..60daa5cc87f0 100644
--- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c
+++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c
@@ -957,6 +957,7 @@ GetAcpiCpuData (
     //
     // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable for all CPUs
     //
+    NumberOfCpus = AcpiCpuData->NumberOfCpus;
     TableSize = 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE);
     RegisterTable  = AllocatePages (EFI_SIZE_TO_PAGES (TableSize));
     ASSERT (RegisterTable != NULL);
-- 
2.27.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#70614): https://edk2.groups.io/g/devel/message/70614
Mute This Topic: https://groups.io/mt/80000246/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH] UefiCpuPkg RegisterCpuFeaturesLib: NumberOfCpus may be uninitialized
Posted by Laszlo Ersek 3 years, 2 months ago
On 01/21/21 10:39, Zeng, Star wrote:
> NumberOfCpus local variable in GetAcpiCpuData will be uninitialized
> when CpuS3DataDxe runs before DxeRegisterCpuFeaturesLib (linked by
> CpuFeaturesDxe) because there is no code to initialize it at
> (AcpiCpuData != NULL) execution path.
> 
> The issue is exposed after cefad282fb31aff3e1a6dcbd368cbbffc3fce900
> and 38ee7bafa72f58982f99ac6f61eef160f80bad69.

Oops, sorry!

> There was negligence in that code review.
> One further topic may be "Could EDK2 CI be enhanced to catch this kind
> of uninitialized local variable case?". :)

Indeed I don't know why none of the toolchains caught this issue in CI.
:/ GCC is otherwise known for its "variable may be used without
initialization" warnings.

> 
> This patch fixes this regression issue.
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Signed-off-by: Star Zeng <star.zeng@intel.com>
> ---
>  .../Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c      | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c
> index 7bb92404027f..60daa5cc87f0 100644
> --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c
> +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c
> @@ -957,6 +957,7 @@ GetAcpiCpuData (
>      //
>      // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable for all CPUs
>      //
> +    NumberOfCpus = AcpiCpuData->NumberOfCpus;
>      TableSize = 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE);
>      RegisterTable  = AllocatePages (EFI_SIZE_TO_PAGES (TableSize));
>      ASSERT (RegisterTable != NULL);
> 

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

(Also, I think Ray's R-b from
<https://edk2.groups.io/g/devel/message/70615> applies here, so I'm
going to pick that up.)

Thanks & sorry again
Laszlo



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#70646): https://edk2.groups.io/g/devel/message/70646
Mute This Topic: https://groups.io/mt/80000246/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH] UefiCpuPkg RegisterCpuFeaturesLib: NumberOfCpus may be uninitialized
Posted by Zeng, Star 3 years, 2 months ago
> -----Original Message-----
> From: Laszlo Ersek <lersek@redhat.com>
> Sent: Thursday, January 21, 2021 9:48 PM
> To: devel@edk2.groups.io; Zeng, Star <star.zeng@intel.com>
> Cc: Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>
> Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg RegisterCpuFeaturesLib:
> NumberOfCpus may be uninitialized
> 
> On 01/21/21 10:39, Zeng, Star wrote:
> > NumberOfCpus local variable in GetAcpiCpuData will be uninitialized
> > when CpuS3DataDxe runs before DxeRegisterCpuFeaturesLib (linked by
> > CpuFeaturesDxe) because there is no code to initialize it at
> > (AcpiCpuData != NULL) execution path.
> >
> > The issue is exposed after cefad282fb31aff3e1a6dcbd368cbbffc3fce900
> > and 38ee7bafa72f58982f99ac6f61eef160f80bad69.
> 
> Oops, sorry!
> 
> > There was negligence in that code review.
> > One further topic may be "Could EDK2 CI be enhanced to catch this kind
> > of uninitialized local variable case?". :)
> 
> Indeed I don't know why none of the toolchains caught this issue in CI.
> :/ GCC is otherwise known for its "variable may be used without
> initialization" warnings.
> 
> >
> > This patch fixes this regression issue.
> >
> > Cc: Eric Dong <eric.dong@intel.com>
> > Cc: Ray Ni <ray.ni@intel.com>
> > Cc: Laszlo Ersek <lersek@redhat.com>
> > Signed-off-by: Star Zeng <star.zeng@intel.com>
> > ---
> >  .../Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c      | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git
> > a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c
> > b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c
> > index 7bb92404027f..60daa5cc87f0 100644
> > ---
> > a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c
> > +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib
> > +++ .c
> > @@ -957,6 +957,7 @@ GetAcpiCpuData (
> >      //
> >      // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable
> for all CPUs
> >      //
> > +    NumberOfCpus = AcpiCpuData->NumberOfCpus;
> >      TableSize = 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE);
> >      RegisterTable  = AllocatePages (EFI_SIZE_TO_PAGES (TableSize));
> >      ASSERT (RegisterTable != NULL);
> >
> 
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> 
> (Also, I think Ray's R-b from
> <https://edk2.groups.io/g/devel/message/70615> applies here, so I'm going
> to pick that up.)

Laszlo and Ray, thanks for the R-b.
Please help push it by pull request if no other feedback is received.

Thanks,
Star

> 
> Thanks & sorry again
> Laszlo



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#70649): https://edk2.groups.io/g/devel/message/70649
Mute This Topic: https://groups.io/mt/80000246/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH] UefiCpuPkg RegisterCpuFeaturesLib: NumberOfCpus may be uninitialized
Posted by Laszlo Ersek 3 years, 2 months ago
On 01/21/21 10:39, Zeng, Star wrote:
> NumberOfCpus local variable in GetAcpiCpuData will be uninitialized
> when CpuS3DataDxe runs before DxeRegisterCpuFeaturesLib (linked by
> CpuFeaturesDxe) because there is no code to initialize it at
> (AcpiCpuData != NULL) execution path.
> 
> The issue is exposed after cefad282fb31aff3e1a6dcbd368cbbffc3fce900
> and 38ee7bafa72f58982f99ac6f61eef160f80bad69.
> There was negligence in that code review.
> One further topic may be "Could EDK2 CI be enhanced to catch this kind
> of uninitialized local variable case?". :)
> 
> This patch fixes this regression issue.
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Signed-off-by: Star Zeng <star.zeng@intel.com>
> ---
>  .../Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c      | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c
> index 7bb92404027f..60daa5cc87f0 100644
> --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c
> +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c
> @@ -957,6 +957,7 @@ GetAcpiCpuData (
>      //
>      // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable for all CPUs
>      //
> +    NumberOfCpus = AcpiCpuData->NumberOfCpus;
>      TableSize = 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE);
>      RegisterTable  = AllocatePages (EFI_SIZE_TO_PAGES (TableSize));
>      ASSERT (RegisterTable != NULL);
> 

Merged as commit 6c5801be6ef3, via
<https://github.com/tianocore/edk2/pull/1380>.

I've picked up Ray's R-b from the detached message
<https://edk2.groups.io/g/devel/message/70615>.

I've also updated the original ticket:
<https://bugzilla.tianocore.org/show_bug.cgi?id=3159>.

Thanks & sorry about the regression,
Laszlo



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#70650): https://edk2.groups.io/g/devel/message/70650
Mute This Topic: https://groups.io/mt/80000246/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH] UefiCpuPkg RegisterCpuFeaturesLib: NumberOfCpus may be uninitialized
Posted by Zeng, Star 3 years, 2 months ago
> -----Original Message-----
> From: Laszlo Ersek <lersek@redhat.com>
> Sent: Thursday, January 21, 2021 10:38 PM
> To: devel@edk2.groups.io; Zeng, Star <star.zeng@intel.com>
> Cc: Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>
> Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg RegisterCpuFeaturesLib:
> NumberOfCpus may be uninitialized
> 
> On 01/21/21 10:39, Zeng, Star wrote:
> > NumberOfCpus local variable in GetAcpiCpuData will be uninitialized
> > when CpuS3DataDxe runs before DxeRegisterCpuFeaturesLib (linked by
> > CpuFeaturesDxe) because there is no code to initialize it at
> > (AcpiCpuData != NULL) execution path.
> >
> > The issue is exposed after cefad282fb31aff3e1a6dcbd368cbbffc3fce900
> > and 38ee7bafa72f58982f99ac6f61eef160f80bad69.
> > There was negligence in that code review.
> > One further topic may be "Could EDK2 CI be enhanced to catch this kind
> > of uninitialized local variable case?". :)
> >
> > This patch fixes this regression issue.
> >
> > Cc: Eric Dong <eric.dong@intel.com>
> > Cc: Ray Ni <ray.ni@intel.com>
> > Cc: Laszlo Ersek <lersek@redhat.com>
> > Signed-off-by: Star Zeng <star.zeng@intel.com>
> > ---
> >  .../Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c      | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git
> > a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c
> > b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c
> > index 7bb92404027f..60daa5cc87f0 100644
> > ---
> > a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c
> > +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib
> > +++ .c
> > @@ -957,6 +957,7 @@ GetAcpiCpuData (
> >      //
> >      // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable
> for all CPUs
> >      //
> > +    NumberOfCpus = AcpiCpuData->NumberOfCpus;
> >      TableSize = 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE);
> >      RegisterTable  = AllocatePages (EFI_SIZE_TO_PAGES (TableSize));
> >      ASSERT (RegisterTable != NULL);
> >
> 
> Merged as commit 6c5801be6ef3, via
> <https://github.com/tianocore/edk2/pull/1380>.
> 
> I've picked up Ray's R-b from the detached message
> <https://edk2.groups.io/g/devel/message/70615>.
> 
> I've also updated the original ticket:
> <https://bugzilla.tianocore.org/show_bug.cgi?id=3159>.
> 
> Thanks & sorry about the regression,
> Laszlo

No worry, it was my negligence for the original code review series.
Fortunately, we catch it quickly. 😊

Star



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#70651): https://edk2.groups.io/g/devel/message/70651
Mute This Topic: https://groups.io/mt/80000246/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-