mirror of
https://git.proxmox.com/git/grub2
synced 2025-07-26 23:41:40 +00:00
usb: Avoid possible out-of-bound accesses caused by malicious devices
The maximum number of configurations and interfaces are fixed but there is no out-of-bound checking to prevent a malicious USB device to report large values for these and cause accesses outside the arrays' memory. Fixes: CVE-2020-25647 Reported-by: Joseph Tartaro <joseph.tartaro@ioactive.com> Reported-by: Ilja Van Sprundel <ivansprundel@ioactive.com> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
parent
7630ec5397
commit
128c16a682
@ -75,6 +75,9 @@ grub_usb_controller_iterate (grub_usb_controller_iterate_hook_t hook,
|
|||||||
grub_usb_err_t
|
grub_usb_err_t
|
||||||
grub_usb_clear_halt (grub_usb_device_t dev, int endpoint)
|
grub_usb_clear_halt (grub_usb_device_t dev, int endpoint)
|
||||||
{
|
{
|
||||||
|
if (endpoint >= GRUB_USB_MAX_TOGGLE)
|
||||||
|
return GRUB_USB_ERR_BADDEVICE;
|
||||||
|
|
||||||
dev->toggle[endpoint] = 0;
|
dev->toggle[endpoint] = 0;
|
||||||
return grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_OUT
|
return grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_OUT
|
||||||
| GRUB_USB_REQTYPE_STANDARD
|
| GRUB_USB_REQTYPE_STANDARD
|
||||||
@ -134,10 +137,10 @@ grub_usb_device_initialize (grub_usb_device_t dev)
|
|||||||
return err;
|
return err;
|
||||||
descdev = &dev->descdev;
|
descdev = &dev->descdev;
|
||||||
|
|
||||||
for (i = 0; i < 8; i++)
|
for (i = 0; i < GRUB_USB_MAX_CONF; i++)
|
||||||
dev->config[i].descconf = NULL;
|
dev->config[i].descconf = NULL;
|
||||||
|
|
||||||
if (descdev->configcnt == 0)
|
if (descdev->configcnt == 0 || descdev->configcnt > GRUB_USB_MAX_CONF)
|
||||||
{
|
{
|
||||||
err = GRUB_USB_ERR_BADDEVICE;
|
err = GRUB_USB_ERR_BADDEVICE;
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -172,6 +175,12 @@ grub_usb_device_initialize (grub_usb_device_t dev)
|
|||||||
/* Skip the configuration descriptor. */
|
/* Skip the configuration descriptor. */
|
||||||
pos = dev->config[i].descconf->length;
|
pos = dev->config[i].descconf->length;
|
||||||
|
|
||||||
|
if (dev->config[i].descconf->numif > GRUB_USB_MAX_IF)
|
||||||
|
{
|
||||||
|
err = GRUB_USB_ERR_BADDEVICE;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
/* Read all interfaces. */
|
/* Read all interfaces. */
|
||||||
for (currif = 0; currif < dev->config[i].descconf->numif; currif++)
|
for (currif = 0; currif < dev->config[i].descconf->numif; currif++)
|
||||||
{
|
{
|
||||||
@ -217,7 +226,7 @@ grub_usb_device_initialize (grub_usb_device_t dev)
|
|||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
|
||||||
for (i = 0; i < 8; i++)
|
for (i = 0; i < GRUB_USB_MAX_CONF; i++)
|
||||||
grub_free (dev->config[i].descconf);
|
grub_free (dev->config[i].descconf);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
@ -23,6 +23,10 @@
|
|||||||
#include <grub/usbdesc.h>
|
#include <grub/usbdesc.h>
|
||||||
#include <grub/usbtrans.h>
|
#include <grub/usbtrans.h>
|
||||||
|
|
||||||
|
#define GRUB_USB_MAX_CONF 8
|
||||||
|
#define GRUB_USB_MAX_IF 32
|
||||||
|
#define GRUB_USB_MAX_TOGGLE 256
|
||||||
|
|
||||||
typedef struct grub_usb_device *grub_usb_device_t;
|
typedef struct grub_usb_device *grub_usb_device_t;
|
||||||
typedef struct grub_usb_controller *grub_usb_controller_t;
|
typedef struct grub_usb_controller *grub_usb_controller_t;
|
||||||
typedef struct grub_usb_controller_dev *grub_usb_controller_dev_t;
|
typedef struct grub_usb_controller_dev *grub_usb_controller_dev_t;
|
||||||
@ -167,7 +171,7 @@ struct grub_usb_configuration
|
|||||||
struct grub_usb_desc_config *descconf;
|
struct grub_usb_desc_config *descconf;
|
||||||
|
|
||||||
/* Interfaces associated to this configuration. */
|
/* Interfaces associated to this configuration. */
|
||||||
struct grub_usb_interface interf[32];
|
struct grub_usb_interface interf[GRUB_USB_MAX_IF];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct grub_usb_hub_port
|
struct grub_usb_hub_port
|
||||||
@ -191,7 +195,7 @@ struct grub_usb_device
|
|||||||
struct grub_usb_controller controller;
|
struct grub_usb_controller controller;
|
||||||
|
|
||||||
/* Device configurations (after opening the device). */
|
/* Device configurations (after opening the device). */
|
||||||
struct grub_usb_configuration config[8];
|
struct grub_usb_configuration config[GRUB_USB_MAX_CONF];
|
||||||
|
|
||||||
/* Device address. */
|
/* Device address. */
|
||||||
int addr;
|
int addr;
|
||||||
@ -203,7 +207,7 @@ struct grub_usb_device
|
|||||||
int initialized;
|
int initialized;
|
||||||
|
|
||||||
/* Data toggle values (used for bulk transfers only). */
|
/* Data toggle values (used for bulk transfers only). */
|
||||||
int toggle[256];
|
int toggle[GRUB_USB_MAX_TOGGLE];
|
||||||
|
|
||||||
/* Used by libusb wrapper. Schedulded for removal. */
|
/* Used by libusb wrapper. Schedulded for removal. */
|
||||||
void *data;
|
void *data;
|
||||||
|
Loading…
Reference in New Issue
Block a user