Re: [PATCH] char: mem: reject wrapped physical ranges
From: Yousef Alhouseen
Date: Thu Jun 25 2026 - 05:07:22 EST
Hi Arnd,
Thanks, I kept the ARM and SH implementations in sync and sent a
follow-up patch:
[PATCH] char: mem: keep arch range checks overflow-safe
I left the broader lower-bound/generalization cleanup for separate work.
Thanks,
Yousef
On Thu, 25 Jun 2026 08:49:49 +0200, Arnd Bergmann <arnd@xxxxxxxx> wrote:
> 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