Skip to content

Commit

Permalink
Encode UUID big endian
Browse files Browse the repository at this point in the history
When encoding a UUID as a sequence of bytes, the spec
(https://www.ietf.org/rfc/rfc4122.txt) says that the u32, and two u16s
should be represented big endian.

Before this patch OPTEE always treated them natively. With this patch
UUIDs are always converted to/from big endian when communicating with
the kernel.

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Fixes: OP-TEE/optee_os#858
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
  • Loading branch information
jenswi-linaro committed Dec 9, 2016
1 parent 7739387 commit 731f8a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
15 changes: 14 additions & 1 deletion libteec/src/tee_client_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,19 @@ static TEEC_Result ioctl_errno_to_res(int err)
}
}

static void uuid_to_octets(uint8_t d[TEE_IOCTL_UUID_LEN], const TEEC_UUID *s)
{
d[0] = s->timeLow >> 24;
d[1] = s->timeLow >> 16;
d[2] = s->timeLow >> 8;
d[3] = s->timeLow;
d[4] = s->timeMid >> 8;
d[5] = s->timeMid;
d[6] = s->timeHiAndVersion >> 8;
d[7] = s->timeHiAndVersion;
memcpy(d + 8, s->clockSeqAndNode, sizeof(s->clockSeqAndNode));
}

TEEC_Result TEEC_OpenSession(TEEC_Context *ctx, TEEC_Session *session,
const TEEC_UUID *destination,
uint32_t connection_method, const void *connection_data,
Expand Down Expand Up @@ -475,7 +488,7 @@ TEEC_Result TEEC_OpenSession(TEEC_Context *ctx, TEEC_Session *session,
arg->num_params = TEEC_CONFIG_PAYLOAD_REF_COUNT;
params = (struct tee_ioctl_param *)(arg + 1);

memcpy(arg->uuid, destination, sizeof(TEEC_UUID));
uuid_to_octets(arg->uuid, destination);
arg->clnt_login = connection_method;

res = teec_pre_process_operation(ctx, operation, params, shm);
Expand Down
10 changes: 9 additions & 1 deletion tee-supplicant/src/tee_supplicant.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ static void process_sql_fs(union tee_rpc_invoke *request)
request->send.ret = sql_fs_process(&request->recv);
}

static void uuid_from_octets(TEEC_UUID *d, const uint8_t s[TEE_IOCTL_UUID_LEN])
{
d->timeLow = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
d->timeMid = (s[4] << 8) | s[5];
d->timeHiAndVersion = (s[6] << 8) | s[7];
memcpy(d->clockSeqAndNode, s + 8, sizeof(d->clockSeqAndNode));
}

static void load_ta(union tee_rpc_invoke *request)
{
int ta_found = 0;
Expand All @@ -194,7 +202,7 @@ static void load_ta(union tee_rpc_invoke *request)
request->send.ret = TEEC_ERROR_BAD_PARAMETERS;
return;
}
memcpy(&uuid, val_cmd, sizeof(uuid));
uuid_from_octets(&uuid, (void *)val_cmd);

size = shm_ta.size;
ta_found = TEECI_LoadSecureModule(ta_dir, &uuid, shm_ta.buffer, &size);
Expand Down

0 comments on commit 731f8a7

Please sign in to comment.