fbutil: Fix integer overflow
Expressions like u64 = u32 * u32 are unsafe because their products are truncated to u32 even if left hand side is u64. This patch fixes all problems like that one in fbutil. To get right result not only left hand side have to be u64 but it's also necessary to cast at least one of the operands of all leaf operators of right hand side to u64, e.g. u64 = u32 * u32 + u32 * u32 should be u64 = (u64)u32 * u32 + (u64)u32 * u32. For 1-bit bitmaps grub_uint64_t have to be used. It's safe because any combination of values in (grub_uint64_t)u32 * u32 + u32 expression will not overflow grub_uint64_t. Other expressions like ptr + u32 * u32 + u32 * u32 are also vulnerable. They should be ptr + (grub_addr_t)u32 * u32 + (grub_addr_t)u32 * u32. This patch also adds a comment to grub_video_fb_get_video_ptr() which says it's arguments must be valid and no sanity check is performed (like its siblings in grub-core/video/fb/fbutil.c). Signed-off-by:Zhang Boyang <zhangboyang.id@gmail.com> Reviewed-by:
Daniel Kiper <daniel.kiper@oracle.com>
Showing
- debian/patches/cve_2022_2601/0010-fbutil-Fix-integer-overflow.patch 85 additions, 0 deletions...ches/cve_2022_2601/0010-fbutil-Fix-integer-overflow.patch
- grub-core/video/fb/fbutil.c 2 additions, 2 deletionsgrub-core/video/fb/fbutil.c
- include/grub/fbutil.h 9 additions, 4 deletionsinclude/grub/fbutil.h
Please register or sign in to comment