All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sumit Garg <sumit.garg@kernel.org>
To: Jens Wiklander <jens.wiklander@oss.qualcomm.com>
Cc: Hongyan Xu <getshell@seu.edu.cn>,
	Jens Wiklander <jenswi@kernel.org>,
	Sumit Garg <sumit.garg@kernel.org>,
	Olivier Masse <olivier.masse@nxp.com>,
	Etienne Carriere <etienne.carriere@foss.st.com>,
	op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, jianhao.xu@seu.edu.cn
Subject: Re: [PATCH] tee: avoid accessing dma-buf shared memory after put
Date: Mon, 9 Nov 2026 11:57:21 +0530	[thread overview]
Message-ID: <avFnybu7UDEdva94@sumit-xelite> (raw)
In-Reply-To: <CAGgiveVEiVqxVO-B0kxW9uCb43g2ocs1bgEZLWpVq=+AERaevA@mail.gmail.com>

On Thu, 05 Nov 2026 at 13:56:51 +0100, Jens Wiklander wrote:
>Hi,
>
>On Thu, Aug 6, 2026 at 8:07 AM Hongyan Xu <getshell@seu.edu.cn> wrote:
>>
>> param_from_user_memref() obtains a temporary reference to the dma-buf
>> tee_shm wrapper by ID. If closing the shared-memory file descriptor races
>> with the ioctl, this temporary reference can be the wrapper's last one.
>> tee_shm_put() then frees the enclosing tee_shm_dmabuf_ref, but the function
>> still reads ref->parent_shm and ref->offset afterwards.
>>
>> Save the parent pointer and offset before dropping the wrapper reference.
>> The additional parent reference keeps the parent shared memory alive for
>> the parameter list as before.
>>
>> Fixes: 146bf4e75eca ("tee: new ioctl to a register tee_shm from a dmabuf file descriptor")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Hongyan Xu <getshell@seu.edu.cn>
>> ---
>>  drivers/tee/tee_core.c | 8 +++++---
>>  1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c
>> index 1aac50c7c1de..489c39d5b35f 100644
>> --- a/drivers/tee/tee_core.c
>> +++ b/drivers/tee/tee_core.c
>> @@ -397,6 +397,7 @@ static int param_from_user_memref(struct tee_context *ctx,
>>                 }
>>
>>                 if (shm->flags & TEE_SHM_DMA_BUF) {
>> +                       struct tee_shm *parent_shm;
>>                         struct tee_shm_dmabuf_ref *ref;
>>
>>                         ref = container_of(shm, struct tee_shm_dmabuf_ref, shm);
>> @@ -409,10 +410,11 @@ static int param_from_user_memref(struct tee_context *ctx,
>>                                  * list instead of the shm we got with
>>                                  * tee_shm_get_from_id() above.
>>                                  */
>> -                               refcount_inc(&ref->parent_shm->refcount);
>> -                               tee_shm_put(shm);
>> -                               shm = ref->parent_shm;
>> +                               parent_shm = ref->parent_shm;
>>                                 offs = ref->offset;
>> +                               refcount_inc(&parent_shm->refcount);
>> +                               tee_shm_put(shm);
>> +                               shm = parent_shm;
>>                         }
>>                 }
>>         } else if (ctx->cap_memref_null) {
>> --
>> 2.50.1.windows.1
>>
>
>Looks good. Sumit, do you agree?
>

Sounds reasonable to me, FWIW:

Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com>

-Sumit

WARNING: multiple messages have this Message-ID (diff)
From: Sumit Garg via OP-TEE <op-tee@lists.trustedfirmware.org>
To: Jens Wiklander <jens.wiklander@oss.qualcomm.com>
Cc: Hongyan Xu <getshell@seu.edu.cn>,
	Jens Wiklander <jenswi@kernel.org>,
	Sumit Garg <sumit.garg@kernel.org>,
	Olivier Masse <olivier.masse@nxp.com>,
	Etienne Carriere <etienne.carriere@foss.st.com>,
	op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, jianhao.xu@seu.edu.cn
Subject: Re: [PATCH] tee: avoid accessing dma-buf shared memory after put
Date: Mon, 9 Nov 2026 11:57:21 +0530	[thread overview]
Message-ID: <avFnybu7UDEdva94@sumit-xelite> (raw)
In-Reply-To: <CAGgiveVEiVqxVO-B0kxW9uCb43g2ocs1bgEZLWpVq=+AERaevA@mail.gmail.com>

On Thu, 05 Nov 2026 at 13:56:51 +0100, Jens Wiklander wrote:
>Hi,
>
>On Thu, Aug 6, 2026 at 8:07 AM Hongyan Xu <getshell@seu.edu.cn> wrote:
>>
>> param_from_user_memref() obtains a temporary reference to the dma-buf
>> tee_shm wrapper by ID. If closing the shared-memory file descriptor races
>> with the ioctl, this temporary reference can be the wrapper's last one.
>> tee_shm_put() then frees the enclosing tee_shm_dmabuf_ref, but the function
>> still reads ref->parent_shm and ref->offset afterwards.
>>
>> Save the parent pointer and offset before dropping the wrapper reference.
>> The additional parent reference keeps the parent shared memory alive for
>> the parameter list as before.
>>
>> Fixes: 146bf4e75eca ("tee: new ioctl to a register tee_shm from a dmabuf file descriptor")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Hongyan Xu <getshell@seu.edu.cn>
>> ---
>>  drivers/tee/tee_core.c | 8 +++++---
>>  1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c
>> index 1aac50c7c1de..489c39d5b35f 100644
>> --- a/drivers/tee/tee_core.c
>> +++ b/drivers/tee/tee_core.c
>> @@ -397,6 +397,7 @@ static int param_from_user_memref(struct tee_context *ctx,
>>                 }
>>
>>                 if (shm->flags & TEE_SHM_DMA_BUF) {
>> +                       struct tee_shm *parent_shm;
>>                         struct tee_shm_dmabuf_ref *ref;
>>
>>                         ref = container_of(shm, struct tee_shm_dmabuf_ref, shm);
>> @@ -409,10 +410,11 @@ static int param_from_user_memref(struct tee_context *ctx,
>>                                  * list instead of the shm we got with
>>                                  * tee_shm_get_from_id() above.
>>                                  */
>> -                               refcount_inc(&ref->parent_shm->refcount);
>> -                               tee_shm_put(shm);
>> -                               shm = ref->parent_shm;
>> +                               parent_shm = ref->parent_shm;
>>                                 offs = ref->offset;
>> +                               refcount_inc(&parent_shm->refcount);
>> +                               tee_shm_put(shm);
>> +                               shm = parent_shm;
>>                         }
>>                 }
>>         } else if (ctx->cap_memref_null) {
>> --
>> 2.50.1.windows.1
>>
>
>Looks good. Sumit, do you agree?
>

Sounds reasonable to me, FWIW:

Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com>

-Sumit

  reply	other threads:[~2026-11-09  6:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06  6:07 [PATCH] tee: avoid accessing dma-buf shared memory after put Hongyan Xu
2026-11-05 12:56 ` Jens Wiklander
2026-11-09  6:27   ` Sumit Garg [this message]
2026-11-09  6:27     ` Sumit Garg via OP-TEE
2026-11-09 16:11     ` Jens Wiklander

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=avFnybu7UDEdva94@sumit-xelite \
    --to=sumit.garg@kernel.org \
    --cc=etienne.carriere@foss.st.com \
    --cc=getshell@seu.edu.cn \
    --cc=jens.wiklander@oss.qualcomm.com \
    --cc=jenswi@kernel.org \
    --cc=jianhao.xu@seu.edu.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olivier.masse@nxp.com \
    --cc=op-tee@lists.trustedfirmware.org \
    --cc=stable@vger.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 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.