From bfccad24747339aaa0e8d11a0361f5c91061af7d Mon Sep 17 00:00:00 2001 From: Michael Ryleev Date: Tue, 18 Sep 2018 15:43:57 -0700 Subject: [PATCH] trusty: keymaster3: Modify TrustyKeymaster3Device::update method Modify TrustyKeymaster3Device::update method to handle the case when amount of input data received exceeds a maximum amount supported by underlying transport. In such case, only send an portion of data that fits and allow higher levels to take care of the rest. This is not an ideal fix as it is not very efficient for large sets of data but at least it should work in more cases. Test: android.keystore.cts Change-Id: Id7360d0da3b87493193d480fc0c78c65dc1fc51f --- .../keymaster/3.0/TrustyKeymaster3Device.cpp | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/trusty/keymaster/3.0/TrustyKeymaster3Device.cpp b/trusty/keymaster/3.0/TrustyKeymaster3Device.cpp index 8e3b3b127..0849ee959 100644 --- a/trusty/keymaster/3.0/TrustyKeymaster3Device.cpp +++ b/trusty/keymaster/3.0/TrustyKeymaster3Device.cpp @@ -21,6 +21,7 @@ #include #include #include +#include using ::keymaster::AbortOperationRequest; using ::keymaster::AbortOperationResponse; @@ -393,20 +394,32 @@ Return TrustyKeymaster3Device::update(uint64_t operationHandle, const hidl_vec& inParams, const hidl_vec& input, update_cb _hidl_cb) { UpdateOperationRequest request; - request.op_handle = operationHandle; - request.input.Reinitialize(input.data(), input.size()); - request.additional_params.Reinitialize(KmParamSet(inParams)); - UpdateOperationResponse response; - impl_->UpdateOperation(request, &response); - - uint32_t resultConsumed = 0; hidl_vec resultParams; hidl_vec resultBlob; - if (response.error == KM_ERROR_OK) { - resultConsumed = response.input_consumed; - resultParams = kmParamSet2Hidl(response.output_params); - resultBlob = kmBuffer2hidlVec(response.output); + uint32_t resultConsumed = 0; + + request.op_handle = operationHandle; + request.additional_params.Reinitialize(KmParamSet(inParams)); + + size_t inp_size = input.size(); + size_t ser_size = request.SerializedSize(); + + if (ser_size > TRUSTY_KEYMASTER_SEND_BUF_SIZE) { + response.error = KM_ERROR_INVALID_INPUT_LENGTH; + } else { + if (ser_size + inp_size > TRUSTY_KEYMASTER_SEND_BUF_SIZE) { + inp_size = TRUSTY_KEYMASTER_SEND_BUF_SIZE - ser_size; + } + request.input.Reinitialize(input.data(), inp_size); + + impl_->UpdateOperation(request, &response); + + if (response.error == KM_ERROR_OK) { + resultConsumed = response.input_consumed; + resultParams = kmParamSet2Hidl(response.output_params); + resultBlob = kmBuffer2hidlVec(response.output); + } } _hidl_cb(legacy_enum_conversion(response.error), resultConsumed, resultParams, resultBlob); return Void();