]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/UsbBusPei: Reject descriptor whose length is bad
authorRuiyu Ni <ruiyu.ni@intel.com>
Thu, 25 Oct 2018 10:09:46 +0000 (18:09 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Mon, 29 Oct 2018 03:11:03 +0000 (11:11 +0800)
Today's implementation doesn't check whether the length of
descriptor is valid before using it.

The patch fixes this issue by syncing the similar fix to UsbBusDxe.
70c3c2370a2aefe71cf0f6c1a1e063f7d74e1d79
*MdeModulePkg/UsbBus: Reject descriptor whose length is bad

Additionally the patch also rejects the data when length is
larger than sizeof (PeiUsbDevice->ConfigurationData).

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c

index 86734f2f7362b4bc0c9f25705e8c9d65086bb2c8..c31247abfe5a851ea65801c4994cc7777fbde180 100644 (file)
@@ -816,6 +816,20 @@ PeiUsbGetAllConfiguration (
   ConfigDesc        = (EFI_USB_CONFIG_DESCRIPTOR *) PeiUsbDevice->ConfigurationData;\r
   ConfigDescLength  = ConfigDesc->TotalLength;\r
 \r
+  //\r
+  // Reject if TotalLength even cannot cover itself.\r
+  //\r
+  if (ConfigDescLength < OFFSET_OF (EFI_USB_CONFIG_DESCRIPTOR, TotalLength) + sizeof (ConfigDesc->TotalLength)) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  //\r
+  // Reject if TotalLength exceeds the PeiUsbDevice->ConfigurationData.\r
+  //\r
+  if (ConfigDescLength > sizeof (PeiUsbDevice->ConfigurationData)) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
   //\r
   // Then we get the total descriptors for this configuration\r
   //\r