Re: [PATCH v2 3/5] of: reserved_mem: reject statically placed regions overlapping existing reservations

From: Marek Szyprowski

Date: Wed Aug 26 2026 - 09:21:07 EST


On 18.08.2026 11:24, Wandun Chen wrote:
> From: Wandun Chen <chenwandun@xxxxxxxxxxx>
>
> memblock_reserve() permits overlapping reservations, so a statically
> placed region whose 'reg' overlaps an existing one is accepted. When
> initialization of a statically placed reserved-memory region
> overlapping an existing reservation fails, memblock_phys_free()
> returns the overlap to the buddy allocator, corrupting that memory.
>
> Reject the overlap up front. Dynamically allocated regions are
> unaffected, as they are allocated from free memory and so cannot
> overlap an existing reservation.
>
> Sashiko found this issue in [1].
>
> Fixes: d0b8ed47e83a ("of: reserved_mem: fix reserve memory leak")
> Signed-off-by: Wandun Chen <chenwandun@xxxxxxxxxxx>
Acked-by: Marek Szyprowski <m.szyprowski@xxxxxxxxxxx>
> Link: https://protect2.fireeye.com/v1/url?k=d2f37e74-b38e94f7-d2f2f53b-74fe48600158-b5e65a51ea74eb99&q=1&e=2078d834-d5d6-4867-9088-f9d3bd0e1d17&u=https%3A%2F%2Fsashiko.dev%2F%23%2Fmessage%2F20260806100605.2C2C01F000E9%2540smtp.kernel.org [1]
> ---
> drivers/of/of_reserved_mem.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
> index 9fb2e4c29443..767ef702392e 100644
> --- a/drivers/of/of_reserved_mem.c
> +++ b/drivers/of/of_reserved_mem.c
> @@ -158,6 +158,11 @@ static int __init early_init_dt_reserve_memory(phys_addr_t base,
>
> return memblock_mark_nomap(base, size);
> }
> +
> + if (memblock_is_region_reserved(base, size) ||
> + memblock_overlaps_nomap(base, size))
> + return -EBUSY;
> +
> return memblock_reserve(base, size);
> }
>

Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland