bootm: bound-check OS id before indexing boot_os[]
PATCH 1/1 bootm: bound-check OS id before indexing boot_os[]
bootm_os_get_boot_func() indexed boot_os[] with the caller-supplied os value without a bounds check. boot_os[] is sized by the highest enabled CONFIG_BOOTM_* entry, but images->os.os is an untrusted uint8_t populated from image metadata: a legacy uImage's raw ih_os byte, or a FIT image's os property truncated to 255 when its name is unrecognized by genimg_get_os_id(). An out-of-range value reads past the array and, if non-NULL, is invoked as a boot_os_fn.
Return NULL for out-of-range indices so the existing "not supported" error path in bootm_run_states() handles it.
--- boot/bootm_os.c | 3 +++ 1 file changed, 3 insertions(+)
boot/bootm_os.c +3 -0
@@ -599,5 +599,8 @@ int boot_selected_os(int state, struct bootm_info *bmi, boot_os_fn *boot_fn)boot_os_fn *bootm_os_get_boot_func (int os) { +if (os <0 || os >=ARRAY_SIZE (boot_os)) +return NULL ; +return boot_os[os]; }
Signature · 1 line
2.43.7
Quoted 9 lines · Pranav Sanwal
bootm_os_get_boot_func()indexed boot_os[] with the caller-supplied os value without a bounds check. boot_os[] is sized by the highest enabled CONFIG_BOOTM_* entry, butimages->os.osis an untrusteduint8_tpopulated from image metadata: a legacy uImage's rawih_osbyte, or a FIT image's os property truncated to 255 when its name is unrecognized bygenimg_get_os_id(). An out-of-range value reads past the array and, if non-NULL, is invoked as aboot_os_fn.[...]
Applied to u-boot/next, thanks!
[1/1] bootm: bound-check OS id before indexing boot_os[]
commit: ed28577c31d895fa766ffb71ec1c35c4b39db2a7
Signature · 1 line
Tom