Skip to content

Commit 8bf4167

Browse files
lyakhkv2019i
authored andcommitted
lib-manager: make authentication context local
The authentication context, used by the library manager to check module signature, is fully reinitialised and released for each loaded module, no need to store it permanently. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 8b181a2 commit 8bf4167

2 files changed

Lines changed: 30 additions & 38 deletions

File tree

src/include/sof/lib_manager.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ struct ext_library {
126126
uint32_t lib_notif_count;
127127

128128
void *runtime_data;
129-
#if CONFIG_LIBRARY_AUTH_SUPPORT
130-
struct auth_api_ctx auth_ctx;
131-
void *auth_buffer;
132-
#endif
133129
};
134130

135131
/* lib manager context, used by lib_notification */

src/library_manager/lib_manager.c

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#if CONFIG_LIBRARY_AUTH_SUPPORT
3838
#include <auth/intel_auth_api.h>
39+
#else
40+
struct auth_api_ctx;
3941
#endif
4042

4143
#include <errno.h>
@@ -60,68 +62,59 @@ struct lib_manager_dma_ext {
6062
static struct ext_library loader_ext_lib;
6163

6264
#if CONFIG_LIBRARY_AUTH_SUPPORT
63-
static int lib_manager_auth_init(void)
65+
static int lib_manager_auth_init(struct auth_api_ctx *auth_ctx, void **auth_buffer)
6466
{
65-
struct ext_library *ext_lib = ext_lib_get();
6667
int ret;
6768

6869
if (auth_api_version().major != AUTH_API_VERSION_MAJOR)
6970
return -EINVAL;
7071

71-
ext_lib->auth_buffer = rballoc_align(0, SOF_MEM_CAPS_RAM,
72-
AUTH_SCRATCH_BUFF_SZ, CONFIG_MM_DRV_PAGE_SIZE);
73-
if (!ext_lib->auth_buffer)
72+
*auth_buffer = rballoc_align(0, SOF_MEM_CAPS_RAM,
73+
AUTH_SCRATCH_BUFF_SZ, CONFIG_MM_DRV_PAGE_SIZE);
74+
if (!*auth_buffer)
7475
return -ENOMEM;
7576

76-
ret = auth_api_init(&ext_lib->auth_ctx, ext_lib->auth_buffer,
77-
AUTH_SCRATCH_BUFF_SZ, IMG_TYPE_LIB);
77+
ret = auth_api_init(auth_ctx, *auth_buffer, AUTH_SCRATCH_BUFF_SZ, IMG_TYPE_LIB);
7878
if (ret != 0) {
7979
tr_err(&lib_manager_tr, "auth_api_init() failed with error: %d", ret);
80-
rfree(ext_lib->auth_buffer);
81-
ret = -EACCES;
80+
rfree(*auth_buffer);
81+
return -EACCES;
8282
}
8383

84-
return ret;
84+
return 0;
8585
}
8686

87-
static void lib_manager_auth_deinit(void)
87+
static void lib_manager_auth_deinit(struct auth_api_ctx *auth_ctx, void *auth_buffer)
8888
{
89-
struct ext_library *ext_lib = ext_lib_get();
90-
91-
if (ext_lib->auth_buffer)
92-
memset(ext_lib->auth_buffer, 0, AUTH_SCRATCH_BUFF_SZ);
93-
94-
rfree(ext_lib->auth_buffer);
95-
ext_lib->auth_buffer = NULL;
96-
memset(&ext_lib->auth_ctx, 0, sizeof(struct auth_api_ctx));
89+
ARG_UNUSED(auth_ctx);
90+
rfree(auth_buffer);
9791
}
9892

99-
static int lib_manager_auth_proc(const void *buffer_data,
100-
size_t buffer_size, enum auth_phase phase)
93+
static int lib_manager_auth_proc(const void *buffer_data, size_t buffer_size,
94+
enum auth_phase phase, struct auth_api_ctx *auth_ctx)
10195
{
102-
struct ext_library *ext_lib = ext_lib_get();
10396
int ret;
10497

105-
ret = auth_api_init_auth_proc(&ext_lib->auth_ctx, buffer_data, buffer_size, phase);
98+
ret = auth_api_init_auth_proc(auth_ctx, buffer_data, buffer_size, phase);
10699

107100
if (ret != 0) {
108101
tr_err(&lib_manager_tr, "auth_api_init_auth_proc() failed with error: %d", ret);
109102
return -ENOTSUP;
110103
}
111104

112105
/* The auth_api_busy() will timeouts internally in case of failure */
113-
while (auth_api_busy(&ext_lib->auth_ctx))
106+
while (auth_api_busy(auth_ctx))
114107
;
115108

116-
ret = auth_api_result(&ext_lib->auth_ctx);
109+
ret = auth_api_result(auth_ctx);
117110

118111
if (ret != AUTH_IMAGE_TRUSTED) {
119112
tr_err(&lib_manager_tr, "Untrusted library!");
120113
return -EACCES;
121114
}
122115

123116
if (phase == AUTH_PHASE_LAST)
124-
auth_api_cleanup(&ext_lib->auth_ctx);
117+
auth_api_cleanup(auth_ctx);
125118

126119
return 0;
127120
}
@@ -819,7 +812,7 @@ static void __sparse_cache *lib_manager_allocate_store_mem(uint32_t size,
819812

820813
static int lib_manager_store_library(struct lib_manager_dma_ext *dma_ext,
821814
const void __sparse_cache *man_buffer,
822-
uint32_t lib_id)
815+
uint32_t lib_id, struct auth_api_ctx *auth_ctx)
823816
{
824817
void __sparse_cache *library_base_address;
825818
const struct sof_man_fw_desc *man_desc = (struct sof_man_fw_desc *)
@@ -850,7 +843,7 @@ static int lib_manager_store_library(struct lib_manager_dma_ext *dma_ext,
850843
#if CONFIG_LIBRARY_AUTH_SUPPORT
851844
/* AUTH_PHASE_FIRST - checks library manifest only. */
852845
ret = lib_manager_auth_proc((__sparse_force const void *)man_buffer,
853-
MAN_MAX_SIZE_V1_8, AUTH_PHASE_FIRST);
846+
MAN_MAX_SIZE_V1_8, AUTH_PHASE_FIRST, auth_ctx);
854847
if (ret < 0) {
855848
rfree((__sparse_force void *)library_base_address);
856849
return ret;
@@ -872,7 +865,7 @@ static int lib_manager_store_library(struct lib_manager_dma_ext *dma_ext,
872865
#if CONFIG_LIBRARY_AUTH_SUPPORT
873866
/* AUTH_PHASE_LAST - do final library authentication checks */
874867
ret = lib_manager_auth_proc((__sparse_force void *)library_base_address,
875-
preload_size - MAN_MAX_SIZE_V1_8, AUTH_PHASE_LAST);
868+
preload_size - MAN_MAX_SIZE_V1_8, AUTH_PHASE_LAST, auth_ctx);
876869
if (ret < 0) {
877870
rfree((__sparse_force void *)library_base_address);
878871
return ret;
@@ -1003,16 +996,19 @@ int lib_manager_load_library(uint32_t dma_id, uint32_t lib_id, uint32_t type)
1003996
goto stop_dma;
1004997

1005998
#if CONFIG_LIBRARY_AUTH_SUPPORT
999+
struct auth_api_ctx auth_ctx;
1000+
void *auth_buffer;
1001+
10061002
/* Initialize authentication support */
1007-
ret = lib_manager_auth_init();
1003+
ret = lib_manager_auth_init(&auth_ctx, &auth_buffer);
10081004
if (ret < 0)
10091005
goto stop_dma;
1010-
#endif /* CONFIG_LIBRARY_AUTH_SUPPORT */
10111006

1012-
ret = lib_manager_store_library(dma_ext, man_tmp_buffer, lib_id);
1007+
ret = lib_manager_store_library(dma_ext, man_tmp_buffer, lib_id, &auth_ctx);
10131008

1014-
#if CONFIG_LIBRARY_AUTH_SUPPORT
1015-
lib_manager_auth_deinit();
1009+
lib_manager_auth_deinit(&auth_ctx, auth_buffer);
1010+
#else
1011+
ret = lib_manager_store_library(dma_ext, man_tmp_buffer, lib_id, NULL);
10161012
#endif /* CONFIG_LIBRARY_AUTH_SUPPORT */
10171013

10181014
stop_dma:

0 commit comments

Comments
 (0)