All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rob Clark" <robin.clark@oss.qualcomm.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v6 01/16] drm/msm: Fix barriers accessing ctx vm
Date: Fri, 17 Jul 2026 21:07:14 +0000	[thread overview]
Message-ID: <20260717210715.81D311F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260717204841.26120-2-robin.clark@oss.qualcomm.com>

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

Pre-existing issues:
- [Critical] Direct access to ctx->vm before lazy initialization causes a NULL pointer dereference.
- [High] TOCTOU race in MSM_PARAM_EN_VM_BIND allows invalid VM configuration.
--

--- Patch [1]: [PATCH v6 01/16] drm/msm: Fix barriers accessing ctx vm ---
commit ca8b3357d768cc8c8e48035f7adbc82abd4eb8c7
Author: Rob Clark <robin.clark@oss.qualcomm.com>

    drm/msm: Fix barriers accessing ctx vm
    
    Don't rely on store ordering to protect us from caller seeing a
    partially initialized vm.

> diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
> index 79f78e7e16e9d..3c8b5083a1fbe 100644
> --- a/drivers/gpu/drm/msm/msm_drv.c
> +++ b/drivers/gpu/drm/msm/msm_drv.c
> @@ -225,18 +225,19 @@ struct drm_gpuvm *msm_context_vm(struct drm_device *dev, struct msm_context *ctx
>  {
>  	static DEFINE_MUTEX(init_lock);
>  	struct msm_drm_private *priv = dev->dev_private;
> +	struct drm_gpuvm *vm = smp_load_acquire(&ctx->vm);
>  
>  	/* Once ctx->vm is created it is valid for the lifetime of the context: */
> -	if (ctx->vm)
> -		return ctx->vm;
> +	if (vm)
> +		return vm;
> +
> +	guard(mutex)(&init_lock);
>  
> -	mutex_lock(&init_lock);
>  	if (!ctx->vm) {
> -		ctx->vm = msm_gpu_create_private_vm(
> +		vm = msm_gpu_create_private_vm(
>  			priv->gpu, current, !ctx->userspace_managed_vm);
> -
> +		smp_store_release(&ctx->vm, vm);
>  	}
> -	mutex_unlock(&init_lock);
>  
>  	return ctx->vm;
>  }

[Severity: Critical]
This is a pre-existing issue, but I noticed that ctx->vm can be accessed 
directly before lazy initialization. If an unprivileged user opens the DRM 
device and immediately calls the MSM_GEM_SUBMIT IOCTL, it evaluates 
to_msm_vm(ctx->vm)->unusable without ensuring the VM has been initialized via 
msm_context_vm():

drivers/gpu/drm/msm/msm_gem_submit.c:msm_ioctl_gem_submit() {
    ...
	if (to_msm_vm(ctx->vm)->unusable)
		return UERR(EPIPE, dev, "context is unusable");
    ...
}

Since ctx->vm is NULL, the to_msm_vm() macro computes an invalid pointer and 
dereferences its unusable field, causing a panic.

Similarly, calling the MSM_GEM_NEW IOCTL with the MSM_BO_NO_SHARE flag 
executes drm_gpuvm_resv_obj(ctx->vm) which also dereferences NULL:

drivers/gpu/drm/msm/msm_gem.c:msm_gem_new_handle() {
    ...
	if (flags & MSM_BO_NO_SHARE) {
		struct msm_context *ctx = file->driver_priv;
		struct drm_gem_object *r_obj = drm_gpuvm_resv_obj(ctx->vm);
    ...
}

Can these paths be updated to ensure the VM is initialized via 
msm_context_vm() before accessing it?


[Severity: High]
This isn't a bug introduced by this patch, but I found a potential TOCTOU 
race in MSM_PARAM_EN_VM_BIND that could allow an invalid VM configuration. 

In adreno_gpu_set_param(), it locklessly checks if (ctx->vm):

drivers/gpu/drm/msm/adreno/adreno_gpu.c:adreno_gpu_set_param() {
    ...
	case MSM_PARAM_EN_VM_BIND:
        ...
		if (ctx->vm)
			return UERR(EBUSY, drm, "VM already created");

		ctx->userspace_managed_vm = value;
    ...
}

If Thread A calls the MSM_SET_PARAM IOCTL, checks ctx->vm and sees NULL, and 
concurrently Thread B calls an IOCTL like MSM_INFO_GET_IOVA which calls 
msm_context_vm(), Thread B will create the VM as kernel-managed. Thread A 
then resumes and sets ctx->userspace_managed_vm = 1. 

Does this result in an inconsistent state where the context claims userspace 
management but the underlying VM is kernel-managed?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260717204841.26120-1-robin.clark@oss.qualcomm.com?part=1

  reply	other threads:[~2026-07-17 21:07 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17 20:48 [PATCH v6 00/16] drm/msm: A couple lazy-vm fixes Rob Clark
2026-07-17 20:48 ` [PATCH v6 01/16] drm/msm: Fix barriers accessing ctx vm Rob Clark
2026-07-17 21:07   ` sashiko-bot [this message]
2026-07-17 20:48 ` [PATCH v6 02/16] drm/msm: Rework queuelock Rob Clark
2026-07-17 21:00   ` sashiko-bot
2026-07-17 20:48 ` [PATCH v6 03/16] drm/msm: Synchronize VM creation on ctxlock Rob Clark
2026-07-17 21:05   ` sashiko-bot
2026-07-17 20:48 ` [PATCH v6 04/16] drm/msm: Synchronize set_sysprof " Rob Clark
2026-07-17 20:48 ` [PATCH v6 05/16] drm/msm: Move nr_cmds initialization Rob Clark
2026-07-17 21:06   ` sashiko-bot
2026-07-17 20:48 ` [PATCH v6 06/16] drm/msm: Remove redundant SIZE_MAX check Rob Clark
2026-07-17 20:58   ` sashiko-bot
2026-07-17 20:48 ` [PATCH v6 07/16] drm/msm/a6xx: Access VM directly in submit path Rob Clark
2026-07-17 21:03   ` sashiko-bot
2026-07-17 20:48 ` [PATCH v6 08/16] drm/msm: Add helper to check for per-process pgtables VM Rob Clark
2026-07-17 20:48 ` [PATCH v6 09/16] drm/msm/gem: Remove useless locking in GEM import Rob Clark
2026-07-17 21:02   ` sashiko-bot
2026-07-17 20:48 ` [PATCH v6 10/16] drm/msm/gem: Extract bookkeeping init helper Rob Clark
2026-07-17 21:22   ` sashiko-bot
2026-07-17 20:48 ` [PATCH v6 11/16] drm/msm/gem: Set resv before exposing obj Rob Clark
2026-07-17 21:06   ` sashiko-bot
2026-07-17 20:48 ` [PATCH v6 12/16] drm/msm/gem: Validate lazy VM in GEM_NEW Rob Clark
2026-07-17 21:05   ` sashiko-bot
2026-07-17 20:48 ` [PATCH v6 13/16] drm/msm: Allow lazy VM creation to fail Rob Clark
2026-07-17 20:48 ` [PATCH v6 14/16] drm/msm: Don't fallback to shared VM for VM_BIND Rob Clark
2026-07-17 21:07   ` sashiko-bot
2026-07-17 20:48 ` [PATCH v6 15/16] drm/msm: Fix per-process-pgtables check Rob Clark
2026-07-17 20:48 ` [PATCH v6 16/16] 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=20260717210715.81D311F000E9@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.