[PATCH v2] kho: use checked arithmetic in deserialize_bitmap()
Andrew Morton
akpm at linux-foundation.org
Thu Mar 19 19:37:35 PDT 2026
On Thu, 19 Mar 2026 22:03:53 +0100 Marco Elver <elver at google.com> wrote:
> The function deserialize_bitmap() calculates the reservation size using:
>
> int sz = 1 << (order + PAGE_SHIFT);
>
> If a corrupted KHO image provides an order >= 20 (on systems with 4KB
> pages), the shift amount becomes >= 32, which overflows the 32-bit
> integer. This results in a zero-size memory reservation.
>
> Furthermore, the physical address calculation:
>
> phys_addr_t phys = elm->phys_start + (bit << (order + PAGE_SHIFT));
>
> can also overflow and wrap around if the order is large. This allows a
> corrupt KHO image to cause out-of-bounds updates to page->private of
> arbitrary physical pages during early boot.
>
> Fix this by changing 'sz' to 'unsigned long' and using checked add and
> shift to safely calculate the shift amount, size, and physical address,
> skipping malformed chunks. This allows preserving memory with an order
> larger than MAX_PAGE_ORDER.
AI review asked questions:
https://sashiko.dev/#/patchset/20260319210528.1694513-2-elver%40google.com
More information about the kexec
mailing list