Skip to contentSkip to conversation

sdio: Read buffer overflow

PATCH In review Roel Kluin 2 participants 3 messages Aug 7, 2009 MMC, SD and SDIO

lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 sdio: Read buffer overflow

If the loop breaks with an index of 0, then we read before the array.

---

drivers/mmc/core/sdio_cis.c +1 -1
index 963f293..0f8853c 100644
@@ -40,7 +40,7 @@ static int cistpl_vers_1(struct mmc_card *card, struct sdio_func *func,
 			nr_strings++;
 	}
 
-	if (buf[i-1] != '\0') {
+	if (i != 0 && buf[i-1] != '\0') {
 		printk(KERN_WARNING "SDIO: ignoring broken CISTPL_VERS_1\n");
 		return 0;
 	}
#1 lore raw
Quoted 1 line · Roel Kluin

If the loop breaks with an index of 0, then we read before the array.

This isn't a helpful subject or changelog comment really. Suggest

sdio: avoid buffer underrun when parsing an invalid CISTPL_VERS_1

drivers/mmc/core/sdio_cis.c static int cistpl_vers_1(struct mmc_card *card, struct sdio_func *func, · line 43

Quoted 12 lines

---

drivers/mmc/core/sdio_cis.c +1 -1
index 963f293..0f8853c 100644
@@ -40,7 +40,7 @@ static int cistpl_vers_1(struct mmc_card *card, struct sdio_func *func,
 			nr_strings++;
 	}
 
-	if (buf[i-1] != '\0') {
+	if (i != 0 && buf[i-1] != '\0') {

Looking at the PC Card 8.0 spec (vol 4, section 3.2.10) this test could simply be:

if (nr_strings < 4) {

Quoted 3 lines
drivers/mmc/core/sdio_cis.c +0 -0
 		printk(KERN_WARNING "SDIO: ignoring broken CISTPL_VERS_1\n");
 		return 0;
 	}
Signature · 6 lines
David Vrabel, Senior Software Engineer, Drivers
CSR, Churchill House, Cambridge Business Park,  Tel: +44 (0)1223 692562
Cowley Road, Cambridge, CB4 0WZ                 http://www.csr.com/


'member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom'
author
#2 lore raw

sdio: avoid buffer underrun when parsing an invalid CISTPL_VERS_1

---
Thanks for comments,

drivers/mmc/core/sdio_cis.c +1 -1
index 963f293..6636354 100644
@@ -40,7 +40,7 @@ static int cistpl_vers_1(struct mmc_card *card, struct sdio_func *func,
 			nr_strings++;
 	}
 
-	if (buf[i-1] != '\0') {
+	if (nr_strings < 4) {
 		printk(KERN_WARNING "SDIO: ignoring broken CISTPL_VERS_1\n");
 		return 0;
 	}