mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mikko Perttunen <mperttunen@nvidia.com>
To: Thierry Reding <thierry.reding@kernel.org>,
	Sang-Hoon Choi <csh0052@gmail.com>
Cc: Jonathan Hunter <jonathanh@nvidia.com>,
	dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org,
	linux-kernel@vger.kernel.org, Changyul Lee <lcy8047@gmail.com>
Subject: Re: [PATCH] drm/tegra: initialize channel context before publishing it
Date: Thu, 19 Nov 2026 14:21:48 +0900	[thread overview]
Message-ID: <jPXD2u1JTf6jvKEETDBwsA@nvidia.com> (raw)
In-Reply-To: <179001455907.44752.8291506500067688174.idr-bug-37@gmail.com>

On Tuesday, September 22, 2026 3:15 AM Sang-Hoon Choi wrote:
> 
> tegra_drm_ioctl_channel_open() stores a new context in fpriv->contexts
> before setting context->client and initializing context->mappings.
> Another thread sharing the DRM file can guess the context ID and issue
> CHANNEL_MAP before CHANNEL_OPEN returns. For example, the first allocated
> ID in an empty context array is 1. The mapping path can then dereference
> an uninitialized client pointer or use the mappings array before it has
> been initialized. CHANNEL_CLOSE can also free the context before the open
> path finishes writing those fields.
> 
> Initialize the fields before xa_alloc() makes the context visible to the
> other channel ioctls.
> 
> Fixes: d7c591bc1a3f ("drm/tegra: Implement new UAPI")
> Reported-by: Changyul Lee <lcy8047@gmail.com>
> Assisted-by: LLM
> Signed-off-by: Sang-Hoon Choi <csh0052@gmail.com>
> ---
> Found during source review at mainline
> 5dd1818b15d98d4a20806cd00b1b40320b06004f. The affected source is unchanged
> at 93f51579e7df248780214094418f205253383cc5.
> 
> The modified uapi.o compiled in an x86 allmodconfig build. I have not
> tested this on Tegra hardware and do not have a runtime sanitizer trace.
> This concerns the UAPI guarded by CONFIG_DRM_TEGRA_STAGING.
> 
>  drivers/gpu/drm/tegra/uapi.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/tegra/uapi.c b/drivers/gpu/drm/tegra/uapi.c
> index c0ac6b45f..1dec2f0ab 100644
> --- a/drivers/gpu/drm/tegra/uapi.c
> +++ b/drivers/gpu/drm/tegra/uapi.c
> @@ -135,14 +135,14 @@ int tegra_drm_ioctl_channel_open(struct drm_device *drm, void *data, struct drm_
>  		}
>  	}
>  
> +	context->client = client;
> +	xa_init_flags(&context->mappings, XA_FLAGS_ALLOC1);
> +
>  	err = xa_alloc(&fpriv->contexts, &args->context, context, XA_LIMIT(1, U32_MAX),
>  		       GFP_KERNEL);
>  	if (err < 0)
>  		goto put_memctx;
>  
> -	context->client = client;
> -	xa_init_flags(&context->mappings, XA_FLAGS_ALLOC1);
> -
>  	args->version = client->version;
>  	args->capabilities = 0;
>  
> 

Reviewed-by: Mikko Perttunen <mperttunen@nvidia.com>




      reply	other threads:[~2026-11-19  5:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21 18:15 Sang-Hoon Choi
2026-11-19  5:21 ` Mikko Perttunen [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=jPXD2u1JTf6jvKEETDBwsA@nvidia.com \
    --to=mperttunen@nvidia.com \
    --cc=csh0052@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jonathanh@nvidia.com \
    --cc=lcy8047@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=thierry.reding@kernel.org \
    /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

all inboxes | Powered by JetHome®