From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796224231; b=W2aVsb9r33eDLEBEpWoM+kMi9np5wCkk+YA8qSorRmd2d/IPwsiccEtuLWzRysXr0x09 UDqcU1XK8OSn9ZkrMIXuSo56990UwxgOi/b18XDlaiXsu/iCnuR/+31HZo11u9k0ECnFj TezDQX0QRZPFXm/szWLuxbGcFEL/1tf7yFidUwcuV0h4/kxRxc1pBx0LtBLhyINiuHgga X3AtZjJnv/AeZBmmHkkyOYihw0nvwzXI64IAuq8FYaP0SctE3UU1BhcriNUH7WuFL+szn /hiOqJIjp/S+98VDkbvLwpZJWfN2+pvoY8le+9lJ5X24hMYCSax6qkHdgLg6QZFvSLQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796224231; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Qv12zssk84CIVRaMXgU+2VqmGEslMPclbA4+kpi7E8Q=; b=mEdLWMg9IOqDKLop+sNu+dWU941Smmu3JfJUChRn16vLNMpVKrDZKxhgX3LqyCFjHAWe 1RpUd0VPMg60ayGgbSV/AfP8gncBlFKoiWJ8ODm1DfWIxr691AGa2BOt803HbLu1SX/yW sdpESCQAUidzIZXJCamiIpE+5BfF9/rbQfNySibWVLgIwNVjfzCVBT5fzlNrjXP9zHErH vDNso5+cN3Md8hfTg+bxGn8RuE0vo1EjKMeWqJWFvy+GoRX/IAz41okhcz5Wr2OeUh1gC I5CaMAlex6slB0TFu6PeayZDWw3hImNBAxc+6TZJpSZ9XNqkmbKDzLD0BGbXuPjRf4w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jIUb3CQW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C0F3606A32C for ; Wed, 2 Dec 2026 15:10:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jIUb3CQW Received: by smtp.kernel.org (Postfix) with ESMTPSA id D88681F0093A; Wed, 2 Dec 2026 15:10:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796224231; bh=Qv12zssk84CIVRaMXgU+2VqmGEslMPclbA4+kpi7E8Q=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=jIUb3CQWWy2NGYPBkF5BmEZVcyoSdIDUtTVMgwxJldgoaAPeSTS29ll7IkDsq6uw8 jdgzokro4DeUUv+eEk47sB0HhVqlvGPxWrqoFjuXNYwMYjKV7TD1pm87EvabcHs6dJ U5cwYY3dIgAaPEJumcq43gHvwIV6Lsl4mHKL6pQjkq24PNxVwGgakFRnFiO2L2Rsqa H3As4bcDvO4rPfnoOkmPX1i7PgW85XEMeLdpFGiacf7vgb4BW5nvYi8XqP2UWvgG4F kaE2o2ZfwuTWs4a4o2nzgrU6ZYnfAyZJGQAMVb7wf1UTTVwGdtugTtpuVvY/dkWrnp SRM5F/gkraqNQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v23 4/6] remoteproc: Add TEE support Reply-To: sashiko-reviews@lists.linux.dev To: "Arnaud Pouliquen" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261202-rproc_tee_v23-b4-v23-4-bac8e36eb405@foss.st.com> References: <20261202-rproc_tee_v23-b4-v23-0-bac8e36eb405@foss.st.com> <20261202-rproc_tee_v23-b4-v23-4-bac8e36eb405@foss.st.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 15:10:30 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 7 potential issues to consider: - [Medium] remoteproc: tee: missing resource table bounds check in rproc_tee_parse_fw() - [Medium] remoteproc: tee: unsafe table_sz update in rproc_tee_find_loaded_rsc_table() - [Medium] remoteproc: tee: duplicate firmware release when rproc_tee_parse_fw() fails - [Medium] remoteproc: tee: missing session_open checks in rproc_tee_register() and ops - [Medium] remoteproc: tee: interruptible lock in rproc_tee_stop() on teardown - [Medium] remoteproc: tee: out-of-bounds read in rproc_tee_parse_fw() on truncated table - [Low] remoteproc: tee: unlocked rproc_tee_ctx.dev access in rproc_tee_parse_fw() -- commit 8c9b0f1db642d51c414b231f4b341810c93277ab Author: Arnaud Pouliquen remoteproc: Add TEE support This commit adds a remoteproc TEE client driver that delegates remote processor firmware authentication, loading, and lifecycle management to a Trusted Application in OP-TEE. > diff --git a/drivers/remoteproc/remoteproc_tee.c b/drivers/remoteproc/rem= oteproc_tee.c > new file mode 100644 > index 0000000000000..a9e9cdb7f6579 > --- /dev/null > +++ b/drivers/remoteproc/remoteproc_tee.c [ ... ] > +int rproc_tee_parse_fw(struct rproc *rproc, const struct firmware *fw) > +{ > + phys_addr_t rsc_table; > + void *rsc_va; > + size_t table_sz; > + int ret; > + > + if (!rproc) > + return -EINVAL; > + > + /* We need first to Load the firmware, to be able to get the resource t= able. */ > + ret =3D rproc_tee_load_fw(rproc, fw); > + if (ret) > + return ret; > + > + ret =3D rproc_tee_get_loaded_rsc_table(rproc, &rsc_table, &table_sz); > + if (ret) > + goto release_fw; > + > + /* A missing resource table is valid for some firmware images. */ > + if (!table_sz) { > + rproc->table_ptr =3D NULL; > + rproc->table_sz =3D 0; > + return 0; > + } > + > + /* > + * We assume here that the memory mapping is the same between the TEE > + * and Linux kernel contexts. Else a new TEE remoteproc service could be > + * needed to get a copy of the resource table. > + */ > + rsc_va =3D memremap(rsc_table, table_sz, MEMREMAP_WC); > + if (!rsc_va) { > + dev_err(rproc_tee_ctx.dev, "Unable to map memory region: %pa+%zx\n", > + &rsc_table, table_sz); > + ret =3D -ENOMEM; > + goto release_fw; > + } [Severity: Low] Is rproc_tee_ctx.dev safe to read here without holding ctx_lock? rproc_tee_remove() clears rproc_tee_ctx.dev under ctx_lock, so logging with &rproc->dev instead avoids a race if the TEE device unbinds concurrently. > + > + /* > + * Create a copy of the resource table to have the same behavior as the > + * ELF loader. This cached table will be used by the remoteproc core > + * after the remoteproc stops to free resources and for crash recovery > + * to reapply the settings. > + * The cached table will be freed by the remoteproc core. > + */ > + rproc->cached_table =3D kmemdup(rsc_va, table_sz, GFP_KERNEL); > + memunmap(rsc_va); > + > + if (!rproc->cached_table) { > + ret =3D -ENOMEM; > + goto release_fw; > + } [Severity: Medium] Should rproc_tee_parse_fw() validate the resource table header and offset array against table_sz the way find_table() in remoteproc_elf_loader.c does? In addition, rproc_tee_get_loaded_rsc_table() checks pa > PHYS_ADDR_MAX and rproc_u64_fit_in_size_t(size) separately without checking whether pa + size overflows before memremap(). > + > + rproc->table_ptr =3D rproc->cached_table; > + rproc->table_sz =3D table_sz; [Severity: Medium] Can setting rproc->table_ptr and rproc->table_sz without checking that table_sz covers sizeof(struct resource_table) and struct_size(table, offset, table->num) cause an out-of-bounds slab read of rproc->cached_table? When rproc_fw_boot() subsequently runs rproc_handle_resources(), rsc_table_for_each_entry() reads table->num and table->offset[i] before checking individual entry offsets against table_sz: include/linux/rsc_table.h:rsc_table_for_each_entry() { ... for (i =3D 0; i < table->num; i++) { u32 offset =3D table->offset[i]; ... } > + > + return 0; > + > +release_fw: > + rproc_tee_release_fw(rproc); > + return ret; > +} [Severity: Medium] Does calling rproc_tee_release_fw() here release the firmware twice when rproc_tee_parse_fw() fails? When rproc_parse_fw() returns an error to rproc_fw_boot(), rproc_boot() also calls rproc_release_fw(rproc) on its error path, invoking TA_RPROC_CMD_RELEASE_FW a second time. [ ... ] > +struct resource_table *rproc_tee_find_loaded_rsc_table(struct rproc *rpr= oc, > + const struct firmware *fw) > +{ > + phys_addr_t rsc_table; > + size_t table_sz; > + int ret; > + > + ret =3D rproc_tee_get_loaded_rsc_table(rproc, &rsc_table, &table_sz); > + if (ret) > + return NULL; > + > + rproc->table_sz =3D table_sz; > + if (!table_sz) > + return NULL; > + > + /* > + * At this step the memory area that contains the resource table should > + * have been registered by the remote proc platform driver and allocated > + * by rproc_alloc_registered_carveouts(). > + */ > + return rproc_pa_to_va(rproc, rsc_table, table_sz, NULL); > +} [Severity: Medium] Can overwriting rproc->table_sz here trigger a NULL pointer dereference or out-of-bounds read in rproc_start()? Right after rproc_find_loaded_rsc_table() returns a non-NULL pointer, rproc_start() runs: drivers/remoteproc/remoteproc_core.c:rproc_start() { ... loaded_table =3D rproc_find_loaded_rsc_table(rproc, fw); if (loaded_table) { memcpy(loaded_table, rproc->cached_table, rproc->table_sz); rproc->table_ptr =3D loaded_table; } ... } During crash recovery, rproc_boot_recovery() reloads the firmware image and calls rproc_start() directly without re-running rproc_parse_fw(). If the n= ew table_sz is larger than the rproc->cached_table allocated at initial boot (= or non-zero when initial boot had no resource table and left rproc->cached_tab= le NULL), memcpy() reads past rproc->cached_table or dereferences NULL. Updat= ing rproc->table_sz before rproc_pa_to_va() also leaves rproc->table_sz out of sync with rproc->cached_table if rproc_pa_to_va() returns NULL. [ ... ] > +int rproc_tee_stop(struct rproc *rproc) > +{ > + struct tee_param param[MAX_TEE_PARAM_ARRAY_MEMBER]; > + struct rproc_tee *trproc; > + struct tee_ioctl_invoke_arg arg; > + int ret; > + > + ret =3D mutex_lock_interruptible(&ctx_lock); > + if (ret) > + return ret; [Severity: Medium] Should rproc_tee_stop() use uninterruptible mutex_lock(&ctx_lock) like the other teardown paths? If a signal is pending when rproc_start() rolls back after a subdevice start failure (or when rproc_del() shuts down the remote processor during rproc_tee_unregister()), mutex_lock_interruptible() returns -EINTR without sending TA_RPROC_CMD_STOP. rproc_start() ignores the return value of rproc->ops->stop(), so rproc_fw_boot() and rproc_boot() proceed to free carveouts and call rproc_tee_release_fw() while the remote processor is sti= ll running. [ ... ] > + list_add(&trproc->node, &rproc_tee_ctx.rproc_list); > + mutex_unlock(&ctx_lock); > + > + ret =3D rproc_add(rproc); > + if (ret) > + goto del_trproc; > + > + return 0; [Severity: Medium] What happens if rproc_tee_remove() runs while ctx_lock is dropped across rproc_add(), or if the TEE driver re-probes while a previously registered trproc remains on rproc_tee_ctx.rproc_list? If rproc_tee_remove() runs during rproc_add(), it closes trproc->session_id and sets trproc->session_open =3D false, but rproc_tee_register() still ret= urns 0 with a closed session. Furthermore, because rproc_tee_remove() leaves registered entries on rproc_tee_ctx.rproc_list with session_open =3D false,= if rproc_tee_probe() later repopulates rproc_tee_ctx.dev and rproc_tee_ctx.tee_ctx, neither rproc_to_trproc() nor the TEE command helpers check trproc->session_open before invoking tee_client_invoke_func() with the stale session_id. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202-rproc_tee_= v23-b4-v23-0-bac8e36eb405@foss.st.com?part=3D4