Re: [PATCH] mm: larger stack guard gap, between vmas

From: Ben Hutchings
Date: Wed Jul 05 2017 - 08:26:48 EST


On Tue, 2017-07-04 at 19:11 +0200, Willy Tarreau wrote:
> On Tue, Jul 04, 2017 at 12:36:11PM +0100, Ben Hutchings wrote:
> > @@ -2323,11 +2330,17 @@ int expand_downwards(struct vm_area_struct *vma,
> > Â if (error)
> > Â return error;
> > Â
> > - /* Enforce stack_guard_gap */
> > + /*
> > + Â* Enforce stack_guard_gap, but allow VM_NONE mappings in the gap
> > + Â* as some applications try to make their own stack guards
> > + Â*/
> > Â gap_addr = address - stack_guard_gap;
> > Â if (gap_addr > address)
> > Â return -ENOMEM;
> > - prev = vma->vm_prev;
> > + for (prev = vma->vm_prev;
> > + ÂÂÂÂÂprev && !(prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC));
> > + ÂÂÂÂÂprev = prev->vm_prev)
> > + ;
> > Â if (prev && prev->vm_end > gap_addr) {
> > Â if (!(prev->vm_flags & VM_GROWSDOWN))
> > Â return -ENOMEM;
>
> Hmmm shouldn't we also stop looping when we're out of the gap ?

Yes, either that or only allow one such vma.

Ben.

> Something like this :
>
> for (prev = vma->vm_prev;
> ÂÂÂÂÂprev && !(prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) &&
> ÂÂÂÂÂÂÂÂaddress - prev->vm_end < stack_guard_gap;
> ÂÂÂÂÂprev = prev->vm_prev)
> ;
>
> This would limit the risk of runaway loops if someone is having fun
> allocating a lot of memory in small chunks (eg: 4 GB in 1 million
> independant mmap() calls).

--
Ben Hutchings
Anthony's Law of Force: Don't force it, get a larger hammer.

Attachment: signature.asc
Description: This is a digitally signed message part