FAT: buffer overflow with FAT12/16
PATCH 1/1 FAT: buffer overflow with FAT12/16
Last commit 3831530dcb7b71329c272ccd6181f8038b6a6dd0a was intended "explicitly specify FAT12/16 root directory parsing buffer size, instead of relying on cluster size". Howver, the underlying function requires the size of the buffer in blocks, not in bytes, and instead of passing a double sector size a request for 1024 blocks is sent. This generates a buffer overflow with overwriting of other structure (in the case seen, USB structures were overwritten).
--- fs/fat/fat.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/fat/fat.c +1 -1
@@ -858,7 +858,7 @@ do_fat_read (const char *filename, void *buffer, unsigned long maxsize,if (disk_read (cursect, (mydata->fatsize ==32 ) ? (mydata->clust_size) : -LINEAR_PREFETCH_SIZE , +LINEAR_PREFETCH_SIZE /SECTOR_SIZE , do_fat_read_block) <0 ) {debug ("Error: reading rootdir block\n" );return -1 ;
Signature · 1 line
1.7.1
Wolfgang Denk
AppliedPATCH 1/1 FAT: buffer overflow with FAT12/16
Dear Stefano Babic,
Quoted 8 lines · In message <[email protected]> you wrote:
Last commit
3831530dcb7b71329c272ccd6181f8038b6a6dd0awas intended "explicitly specify FAT12/16 root directory parsing buffer size, instead of relying on cluster size". Howver, the underlying function requires the size of the buffer in blocks, not in bytes, and instead of passing a double sector size a request for 1024 blocks is sent. This generates a buffer overflow with overwriting of other structure (in the case seen, USB structures were overwritten).
Quoted 6 lines
Signed-off-by Stefano Babic <[email protected]>CC Mikhail Zolotaryov <[email protected]>--- fs/fat/fat.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Nice catch!
Applied, thanks.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Never worry about theory as long as the machinery does what it's supposed to do. - R. A. Heinlein
PATCH 1/1 FAT: buffer overflow with FAT12/16
In reply to Stefano BabicStefano,
you're right, sorry for that. Isn't it better to define LINEAR_PREFETCH_SIZE as 2 (blocks) and change get_vfatname() to something like that in such case:
__u8 *buflimit = cluster + ((curclust == 0) ?
LINEAR_PREFETCH_SIZE :
mydata->clust_size
) * SECTOR_SIZE;Regards,
Mikhail
Quoted 28 lines · Stefano Babic
Last commit
3831530dcb7b71329c272ccd6181f8038b6a6dd0awas intended "explicitly specify FAT12/16 root directory parsing buffer size, instead of relying on cluster size". Howver, the underlying function requires the size of the buffer in blocks, not in bytes, and instead of passing a double sector size a request for 1024 blocks is sent. This generates a buffer overflow with overwriting of other structure (in the case seen, USB structures were overwritten).Signed-off-by Stefano Babic <[email protected]>CC Mikhail Zolotaryov <[email protected]>--- fs/fat/fat.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)fs/fat/fat.c +1
-1@@ -858,7 +858,7 @@ do_fat_read (const char *filename, void *buffer, unsigned long maxsize,if (disk_read (cursect, (mydata->fatsize ==32 ) ? (mydata->clust_size) : -LINEAR_PREFETCH_SIZE , +LINEAR_PREFETCH_SIZE /SECTOR_SIZE , do_fat_read_block) <0 ) {debug ("Error: reading rootdir block\n" );return -1 ;