Skip to content

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

Merged
merged 1 commit into from
Jan 15, 2018

Conversation

deepikabhavnani
Copy link

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.

@deepikabhavnani deepikabhavnani requested a review from geky January 11, 2018 20:57
@deepikabhavnani
Copy link
Author

This should resolve issue 3 in #5780

Copy link
Contributor

@geky geky left a 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;
Copy link
Contributor

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;
Copy link
Contributor

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
@cmonr
Copy link
Contributor

cmonr commented Jan 12, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Jan 12, 2018

Build : SUCCESS

Build number : 859
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5829/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build

@mbed-ci
Copy link

mbed-ci commented Jan 12, 2018

@cmonr
Copy link
Contributor

cmonr commented Jan 12, 2018

/morph uvisor-test

@mbed-ci
Copy link

mbed-ci commented Jan 13, 2018

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 15, 2018

Travis restarted due to failing update command, once green, it shall be ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants