Skip to content

Commit c1c2cc1

Browse files
Dan Carpentergregkh
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 0c7b4e0 commit c1c2cc1

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/net/wireless/mwifiex/debugfs.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -731,15 +731,15 @@ mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
731731
(struct mwifiex_private *) file->private_data;
732732
unsigned long addr = get_zeroed_page(GFP_KERNEL);
733733
char *buf = (char *) addr;
734-
int pos = 0, ret = 0, i;
734+
int pos, ret, i;
735735
u8 value[MAX_EEPROM_DATA];
736736

737737
if (!buf)
738738
return -ENOMEM;
739739

740740
if (saved_offset == -1) {
741741
/* No command has been given */
742-
pos += snprintf(buf, PAGE_SIZE, "0");
742+
pos = snprintf(buf, PAGE_SIZE, "0");
743743
goto done;
744744
}
745745

@@ -748,17 +748,17 @@ mwifiex_rdeeprom_read(struct file *file, char __user *ubuf,
748748
(u16) saved_bytes, value);
749749
if (ret) {
750750
ret = -EINVAL;
751-
goto done;
751+
goto out_free;
752752
}
753753

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

756756
for (i = 0; i < saved_bytes; i++)
757-
pos += snprintf(buf + strlen(buf), PAGE_SIZE, "%d ", value[i]);
758-
759-
ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
757+
pos += scnprintf(buf + pos, PAGE_SIZE - pos, "%d ", value[i]);
760758

761759
done:
760+
ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos);
761+
out_free:
762762
free_page(addr);
763763
return ret;
764764
}

0 commit comments

Comments
 (0)