Skip to content

Commit

Permalink
TSP enlarge response buffer for error message.
Browse files Browse the repository at this point in the history
Signed-off-by: Jiewen Yao <[email protected]>
  • Loading branch information
jyao1 committed Oct 17, 2024
1 parent a3bf75d commit c6ebab7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
2 changes: 2 additions & 0 deletions include/library/cxl_tsp_common_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#define LIBCXLTSP_CONFIGURATION_REPORT_PORTION_LEN 0x40

#define LIBCXLTSP_ERROR_MESSAGE_MAX_SIZE (sizeof(cxl_tsp_error_rsp_t))

typedef struct {
uint16_t memory_encryption_features_supported;
uint32_t memory_encryption_algorithms_supported;
Expand Down
16 changes: 9 additions & 7 deletions library/cxl_tsp_requester_lib/cxl_tsp_req_get_version.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,38 @@ libspdm_return_t cxl_tsp_get_version(
libspdm_return_t status;
cxl_tsp_get_target_tsp_version_req_t request;
size_t request_size;
cxl_tsp_get_target_tsp_version_rsp_mine_t response;
uint8_t res_buf[LIBCXLTSP_ERROR_MESSAGE_MAX_SIZE];
cxl_tsp_get_target_tsp_version_rsp_mine_t *response;
size_t response_size;

libspdm_zero_mem (&request, sizeof(request));
request.header.tsp_version = CXL_TSP_MESSAGE_VERSION_10;
request.header.op_code = CXL_TSP_OPCODE_GET_TARGET_TSP_VERSION;

request_size = sizeof(request);
response_size = sizeof(response);
response = (void *)res_buf;
response_size = sizeof(res_buf);
status = cxl_tsp_send_receive_data(spdm_context, session_id,
&request, request_size,
&response, &response_size);
response, &response_size);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}

if (response_size != sizeof(cxl_tsp_get_target_tsp_version_rsp_mine_t)) {
return LIBSPDM_STATUS_INVALID_MSG_SIZE;
}
if (response.header.tsp_version != request.header.tsp_version) {
if (response->header.tsp_version != request.header.tsp_version) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}
if (response.header.op_code != CXL_TSP_OPCODE_GET_TARGET_TSP_VERSION_RSP) {
if (response->header.op_code != CXL_TSP_OPCODE_GET_TARGET_TSP_VERSION_RSP) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}

if (response.version_number_entry_count != 1) {
if (response->version_number_entry_count != 1) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}
if (response.version_number_entry[0] != CXL_TSP_MESSAGE_VERSION_10) {
if (response->version_number_entry[0] != CXL_TSP_MESSAGE_VERSION_10) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}

Expand Down
12 changes: 7 additions & 5 deletions library/cxl_tsp_requester_lib/cxl_tsp_req_lock_configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,31 @@ libspdm_return_t cxl_tsp_lock_configuration(
libspdm_return_t status;
cxl_tsp_lock_target_configuration_req_t request;
size_t request_size;
cxl_tsp_lock_target_configuration_rsp_t response;
uint8_t res_buf[LIBCXLTSP_ERROR_MESSAGE_MAX_SIZE];
cxl_tsp_lock_target_configuration_rsp_t *response;
size_t response_size;

libspdm_zero_mem (&request, sizeof(request));
request.header.tsp_version = CXL_TSP_MESSAGE_VERSION_10;
request.header.op_code = CXL_TSP_OPCODE_LOCK_TARGET_CONFIGURATION;

request_size = sizeof(request);
response_size = sizeof(response);
response = (void *)res_buf;
response_size = sizeof(res_buf);
status = cxl_tsp_send_receive_data(spdm_context, session_id,
&request, request_size,
&response, &response_size);
response, &response_size);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}

if (response_size != sizeof(cxl_tsp_lock_target_configuration_rsp_t)) {
return LIBSPDM_STATUS_INVALID_MSG_SIZE;
}
if (response.header.tsp_version != request.header.tsp_version) {
if (response->header.tsp_version != request.header.tsp_version) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}
if (response.header.op_code != CXL_TSP_OPCODE_LOCK_TARGET_CONFIGURATION_RSP) {
if (response->header.op_code != CXL_TSP_OPCODE_LOCK_TARGET_CONFIGURATION_RSP) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}

Expand Down
12 changes: 7 additions & 5 deletions library/cxl_tsp_requester_lib/cxl_tsp_req_set_configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ libspdm_return_t cxl_tsp_set_configuration(
libspdm_return_t status;
cxl_tsp_set_target_configuration_req_t request;
size_t request_size;
cxl_tsp_set_target_configuration_rsp_t response;
uint8_t res_buf[LIBCXLTSP_ERROR_MESSAGE_MAX_SIZE];
cxl_tsp_set_target_configuration_rsp_t *response;
size_t response_size;

libspdm_zero_mem (&request, sizeof(request));
Expand Down Expand Up @@ -59,21 +60,22 @@ libspdm_return_t cxl_tsp_set_configuration(
sizeof(device_2nd_session_info->secondary_session_psk_key_material));

request_size = sizeof(request);
response_size = sizeof(response);
response = (void *)res_buf;
response_size = sizeof(res_buf);
status = cxl_tsp_send_receive_data(spdm_context, session_id,
&request, request_size,
&response, &response_size);
response, &response_size);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}

if (response_size != sizeof(cxl_tsp_set_target_configuration_rsp_t)) {
return LIBSPDM_STATUS_INVALID_MSG_SIZE;
}
if (response.header.tsp_version != request.header.tsp_version) {
if (response->header.tsp_version != request.header.tsp_version) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}
if (response.header.op_code != CXL_TSP_OPCODE_SET_TARGET_CONFIGURATION_RSP) {
if (response->header.op_code != CXL_TSP_OPCODE_SET_TARGET_CONFIGURATION_RSP) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}

Expand Down
12 changes: 7 additions & 5 deletions library/cxl_tsp_requester_lib/cxl_tsp_req_set_te_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ libspdm_return_t cxl_tsp_set_te_state(
libspdm_return_t status;
cxl_tsp_set_target_te_state_req_mine_t request;
size_t request_size;
cxl_tsp_set_target_te_state_rsp_t response;
uint8_t res_buf[LIBCXLTSP_ERROR_MESSAGE_MAX_SIZE];
cxl_tsp_set_target_te_state_rsp_t *response;
size_t response_size;

libspdm_zero_mem (&request, sizeof(request));
Expand All @@ -60,21 +61,22 @@ libspdm_return_t cxl_tsp_set_te_state(

request_size = sizeof(cxl_tsp_set_target_te_state_req_t) +
number_of_memory_ranges * sizeof(cxl_tsp_memory_range_t);
response_size = sizeof(response);
response = (void *)res_buf;
response_size = sizeof(res_buf);
status = cxl_tsp_send_receive_data(spdm_context, session_id,
&request, request_size,
&response, &response_size);
response, &response_size);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}

if (response_size != sizeof(cxl_tsp_set_target_te_state_rsp_t)) {
return LIBSPDM_STATUS_INVALID_MSG_SIZE;
}
if (response.header.tsp_version != request.header.tsp_version) {
if (response->header.tsp_version != request.header.tsp_version) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}
if (response.header.op_code != CXL_TSP_OPCODE_SET_TARGET_TE_STATE_RSP) {
if (response->header.op_code != CXL_TSP_OPCODE_SET_TARGET_TE_STATE_RSP) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}

Expand Down

0 comments on commit c6ebab7

Please sign in to comment.