Repository navigation
tools: rimage: bound pin and mod_cfg writes to their allocations - #11288
Open
Shrusti-pk wants to merge 1 commit into
Open
Shrusti-pk wants to merge 1 commit into
Shrusti-pk wants to merge 1 commit into
Conversation
parse_pin() allocates toml_array_nelem(arr) / 6 pin descriptors and then loops with "for (i = 0; ; i += 6, j++)", breaking only once toml_raw_at() returns NULL. A pin array whose length is not a multiple of 6 still has a valid element at index 6 * (nelem / 6), so the loop runs once more and writes pin_desc[nelem / 6], one descriptor past the end of the calloc. parse_mod_config() writes one int per array element into modules->mod_cfg, which parse_module() sized for entry_count * MAX_MODULES configurations of 11 uint32 each. The mod_cfg_count > tmp_cfg_count guard in parse_module() only runs after parse_mod_config() has returned, so a mod_cfg array declaring more configurations than the remaining capacity overruns the allocation with config-supplied values first. Validate both arrays before writing anything: reject a pin length that is not a multiple of 6, and a mod_cfg length that is not a multiple of 11 or that exceeds the mod_cfg entries still free. Bound the pin loop with the entry count it already computed. Every pin array in tree is a multiple of 6 and every mod_cfg a multiple of 11, so valid configurations keep their behaviour. Signed-off-by: Shrushti P K <shrusthi@labs.digiscrypt.com>
Shrusti-pk
requested review from
dbaluta,
kv2019i,
lbetlej,
lgirdwood,
mmaka1 and
plbossart
as code owners
October 8, 2026 18:40
Collaborator
|
Can one of the admins verify this patch?
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two heap overflows in the rimage manifest parser, both because the write loop follows the toml array length while the destination was sized from the divided count:
Both arrays are now checked before anything is written, which is what the existing post-loop "only %u parsed for %u cfgs" error was already trying to catch. Verified under ASan: a pin array of 7 is a 4-byte write 0 bytes after the 24-byte region, and a mod_cfg of 363 ints is a write 0 bytes after the 1408-byte region; both are clean rejections after this. Every pin array in tree is a multiple of 6 and every mod_cfg a multiple of 11, so valid configurations keep their behaviour, and the verbose config dump for 32 real module entries is identical before and after.