Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: fix potential double free in ta_open() #1970

Merged
merged 1 commit into from
Nov 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions core/arch/arm/kernel/ree_fs_ta.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,27 @@ struct user_ta_store_handle {
uint32_t hash_algo;
};

static TEE_Result alloc_and_copy_shdr(struct shdr **shdr,
static TEE_Result alloc_and_copy_shdr(struct shdr **shdr_ret,
const struct shdr *nw_ta,
size_t ta_size)
{
struct shdr *shdr;
size_t shdr_size;

if (ta_size < sizeof(struct shdr))
return TEE_ERROR_SECURITY;
shdr_size = SHDR_GET_SIZE(nw_ta);
if (ta_size < shdr_size)
return TEE_ERROR_SECURITY;
*shdr = malloc(shdr_size);
if (!*shdr)
shdr = malloc(shdr_size);
if (!shdr)
return TEE_ERROR_SECURITY;
memcpy(*shdr, nw_ta, shdr_size);
if (shdr_size != SHDR_GET_SIZE(*shdr)) {
free(*shdr);
memcpy(shdr, nw_ta, shdr_size);
if (shdr_size != SHDR_GET_SIZE(shdr)) {
free(shdr);
return TEE_ERROR_SECURITY;
}
*shdr_ret = shdr;
return TEE_SUCCESS;
}

Expand Down