Re: [PATCH] char: mem: reject wrapped physical ranges

From: Arnd Bergmann

Date: Thu Jun 25 2026 - 02:51:06 EST


On Wed, Jun 24, 2026, at 21:01, Yousef Alhouseen wrote:
> index 63253d1de..9e22b18f7 100644
> --- a/drivers/char/mem.c
> +++ b/drivers/char/mem.c
> @@ -47,7 +47,9 @@ static inline unsigned long size_inside_page(unsigned
> long start,
> #ifndef ARCH_HAS_VALID_PHYS_ADDR_RANGE
> static inline int valid_phys_addr_range(phys_addr_t addr, size_t count)
> {
> - return addr + count <= __pa(high_memory);
> + phys_addr_t end = __pa(high_memory);
> +
> + return addr <= end && count <= end - addr;
> }

The change looks correct, but the same thing still happens in the
arch/arm and arch/sh versions of the same function.

Please keep them in sync.

Ideally we'd generalize this function to check the lower bound
against ARCH_PFN_OFFSET and remove the arm and sh versions.
I see that half the architectures allow having RAM start at
a non-zero address but don't have this check, e.g. mips,
powerpc, and riscv.

Arnd