From: "Dong, Eric" <eric.dong@intel.com>
To: "Kinney, Michael D" <michael.d.kinney@intel.com>,
"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Ni, Ruiyu" <ruiyu.ni@intel.com>
Subject: Re: [Patch] UefiCpuPkg/MpLib: fix potential overflow issue.
Date: Thu, 24 Aug 2017 03:04:52 +0000 [thread overview]
Message-ID: <ED077930C258884BBCB450DB737E66224A9C41D6@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <E92EE9817A31E24EB0585FDF735412F5A7D84A1F@ORSMSX113.amr.corp.intel.com>
Mike,
Thanks for the comments, I updated the patch, please help to review the new patch.
Thanks,
Eric
-----Original Message-----
From: Kinney, Michael D
Sent: Thursday, August 24, 2017 5:51 AM
To: Dong, Eric <eric.dong@intel.com>; edk2-devel@lists.01.org; Kinney, Michael D <michael.d.kinney@intel.com>
Cc: Ni, Ruiyu <ruiyu.ni@intel.com>
Subject: RE: [Patch] UefiCpuPkg/MpLib: fix potential overflow issue.
Hi Eric,
With this patch GetPerformanceCounterProperties() is called twice. I think you can use TimestampCounterFreq in the else clause.
Also, the comment blocks are no longer correct. The original comment block goes with the else clause, and you need a new comment block for the if statement that describes the check for an overflow.
Mike
> -----Original Message-----
> From: Dong, Eric
> Sent: Tuesday, August 22, 2017 10:30 PM
> To: edk2-devel@lists.01.org
> Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Ni, Ruiyu
> <ruiyu.ni@intel.com>
> Subject: [Patch] UefiCpuPkg/MpLib: fix potential overflow issue.
>
> Current calculate timeout logic may have overflow if the input timeout
> value too large. This patch fix this potential overflow issue.
>
> Cc: Michael Kinney <michael.d.kinney@intel.com>
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Eric Dong <eric.dong@intel.com>
> ---
> UefiCpuPkg/Library/MpInitLib/MpLib.c | 30
> +++++++++++++++++++++++-------
> 1 file changed, 23 insertions(+), 7 deletions(-)
>
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> index ed1f55e..005dec4 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
> @@ -1001,6 +1001,9 @@ CalculateTimeout (
> OUT UINT64 *CurrentTime
> )
> {
> + UINT64 TimeoutInSeconds;
> + UINT64 TimestampCounterFreq;
> +
> //
> // Read the current value of the performance counter
> //
> @@ -1019,13 +1022,26 @@ CalculateTimeout (
> // in Hz. So multiply the return value with TimeoutInMicroseconds
> and then divide
> // it by 1,000,000, to get the number of ticks for the timeout
> value.
> //
> - return DivU64x32 (
> - MultU64x64 (
> - GetPerformanceCounterProperties (NULL, NULL),
> - TimeoutInMicroseconds
> - ),
> - 1000000
> - );
> + TimestampCounterFreq = GetPerformanceCounterProperties
> (NULL, NULL);
> + if (DivU64x64Remainder (MAX_UINT64, TimeoutInMicroseconds,
> NULL) < TimestampCounterFreq) {
> + //
> + // Convert microseconds into seconds if direct
> multiplication overflows
> + //
> + TimeoutInSeconds = DivU64x32 (TimeoutInMicroseconds,
> 1000000);
> + //
> + // Assertion if the final tick count exceeds MAX_UINT64
> + //
> + ASSERT (DivU64x64Remainder (MAX_UINT64, TimeoutInSeconds,
> NULL) >= TimestampCounterFreq);
> + return MultU64x64 (TimestampCounterFreq,
> TimeoutInSeconds);
> + } else {
> + return DivU64x32 (
> + MultU64x64 (
> + GetPerformanceCounterProperties (NULL, NULL),
Use TimestampCounterFreq instead.
> + TimeoutInMicroseconds
> + ),
> + 1000000
> + );
> + }
> }
>
> /**
> --
> 2.7.0.windows.1
next prev parent reply other threads:[~2017-08-24 3:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-23 5:29 [Patch] UefiCpuPkg/MpLib: fix potential overflow issue Eric Dong
2017-08-23 21:50 ` Kinney, Michael D
2017-08-24 3:04 ` Dong, Eric [this message]
-- strict thread matches above, loose matches on Subject: below --
2017-08-24 2:56 Eric Dong
2017-08-25 0:36 ` Kinney, Michael D
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=ED077930C258884BBCB450DB737E66224A9C41D6@shsmsx102.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