dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Zhaoyu Liu" <liuzhaoyu.zackary@picoheart.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2] drm/pagemap: no need to recheck own pagemap in migrate_to_devmem
Date: Thu, 06 Aug 2026 13:34:31 +0000	[thread overview]
Message-ID: <20260806133432.188F01F000E9@smtp.kernel.org> (raw)
In-Reply-To: <anSKZabjuhl5Ojl4@hostpc>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Migration error paths pass unencoded raw PFNs to migrate_vma_pages(), causing out-of-bounds dereferences or mapping arbitrary physical memory into userspace.
--

--- Patch [1]: [PATCH v2] drm/pagemap: no need to recheck own pagemap in migrate_to_devmem ---
commit f37b1a946d737409d8a543e854c0c96738771e75
Author: Zhaoyu Liu <liuzhaoyu.zackary@picoheart.com>

drm/pagemap: no need to recheck own pagemap in migrate_to_devmem
    
The second loop in drm_pagemap_migrate_to_devmem() checks to skip pages
already on the target pagemap. However, this condition is always false at
this point since the first loop already aborts if necessary. This commit
removes the dead code and simplifies the error jumping paths.

> diff --git a/drivers/gpu/drm/drm_pagemap.c b/drivers/gpu/drm/drm_pagemap.c
> index 15c78eca180b7..64922b944092c 100644
> --- a/drivers/gpu/drm/drm_pagemap.c
> +++ b/drivers/gpu/drm/drm_pagemap.c

[ ... ]

> @@ -786,7 +779,6 @@ int drm_pagemap_migrate_to_devmem(struct drm_pagemap_devmem *devmem_allocation,
>  			goto err_finalize;
>  		}
>  
> -next:
>  		i += NR_PAGES(order);
>  	}

[Severity: Critical]
This is a pre-existing issue, but I noticed a potential problem in the
error handling path during the migration loop.

If drm_pagemap_migrate_range() fails in the middle of this loop, the local
npages variable is truncated to i + 1 before jumping to err_finalize. 
However, err_finalize falls through to err_aborted_migration:

err_finalize:
	if (err)
		drm_pagemap_migration_unlock_put_pages(npages, migrate.dst);
err_aborted_migration:
	migrate_vma_pages(&migrate);

Because migrate_vma_pages() uses the struct field migrate.npages, it will
process the entire original array length rather than the truncated local
npages value. The remaining elements in migrate.dst still contain unencoded
raw PFNs previously populated by ops->populate_devmem_pfn().

If one of these raw PFNs happens to be odd (bit 0 set), it matches
MIGRATE_PFN_VALID. This could cause the kernel to shift it by 6 and use it
as a struct page pointer, leading to an out-of-bounds dereference or mapping
arbitrary physical memory into userspace.

Could this error path be updated to avoid passing unencoded PFNs to
migrate_vma_pages() when the migration loop aborts early?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/anSKZabjuhl5Ojl4@hostpc?part=1

      reply	other threads:[~2026-08-06 13:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06 13:21 [PATCH v2] drm/pagemap: no need to recheck own pagemap in migrate_to_devmem Zhaoyu Liu
2026-08-06 13:34 ` sashiko-bot [this message]

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=20260806133432.188F01F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=liuzhaoyu.zackary@picoheart.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox