mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 12:44:03 +02:00
firewire: core: validate sub-block lengths in fw_core_add_descriptor()
When traversing internal block structures of a descriptor in fw_core_add_descriptor(), each sub-block header specifies its own length in the upper 16 bits of its header quadlet. If a malformed or corrupted descriptor provides a sub-block length that exceeds the remaining total length of the descriptor buffer, the parsing loop advances past the allocated boundary of desc->data, leading to an out-of-bounds read access. Validate each sub-block's length against the remaining descriptor size before advancing the offset pointer to ensure loop bounds safety. Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com> Link: https://lore.kernel.org/r/20260725155255.3054-3-sreekuttan2156239@gmail.com Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
This commit is contained in:
parent
e8e659f791
commit
a5367912ba
|
|
@ -173,9 +173,25 @@ int fw_core_add_descriptor(struct fw_descriptor *desc)
|
|||
return -EINVAL;
|
||||
|
||||
i = 0;
|
||||
while (i < desc->length)
|
||||
i += (desc->data[i] >> 16) + 1;
|
||||
/*
|
||||
* Validate internal block structures within the descriptor. Each sub-block
|
||||
* encodes its length in the top 16 bits of its header quadlet.
|
||||
*/
|
||||
while (i < desc->length) {
|
||||
u16 block_len = desc->data[i] >> 16;
|
||||
|
||||
/*
|
||||
* Guard against corrupted descriptors where an individual block length
|
||||
* claims to extend past the allocated end of desc->data, avoiding
|
||||
* out-of-bounds reads.
|
||||
*/
|
||||
if (block_len >= desc->length - i)
|
||||
return -EINVAL;
|
||||
|
||||
i += block_len + 1;
|
||||
}
|
||||
|
||||
/* The sum of sub-block lengths must match total descriptor length */
|
||||
if (i != desc->length)
|
||||
return -EINVAL;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user