public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2] SecurityPkg/Tpm2Help.c: Add boundary check for array
@ 2019-12-16  7:52 Zhang, Shenglei
  2019-12-16  7:55 ` Yao, Jiewen
  0 siblings, 1 reply; 2+ messages in thread
From: Zhang, Shenglei @ 2019-12-16  7:52 UTC (permalink / raw)
  To: devel; +Cc: Jiewen Yao, Jian J Wang, Chao Zhang

Add 'Index < HASH_COUNT' to ensure things out of digests[]
can not be visited.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Chao Zhang <chao.b.zhang@intel.com>
Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
---
v2: Remove the comma operator and use &&.

 SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
index 36c240d1221c..d7bc94006003 100644
--- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
+++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
@@ -299,7 +299,7 @@ GetDigestListSize (
   UINT32 TotalSize;
 
   TotalSize = sizeof(DigestList->count);
-  for (Index = 0; Index < DigestList->count; Index++) {
+  for (Index = 0; Index < DigestList->count && Index < HASH_COUNT; Index++) {
     DigestSize = GetHashSizeFromAlgo (DigestList->digests[Index].hashAlg);
     TotalSize += sizeof(DigestList->digests[Index].hashAlg) + DigestSize;
   }
-- 
2.18.0.windows.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] SecurityPkg/Tpm2Help.c: Add boundary check for array
  2019-12-16  7:52 [PATCH v2] SecurityPkg/Tpm2Help.c: Add boundary check for array Zhang, Shenglei
@ 2019-12-16  7:55 ` Yao, Jiewen
  0 siblings, 0 replies; 2+ messages in thread
From: Yao, Jiewen @ 2019-12-16  7:55 UTC (permalink / raw)
  To: Zhang, Shenglei, devel@edk2.groups.io; +Cc: Wang, Jian J, Zhang, Chao B

I don't think it is good idea to *ignore* the error.

If you don't assert, please stop processor and return error.


> -----Original Message-----
> From: Zhang, Shenglei <shenglei.zhang@intel.com>
> Sent: Monday, December 16, 2019 3:53 PM
> To: devel@edk2.groups.io
> Cc: Yao, Jiewen <jiewen.yao@intel.com>; Wang, Jian J <jian.j.wang@intel.com>;
> Zhang, Chao B <chao.b.zhang@intel.com>
> Subject: [PATCH v2] SecurityPkg/Tpm2Help.c: Add boundary check for array
> 
> Add 'Index < HASH_COUNT' to ensure things out of digests[]
> can not be visited.
> 
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Chao Zhang <chao.b.zhang@intel.com>
> Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
> ---
> v2: Remove the comma operator and use &&.
> 
>  SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
> b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
> index 36c240d1221c..d7bc94006003 100644
> --- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
> +++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Help.c
> @@ -299,7 +299,7 @@ GetDigestListSize (
>    UINT32 TotalSize;
> 
>    TotalSize = sizeof(DigestList->count);
> -  for (Index = 0; Index < DigestList->count; Index++) {
> +  for (Index = 0; Index < DigestList->count && Index < HASH_COUNT; Index++) {
>      DigestSize = GetHashSizeFromAlgo (DigestList->digests[Index].hashAlg);
>      TotalSize += sizeof(DigestList->digests[Index].hashAlg) + DigestSize;
>    }
> --
> 2.18.0.windows.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-16  7:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-16  7:52 [PATCH v2] SecurityPkg/Tpm2Help.c: Add boundary check for array Zhang, Shenglei
2019-12-16  7:55 ` Yao, Jiewen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox