Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Amirreza Zarrabi" <amirreza.zarrabi@oss.qualcomm.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH RFC v2 4/8] tee: optee: add RPMI dynamic shared-memory pool
Date: Tue, 06 Oct 2026 00:55:22 +0000	[thread overview]
Message-ID: <20261006005523.3C10B1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261005-rpmi-tee-service-grp-dev-v2-4-72f222e23ec1@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] tee: optee: UAF in optee_rpmi_shm_rht_rm() due to synchronous kfree()
- [Low] build: unused static function optee_rpmi_shm_pool_alloc breaks bisect
--

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

tee: optee: add RPMI dynamic shared-memory pool

This patch adds a page-based dynamic shared-memory pool for the RPMI backend
using the common TEE allocation and free helpers. It registers allocated
pages as RPMI parcels so OP-TEE can access them, and unregisters the parcels
before freeing their backing pages.

> diff --git a/drivers/tee/optee/rpmi_abi.c b/drivers/tee/optee/rpmi_abi.c
> index e7fc853cfb150..c29b7ac4552a9 100644
> --- a/drivers/tee/optee/rpmi_abi.c
> +++ b/drivers/tee/optee/rpmi_abi.c

[ ... ]

> +static void optee_rpmi_pool_free(struct tee_shm_pool *pool, struct tee_shm *shm)
> +{
> +	tee_dyn_shm_free_helper(shm, optee_rpmi_shm_unregister);
> +}

[Severity: High]
Is there a risk of a use-after-free during bucket traversal here?

When tee_dyn_shm_free_helper() executes optee_rpmi_shm_unregister() in
drivers/tee/optee/rpmi_abi.c, it subsequently calls optee_rpmi_shm_rht_rm()
to remove the hash table entry. This same path is also triggered via
optee_rpmi_shm_unregister_supp().

In optee_rpmi_shm_rht_rm():

	if (entry)
		ret = rhashtable_remove_fast(&optee->rpmi.shm_rht,
					     &entry->node,
					     optee_rpmi_shm_rht_params);
	if (!ret)
		kfree(entry);

Because rhashtable uses RCU-based worker threads (rht_deferred_worker) to
traverse the hash table concurrently during automatic resizing, freeing
the entry synchronously via kfree() instead of kfree_rcu() might cause a
use-after-free if a rehash worker is actively traversing the removed node's
bucket list.

Note that this issue is reachable from unprivileged user space by repeatedly
registering and unregistering memory, driving the size of the table up and
down to trigger rehashing.

[ ... ]

> +static struct tee_shm_pool *optee_rpmi_shm_pool_alloc(void)
> +{
> +	struct tee_shm_pool *pool;
> +
> +	pool = kzalloc_obj(*pool);
> +	if (!pool)
> +		return ERR_PTR(-ENOMEM);
> +
> +	pool->ops = &optee_rpmi_pool_ops;
> +
> +	return pool;
> +}

[Severity: Low]
Could this unused function break git bisect?

The static function optee_rpmi_shm_pool_alloc() in
drivers/tee/optee/rpmi_abi.c is defined here but is never invoked in this
patch. Under CONFIG_WERROR=y, the compiler warning for an unused function
promotes to a build error.

While this is fixed later in the series by commit
3ef22394684ff6d8b2126c91fa4c8bb2d1960d68 (tee: optee: bind RPMI services and
negotiate backend capabilities), each individual patch in a series
should compile cleanly to ensure git bisect continues to work.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261005-rpmi-tee-service-grp-dev-v2-0-72f222e23ec1@oss.qualcomm.com?part=4

  reply	other threads:[~2026-10-06  0:55 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-06  0:39 [PATCH RFC v2 0/8] tee: optee: add RPMI backend support on RISC-V Amirreza Zarrabi
2026-10-06  0:39 ` [PATCH RFC v2 1/8] tee: optee: allow RPMI transport builds " Amirreza Zarrabi
2026-10-06  0:52   ` sashiko-bot
2026-10-06  0:39 ` [PATCH RFC v2 2/8] tee: optee: define the RPMI control and parcel-reference ABI Amirreza Zarrabi
2026-10-08  6:51   ` Jens Wiklander
2026-10-08 22:02     ` Amirreza Zarrabi
2026-10-06  0:39 ` [PATCH RFC v2 3/8] tee: optee: add RPMI shared-memory and parameter support Amirreza Zarrabi
2026-10-08  7:10   ` Jens Wiklander
2026-10-08 22:27     ` Amirreza Zarrabi
2026-10-06  0:39 ` [PATCH RFC v2 4/8] tee: optee: add RPMI dynamic shared-memory pool Amirreza Zarrabi
2026-10-06  0:55   ` sashiko-bot [this message]
2026-10-06  0:39 ` [PATCH RFC v2 5/8] tee: optee: add RPMI RPC handling Amirreza Zarrabi
2026-10-06  0:39 ` [PATCH RFC v2 6/8] tee: optee: execute yielding RPMI calls Amirreza Zarrabi
2026-10-06  0:55   ` sashiko-bot
2026-10-08  8:11   ` Jens Wiklander
2026-10-08 22:56     ` Amirreza Zarrabi
2026-10-06  0:39 ` [PATCH RFC v2 7/8] tee: optee: bind RPMI services and negotiate backend capabilities Amirreza Zarrabi
2026-10-06  0:53   ` sashiko-bot
2026-10-08  8:20   ` Jens Wiklander
2026-10-08 23:10     ` Amirreza Zarrabi
2026-10-06  0:39 ` [PATCH RFC v2 8/8] tee: optee: support RPMI asynchronous notification doorbells Amirreza Zarrabi
2026-10-06  0:47   ` sashiko-bot
2026-10-08  6:15 ` [PATCH RFC v2 0/8] tee: optee: add RPMI backend support on RISC-V Jens Wiklander
2026-10-08 23:21   ` Amirreza Zarrabi

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=20261006005523.3C10B1F000FF@smtp.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox