]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
cmd: optee_rpmb: close tee session
authorIgor Opaniuk <igor.opaniuk@gmail.com>
Thu, 4 Apr 2024 13:19:48 +0000 (15:19 +0200)
committerIlias Apalodimas <ilias.apalodimas@linaro.org>
Thu, 18 Apr 2024 13:04:48 +0000 (16:04 +0300)
Close tee session after each optee_rpmb invocation, as there is no
reason to keep it open, considering the absence of any available mechanism
to clean up all open sessions automatically before handing over control
to the Linux kernel. Without proper clean-up we might end up with orphaned
sessions registered in OP-TEE OS core (obvious resource leak).

Signed-off-by: Igor Opaniuk <igor.opaniuk@gmail.com>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
cmd/optee_rpmb.c

index e0e44bbed042a5cc5516fd45d81c536b7948477d..b3cafd924108fa417bc483b843bf42514c2be14a 100644 (file)
@@ -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;
 }