Skip to content

Commit 65ba963

Browse files
lyakhlgirdwood
authored andcommitted
lib-manager: check total claimed library size when loading
A corrupted or malformed library can provide the required page count that overflows 32-bit multiplication. Check once when loading. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent a1c1f84 commit 65ba963

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/library_manager/lib_manager.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -997,9 +997,17 @@ static int lib_manager_store_library(struct lib_manager_dma_ext *dma_ext,
997997
void __sparse_cache *library_base_address;
998998
const struct sof_man_fw_desc *man_desc = (struct sof_man_fw_desc *)
999999
((__sparse_force uint8_t *)man_buffer + SOF_MAN_ELF_TEXT_OFFSET);
1000-
uint32_t preload_size = man_desc->header.preload_page_count * PAGE_SZ;
10011000
int ret;
10021001

1002+
/* Zephyr UINT_MAX is explicitly 32 bits, and so is preload_page_count */
1003+
if (man_desc->header.preload_page_count >= UINT_MAX / PAGE_SZ) {
1004+
tr_err(&lib_manager_tr, "Invalid preload page count %u.",
1005+
man_desc->header.preload_page_count);
1006+
return -EINVAL;
1007+
}
1008+
1009+
uint32_t preload_size = man_desc->header.preload_page_count * PAGE_SZ;
1010+
10031011
/*
10041012
* The module manifest structure always has its maximum size regardless of
10051013
* the actual size of the manifest.
@@ -1009,10 +1017,10 @@ static int lib_manager_store_library(struct lib_manager_dma_ext *dma_ext,
10091017
return -EINVAL;
10101018
}
10111019

1012-
/* Prepare storage memory, note: it is never freed, library unloading is unsupported */
10131020
/*
1014-
* Prepare storage memory, note: it is never freed, it is assumed, that this
1015-
* memory is abundant, so we store all loaded modules there permanently
1021+
* Prepare storage memory, note: it is never freed, it is assumed, that
1022+
* this memory is abundant, so we store all loaded modules there
1023+
* permanently, unloading is unsupported
10161024
*/
10171025
library_base_address = lib_manager_allocate_store_mem(preload_size, 0);
10181026
if (!library_base_address)

0 commit comments

Comments
 (0)