summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2024-04-18 12:13:40 -0600
committerTom Rini <[email protected]>2024-04-18 12:13:40 -0600
commitd893c93205701b77f9b3f2e8074297a32d8710db (patch)
tree4cf5108b5791612b65d21fb649114345bee70a32 /cmd
parentcdf0195e90b66f25ed44fa5ed5634ec064e8dcb9 (diff)
parentb905599b36e3d8158c5cd045c26278416909b422 (diff)
Merge tag 'tpm-master-18042024' of https://source.denx.de/u-boot/custodians/u-boot-tpm
Igor says: "The problem initially was in the TEE sandbox driver implementation (drivers/tee/sandbox.c) and it's limitations, which doesn't permit to have multiple simultaneous sessions with different TAs. This is what actually happened in this CI run [1], firstly "optee_rpmb" cmd was executed (and after execution we had one session open), and then "scp03", which also makes calls to OP-TEE, however it fails in sandbox_tee_open_session() because of this check: if (state->ta) { printf("A session is already open\n"); return -EBUSY; } I had two ways in mind to address that: 1. Close a session on each optee_rpmb cmd invocation. I don't see any reason to keep this session open, as obviously there is no other mechanism (tbh, I don't know if DM calls ".remove" for active devices) to close it automatically before handing over control to Linux kernel. As a result we might end up with some orphaned sessions registered in OP-TEE OS core (obvious resource leak). 2. Extend TEE sandbox driver, add support for multiple simultaneous sessions just to handle the case. I've chosen the first approach, as IMO it was "kill two birds with one stone", I could address resource leak in OP-TEE and bypass limitations of TEE sandbox driver." Link: https://lore.kernel.org/u-boot/CAByghJZVRbnFUwJdgU534tvGA+DX2pArf0i7ySik=BrXgADe3Q@mail.gmail.com/ The CI https://source.denx.de/u-boot/custodians/u-boot-tpm/-/pipelines/20414 showed no problems
Diffstat (limited to 'cmd')
-rw-r--r--cmd/Kconfig4
-rw-r--r--cmd/optee_rpmb.c23
2 files changed, 20 insertions, 7 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 126bdeeb6d2..408cc84c182 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1396,7 +1396,9 @@ config CMD_CLONE
config CMD_OPTEE_RPMB
bool "Enable read/write support on RPMB via OPTEE"
- depends on SUPPORT_EMMC_RPMB && OPTEE
+ depends on (SUPPORT_EMMC_RPMB && OPTEE) || SANDBOX_TEE
+ default y if SANDBOX_TEE
+ select OPTEE_TA_AVB if SANDBOX_TEE
help
Enable the commands for reading, writing persistent named values
in the Replay Protection Memory Block partition in eMMC by
diff --git a/cmd/optee_rpmb.c b/cmd/optee_rpmb.c
index e0e44bbed04..b3cafd92410 100644
--- a/cmd/optee_rpmb.c
+++ b/cmd/optee_rpmb.c
@@ -87,8 +87,10 @@ static int read_persistent_value(const char *name,
rc = tee_shm_alloc(tee, name_size,
TEE_SHM_ALLOC, &shm_name);
- if (rc)
- return -ENOMEM;
+ if (rc) {
+ rc = -ENOMEM;
+ goto close_session;
+ }
rc = tee_shm_alloc(tee, buffer_size,
TEE_SHM_ALLOC, &shm_buf);
@@ -125,6 +127,9 @@ out:
tee_shm_free(shm_buf);
free_name:
tee_shm_free(shm_name);
+close_session:
+ tee_close_session(tee, session);
+ tee = NULL;
return rc;
}
@@ -139,17 +144,20 @@ static int write_persistent_value(const char *name,
struct tee_param param[2];
size_t name_size = strlen(name) + 1;
+ if (!value_size)
+ return -EINVAL;
+
if (!tee) {
if (avb_ta_open_session())
return -ENODEV;
}
- if (!value_size)
- return -EINVAL;
rc = tee_shm_alloc(tee, name_size,
TEE_SHM_ALLOC, &shm_name);
- if (rc)
- return -ENOMEM;
+ if (rc) {
+ rc = -ENOMEM;
+ goto close_session;
+ }
rc = tee_shm_alloc(tee, value_size,
TEE_SHM_ALLOC, &shm_buf);
@@ -178,6 +186,9 @@ out:
tee_shm_free(shm_buf);
free_name:
tee_shm_free(shm_name);
+close_session:
+ tee_close_session(tee, session);
+ tee = NULL;
return rc;
}