From: sashiko-bot@kernel.org
To: "Matthew Brost" <matthew.brost@intel.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/pagemap: Fix folio allocation fallback and use-after-put
Date: Wed, 05 Aug 2026 04:57:07 +0000 [thread overview]
Message-ID: <20260805045708.6EA521F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260805044349.3474498-1-matthew.brost@intel.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] The order-0 allocation fallback loop causes a heap buffer overflow and memory leaks when migrating a partial THP or when some subpages lack the MIGRATE_PFN_MIGRATE flag.
--
--- Patch [1]: [PATCH] drm/pagemap: Fix folio allocation fallback and use-after-put ---
commit 0e0b48c51914bc3498ff387aa623528489adafed
Author: Matthew Brost <matthew.brost@intel.com>
drm/pagemap: Fix folio allocation fallback and use-after-put
This commit fixes a missing __GFP_NOWARN in higher-order folio allocations
and implements a fallback to order-0 allocations when THP allocation fails.
It also fixes a use-after-free issue where folio_order() was called after
dropping the page reference.
Cc: stable@vger.kernel.org
> diff --git a/drivers/gpu/drm/drm_pagemap.c b/drivers/gpu/drm/drm_pagemap.c
> index 15c78eca180b7..407c7546e168a 100644
> --- a/drivers/gpu/drm/drm_pagemap.c
> +++ b/drivers/gpu/drm/drm_pagemap.c
[ ... ]
> @@ -886,11 +886,34 @@ static int drm_pagemap_migrate_populate_ram_pfn(struct vm_area_struct *vas,
>
> order = folio_order(page_folio(src_page));
>
> - /* TODO: Support fallback to single pages if THP allocation fails */
> if (vas)
> - folio = vma_alloc_folio(GFP_HIGHUSER, order, vas, addr);
> + folio = vma_alloc_folio(GFP_HIGHUSER | __GFP_NOWARN, order, vas, addr);
> else
> - folio = folio_alloc(GFP_HIGHUSER, order);
> + folio = folio_alloc(GFP_HIGHUSER | __GFP_NOWARN, order);
> +
> + if (!folio && order) {
> + /*
> + * Higher-order allocation failed, fall back to
> + * order-0 allocations for the entire range covered
> + * by the original higher-order allocation, without
> + * setting MIGRATE_PFN_COMPOUND, until we move past
> + * that range.
> + */
> + unsigned long nr = NR_PAGES(order);
> + unsigned long j;
> +
> + for (j = 0; j < nr; j++, i++, addr += PAGE_SIZE) {
> + folio = vas ?
> + vma_alloc_folio(GFP_HIGHUSER, 0, vas, addr) :
> + folio_alloc(GFP_HIGHUSER, 0);
> + if (!folio)
> + goto free_pages;
> +
> + page = folio_page(folio, 0);
> + mpfn[i] = migrate_pfn(page_to_pfn(page));
[Severity: Critical]
Can this fallback loop write past the end of the mpfn array?
If the migration request only covers a partial THP, or if we are near the
end of the npages limit, nr could be larger than the remaining entries
(npages - i). Since this loop unconditionally increments i and writes to
mpfn[i] nr times, it appears it could cause a heap buffer overflow.
Additionally, this loop doesn't check if the subpages have the
MIGRATE_PFN_MIGRATE flag set in src_mpfn. Can this cause memory leaks if we
allocate and assign order-0 folios for subpages that weren't actually
requested for migration and thus might not be cleaned up later?
> + }
> + continue;
> + }
>
> if (!folio)
> goto free_pages;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260805044349.3474498-1-matthew.brost@intel.com?part=1
next prev parent reply other threads:[~2026-08-05 4:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 4:43 [PATCH] drm/pagemap: Fix folio allocation fallback and use-after-put Matthew Brost
2026-08-05 4:52 ` ✓ CI.KUnit: success for " Patchwork
2026-08-05 4:57 ` sashiko-bot [this message]
2026-08-05 5:56 ` ✗ Xe.CI.BAT: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260805045708.6EA521F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=matthew.brost@intel.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.