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: <CAHS8izOV9s-A+DwRyt7V2Q_4N3nv3tRVe1W=Bii8ve-uQEQcXQ@mail.gmail.com>
Date:   Sat, 22 May 2021 14:32:40 -0700
From:   Mina Almasry <almasrymina@...gle.com>
To:     Andrew Morton <akpm@...ux-foundation.org>
Cc:     Axel Rasmussen <axelrasmussen@...gle.com>,
        Peter Xu <peterx@...hat.com>, Linux-MM <linux-mm@...ck.org>,
        Mike Kravetz <mike.kravetz@...cle.com>,
        open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v3] mm, hugetlb: fix resv_huge_pages underflow on UFFDIO_COPY

On Sat, May 22, 2021 at 2:19 PM Andrew Morton <akpm@...ux-foundation.org> wrote:
>
> On Fri, 21 May 2021 00:44:33 -0700 Mina Almasry <almasrymina@...gle.com> wrote:
>
> > The userfaultfd hugetlb tests detect a resv_huge_pages underflow. This
> > happens when hugetlb_mcopy_atomic_pte() is called with !is_continue on
> > an index for which we already have a page in the cache. When this
> > happens, we allocate a second page, double consuming the reservation,
> > and then fail to insert the page into the cache and return -EEXIST.
> >
> > To fix this, we first if there exists a page in the cache which already
>
>                        ^ check
>
> > consumed the reservation, and return -EEXIST immediately if so.
> >
> > Secondly, if we fail to copy the page contents while holding the
> > hugetlb_fault_mutex, we will drop the mutex and return to the caller
> > after allocating a page that consumed a reservation. In this case there
> > may be a fault that double consumes the reservation. To handle this, we
> > free the allocated page, fix the reservations, and allocate a temporary
> > hugetlb page and return that to the caller. When the caller does the
> > copy outside of the lock, we again check the cache, and allocate a page
> > consuming the reservation, and copy over the contents.
> >
> > Test:
> > Hacked the code locally such that resv_huge_pages underflows produce
> > a warning and the copy_huge_page_from_user() always fails, then:
> >
> > ./tools/testing/selftests/vm/userfaultfd hugetlb_shared 10
> >       2 /tmp/kokonut_test/huge/userfaultfd_test && echo test success
> > ./tools/testing/selftests/vm/userfaultfd hugetlb 10
> >       2 /tmp/kokonut_test/huge/userfaultfd_test && echo test success
> >
> > Both tests succeed and produce no warnings. After the test runs
> > number of free/resv hugepages is correct.
> >
> > ...
> >
> >  include/linux/hugetlb.h |   4 ++
> >  mm/hugetlb.c            | 103 ++++++++++++++++++++++++++++++++++++----
> >  mm/migrate.c            |  39 +++------------
> >  3 files changed, 103 insertions(+), 43 deletions(-)
>
> I'm assuming we want this in -stable?
>

Umm I'll yield to Mike. This is a transient underflow; not actually
THAT serious of an issue. Sorry, I'll clarify that in the commit
message for the next version.

> Are we able to identify a Fixes: for this?
>

No, this issue has been there latent for some time. It repros as far
back as 5.11 at least, which is why maybe it's not that serious to
require in -stable.

> It's a large change.  Can we come up with some smaller and easier to
> review and integrate version which we can feed into 5.13 and -stable
> and do the fancier version for 5.14?
>

Yes. If we only do the hugetlbfs_pagecache_present() check then that
gets us some 90% of the way there, the rest of the patch addresses an
unlikely race.

> If you don't think -stable needs this then this version will be OK as-is.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ