From: sashiko-bot@kernel.org
To: "Rob Clark" <robin.clark@oss.qualcomm.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v7 15/17] drm/msm: Don't fallback to shared VM for VM_BIND
Date: Wed, 29 Jul 2026 16:27:50 +0000 [thread overview]
Message-ID: <20260729162750.A2A141F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260729155609.20190-16-robin.clark@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Unbounded memory leak of mmu objects in a6xx_create_private_vm() on userspace-managed VM creation failure
- [Medium] Flawed struct_size() overflow check in submit_create()
--
--- Patch [15]: [PATCH v7 15/17] drm/msm: Don't fallback to shared VM for VM_BIND ---
commit fad81fcf16686d778f256dee3ff6070327d5931e
Author: Rob Clark <robin.clark@oss.qualcomm.com>
Subject: drm/msm: Don't fallback to shared VM for VM_BIND
This patch modifies the virtual memory creation path in the MSM DRM driver.
If a user process requests a userspace managed VM, the driver will no longer
silently fall back to the shared, kernel-managed VM upon failure or absence
of private VM support.
> diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
> index 84b126c6347f7..db1b655dd055b 100644
> --- a/drivers/gpu/drm/msm/msm_drv.c
> +++ b/drivers/gpu/drm/msm/msm_drv.c
> @@ -234,7 +234,8 @@ struct drm_gpuvm *msm_context_vm(struct drm_device *dev, struct msm_context *ctx
> if (!ctx->vm) {
> vm = msm_gpu_create_private_vm(
> priv->gpu, current, !ctx->userspace_managed_vm);
> - smp_store_release(&ctx->vm, vm);
> + if (!IS_ERR_OR_NULL(vm))
> + smp_store_release(&ctx->vm, vm);
> }
>
> return ctx->vm;
> diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c
> index 03c0578560658..0c2c356362518 100644
> --- a/drivers/gpu/drm/msm/msm_gpu.c
> +++ b/drivers/gpu/drm/msm/msm_gpu.c
> @@ -879,7 +879,7 @@ msm_gpu_create_private_vm(struct msm_gpu *gpu, struct task_struct *task,
> to_msm_vm(vm)->pid = get_pid(task_pid(task));
> }
>
> - if (IS_ERR_OR_NULL(vm))
> + if (IS_ERR_OR_NULL(vm) && kernel_managed)
> vm = drm_gpuvm_get(gpu->vm);
>
> return vm;
[Severity: High]
This isn't a bug introduced by this patch, but does this change allow
userspace to trigger an unbounded memory leak?
When kernel_managed is false and gpu->funcs->create_private_vm()
(e.g., a6xx_create_private_vm()) fails, it returns an error pointer.
Before this patch, the code would fall back to the global gpu->vm.
Now, it propagates the error pointer back to the caller.
If we look at a6xx_create_private_vm():
drivers/gpu/drm/msm/adreno/a6xx_gpu.c:a6xx_create_private_vm() {
...
mmu = msm_iommu_pagetable_create(gpu->aspace->mmu);
if (IS_ERR(mmu))
return ERR_CAST(mmu);
return msm_gem_vm_create(gpu->dev, mmu, "gpu", ADRENO_VM_START,
adreno_private_vm_size(gpu), kernel_managed);
}
If msm_gem_vm_create() fails, the previously allocated mmu object is not
freed.
Because this patch propagates the error and leaves ctx->vm as NULL in
msm_context_vm(), can an unprivileged user repeatedly issue an ioctl with
MSM_PARAM_EN_VM_BIND set, hit this error path, and continuously leak
mmu objects?
A similar pre-existing leak exists in the GMU probe path if
msm_gem_vm_create() fails:
drivers/gpu/drm/msm/adreno/a6xx_gmu.c:a6xx_gmu_memory_probe() {
...
gmu->vm = msm_gem_vm_create(drm, mmu, "gmu", 0x0, 0x80000000, true);
if (IS_ERR(gmu->vm))
return PTR_ERR(gmu->vm);
...
}
[Severity: Medium]
This is a pre-existing issue, but does this code properly handle overflow?
Looking at submit_create() in msm_gem_submit.c:
drivers/gpu/drm/msm/msm_gem_submit.c:submit_create() {
...
sz = struct_size(submit, bos, nr_bos) +
((u64)nr_cmds * sizeof(submit->cmd[0]));
if (sz > SIZE_MAX)
return ERR_PTR(-ENOMEM);
...
}
According to the DRM subsystem guidelines, struct_size() saturates at
SIZE_MAX upon overflow. On a 64-bit system where SIZE_MAX is UINT64_MAX,
adding a non-zero value wraps the uint64_t variable to a small value.
Does this make the sz > SIZE_MAX check dead code that fails to catch the
overflow?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260729155609.20190-1-robin.clark@oss.qualcomm.com?part=15
next prev parent reply other threads:[~2026-07-29 16:27 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 15:55 [PATCH v7 00/17] drm/msm: A couple lazy-vm fixes Rob Clark
2026-07-29 15:55 ` [PATCH v7 01/17] drm/msm: Fix barriers accessing ctx vm Rob Clark
2026-07-29 16:15 ` sashiko-bot
2026-07-29 15:55 ` [PATCH v7 02/17] drm/msm: Rework queuelock Rob Clark
2026-07-29 16:21 ` sashiko-bot
2026-07-29 15:55 ` [PATCH v7 03/17] drm/msm: Synchronize VM creation on ctxlock Rob Clark
2026-07-29 16:10 ` sashiko-bot
2026-07-29 15:55 ` [PATCH v7 04/17] drm/msm: Synchronize set_sysprof " Rob Clark
2026-07-29 16:12 ` sashiko-bot
2026-07-29 15:55 ` [PATCH v7 05/17] drm/msm: Move nr_cmds initialization Rob Clark
2026-07-29 18:14 ` sashiko-bot
2026-07-29 15:55 ` [PATCH v7 06/17] drm/msm: Remove redundant SIZE_MAX check Rob Clark
2026-07-29 16:09 ` sashiko-bot
2026-07-29 15:55 ` [PATCH v7 07/17] drm/msm/a6xx: Access VM directly in submit path Rob Clark
2026-07-29 16:12 ` sashiko-bot
2026-07-29 15:55 ` [PATCH v7 08/17] drm/msm: Add helper to check for per-process pgtables VM Rob Clark
2026-07-29 16:11 ` sashiko-bot
2026-07-29 15:55 ` [PATCH v7 09/17] drm/msm/gem: Fix dma_buf import error paths Rob Clark
2026-07-29 15:55 ` [PATCH v7 10/17] drm/msm/gem: Remove useless locking in GEM import Rob Clark
2026-07-29 16:11 ` sashiko-bot
2026-07-29 15:55 ` [PATCH v7 11/17] drm/msm/gem: Extract bookkeeping init helper Rob Clark
2026-07-29 15:55 ` [PATCH v7 12/17] drm/msm/gem: Set resv before exposing obj Rob Clark
2026-07-29 16:25 ` sashiko-bot
2026-07-29 15:55 ` [PATCH v7 13/17] drm/msm/gem: Validate lazy VM in GEM_NEW Rob Clark
2026-07-29 16:26 ` sashiko-bot
2026-07-29 15:55 ` [PATCH v7 14/17] drm/msm: Allow lazy VM creation to fail Rob Clark
2026-07-29 16:21 ` sashiko-bot
2026-07-29 15:55 ` [PATCH v7 15/17] drm/msm: Don't fallback to shared VM for VM_BIND Rob Clark
2026-07-29 16:27 ` sashiko-bot [this message]
2026-07-29 15:55 ` [PATCH v7 16/17] drm/msm: Fix per-process-pgtables check Rob Clark
2026-07-29 15:55 ` [PATCH v7 17/17] drm/msm: Fixup invalid overflow check Rob Clark
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=20260729162750.A2A141F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=robin.clark@oss.qualcomm.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.