]> xenbits.xensource.com Git - people/aperard/linux-chromebook.git/commitdiff
arm: exynos: Fix potential buffer overrun in printk with asv
authorDoug Anderson <dianders@chromium.org>
Fri, 14 Dec 2012 16:56:34 +0000 (08:56 -0800)
committerGerrit <chrome-bot@google.com>
Fri, 14 Dec 2012 23:54:43 +0000 (15:54 -0800)
The asv code stores 5 characters in in a 5-byte array.  It properly
compares against this with strncmp, but then goes and passes the
character array to printk() which could read off the end.

Terminate the array properly, then go ahead and promote the printout
to print all the details we have every time.

BUG=chrome-os-partner:16820
TEST=Boot and see message printed out.

Change-Id: I8fb7044a8e14c6ce43d8866be2eee5ca167addbb
Signed-off-by: Doug Anderson <dianders@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/39710
Reviewed-by: Bryan Freed <bfreed@chromium.org>
arch/arm/mach-exynos/asv-5250.c

index 099bdada867ad7eb766b0f63b682aec9c4550279..e5cd0f5c3f01391a49041f5bd6d3b53bcd9f476c 100644 (file)
@@ -184,7 +184,7 @@ static int exynos5250_check_lot_id(struct samsung_asv *asv_info)
        unsigned int i;
        unsigned int tmp;
        unsigned int wno;
-       char lot_id[5];
+       char lot_id[6];
 
        lid_reg = __raw_readl(LOT_ID_REG);
 
@@ -201,26 +201,24 @@ static int exynos5250_check_lot_id(struct samsung_asv *asv_info)
                lid_reg /= 36;
                lot_id[i] = (tmp < 10) ? (tmp + '0') : ((tmp - 10) + 'A');
        }
+       lot_id[5] = '\0';
 
        wno = (rev_lid >> 6) & 0x1f;
 
+       printk(KERN_INFO "Exynos5250: Lot ID is %s and wafer number is %d\n",
+                       lot_id, wno);
+
        /* NZVPU lot has incorrect IDS value */
-       if ((!strncmp(lot_id, "NZVPU", ARRAY_SIZE(lot_id)))) {
+       if (!strcmp(lot_id, "NZVPU")) {
                exynos_lot_is_nzvpu = true;
-               printk(KERN_INFO "Exynos5250: Lot ID is %s and wafer number is %d\n",
-                               lot_id, wno);
                if (wno >= 2 && wno <= 6)
                        asv_info->ids_result -= 16;
                return 0;
        }
 
-       for (i = 0; i < ARRAY_SIZE(special_lot_id_list); i++) {
-               if (!strncmp(lot_id, special_lot_id_list[i],
-                                               ARRAY_SIZE(lot_id))) {
-                       printk(KERN_INFO "Exynos5250: Lot ID is %s\n", lot_id);
+       for (i = 0; i < ARRAY_SIZE(special_lot_id_list); i++)
+               if (!strcmp(lot_id, special_lot_id_list[i]))
                        return 0;
-               }
-       }
 
        return -EINVAL;
 }