Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Sumit Garg <sumit.garg@kernel.org>
To: Jens Wiklander <jens.wiklander@oss.qualcomm.com>
Cc: Tyler Baker <tyler.baker@oss.qualcomm.com>,
	Jens Wiklander <jenswi@kernel.org>,
	Sumit Garg <sumit.garg@kernel.org>,
	op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org,
	Vincent Donnefort <vdonnefort@google.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH] tee: shm: sync DMA memory for the device before it is lent
Date: Wed, 25 Nov 2026 17:55:23 +0530	[thread overview]
Message-ID: <awbTs4Ad041c1AjO@sumit-xelite> (raw)
In-Reply-To: <CAGgiveWm-xH_SjA5QrBJx6NtQhWyQWMw2FvfSd9SfG-wghpwmw@mail.gmail.com>

On Tue, 24 Nov 2026 at 09:52:00 +0100, Jens Wiklander wrote:
>Hi,
>
>On Fri, Nov 13, 2026 at 2:22 PM Tyler Baker
><tyler.baker@oss.qualcomm.com> wrote:
>>
>> tee_shm_alloc_dma_mem() returns dma_alloc_pages() memory without the
>> dma_sync_single_for_device() that the DMA API requires before a device
>> uses it. dma_alloc_pages() zeroes the pages through the cacheable
>> linear map, so the zeroes can still be dirty in the cache when the
>> optee protected memory pool lends the pages and a Secure Data Path TA
>> writes them through its secure mapping. A later eviction of those
>> lines overwrites the TA's data.
>>
>> On an Eliza EVK with OP-TEE as the FF-A SPMC, a TA decrypts into a
>> protected buffer, a read of all RAM through /proc/kcore evicts the
>> lines, and the TA's digest of the buffer no longer matches:
>>
>>   frame 0: 0e534d8c..., reference d98ddba1...
>>
>> Sync the allocation for the device before returning it.
>>
>> Fixes: ab09dd6d9201 ("tee: add tee_shm_alloc_dma_mem()")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Tyler Baker <tyler.baker@oss.qualcomm.com>
>> ---
>> Vincent's direct-map series [1] cleans the range in
>> dma_zap_direct_map() before the lend, which also covers this when it
>> can unmap. It returns -ENODEV without any cache maintenance when there
>> is no lendable pool and the direct map cannot change (arm64 with
>> rodata=noalias or rodata=off), and it is not a stable candidate.
>>
>> On a dma-coherent TEE device the sync does nothing. teedev->dev is not
>> configured from firmware, so it is not coherent today.
>>
>> Without the fix the TA's data is lost:
>>   https://lava.infra.foundries.io/scheduler/job/554467#L2262
>> With it, the data is intact after the scan and 50 lend rounds:
>>   https://lava.infra.foundries.io/scheduler/job/563840#L1979
>>   https://lava.infra.foundries.io/scheduler/job/563840#L2008
>>
>> [1] https://lore.kernel.org/all/20261111110738.872947-1-vdonnefort@google.com/
>> ---
>>  drivers/tee/tee_shm.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c
>> index 5c47a36916c45..70a273a425f88 100644
>> --- a/drivers/tee/tee_shm.c
>> +++ b/drivers/tee/tee_shm.c
>> @@ -297,6 +297,9 @@ struct tee_shm *tee_shm_alloc_dma_mem(struct tee_context *ctx,
>>         if (!page)
>>                 goto err_put_teedev;
>>
>> +       dma_sync_single_for_device(&teedev->dev, dma_addr,
>> +                                  page_count * PAGE_SIZE, DMA_BIDIRECTIONAL);
>> +
>>         dma_mem = kzalloc_obj(*dma_mem);
>>         if (!dma_mem)
>>                 goto err_free_pages;
>>
>> ---
>
>Looks good. Sumit, do you agree?

Looks like a reasonable fix to me, feel free to add:

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

-Sumit

      reply	other threads:[~2026-11-25 12:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 13:22 [PATCH] tee: shm: sync DMA memory for the device before it is lent Tyler Baker
2026-11-24  8:52 ` Jens Wiklander
2026-11-25 12:25   ` Sumit Garg [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=awbTs4Ad041c1AjO@sumit-xelite \
    --to=sumit.garg@kernel.org \
    --cc=jens.wiklander@oss.qualcomm.com \
    --cc=jenswi@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=op-tee@lists.trustedfirmware.org \
    --cc=stable@vger.kernel.org \
    --cc=tyler.baker@oss.qualcomm.com \
    --cc=vdonnefort@google.com \
    /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