Skip to content

Commit bc44143

Browse files
committed
smex: bound the extended manifest walk
The extended-manifest walk advanced by an element size read from the section without validating it, so a zero size looped forever and a large size read past the section. Stop on a zero size or one that would leave the section. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent c4d2876 commit bc44143

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

smex/ldc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,22 @@ static int fw_version_copy(const struct elf_module *src,
5757
return section_size;
5858

5959
ext_hdr = (struct ext_man_elem_header *)buffer;
60-
while ((uintptr_t)ext_hdr < (uintptr_t)buffer + section_size) {
60+
while ((uintptr_t)ext_hdr + sizeof(*ext_hdr) <=
61+
(uintptr_t)buffer + section_size) {
6162
if (ext_hdr->type == EXT_MAN_ELEM_DBG_ABI) {
6263
header->version.abi_version =
6364
((struct ext_man_dbg_abi *)
6465
ext_hdr)->dbg_abi.abi_dbg_version;
6566
break;
6667
}
68+
/* elem_size must advance the cursor and keep the next header
69+
* within the section; otherwise stop instead of looping
70+
* forever (elem_size == 0) or reading past the section
71+
*/
72+
if (ext_hdr->elem_size == 0 ||
73+
(uintptr_t)ext_hdr + ext_hdr->elem_size >
74+
(uintptr_t)buffer + section_size)
75+
break;
6776
//move to the next entry
6877
ext_hdr = (struct ext_man_elem_header *)
6978
((uint8_t *)ext_hdr + ext_hdr->elem_size);

0 commit comments

Comments
 (0)