mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tyler Baker <tyler.baker@oss.qualcomm.com>
To: Jens Wiklander <jenswi@kernel.org>, Sumit Garg <sumit.garg@kernel.org>
Cc: op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org,
	Vincent Donnefort <vdonnefort@google.com>,
	stable@vger.kernel.org,
	Tyler Baker <tyler.baker@oss.qualcomm.com>
Subject: [PATCH] tee: shm: sync DMA memory for the device before it is lent
Date: Fri, 13 Nov 2026 08:22:46 -0500	[thread overview]
Message-ID: <20261113-tee-shm-dma-sync-v1-1-19d4efdfb4cd@oss.qualcomm.com> (raw)

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;

---
base-commit: e21989d08e0d6abacfff71387d0cb36dd96a4079
change-id: 20261113-tee-shm-dma-sync-12f58435b81e

Best regards,
--  
Tyler Baker <tyler.baker@oss.qualcomm.com>


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

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261113-tee-shm-dma-sync-v1-1-19d4efdfb4cd@oss.qualcomm.com \
    --to=tyler.baker@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=sumit.garg@kernel.org \
    --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

all inboxes | Powered by JetHome®