From: sashiko-bot@kernel.org
To: "Matthew Brost" <matthew.brost@intel.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3 2/6] mm/migrate_device: Do not write past the end of the src_pfns array
Date: Wed, 05 Aug 2026 23:25:04 +0000 [thread overview]
Message-ID: <20260805232505.7C7C51F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260805231041.3791771-3-matthew.brost@intel.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Unsafe speculative read of `folio_nr_pages(folio)` without lock success check leads to array corruption and PFN iterator overshoot.
- [High] `migrate_device_pfns()` corrupts non-contiguous caller arrays by indiscriminately zeroing elements when encountering a compound page.
--
--- Patch [2]: [PATCH v3 2/6] mm/migrate_device: Do not write past the end of the src_pfns array ---
commit f29e7afad950b0af66d7edea5f1c3b8203675195
Author: Matthew Brost <matthew.brost@intel.com>
mm/migrate_device: Do not write past the end of the src_pfns array
migrate_device_range() and migrate_device_pfns() zero the tail entries
of a large folio without checking them against @npages. This commit bounds
the loop by @npages to prevent corrupting whatever follows the array.
> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
> index 9a346162c6881..e1a18d291b9c1 100644
> --- a/mm/migrate_device.c
> +++ b/mm/migrate_device.c
> @@ -1425,7 +1425,7 @@ int migrate_device_range(unsigned long *src_pfns, unsigned long start,
[ ... ]
> src_pfns[i] = migrate_device_pfn_lock(pfn);
> nr = folio_nr_pages(folio);
> if (nr > 1) {
[Severity: High]
This isn't a bug introduced by this patch, but does this code speculatively
read the folio size even if the lock fails?
If migrate_device_pfn_lock() fails (e.g., due to a concurrent free or split),
folio_nr_pages(folio) accesses unstable memory, yielding a garbage nr. This
can cause unbounded iterator advancement and arbitrary zeroing of src_pfns.
Additionally, if the PFN is a tail page, the lock correctly fails, but
folio_nr_pages() reads the head page's size and advances pfn += nr - 1,
overshooting the end of the folio and silently skipping unrelated PFNs in the
migration range.
Should there be a check to ensure src_pfns[i] indicates a successful lock
before reading the folio size?
> src_pfns[i] |= MIGRATE_PFN_COMPOUND;
> - for (j = 1; j < nr; j++)
> + for (j = 1; j < nr && (i + j) < npages; j++)
> src_pfns[i+j] = 0;
> i += j - 1;
> pfn += j - 1;
> @@ -1459,7 +1459,7 @@ int migrate_device_pfns(unsigned long *src_pfns, unsigned long npages)
[ ... ]
> src_pfns[i] = migrate_device_pfn_lock(src_pfns[i]);
> nr = folio_nr_pages(folio);
> if (nr > 1) {
[Severity: High]
This is also a pre-existing issue, but is it safe to read the folio size
here without confirming that migrate_device_pfn_lock() succeeded, similar to
the issue in migrate_device_range() above?
> src_pfns[i] |= MIGRATE_PFN_COMPOUND;
> - for (j = 1; j < nr; j++)
> + for (j = 1; j < nr && (i + j) < npages; j++)
> src_pfns[i+j] = 0;
[Severity: High]
This is a pre-existing issue, but does this zeroing logic break support for
non-contiguous PFN arrays?
migrate_device_pfns() documents that it supports non-contiguous pre-populated
arrays of device pages to migrate. However, when it encounters a compound
page, it reuses the large-folio iteration logic and zeroes out the next
nr - 1 elements.
In a non-contiguous array, these subsequent elements are independent,
unrelated PFNs provided by the caller, which would be overwritten
and excluded from migration.
> i += j - 1;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260805231041.3791771-1-matthew.brost@intel.com?part=2
next prev parent reply other threads:[~2026-08-05 23:25 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 23:10 [PATCH v3 0/6] Fix device page migration in low memory fallback Matthew Brost
2026-08-05 23:10 ` [PATCH v3 1/6] mm/migrate_device: Clear stale mapping after freeing swapcache Matthew Brost
2026-08-05 23:22 ` sashiko-bot
2026-08-05 23:10 ` [PATCH v3 2/6] mm/migrate_device: Do not write past the end of the src_pfns array Matthew Brost
2026-08-05 23:25 ` sashiko-bot [this message]
2026-08-05 23:29 ` Balbir Singh
2026-08-05 23:10 ` [PATCH v3 3/6] mm/migrate_device: Fix THP splitting of a CPU faulted device private folio Matthew Brost
2026-08-06 8:10 ` Balbir Singh
2026-08-10 2:26 ` Huang, Ying
2026-08-10 19:43 ` Matthew Brost
2026-08-05 23:10 ` [PATCH v3 4/6] drm/pagemap: dma-unmap pages before handling migration errors Matthew Brost
2026-08-05 23:22 ` sashiko-bot
2026-08-05 23:10 ` [PATCH v3 5/6] drm/pagemap: Fix folio allocation fallback and use-after-put Matthew Brost
2026-08-05 23:10 ` [PATCH v3 6/6] drm/pagemap: Add fault injection for higher-order RAM folio allocation Matthew Brost
2026-08-05 23:24 ` sashiko-bot
2026-08-05 23:17 ` ✗ CI.checkpatch: warning for Fix device page migration in low memory fallback (rev3) Patchwork
2026-08-05 23:18 ` ✓ CI.KUnit: success " Patchwork
2026-08-06 0:02 ` ✓ Xe.CI.BAT: " Patchwork
2026-08-06 9:15 ` ✓ Xe.CI.FULL: " 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=20260805232505.7C7C51F000E9@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.