Re: [PATCH] x86/mm: Do not allow non-MAP_FIXED mapping across DEFAULT_MAP_WINDOW border

From: Thomas Gleixner
Date: Tue Nov 14 2017 - 07:12:48 EST


On Tue, 14 Nov 2017, Kirill A. Shutemov wrote:
> On Mon, Nov 13, 2017 at 10:14:36PM +0100, Thomas Gleixner wrote:
> > I can see where you are heading to. Now the case I was looking at is:
> >
> > arch_get_unmapped_area_topdown()
> >
> > addr0 = addr;
> >
> > ....
> > if (addr) {
> > if (cross_border(addr, len))
> > goto get_unmapped_area;
> > ...
> > }
> > get_unmapped_area:
> > ...
> > if (addr > DEFAULT_MAP_WINDOW && !in_compat_syscall())
> >
> > ^^^ evaluates to false because addr < DEFAULT_MAP_WINDOW
> >
> > addr - vm_unmapped_area(&info);
> >
> > ^^^ fails for whatever reason.
> >
> > bottomup:
> > return arch_get_unmapped_area(.., addr0, len, ....);
> >
> >
> > AFAICT arch_get_unmapped_area() can allocate a mapping which crosses the
> > border, i.e. a mapping which you want to prevent for the !MAP_FIXED case.
>
> No, it can't as long as addr0 is below DEFAULT_MAP_WINDOW:
>
> arch_get_unmapped_area()
> {
> ...
> find_start_end(addr, flags, &begin, &end);
> // end is DEFAULT_MAP_WINDOW here, since addr is below the border

Sigh, I missed that task_size_64bit() magic in find_start_end().

This is really convoluted and non intuitive. I'm so not looking forward to
debug any failure in that context.

Thanks,

tglx