remoteproc: k3-r5: Build fixes and security improvements
Subsystems (4)
cover remoteproc: k3-r5: Build fixes and security improvements
From: Philippe Schenker <[email protected]>
This series fixes compilation errors when building for R5 cores and addresses a security issue where authenticated images were not being used correctly.
Patch 1: Cosmetic removal of duplicate code
Patches 2-3: Fix build errors caused by type mismatches between function signatures and the types used in R5 builds.
Patches 4-5: fix a bug where ti_secure_image_post_process() relocates images during authentication, but callers were still using the original unverified addresses.
Patch 6: Implements is_running operation to allow querying R5F core status.
Note: If preferred, I can split this series.
Philippe Schenker (6):
arm: dts: k3-am642-evm: Remove duplicate node
remoteproc: k3-r5: cast size to size_t
soc: ti: pruss: Fix size ptr type in probe
mach-k3: security: Propagate verified image addr
remoteproc: k3-r5: Use verified image address
remoteproc: k3-r5: Implement is_running operation
arch/arm/dts/k3-am642-evm-u-boot.dtsi | 4 ---- arch/arm/mach-k3/security.c | 2 ++ drivers/remoteproc/ti_k3_r5f_rproc.c | 23 ++++++++++++++++++++--- drivers/soc/ti/pruss.c | 2 +- 4 files changed, 23 insertions(+), 8 deletions(-)
Signature · 4 lines
2.51.1 base-commit: 813a0df27a8af587bd25a6a4719f68066b370091 branch: am64x-various-fixes__master
PATCH 1/6 arm: dts: k3-am642-evm: Remove duplicate node
From: Philippe Schenker <[email protected]>
The device tree contained a duplicate DT node 'main_mmc1_pins_default', which was already defined a few lines below. This patch removes the redundant entry.
---
arch/arm/dts/k3-am642-evm-u-boot.dtsi | 4 ---- 1 file changed, 4 deletions(-)
arch/arm/dts/k3-am642-evm-u-boot.dtsi +0 -4
@@ -19,10 +19,6 @@ dr_mode="peripheral"; }; -&main_mmc1_pins_default { - bootph-all; -}; - &sdhci0 { bootph-all; };
Signature · 1 line
2.51.1
PATCH 2/6 remoteproc: k3-r5: cast size to size_t
In reply to Philippe SchenkerFrom: Philippe Schenker <[email protected]>
When compiling for R5 core with CONFIG_REMOTEPROC_TI_K3_R5F, passing 'size' (ulong) to ti_secure_image_post_process() caused a type mismatch compiler error.
Cast 'size' to (size_t *) to fix it.
---
drivers/remoteproc/ti_k3_r5f_rproc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/remoteproc/ti_k3_r5f_rproc.c +1 -1
@@ -341,7 +341,7 @@ static int k3_r5f_load(struct udevice *dev, ulong addr, ulong size)k3_r5f_init_tcm_memories (core, mem_auto_init); -ti_secure_image_post_process (&image_addr, &size); +ti_secure_image_post_process (&image_addr, (size_t *)&size); ret =rproc_elf_load_image (dev, addr, size);if (ret <0 ) {
Signature · 1 line
2.51.1
Re: [PATCH v1 2/6] remoteproc: k3-r5: cast size to size_t
Quoted 6 lines · Philippe Schenker
From: Philippe Schenker <[email protected]>
When compiling for R5 core with
CONFIG_REMOTEPROC_TI_K3_R5F, passing 'size' (ulong) toti_secure_image_post_process()caused a type mismatch compiler error.
size_t and ulong should both be 32bit on any reasonable 32bit machine, odd the compiler would complain here.
Casting pointers always worries me anyway, if the var being cast is smaller then you will read out of bounds, if the var is larger than what it is cast to then you run into endianness issues. Always safer to dereference into a temp variable of the correct type and pass a pointer to that.
For this, probably fine either way,
Quoted 21 lines
Cast 'size' to (
size_t*) to fix it.Signed-off-by Philippe Schenker <[email protected]>---
drivers/remoteproc/ti_k3_r5f_rproc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/remoteproc/ti_k3_r5f_rproc.c +1
-1@@ -341,7 +341,7 @@ static int k3_r5f_load(struct udevice *dev, ulong addr, ulong size)k3_r5f_init_tcm_memories (core, mem_auto_init); -ti_secure_image_post_process (&image_addr, &size); +ti_secure_image_post_process (&image_addr, (size_t *)&size); ret =rproc_elf_load_image (dev, addr, size);if (ret <0 ) {
PATCH 3/6 soc: ti: pruss: Fix size ptr type in probe
In reply to Philippe SchenkerFrom: Philippe Schenker <[email protected]>
When compiling for R5 with CONFIG_TI_PRUSS enabled, the pruss_probe() function passed a u64* to ofnode_get_addr_size_index(), which expects an fdt_size_t*. This caused a compiler error about incompatible pointer types.
Cast the size pointer to fdt_size_t* to match the function signature.
---
drivers/soc/ti/pruss.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/ti/pruss.c +1 -1
@@ -163,7 +163,7 @@ static int pruss_probe(struct udevice *dev)for (i =0 ; i <ARRAY_SIZE (mem_names); i++) { idx =ofnode_stringlist_search (memories,"reg-names" , mem_names[i]); priv->mem_regions[i].pa =ofnode_get_addr_size_index (memories, idx, - (u64 *)&priv->mem_regions[i].size); + (fdt_size_t *)&priv->mem_regions[i].size); } sub_node =ofnode_find_subnode (node,"cfg" );
Signature · 1 line
2.51.1
PATCH 4/6 mach-k3: security: Propagate verified image addr
In reply to Philippe SchenkerFrom: Philippe Schenker <[email protected]>
The ti_secure_image_check() function may relocate the image during authentication, updating image_addr to point to the verified location. The caller was not updated with this new address, causing it to reference the original unverified location.
Update p_image with the verified image address after authentication to ensure subsequent operations use the correct location.
---
arch/arm/mach-k3/security.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm/mach-k3/security.c +2 -0
@@ -119,6 +119,8 @@ void ti_secure_image_post_process(void **p_image, size_t *p_size)*/ *p_size = image_size; + *p_image = (void *)image_addr; +/* * Output notification of successful authentication to re-assure the * user that the secure code is being processed as expected. However
Signature · 1 line
2.51.1
Re: [PATCH v1 4/6] mach-k3: security: Propagate verified image addr
Quoted 7 lines · Philippe Schenker
From: Philippe Schenker <[email protected]>
The
ti_secure_image_check()function may relocate the image during authentication, updatingimage_addrto point to the verified location. The caller was not updated with this new address, causing it to reference the original unverified location.
Quoted 5 lines
Update
p_imagewith the verified image address after authentication to ensure subsequent operations use the correct location.Signed-off-by Philippe Schenker <[email protected]>---
Seems reasonable,
BTW, did you actually run into an issue with having a binary moved by the authentication, or was this found some other way? Normally binaries don't move (but they can, so this is still valid).
Quoted 17 lines
arch/arm/mach-k3/security.c | 2 ++ 1 file changed, 2 insertions(+)arch/arm/mach-k3/security.c +2
-0@@ -119,6 +119,8 @@ void ti_secure_image_post_process(void **p_image, size_t *p_size)*/ *p_size = image_size; + *p_image = (void *)image_addr; +/* * Output notification of successful authentication to re-assure the * user that the secure code is being processed as expected. However
Re: [PATCH v1 4/6] mach-k3: security: Propagate verified image addr
Quoted 15 lines · Andrew Davis
Quoted 8 lines · Philippe Schenker
From: Philippe Schenker <[email protected]>
The
ti_secure_image_check()function may relocate the image during authentication, updatingimage_addrto point to the verified location.
The caller was not updated with this new address, causing it to reference the original unverified location.Quoted 5 lines
Update
p_imagewith the verified image address after authentication to ensure subsequent operations use the correct location.Signed-off-by Philippe Schenker <[email protected]>---
Quoted 7 lines
Seems reasonable,
Acked-by Andrew Davis <[email protected]>BTW, did you actually run into an issue with having a binary moved by the authentication, or was this found some other way? Normally binaries don't move (but they can, so this is still valid).
Thanks for your acked-by's! Sorry forgot to answer and just now saw it again. Yes I ran into an issue where I have a signed elf file. The step of loading the elf file was failing because the pointer still pointing to the signature.
Philippe
Quoted 22 lines
Quoted 22 lines
arch/arm/mach-k3/security.c| 2 ++1 file changed, 2 insertions(+)arch/arm/mach- renamed from arch/arm/mach-k3/security.c +0
-0
k3/security.c
index3468a370a455..9255505a7944100644arch/arm/mach-k3/security.c +0
-0@@ -119,6 +119,8 @@ void ti_secure_image_post_process(void**p_image, size_t *p_size) */ *p_size = image_size;
+*p_image= (void *)image_addr;
+
/*
* Output notification of successful authentication to re-assure the
* user that the secure code is being processed as expected. However
PATCH 5/6 remoteproc: k3-r5: Use verified image address
In reply to Philippe SchenkerFrom: Philippe Schenker <[email protected]>
After ti_secure_image_post_process() authenticates the image, it may relocate it to a different memory location and update image_addr to point to the verified image.
However, rproc_elf_load_image() and rproc_elf_get_boot_addr() were still using the original "addr" parameter, potentially operating on the unverified or stale image location instead of the authenticated image.
Use image_addr (cast to ulong to match function signatures) after authentication to ensure all operations work with the verified image.
---
drivers/remoteproc/ti_k3_r5f_rproc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/remoteproc/ti_k3_r5f_rproc.c +2 -2
@@ -343,13 +343,13 @@ static int k3_r5f_load(struct udevice *dev, ulong addr, ulong size)ti_secure_image_post_process (&image_addr, (size_t *)&size); - ret =rproc_elf_load_image (dev, addr, size); + ret =rproc_elf_load_image (dev, (ulong )image_addr, size);if (ret <0 ) {dev_err (dev,"Loading elf failedi %d\n" , ret); goto proc_release; } - boot_vector =rproc_elf_get_boot_addr (dev, addr); + boot_vector =rproc_elf_get_boot_addr (dev, (ulong )image_addr);dev_dbg (dev,"%s: Boot vector = 0x%llx\n" , __func__, boot_vector);
Signature · 1 line
2.51.1
PATCH 6/6 remoteproc: k3-r5: Implement is_running operation
In reply to Philippe SchenkerFrom: Philippe Schenker <[email protected]>
Add is_running callback to query the R5F core halt status via the TI-SCI processor control API. This allows the remoteproc framework to determine whether the R5F core is currently runnin.
The core is considered running when the PROC_BOOT_CTRL_FLAG_R5_CORE_HALT bit is not set in the control flags.
---
drivers/remoteproc/ti_k3_r5f_rproc.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/remoteproc/ti_k3_r5f_rproc.c +17 -0
@@ -570,6 +570,22 @@ static void *k3_r5f_da_to_va(struct udevice *dev, ulong da, ulong size)return map_physmem (da, size,MAP_NOCACHE ); } +static int k3_r5f_is_running (struct udevice *dev) +{ +struct k3_r5f_core *core =dev_get_priv (dev); +u32 cfg, ctrl, sts; +u64 boot_vec; +int ret; + +dev_dbg (dev,"%s\n" , __func__); + + ret =ti_sci_proc_get_status (&core->tsp, &boot_vec, &cfg, &ctrl, &sts); +if (ret) +return -1 ; + +return !!(ctrl &PROC_BOOT_CTRL_FLAG_R5_CORE_HALT ); +} +static int k3_r5f_init (struct udevice *dev) {return 0 ;
@@ -587,6 +603,7 @@ static const struct dm_rproc_ops k3_r5f_rproc_ops = { .stop = k3_r5f_stop, .load = k3_r5f_load, .device_to_virt = k3_r5f_da_to_va, + .is_running = k3_r5f_is_running, };static int k3_r5f_rproc_configure (struct k3_r5f_core *core)
Signature · 1 line
2.51.1
Quoted 12 lines · Philippe Schenker
From: Philippe Schenker <[email protected]>
This series fixes compilation errors when building for R5 cores and addresses a security issue where authenticated images were not being used correctly.
Patch 1: Cosmetic removal of duplicate code
Patches 2-3: Fix build errors caused by type mismatches between function signatures and the types used in R5 builds.
Quoted 7 lines
Patches 4-5: fix a bug where
ti_secure_image_post_process()relocates images during authentication, but callers were still using the original unverified addresses.Patch 6: Implements
is_runningoperation to allow querying R5F core status.Note: If preferred, I can split this series.
With the series applied, I see warnings now on:j721e_beagleboneai64_r5 am62x_beagleplay_r5 am67a_beagley_ai_r5phycore_am62ax_r5 phycore_am62ax_r5_ethboot phycore_am62ax_r5_usbdfuphycore_am62x_r5 phycore_am62x_r5_ethboot phycore_am62x_r5_usbdfuphycore_am64x_r5 am62ax_evm_r5 am62dx_evm_r5 am62px_evm_r5am62px_evm_r5_ethboot am62x_evm_r5 am62x_evm_r5_ethboot am62x_lpsk_r5am64x_evm_r5 am65x_evm_r5 am65x_evm_r5_usbdfu am65x_evm_r5_usbmscj7200_evm_r5 j721e_evm_r5 j721e_sk_r5 am68_sk_r5 am68_sk_r5_ethbootj721s2_evm_r5 j722s_evm_r5 j722s_evm_r5_ethboot am69_sk_r5am69_sk_r5_ethboot j742s2_evm_r5 j784s4_evm_r5 verdin-am62_r5
verdin-am62p_r5
like:arch/arm/mach-k3/security.c:122:20: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
122 | *p_image = (void *)image_addr;
Signature · 1 line
Tom
Hi Tom,
Sorry for not spotting this. I will improve the patchset and send a v2.
Quoted 41 lines · Tom Rini
Quoted 19 lines · Philippe Schenker
From: Philippe Schenker <[email protected]>
This series fixes compilation errors when building for R5 cores and addresses a security issue where authenticated images were not being
used correctly.Patch 1: Cosmetic removal of duplicate code
Patches 2-3: Fix build errors caused by type mismatches between function signatures and the types used in R5 builds.
Patches 4-5: fix a bug where
ti_secure_image_post_process()relocates
images during authentication, but callers were still using the original
unverified addresses.Quoted 4 lines
Patch 6: Implements
is_runningoperation to allow querying R5F core status.Note: If preferred, I can split this series.
With the series applied, I see warnings now on:
j721e_beagleboneai64_r5am62x_beagleplay_r5am67a_beagley_ai_r5phycore_am62ax_r5phycore_am62ax_r5_ethbootphycore_am62ax_r5_usbdfuphycore_am62x_r5phycore_am62x_r5_ethbootphycore_am62x_r5_usbdfuphycore_am64x_r5am62ax_evm_r5am62dx_evm_r5am62px_evm_r5am62px_evm_r5_ethbootam62x_evm_r5am62x_evm_r5_ethbootam62x_lpsk_r5am64x_evm_r5am65x_evm_r5am65x_evm_r5_usbdfuam65x_evm_r5_usbmscj7200_evm_r5j721e_evm_r5j721e_sk_r5am68_sk_r5am68_sk_r5_ethbootj721s2_evm_r5j722s_evm_r5j722s_evm_r5_ethbootam69_sk_r5am69_sk_r5_ethbootj742s2_evm_r5j784s4_evm_r5verdin-am62_r5 verdin-am62p_r5
like:arch/arm/mach-k3/security.c:122:20: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast] 122 |*p_image= (void *)image_addr;