grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix invalid USB descriptor endless loop.
@ 2013-09-09  6:22 Melki Christian (consultant)
  2013-09-17 22:06 ` Aleš Nesrsta
  2013-09-18 11:27 ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 2 replies; 3+ messages in thread
From: Melki Christian (consultant) @ 2013-09-09  6:22 UTC (permalink / raw)
  To: grub-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 597 bytes --]

Hi,

I discovered that on some PC's the USB stack would produce an invalid descriptor upon query without an error.
I don't know why this is the case, maybe broken hardware but I seriously doubt it.
GRUB doesn't handle TT's at all, Clearing TT's or resetting them. Maybe thats a case for stuck transactions?
The descriptor would contain 0 in length, or atleast the code would think that offset was the length
and cause an endless loop.
Maybe this type of parsing is completely avoidable but for now I just added a break condition.
GRUB should not hang on faulty devices.

BR,
Christian

[-- Attachment #2: usb-invalid-desc.patch --]
[-- Type: application/octet-stream, Size: 1951 bytes --]

Index: grub-core/bus/usb/usb.c
===================================================================
--- grub-core/bus/usb/usb.c	(revision 5260)
+++ grub-core/bus/usb/usb.c	(revision 5261)
@@ -148,6 +148,7 @@
       int pos;
       int currif;
       char *data;
+      struct grub_usb_desc *desc;
 
       /* First just read the first 4 bytes of the configuration
 	 descriptor, after that it is known how many bytes really have
@@ -174,18 +175,35 @@
       /* Read all interfaces.  */
       for (currif = 0; currif < dev->config[i].descconf->numif; currif++)
 	{
-	  while (pos < config.totallen
-		 && ((struct grub_usb_desc *)&data[pos])->type
-		 != GRUB_USB_DESCRIPTOR_INTERFACE)
-	    pos += ((struct grub_usb_desc *)&data[pos])->length;
+	  while (pos < config.totallen)
+            {
+              desc = (struct grub_usb_desc *)&data[pos];
+              if (desc->type == GRUB_USB_DESCRIPTOR_INTERFACE)
+                break;
+              if (!desc->length)
+                {
+                  err = GRUB_USB_ERR_BADDEVICE;
+                  goto fail;
+                }
+              pos += desc->length;
+            }
+
 	  dev->config[i].interf[currif].descif
 	    = (struct grub_usb_desc_if *) &data[pos];
 	  pos += dev->config[i].interf[currif].descif->length;
 
-	  while (pos < config.totallen
-		 && ((struct grub_usb_desc *)&data[pos])->type
-		 != GRUB_USB_DESCRIPTOR_ENDPOINT)
-	    pos += ((struct grub_usb_desc *)&data[pos])->length;
+	  while (pos < config.totallen)
+            {
+              desc = (struct grub_usb_desc *)&data[pos];
+              if (desc->type == GRUB_USB_DESCRIPTOR_ENDPOINT)
+                break;
+              if (!desc->length)
+                {
+                  err = GRUB_USB_ERR_BADDEVICE;
+                  goto fail;
+                }
+              pos += desc->length;
+            }
 
 	  /* Point to the first endpoint.  */
 	  dev->config[i].interf[currif].descendp

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

end of thread, other threads:[~2013-09-18 11:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-09  6:22 [PATCH] Fix invalid USB descriptor endless loop Melki Christian (consultant)
2013-09-17 22:06 ` Aleš Nesrsta
2013-09-18 11:27 ` Vladimir 'φ-coder/phcoder' Serbinenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).