public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ni, Ray" <ray.ni@intel.com>
To: "Chen, Chen A" <chen.a.chen@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Dong, Eric" <eric.dong@intel.com>
Subject: Re: [PATCH] UefiCpuPkg/Microcode.c: Add verification before calculate CheckSum32
Date: Wed, 6 Mar 2019 02:15:18 +0000	[thread overview]
Message-ID: <734D49CCEBEEF84792F5B80ED585239D5C05FD4A@SHSMSX104.ccr.corp.intel.com> (raw)
In-Reply-To: <20190305002118.10572-1-chen.a.chen@intel.com>

Reviewed-by: Ray Ni <ray.ni@intel.com>

> -----Original Message-----
> From: edk2-devel <edk2-devel-bounces@lists.01.org> On Behalf Of Chen A
> Chen
> Sent: Tuesday, March 5, 2019 8:21 AM
> To: edk2-devel@lists.01.org
> Cc: Dong, Eric <eric.dong@intel.com>
> Subject: [edk2] [PATCH] UefiCpuPkg/Microcode.c: Add verification before
> calculate CheckSum32
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1020
> 
> Should make sure the TotalSize of Microcode is aligned with 4 bytes
> before calling CalculateSum32 function.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> ---
>  UefiCpuPkg/Library/MpInitLib/Microcode.c | 31 ++++++++++++++++++++--
> ---------
>  1 file changed, 20 insertions(+), 11 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c
> b/UefiCpuPkg/Library/MpInitLib/Microcode.c
> index 5f9ae22794..643a6f94f4 100644
> --- a/UefiCpuPkg/Library/MpInitLib/Microcode.c
> +++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c
> @@ -166,20 +166,29 @@ MicrocodeDetect (
>      //
>      CorrectMicrocode = FALSE;
> 
> -    //
> -    // Save an in-complete CheckSum32 from CheckSum Part1 for common
> parts.
> -    //
>      if (MicrocodeEntryPoint->DataSize == 0) {
> -      InCompleteCheckSum32 = CalculateSum32 (
> -                               (UINT32 *) MicrocodeEntryPoint,
> -                               sizeof (CPU_MICROCODE_HEADER) + 2000
> -                               );
> +      TotalSize = sizeof (CPU_MICROCODE_HEADER) + 2000;
>      } else {
> -      InCompleteCheckSum32 = CalculateSum32 (
> -                               (UINT32 *) MicrocodeEntryPoint,
> -                               sizeof (CPU_MICROCODE_HEADER) + MicrocodeEntryPoint-
> >DataSize
> -                               );
> +      TotalSize = sizeof (CPU_MICROCODE_HEADER) + MicrocodeEntryPoint-
> >DataSize;
>      }
> +
> +    ///
> +    /// Check overflow and whether TotalSize is aligned with 4 bytes.
> +    ///
> +    if ( ((UINTN)MicrocodeEntryPoint + TotalSize) > MicrocodeEnd ||
> +         (TotalSize & 0x3) != 0
> +       ) {
> +      MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (((UINTN)
> MicrocodeEntryPoint) + SIZE_1KB);
> +      continue;
> +    }
> +
> +    //
> +    // Save an in-complete CheckSum32 from CheckSum Part1 for common
> parts.
> +    //
> +    InCompleteCheckSum32 = CalculateSum32 (
> +                             (UINT32 *) MicrocodeEntryPoint,
> +                             TotalSize
> +                             );
>      InCompleteCheckSum32 -= MicrocodeEntryPoint-
> >ProcessorSignature.Uint32;
>      InCompleteCheckSum32 -= MicrocodeEntryPoint->ProcessorFlags;
>      InCompleteCheckSum32 -= MicrocodeEntryPoint->Checksum;
> --
> 2.16.2.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


  reply	other threads:[~2019-03-06  2:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-05  0:21 [PATCH] UefiCpuPkg/Microcode.c: Add verification before calculate CheckSum32 Chen A Chen
2019-03-06  2:15 ` Ni, Ray [this message]
2019-03-06  5:35   ` Ni, Ray
2019-03-06  5:38     ` Gao, Liming
2019-03-06  5:46       ` Ni, Ray

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=734D49CCEBEEF84792F5B80ED585239D5C05FD4A@SHSMSX104.ccr.corp.intel.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