-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix: Sector/Size overflow from uint32_t #5829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This should resolve issue 3 in #5780 |
b965e7e
to
eafa8a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
Thanks for hunting down this fix
@@ -196,20 +196,24 @@ DRESULT disk_read(BYTE pdrv, BYTE *buff, DWORD sector, UINT count) | |||
{ | |||
debug_if(FFS_DBG, "disk_read(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv); | |||
DWORD ssize = disk_get_sector_size(pdrv); | |||
int err = _ffs[pdrv]->read(buff, sector*ssize, count*ssize); | |||
bd_addr_t addr = (bd_addr_t)sector * ssize; | |||
bd_size_t size = (bd_size_t)count*ssize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: consistent style for these two lines.
return err ? RES_PARERR : RES_OK; | ||
} | ||
|
||
DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count) | ||
{ | ||
debug_if(FFS_DBG, "disk_write(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv); | ||
DWORD ssize = disk_get_sector_size(pdrv); | ||
int err = _ffs[pdrv]->erase(sector*ssize, count*ssize); | ||
bd_addr_t addr = (bd_addr_t)sector * ssize; | ||
bd_size_t size = (bd_size_t)count*ssize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: consistent style for these two lines
FATFilesystem declares sector count and size as uint32_t and block device class arguments are addr and size which is uint64_t While passing arguments to program/read/write API's of block device, multiplication of uint32_t*uint32_t was not typecasted properly to uint64_t which resulted in MSB truncation. Eg. If block 0x800000 is accessed with block size 0x200, addr to be passed (0x800000*0x200)0x100000000, but actual address passed was 0x0 which resulted in over-writting the root directory, and hence corrupted filesystem
eafa8a7
to
c86d757
Compare
/morph build |
Build : SUCCESSBuild number : 859 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 530 |
/morph uvisor-test |
Test : SUCCESSBuild number : 703 |
Travis restarted due to failing update command, once green, it shall be ready |
FATFilesystem declares sector count and size as uint32_t and block device class arguments are addr and size which is uint64_t. While passing arguments to program/read/write API's of block device, multiplication of uint32_t*uint32_t was not type-casted to uint64_t which resulted in truncation.
Example of FAT corruption:
If sector 0x800000 is accessed with block size 0x200, addr to be passed 0x1 0000 0000 (0x800000*0x200), but actual address passed was 0x0000 0000 which resulted in over-writting the root directory, and hence corrupted filesystem.