Skip to content

Commit 3f98734

Browse files
Dan Carpentergregkh
Dan Carpenter
authored andcommitted
mwifiex: fix mwifiex_rdeeprom_read()
commit 1f9c6e1 upstream. There were several bugs here. 1) The done label was in the wrong place so we didn't copy any information out when there was no command given. 2) We were using PAGE_SIZE as the size of the buffer instead of "PAGE_SIZE - pos". 3) snprintf() returns the number of characters that would have been printed if there were enough space. If there was not enough space (and we had fixed the memory corruption bug #2) then it would result in an information leak when we do simple_read_from_buffer(). I've changed it to use scnprintf() instead. I also removed the initialization at the start of the function, because I thought it made the code a little more clear. Fixes: 5e6e3a9 ('wireless: mwifiex: initial commit for Marvell mwifiex driver') Signed-off-by: Dan Carpenter <[email protected]> Acked-by: Amitkumar Karwar <[email protected]> Signed-off-by: Kalle Valo <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a8bfcb9 commit 3f98734

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/net/wireless/mwifiex/debugfs.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -637,15 +637,15 @@ mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
637637
(struct mwifiex_private *) file->private_data;
638638
unsigned long addr = get_zeroed_page(GFP_KERNEL);
639639
char *buf = (char *) addr;
640-
int pos = 0, ret = 0, i;
640+
int pos, ret, i;
641641
u8 value[MAX_EEPROM_DATA];
642642

643643
if (!buf)
644644
return -ENOMEM;
645645

646646
if (saved_offset == -1) {
647647
/* No command has been given */
648-
pos += snprintf(buf, PAGE_SIZE, "0");
648+
pos = snprintf(buf, PAGE_SIZE, "0");
649649
goto done;
650650
}
651651

@@ -654,17 +654,17 @@ mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
654654
(u16) saved_bytes, value);
655655
if (ret) {
656656
ret = -EINVAL;
657-
goto done;
657+
goto out_free;
658658
}
659659

660-
pos += snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes);
660+
pos = snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes);
661661

662662
for (i = 0; i < saved_bytes; i++)
663-
pos += snprintf(buf + strlen(buf), PAGE_SIZE, "%d ", value[i]);
664-
665-
ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
663+
pos += scnprintf(buf + pos, PAGE_SIZE - pos, "%d ", value[i]);
666664

667665
done:
666+
ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
667+
out_free:
668668
free_page(addr);
669669
return ret;
670670
}

0 commit comments

Comments
 (0)