Skip to content

Commit 339d01f

Browse files
committed
Prevent out-of-range reads via msc
Some ports implement their own protection against this at a low level but it doesn't hurt to add it here instead. Based on a patch from @drath42 Closes: #8788
1 parent 0c3b62f commit 339d01f

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)