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: <ftfdjb5qindsjv7c5edvb5tadp35supeh5qnigel3qtwwkfhw7@smfi3f5y2fnj>
Date: Wed, 10 Jul 2024 13:18:02 -0400
From: "Liam R. Howlett" <Liam.Howlett@...cle.com>
To: Suren Baghdasaryan <surenb@...gle.com>
Cc: linux-mm@...ck.org, Andrew Morton <akpm@...ux-foundation.org>,
        Vlastimil Babka <vbabka@...e.cz>, Lorenzo Stoakes <lstoakes@...il.com>,
        Matthew Wilcox <willy@...radead.org>, sidhartha.kumar@...cle.com,
        "Paul E . McKenney" <paulmck@...nel.org>,
        Bert Karwatzki <spasswolf@....de>, Jiri Olsa <olsajiri@...il.com>,
        linux-kernel@...r.kernel.org, Kees Cook <kees@...nel.org>
Subject: Re: [PATCH v3 10/16] mm/mmap: Reposition vma iterator in
 mmap_region()

* Suren Baghdasaryan <surenb@...gle.com> [240710 12:48]:
> On Thu, Jul 4, 2024 at 11:27 AM Liam R. Howlett <Liam.Howlett@...cle.com> wrote:
> >
> > From: "Liam R. Howlett" <Liam.Howlett@...cle.com>
> >
> > Instead of moving (or leaving) the vma iterator pointing at the previous
> > vma, leave it pointing at the insert location.  Pointing the vma
> > iterator at the insert location allows for a cleaner walk of the vma
> > tree for MAP_FIXED and the no expansion cases.
> >
> > Signed-off-by: Liam R. Howlett <Liam.Howlett@...cle.com>
> > ---
> >  mm/mmap.c | 28 ++++++++++++++--------------
> >  1 file changed, 14 insertions(+), 14 deletions(-)
> >
> > diff --git a/mm/mmap.c b/mm/mmap.c
> > index f5b33de4e717..ecf55d32e804 100644
> > --- a/mm/mmap.c
> > +++ b/mm/mmap.c
> > @@ -2963,11 +2963,12 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
> >                 vms_complete_munmap_vmas(&vms, &mas_detach);
> >                 next = vms.next;
> >                 prev = vms.prev;
> > -               vma_prev(&vmi);
> >                 vma = NULL;
> >         } else {
> >                 next = vma_next(&vmi);
> >                 prev = vma_prev(&vmi);
> > +               if (prev)
> > +                       vma_iter_next_range(&vmi);
> >         }
> >
> >         /*
> > @@ -2980,11 +2981,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
> >                 vm_flags |= VM_ACCOUNT;
> >         }
> >
> > -       if (vm_flags & VM_SPECIAL) {
> > -               if (prev)
> > -                       vma_iter_next_range(&vmi);
> > +       if (vm_flags & VM_SPECIAL)
> >                 goto cannot_expand;
> > -       }
> >
> >         /* Attempt to expand an old mapping */
> >         /* Check next */
> > @@ -3005,19 +3003,21 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
> >                 merge_start = prev->vm_start;
> >                 vma = prev;
> >                 vm_pgoff = prev->vm_pgoff;
> > -       } else if (prev) {
> > -               vma_iter_next_range(&vmi);
> > +               vma_prev(&vmi);
> >         }
> >
> > -       /* Actually expand, if possible */
> > -       if (vma &&
> > -           !vma_expand(&vmi, vma, merge_start, merge_end, vm_pgoff, next)) {
> > -               khugepaged_enter_vma(vma, vm_flags);
> > -               goto expanded;
> > +       if (vma) {
> > +               /* Actually expand, if possible */
> > +               if (!vma_expand(&vmi, vma, merge_start, merge_end, vm_pgoff, next)) {
> > +                       khugepaged_enter_vma(vma, vm_flags);
> > +                       goto expanded;
> > +               }
> > +
> > +               /* If the expand fails, then reposition the vma iterator */
> > +               if (unlikely(vma == prev))
> > +                       vma_iter_set(&vmi, addr);
> >         }
> >
> > -       if (vma == prev)
> > -               vma_iter_set(&vmi, addr);
> 
> Before this change we would reposition vmi if vma == prev == NULL.
> After this change we don't do that. Is this situation possible and if
> so, will vmi be correct?

vma == NULL can happen if it is a MAP_FIXED or we cannot expand (no
prev/next that match the checks for expanding).  If there is no prev,
then we can have a case where vma == prev == NULL.  So the situation can
be reached.

In the MAP_FIXED situation, the vms_complete_munmap_vmas() call will
return with the iterator pointing at the range of addr, so this is fine.

In the other case, we cannot move the vma iterator to prev since there
isn't one and the vma iterator is left pointing at the first range in
the tree (0 to .. whatever) that includes the addr.

So yes it is possible and yes it is correctly positioned.

Thanks,
Liam

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ