All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Amirreza Zarrabi" <amirreza.zarrabi@oss.qualcomm.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH RFC v3 1/9] tee: optee: share the global shared-memory ID mapping
Date: Tue, 13 Oct 2026 05:56:08 +0000	[thread overview]
Message-ID: <sashiko-outbox-169021@kernel.org> (raw)
In-Reply-To: <20261012-rpmi-tee-service-grp-dev-v3-1-975b574667e2@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] tee: optee: UAF race in SHM free via unreferenced lookup
--

commit 39c6675fd3cd9df49f5b14024b5f0c43a9129fe8
Author: Amirreza Zarrabi <amirreza.zarrabi@oss.qualcomm.com>

tee: optee: share the global shared-memory ID mapping

This commit moves the FF-A backend's hash table mapping secure-world memory
handles to TEE shared-memory objects into common helpers. It also converts
the FF-A backend to use this new shared mapping API.

> diff --git a/drivers/tee/optee/ffa_abi.c b/drivers/tee/optee/ffa_abi.c
> --- a/drivers/tee/optee/ffa_abi.c
> +++ b/drivers/tee/optee/ffa_abi.c
> @@ -488,7 +404,8 @@ static void handle_ffa_rpc_func_cmd_shm_free(struct tee_context *ctx,
>  	    arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_VALUE_INPUT)
>  		goto err_bad_param;
>  
> -	shm = optee_shm_from_ffa_handle(optee, arg->params[0].u.value.b);
> +	shm = optee_shm_handle_map_lookup(&optee->ffa.shm_map,
> +					  arg->params[0].u.value.b);
>  	if (!shm)
>  		goto err_bad_param;

[Severity: High]
Could this lookup introduce a Use-After-Free race if multiple RPCs are
processed concurrently?

If a compromised Secure World sends concurrent OPTEE_RPC_CMD_SHM_FREE RPCs
for the same shared memory global_id, both threads can look up the pointer
before either has a chance to free it.

Since optee_shm_handle_map_lookup() returns the tee_shm pointer without
incrementing its reference count, both threads will then proceed down to
tee_shm_free() or optee_rpc_cmd_free_suppl(). The first thread will drop
the reference to 0, freeing the object, and the second thread will
subsequently access shm->refcount on the freed pointer.

> diff --git a/drivers/tee/optee/shm_handle_map.c b/drivers/tee/optee/shm_handle_map.c
> --- /dev/null
> +++ b/drivers/tee/optee/shm_handle_map.c
[ ... ]
> +struct tee_shm *
> +optee_shm_handle_map_lookup(struct optee_shm_handle_map *map, u64 global_id)
> +{
> +	struct optee_shm_handle_map_entry *entry;
> +	struct tee_shm *shm = NULL;
> +
> +	mutex_lock(&map->mutex);
> +	entry = rhashtable_lookup_fast(&map->rht, &global_id,
> +				       shm_handle_map_params);
> +	if (entry)
> +		shm = entry->shm;
> +	mutex_unlock(&map->mutex);
> +
> +	return shm;
> +}

[Severity: High]
Since this new API helper retrieves the shared memory pointer without acquiring
a reference, does it allow the object to be freed concurrently by another
thread once the mutex is released?

The kerneldoc above this function mentions "The caller must keep the SHM
object alive; no reference is acquired here", but as seen in
handle_ffa_rpc_func_cmd_shm_free(), the caller isn't guaranteed to hold a
reference when handling incoming RPCs from the secure world.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261012-rpmi-tee-service-grp-dev-v3-0-975b574667e2@oss.qualcomm.com?part=1

  reply	other threads:[~2026-10-13  5:56 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13  5:41 [PATCH RFC v3 0/9] tee: optee: add RPMI backend support on RISC-V Amirreza Zarrabi
2026-10-13  5:41 ` Amirreza Zarrabi via OP-TEE
2026-10-13  5:41 ` Amirreza Zarrabi
2026-10-13  5:41 ` [PATCH RFC v3 1/9] tee: optee: share the global shared-memory ID mapping Amirreza Zarrabi
2026-10-13  5:41   ` Amirreza Zarrabi via OP-TEE
2026-10-13  5:41   ` Amirreza Zarrabi
2026-10-13  5:56   ` sashiko-bot [this message]
2026-10-13  5:41 ` [PATCH RFC v3 2/9] tee: optee: allow RPMI transport builds on RISC-V Amirreza Zarrabi
2026-10-13  5:41   ` Amirreza Zarrabi via OP-TEE
2026-10-13  5:41   ` Amirreza Zarrabi
2026-10-13  5:55   ` sashiko-bot
2026-10-13  5:41 ` [PATCH RFC v3 3/9] tee: optee: define the RPMI control and parcel-reference ABI Amirreza Zarrabi
2026-10-13  5:41   ` Amirreza Zarrabi via OP-TEE
2026-10-13  5:41   ` Amirreza Zarrabi
2026-10-13  5:41 ` [PATCH RFC v3 4/9] tee: optee: add RPMI shared-memory and parameter support Amirreza Zarrabi
2026-10-13  5:41   ` Amirreza Zarrabi via OP-TEE
2026-10-13  5:41   ` Amirreza Zarrabi
2026-10-13  5:57   ` sashiko-bot
2026-10-13  5:41 ` [PATCH RFC v3 5/9] tee: optee: add RPMI dynamic shared-memory pool Amirreza Zarrabi
2026-10-13  5:41   ` Amirreza Zarrabi via OP-TEE
2026-10-13  5:41   ` Amirreza Zarrabi
2026-10-13  5:41 ` [PATCH RFC v3 6/9] tee: optee: add RPMI RPC handling Amirreza Zarrabi
2026-10-13  5:41   ` Amirreza Zarrabi via OP-TEE
2026-10-13  5:41   ` Amirreza Zarrabi
2026-10-13  5:59   ` sashiko-bot
2026-10-13  5:41 ` [PATCH RFC v3 7/9] tee: optee: execute yielding RPMI calls Amirreza Zarrabi
2026-10-13  5:41   ` Amirreza Zarrabi via OP-TEE
2026-10-13  5:41   ` Amirreza Zarrabi
2026-10-13  5:56   ` sashiko-bot
2026-10-13  5:41 ` [PATCH RFC v3 8/9] tee: optee: bind RPMI services and negotiate backend capabilities Amirreza Zarrabi
2026-10-13  5:41   ` Amirreza Zarrabi via OP-TEE
2026-10-13  5:41   ` Amirreza Zarrabi
2026-10-13  5:56   ` sashiko-bot
2026-10-13  5:41 ` [PATCH RFC v3 9/9] tee: optee: support RPMI asynchronous notification doorbells Amirreza Zarrabi
2026-10-13  5:41   ` Amirreza Zarrabi via OP-TEE
2026-10-13  5:41   ` Amirreza Zarrabi
2026-10-13  5:48   ` sashiko-bot

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=sashiko-outbox-169021@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amirreza.zarrabi@oss.qualcomm.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --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.