fw: Limit flash offsets to be within sane limits

Limit flash offsets passed to syscalls. Be sure to check the limits
before doing any form of calculation with the passed values.

Co-authored-by: Mikael Ågren <mikael@tillitis.se>
This commit is contained in:
Michael Cardell Widerkrantz 2025-04-25 15:16:41 +02:00
parent 506b4c8269
commit 632b6d8fc7
No known key found for this signature in database
GPG key ID: D3DB3DDF57E704E5
2 changed files with 30 additions and 2 deletions

View file

@ -67,7 +67,15 @@ int preload_store(struct partition_table *part_table, uint32_t offset,
return -1;
}
if ((offset + size) > SIZE_PRE_LOADED_APP || size > 4096) {
if (offset > SIZE_PRE_LOADED_APP) {
return -2;
}
if (size > 4096) {
return -2;
}
if ((offset + size) > SIZE_PRE_LOADED_APP) {
/* Writing outside of area */
return -2;
}