Patchwork [6/8] slram: fix read buffer overflow

login
register
mail settings
Submitter Andrew Morton
Date Aug. 6, 2009, 11:05 p.m.
Message ID <200908062305.n76N5aeS004967@imap1.linux-foundation.org>
Download mbox | patch
Permalink /patch/30904/
State New, archived
Headers show

Comments

Andrew Morton - Aug. 6, 2009, 11:05 p.m.
From: Roel Kluin <roel.kluin@gmail.com>

map[count] is checked before count < SLRAM_MAX_DEVICES_PARAMS

declared on drivers/mtd/devices/slram.c:66:

static char *map[SLRAM_MAX_DEVICES_PARAMS];

[akpm@linux-foundation.org: cleanups]
Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/mtd/devices/slram.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Josh Boyer - Aug. 7, 2009, 2:58 a.m.
On Thu, Aug 06, 2009 at 04:05:36PM -0700, akpm@linux-foundation.org wrote:
>From: Roel Kluin <roel.kluin@gmail.com>
>
>map[count] is checked before count < SLRAM_MAX_DEVICES_PARAMS
>
>declared on drivers/mtd/devices/slram.c:66:

Didn't we obsolete this driver with phram?  I don't mean to derail the patch,
but I'm wondering why slram still exists at all.

josh
Artem Bityutskiy - Aug. 10, 2009, 7:04 a.m.
On 08/07/2009 05:58 AM, Josh Boyer wrote:
> On Thu, Aug 06, 2009 at 04:05:36PM -0700, akpm@linux-foundation.org wrote:
>> From: Roel Kluin<roel.kluin@gmail.com>
>>
>> map[count] is checked before count<  SLRAM_MAX_DEVICES_PARAMS
>>
>> declared on drivers/mtd/devices/slram.c:66:
>
> Didn't we obsolete this driver with phram?  I don't mean to derail the patch,
> but I'm wondering why slram still exists at all.

Feel free to send a patch. Meanwhile, I've put this fix to my l2-mtd-2.6.git.

Patch

diff -puN drivers/mtd/devices/slram.c~slram-read-buffer-overflow drivers/mtd/devices/slram.c
--- a/drivers/mtd/devices/slram.c~slram-read-buffer-overflow
+++ a/drivers/mtd/devices/slram.c
@@ -341,9 +341,8 @@  static int __init init_slram(void)
 #else
 	int count;
 
-	for (count = 0; (map[count]) && (count < SLRAM_MAX_DEVICES_PARAMS);
-			count++) {
-	}
+	for (count = 0; count < SLRAM_MAX_DEVICES_PARAMS && map[count]; count++)
+		;
 
 	if ((count % 3 != 0) || (count == 0)) {
 		E("slram: not enough parameters.\n");