Re: [PATCH 1/1] x86/mm: Fix limit mmap() of /dev/mem to valid physical addresses

From: Thomas Gleixner
Date: Mon Mar 25 2019 - 18:55:33 EST


Ralph,

On Mon, 25 Mar 2019, Ralph Campbell wrote:
> On 3/23/19 12:02 PM, Thomas Gleixner wrote:
> > > --- a/arch/x86/mm/mmap.c
> > > +++ b/arch/x86/mm/mmap.c
> > > @@ -230,7 +230,7 @@ bool mmap_address_hint_valid(unsigned long addr,
> > > unsigned long len)
> > > /* Can we access it for direct reading/writing? Must be RAM: */
> > > int valid_phys_addr_range(phys_addr_t addr, size_t count)
> > > {
> > > - return addr + count <= __pa(high_memory);
> > > + return addr + count <= __pa_nodebug(high_memory);
> >
> > This lacks a comment. Aside of that I think there is no point in using
> > __pa(high_memory) here. This is all about the physical address range. So
> > this can be simply expressed via:
> >
> > return addr + count <= max_pfn * PAGE_SIZE;
> >
> > which is much more obvious.
>
> This looks OK to me for x86_64 but looking at arch/x86/mm/init_32.c,
> initmem_init() sets high_memory based on highstart_pfn or max_low_pfn
> depending on CONFIG_HIGHMEM. Would using max_pfn in this case work?

Aargh. There is also numa_32.c ...

So __pa_nodebug(high_memory) should be fine, but looking at the other
places which do __pa() on high_memory they all use __pa(high_memory - 1)
which is more obvious that the nodebug thing.

Thanks,

tglx