Skip to content

Commit c8aab4f

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 4363677 commit c8aab4f

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

smex/ldc.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,37 @@ 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) {
63+
/* make sure the whole dbg-abi element is within the
64+
* section before reading it
65+
*/
66+
if (ext_hdr->elem_size < sizeof(struct ext_man_dbg_abi) ||
67+
(uintptr_t)ext_hdr + sizeof(struct ext_man_dbg_abi) >
68+
(uintptr_t)buffer + section_size) {
69+
fprintf(stderr, "error: %s truncated dbg-abi element\n",
70+
src->elf_file);
71+
free(buffer);
72+
return -ENOEXEC;
73+
}
6274
header->version.abi_version =
6375
((struct ext_man_dbg_abi *)
6476
ext_hdr)->dbg_abi.abi_dbg_version;
6577
break;
6678
}
79+
/* a malformed element size would loop forever (0) or advance
80+
* the cursor past the section; reject the image rather than
81+
* silently stopping
82+
*/
83+
if (ext_hdr->elem_size == 0 ||
84+
(uintptr_t)ext_hdr + ext_hdr->elem_size >
85+
(uintptr_t)buffer + section_size) {
86+
fprintf(stderr, "error: %s malformed ext-manifest element\n",
87+
src->elf_file);
88+
free(buffer);
89+
return -ENOEXEC;
90+
}
6791
//move to the next entry
6892
ext_hdr = (struct ext_man_elem_header *)
6993
((uint8_t *)ext_hdr + ext_hdr->elem_size);

0 commit comments

Comments
 (0)