]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
[SCSI] hpsa: fix potential array overflow in hpsa_update_scsi_devices
authorScott Teel <scott.teel@hp.com>
Wed, 26 Oct 2011 21:21:12 +0000 (16:21 -0500)
committerJoe Jin <joe.jin@oracle.com>
Tue, 15 May 2012 06:47:37 +0000 (14:47 +0800)
The currentsd[] array in hpsa_update_scsi_devices had room for
256 devices.  The code was iterating over however many physical
and logical devices plus an additional number of possible external
MSA2XXX controllers, which together could potentially exceed 256.

We increased the size of the currentsd array to 1024 + 1024 + 32 + 1
elements to reflect a reasonable maximum possible number of devices
which might be encountered.  We also don't just walk off the end
of the array if the array controller reports more devices than we
are prepared to handle, we just ignore the excessive devices.

Signed-off-by: Scott Teel <scott.teel@hp.com>
Signed-off-by: Stephen M. Cameron <scameron@beardog.cce.hp.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
(cherry picked from commit b7ec021fe6fe979dbd4e62604a4942f964b12864)

Signed-off-by: Joe Jin <joe.jin@oracle.com>
drivers/scsi/hpsa.c
drivers/scsi/hpsa.h
drivers/scsi/hpsa_cmd.h

index eaf836b72ae26a77c855719dfa4f4e77923c0977..3e0d659d232c0f0e48790067640d4f2be7a30001 100644 (file)
@@ -1727,7 +1727,6 @@ static int add_msa2xxx_enclosure_device(struct ctlr_info *h,
        if (is_scsi_rev_5(h))
                return 0; /* p1210m doesn't need to do this. */
 
-#define MAX_MSA2XXX_ENCLOSURES 32
        if (*nmsa2xxx_enclosures >= MAX_MSA2XXX_ENCLOSURES) {
                dev_warn(&h->pdev->dev, "Maximum number of MSA2XXX "
                        "enclosures exceeded.  Check your hardware "
@@ -1861,6 +1860,13 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
 
        /* Allocate the per device structures */
        for (i = 0; i < ndevs_to_allocate; i++) {
+               if (i >= HPSA_MAX_DEVICES) {
+                       dev_warn(&h->pdev->dev, "maximum devices (%d) exceeded."
+                               "  %d devices ignored.\n", HPSA_MAX_DEVICES,
+                               ndevs_to_allocate - HPSA_MAX_DEVICES);
+                       break;
+               }
+
                currentsd[i] = kzalloc(sizeof(*currentsd[i]), GFP_KERNEL);
                if (!currentsd[i]) {
                        dev_warn(&h->pdev->dev, "out of memory at %s:%d\n",
index bf1ab0ce8a1f281976d04454df771927d05ebe3a..e1e158d6172fd6a58e0a1bcbdddcaee349fbf2ab 100644 (file)
@@ -104,7 +104,6 @@ struct ctlr_info {
        struct Scsi_Host *scsi_host;
        spinlock_t devlock; /* to protect hba[ctlr]->dev[];  */
        int ndevices; /* number of used elements in .dev[] array. */
-#define HPSA_MAX_DEVICES 256
        struct hpsa_scsi_dev_t *dev[HPSA_MAX_DEVICES];
        /*
         * Performant mode tables.
index 55d741b019db22cf49b374f9c8a6994f7ccfcae7..3fd4715935c27658a74ea1e14db98e56e17b4d99 100644 (file)
@@ -123,8 +123,11 @@ union u64bit {
 
 /* FIXME this is a per controller value (barf!) */
 #define HPSA_MAX_TARGETS_PER_CTLR 16
-#define HPSA_MAX_LUN 256
+#define HPSA_MAX_LUN 1024
 #define HPSA_MAX_PHYS_LUN 1024
+#define MAX_MSA2XXX_ENCLOSURES 32
+#define HPSA_MAX_DEVICES (HPSA_MAX_PHYS_LUN + HPSA_MAX_LUN + \
+       MAX_MSA2XXX_ENCLOSURES + 1) /* + 1 is for the controller itself */
 
 /* SCSI-3 Commands */
 #pragma pack(1)