lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5n37yzto6ylq2a5lnxwcr7osygwkvlbv35fkilkhfc5eqhdqca@iji543qzcy2t>
Date: Thu, 4 Sep 2025 14:41:09 -0400
From: "Liam R. Howlett" <Liam.Howlett@...cle.com>
To: Kalesh Singh <kaleshsingh@...gle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>, akpm@...ux-foundation.org,
        minchan@...nel.org, kernel-team@...roid.com, android-mm@...gle.com,
        David Hildenbrand <david@...hat.com>, Vlastimil Babka <vbabka@...e.cz>,
        Mike Rapoport <rppt@...nel.org>,
        Suren Baghdasaryan <surenb@...gle.com>, Michal Hocko <mhocko@...e.com>,
        Jann Horn <jannh@...gle.com>, Pedro Falcato <pfalcato@...e.de>,
        linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] mm: centralize and fix max map count limit checking

* Kalesh Singh <kaleshsingh@...gle.com> [250904 13:44]:
> On Thu, Sep 4, 2025 at 10:33 AM Lorenzo Stoakes
> <lorenzo.stoakes@...cle.com> wrote:
> >
> > On Thu, Sep 04, 2025 at 01:22:51PM -0400, Liam R. Howlett wrote:
> > > > > diff --git a/mm/mremap.c b/mm/mremap.c
> > > > > index e618a706aff5..793fad58302c 100644
> > > > > --- a/mm/mremap.c
> > > > > +++ b/mm/mremap.c
> > > > > @@ -1040,7 +1040,7 @@ static unsigned long prep_move_vma(struct vma_remap_struct *vrm)
> > > > >    * We'd prefer to avoid failure later on in do_munmap:
> > > > >    * which may split one vma into three before unmapping.
> > > > >    */
> > > > > - if (current->mm->map_count >= sysctl_max_map_count - 3)
> > > > > + if (exceeds_max_map_count(current->mm, 4))
> > > > >           return -ENOMEM;
> > > >
> > > > In my version this would be:
> > > >
> > > >     if (map_count_capacity(current->mm) < 4)
> > > >             return -ENOMEM;
> > > >
> > >
> > > Someone could write map_count_capacity(current->mm) <= 4 and reintroduce
> > > what this is trying to solve.  And with the way it is written in this
> > > patch, someone could pass in the wrong number.
> 
> Hi Liam,
> 
> I still think there is value to this as it's lot less likely to get
> the common case incorrectly:
> 
> if (!map_count_capacity(mm))
>         return -ENOMEM;
> 
> It also facilitate us adding the asserts as Pedro suggested (excluding
> the munmap() case.

And munmap() callers case, I guess.

There is still the possibility of us failing to unmap after a split and
having shot ourselves, so just don't assert that in the case of the
failure and recovery path (ie exit_mmap()).

> 
> >
> > Right, but I think 'capacity' is pretty clear here, if the caller does something
> > silly then that's on them...

Turns out it's on us, not them :)

> >
> > >
> > > I'm not sure this is worth doing.  There are places we allow the count
> > > to go higher.
> >
> > ...But yeah, it's kinda borderline as to how useful this is.
> >
> > I _do_ however like the 'put map count in one place statically' rather than
> > having a global, so a minimal version of this could be to just have a helper
> > function that gets the sysctl_max_map_count, e.g.:
> >
> > if (current->mm->mmap_count >= max_map_count() - 3)
> >
> > etc. etc.
> >
> > >
> > > Certainly fix the brk < to be <= and any other calculations, but the
> > > rest seem okay as-is to me.  The only real way to be sure we don't cause
> > > a bug in the future is to have better testing.
> >
> > Speaking of testing - Kalesh - do make sure to test the VMA tests to make sure
> > this doesn't break those - they live in tools/testing/vma and you just have to
> > do make && ./vma

Bonus points if you can add some tests for it!

Thanks,
Liam

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ