]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SecurityPkg/Pkcs7VerifyDxe: Add format check in DB list contents
authorLong Qin <qin.long@intel.com>
Wed, 3 May 2017 09:25:48 +0000 (17:25 +0800)
committerLong Qin <qin.long@intel.com>
Fri, 5 May 2017 06:58:47 +0000 (14:58 +0800)
Add the size check for invalid format detection in AllowedDb,
RevokedDb and TimeStampDb list contents.

Cc: Chao Zhang <chao.b.zhang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qin Long <qin.long@intel.com>
Reviewed-by: Chao Zhang <chao.b.zhang@intel.com>
SecurityPkg/Pkcs7Verify/Pkcs7VerifyDxe/Pkcs7VerifyDxe.c

index 07fdf552be17cfefc9206146eaa779d1d849b030..3776f903d4429973cb7788ce2a83831e6e515618 100644 (file)
@@ -5,7 +5,7 @@
   verify data signed using PKCS7 structure. The PKCS7 data to be verified must\r
   be ASN.1 (DER) encoded.\r
 \r
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -801,11 +801,13 @@ VerifyBuffer (
   IN OUT UINTN                    *ContentSize\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-  UINT8       *AttachedData;\r
-  UINTN       AttachedDataSize;\r
-  UINT8       *DataPtr;\r
-  UINTN       DataSize;\r
+  EFI_STATUS          Status;\r
+  EFI_SIGNATURE_LIST  *SigList;\r
+  UINTN               Index;\r
+  UINT8               *AttachedData;\r
+  UINTN               AttachedDataSize;\r
+  UINT8               *DataPtr;\r
+  UINTN               DataSize;\r
 \r
   //\r
   // Parameters Checking\r
@@ -817,6 +819,58 @@ VerifyBuffer (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  //\r
+  // Check if any invalid entry format in AllowedDb list contents\r
+  //\r
+  for (Index = 0; ; Index++) {\r
+    SigList = (EFI_SIGNATURE_LIST *)(AllowedDb[Index]);\r
+\r
+    if (SigList == NULL) {\r
+      break;\r
+    }\r
+    if (SigList->SignatureListSize < sizeof (EFI_SIGNATURE_LIST) +\r
+                                     SigList->SignatureHeaderSize +\r
+                                     SigList->SignatureSize) {\r
+      return EFI_ABORTED;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Check if any invalid entry format in RevokedDb list contents\r
+  //\r
+  if (RevokedDb != NULL) {\r
+    for (Index = 0; ; Index++) {\r
+      SigList = (EFI_SIGNATURE_LIST *)(RevokedDb[Index]);\r
+\r
+      if (SigList == NULL) {\r
+        break;\r
+      }\r
+      if (SigList->SignatureListSize < sizeof (EFI_SIGNATURE_LIST) +\r
+                                       SigList->SignatureHeaderSize +\r
+                                       SigList->SignatureSize) {\r
+        return EFI_ABORTED;\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // Check if any invalid entry format in TimeStampDb list contents\r
+  //\r
+  if (TimeStampDb != NULL) {\r
+    for (Index = 0; ; Index++) {\r
+      SigList = (EFI_SIGNATURE_LIST *)(TimeStampDb[Index]);\r
+\r
+      if (SigList == NULL) {\r
+        break;\r
+      }\r
+      if (SigList->SignatureListSize < sizeof (EFI_SIGNATURE_LIST) +\r
+                                       SigList->SignatureHeaderSize +\r
+                                       SigList->SignatureSize) {\r
+        return EFI_ABORTED;\r
+      }\r
+    }\r
+  }\r
+\r
   //\r
   // Try to retrieve the attached content from PKCS7 signedData\r
   //\r