]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
mm/gup: fix memfd_pin_folios alloc race panic
authorSteve Sistare <steven.sistare@oracle.com>
Tue, 3 Sep 2024 14:25:21 +0000 (07:25 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Oct 2024 10:04:06 +0000 (12:04 +0200)
commite28f39b359c0cfdcc011603e51187085a5f1e5e3
treeee8d4635f70561f7e7cfeacabfe0799de0122a64
parent0b20d2809006a5206c9b03d0e26842f224087526
mm/gup: fix memfd_pin_folios alloc race panic

commit ce645b9fdc78ec5d28067286e92871ddae6817d5 upstream.

If memfd_pin_folios tries to create a hugetlb page, but someone else
already did, then folio gets the value -EEXIST here:

        folio = memfd_alloc_folio(memfd, start_idx);
        if (IS_ERR(folio)) {
                ret = PTR_ERR(folio);
                if (ret != -EEXIST)
                        goto err;

then on the next trip through the "while start_idx" loop we panic here:

        if (folio) {
                folio_put(folio);

To fix, set the folio to NULL on error.

Link: https://lkml.kernel.org/r/1725373521-451395-6-git-send-email-steven.sistare@oracle.com
Fixes: 89c1905d9c14 ("mm/gup: introduce memfd_pin_folios() for pinning memfd folios")
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Acked-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Peter Xu <peterx@redhat.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
mm/gup.c