Skip to content

Commit 17cd6aa

Browse files
authored
Merge pull request #8933 from jepler/avoid-out-of-range-msc-read
Prevent out-of-range reads via msc
2 parents 294d563 + 339d01f commit 17cd6aa

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

supervisor/shared/usb/usb_msc_flash.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void *buff
159159
const uint32_t block_count = bufsize / MSC_FLASH_BLOCK_SIZE;
160160

161161
fs_user_mount_t *vfs = get_vfs(lun);
162+
uint32_t disk_block_count;
163+
disk_ioctl(vfs, GET_SECTOR_COUNT, &disk_block_count);
164+
165+
if (lba + block_count > disk_block_count) {
166+
return -1;
167+
}
168+
162169
disk_read(vfs, buffer, lba, block_count);
163170

164171
return block_count * MSC_FLASH_BLOCK_SIZE;

0 commit comments

Comments
 (0)