From: sashiko-bot@kernel.org
To: "Vincent Donnefort" <vdonnefort@google.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v9 10/10] optee: Add support for arm,ffa-lend-pool
Date: Wed, 02 Sep 2026 11:09:19 +0000 [thread overview]
Message-ID: <20260902110919.E00211F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260902104712.2399797-11-vdonnefort@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Use-After-Free during driver removal when releasing the reserved memory / lend pool device.
- [High] Memory leak and dangling pointer in global lists on probe error paths.
--
commit a9ed483b0a922615c4b6f53cf658491bee8ed6a1
Author: Vincent Donnefort <vdonnefort@google.com>
optee: Add support for arm,ffa-lend-pool
This commit hooks OP-TEE dynamically allocated protected memory pools to the
"arm,ffa-lend-pool" driver. It also adds reserved memory device
initialization and release for SMC transport platform devices.
> 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
> @@ -979,6 +979,7 @@ static void optee_ffa_remove(struct ffa_device *ffa_dev)
>
> mutex_destroy(&optee->ffa.mutex);
> rhashtable_free_and_destroy(&optee->ffa.global_ids, rh_free_fn, NULL);
> + ffa_lend_pool_detach(&optee->teedev->dev);
[Severity: High]
Can this cause a use-after-free when unbinding the driver?
The call to optee_remove_common() slightly earlier in this function will
unregister and eventually free optee->teedev. Does this subsequent call to
ffa_lend_pool_detach() dereference the already-freed optee->teedev pointer?
>
> kfree(optee);
> }
[ ... ]
> @@ -1042,13 +1043,21 @@ static int optee_ffa_protmem_pool_init(struct optee *optee, u32 sec_caps)
> int rc = 0;
>
> if (sec_caps & OPTEE_FFA_SEC_CAP_PROTMEM) {
> + rc = ffa_lend_pool_attach(&optee->teedev->dev);
[Severity: High]
Does this introduce a resource leak and dangling pointer on the probe error
paths?
If optee_ffa_probe() fails after this pool is successfully attached, the
error paths will unregister and free optee->teedev. However, it doesn't
appear that the error paths call ffa_lend_pool_detach() to clean this up.
Could this leave the freed device pointer tracked in the lend pool tracking,
leading to a use-after-free later if list operations occur?
> + if (rc && rc != -ENODEV)
> return rc;
>
> pool = optee_protmem_alloc_dyn_pool(optee, id);
> - if (IS_ERR(pool))
> + if (IS_ERR(pool)) {
> + ffa_lend_pool_detach(&optee->teedev->dev);
> return PTR_ERR(pool);
> + }
[ ... ]
> diff --git a/drivers/tee/optee/smc_abi.c b/drivers/tee/optee/smc_abi.c
> --- a/drivers/tee/optee/smc_abi.c
> +++ b/drivers/tee/optee/smc_abi.c
> @@ -1528,6 +1529,8 @@ static void optee_smc_remove(struct platform_device *pdev)
> if (optee->smc.memremaped_shm)
> memunmap(optee->smc.memremaped_shm);
>
> + of_reserved_mem_device_release(&optee->teedev->dev);
[Severity: High]
Does this also trigger a use-after-free during driver removal?
Similar to optee_ffa_remove(), optee_smc_remove() calls
optee_remove_common() before reaching this code, which frees optee->teedev.
Is it safe to access optee->teedev->dev here after it has been freed?
> +
> kfree(optee);
> }
[ ... ]
> @@ -1712,16 +1715,22 @@ static int optee_protmem_pool_init(struct optee *optee)
> if (!protm && !dyn_protm)
> return 0;
>
> + of_reserved_mem_device_init_by_idx(&optee->teedev->dev,
> + dev_of_node(optee->teedev->dev.parent), 0);
[Severity: High]
Is there a missing of_reserved_mem_device_release() on the optee_probe()
error paths?
If a failure occurs later in optee_probe() (for instance, if
optee_enumerate_devices() fails), the error handling jumps to labels like
err_disable_shm_cache and err_unreg_teedev. Those paths unregister and free
optee->teedev, but do not release this reserved memory device.
Could this leave the freed dev pointer tracked in the global
of_rmem_assigned_device_list, risking memory corruption if another device
requests memory later?
> if (protm)
> pool = static_protmem_pool_init(optee);
> if (dyn_protm && IS_ERR(pool))
> pool = optee_protmem_alloc_dyn_pool(optee, heap_id);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260902104712.2399797-1-vdonnefort@google.com?part=10
next prev parent reply other threads:[~2026-09-02 11:09 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 10:47 [PATCH v9 00/10] arm64: Unmap FF-A lent memory from direct map Vincent Donnefort
2026-09-02 10:47 ` Vincent Donnefort via OP-TEE
2026-09-02 10:47 ` [PATCH v9 01/10] memblock: Introduce MEMBLOCK_LLMAP Vincent Donnefort
2026-09-02 10:47 ` Vincent Donnefort via OP-TEE
2026-09-06 19:33 ` Mike Rapoport via OP-TEE
2026-09-06 19:33 ` Mike Rapoport
2026-09-07 9:50 ` Vincent Donnefort via OP-TEE
2026-09-07 9:50 ` Vincent Donnefort
2026-09-08 7:40 ` Mike Rapoport
2026-09-08 7:40 ` Mike Rapoport via OP-TEE
2026-09-08 9:18 ` Thierry Reding
2026-09-08 9:18 ` Thierry Reding via OP-TEE
2026-09-08 10:17 ` Mike Rapoport via OP-TEE
2026-09-08 10:17 ` Mike Rapoport
2026-09-02 10:47 ` [PATCH v9 02/10] of: reserved_mem: Introduce "ll-map" property Vincent Donnefort
2026-09-02 10:47 ` Vincent Donnefort via OP-TEE
2026-09-02 11:02 ` sashiko-bot
2026-09-02 17:24 ` Rob Herring
2026-09-02 17:24 ` Rob Herring via OP-TEE
2026-09-03 10:03 ` Vincent Donnefort
2026-09-03 10:03 ` Vincent Donnefort via OP-TEE
2026-09-07 14:00 ` Thierry Reding
2026-09-07 14:00 ` Thierry Reding via OP-TEE
2026-09-07 17:03 ` Vincent Donnefort
2026-09-07 17:03 ` Vincent Donnefort via OP-TEE
2026-09-02 10:47 ` [PATCH v9 03/10] set_memory.h: Introduce can_set_direct_map_range() Vincent Donnefort
2026-09-02 10:47 ` Vincent Donnefort via OP-TEE
2026-09-06 19:39 ` Mike Rapoport via OP-TEE
2026-09-06 19:39 ` Mike Rapoport
2026-09-07 9:52 ` Vincent Donnefort
2026-09-07 9:52 ` Vincent Donnefort via OP-TEE
2026-09-02 10:47 ` [PATCH v9 04/10] set_memory.h: Introduce __set_direct_map*() Vincent Donnefort
2026-09-02 10:47 ` Vincent Donnefort via OP-TEE
2026-09-02 10:47 ` [PATCH v9 05/10] arm64: can_set_direct_map() if BBML3 Vincent Donnefort
2026-09-02 10:47 ` Vincent Donnefort via OP-TEE
2026-09-02 11:09 ` sashiko-bot
2026-09-02 10:47 ` [PATCH v9 06/10] arm64: Implement can_set_direct_map_range() Vincent Donnefort
2026-09-02 10:47 ` Vincent Donnefort via OP-TEE
2026-09-02 11:06 ` sashiko-bot
2026-09-02 10:47 ` [PATCH v9 07/10] arm64: Implement __set_direct_map*() Vincent Donnefort
2026-09-02 10:47 ` Vincent Donnefort via OP-TEE
2026-09-08 9:27 ` Thierry Reding
2026-09-08 9:27 ` Thierry Reding via OP-TEE
2026-09-02 10:47 ` [PATCH v9 08/10] arm64: Add support for MEMBLOCK_LLMAP Vincent Donnefort
2026-09-02 10:47 ` Vincent Donnefort via OP-TEE
2026-09-02 10:47 ` [PATCH v9 09/10] firmware: arm_ffa: Introduce ffa-lend-pool Vincent Donnefort
2026-09-02 10:47 ` Vincent Donnefort via OP-TEE
2026-09-02 11:06 ` sashiko-bot
2026-09-02 17:38 ` Rob Herring
2026-09-02 17:38 ` Rob Herring via OP-TEE
2026-09-03 10:10 ` Vincent Donnefort
2026-09-03 10:10 ` Vincent Donnefort via OP-TEE
2026-09-02 10:47 ` [PATCH v9 10/10] optee: Add support for arm,ffa-lend-pool Vincent Donnefort
2026-09-02 10:47 ` Vincent Donnefort via OP-TEE
2026-09-02 11:09 ` sashiko-bot [this message]
2026-09-02 13:27 ` [PATCH v9 00/10] arm64: Unmap FF-A lent memory from direct map Vincent Donnefort
2026-09-02 13:27 ` Vincent Donnefort via OP-TEE
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=20260902110919.E00211F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--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 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.