-
Notifications
You must be signed in to change notification settings - Fork 236
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
libckteec: fix null pointer dereference on template serialization #392
Open
hoyong2007
wants to merge
1
commit into
OP-TEE:master
Choose a base branch
from
hoyong2007:add_nullcheck
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -393,6 +393,9 @@ static CK_RV serialize_mecha_aes_ctr(struct serializer *obj, | |
CK_RV rv = CKR_GENERAL_ERROR; | ||
uint32_t size = 0; | ||
|
||
if (!param) | ||
return CKR_MECHANISM_PARAM_INVALID; | ||
|
||
rv = serialize_32b(obj, obj->type); | ||
if (rv) | ||
return rv; | ||
|
@@ -420,13 +423,13 @@ static CK_RV serialize_mecha_aes_gcm(struct serializer *obj, | |
CK_RV rv = CKR_GENERAL_ERROR; | ||
CK_ULONG aad_len = 0; | ||
|
||
if (!param || !param->pIv) | ||
return CKR_MECHANISM_PARAM_INVALID; | ||
|
||
/* AAD is not manadatory */ | ||
if (param->pAAD) | ||
aad_len = param->ulAADLen; | ||
|
||
if (!param->pIv) | ||
return CKR_MECHANISM_PARAM_INVALID; | ||
|
||
rv = serialize_32b(obj, obj->type); | ||
if (rv) | ||
return rv; | ||
|
@@ -461,6 +464,9 @@ static CK_RV serialize_mecha_aes_iv(struct serializer *obj, | |
uint32_t iv_size = mecha->ulParameterLen; | ||
CK_RV rv = CKR_GENERAL_ERROR; | ||
|
||
if (iv_size && !mecha->pParameter) | ||
return CKR_MECHANISM_PARAM_INVALID; | ||
|
||
rv = serialize_32b(obj, obj->type); | ||
if (rv) | ||
return rv; | ||
|
@@ -479,6 +485,9 @@ static CK_RV serialize_mecha_key_deriv_str(struct serializer *obj, | |
CK_RV rv = CKR_GENERAL_ERROR; | ||
uint32_t size = 0; | ||
|
||
if (!param || (param->ulLen && !param->pData)) | ||
return CKR_MECHANISM_PARAM_INVALID; | ||
|
||
rv = serialize_32b(obj, obj->type); | ||
if (rv) | ||
return rv; | ||
|
@@ -500,7 +509,14 @@ static CK_RV serialize_mecha_ecdh1_derive_param(struct serializer *obj, | |
{ | ||
CK_ECDH1_DERIVE_PARAMS *params = mecha->pParameter; | ||
CK_RV rv = CKR_GENERAL_ERROR; | ||
size_t params_size = 3 * sizeof(uint32_t) + params->ulSharedDataLen + | ||
size_t params_size = 0; | ||
|
||
if (!params || | ||
(params->ulSharedDataLen && !params->pSharedData) || | ||
(params->ulPublicDataLen && !params->pPublicData)) | ||
return CKR_MECHANISM_PARAM_INVALID; | ||
|
||
params_size = 3 * sizeof(uint32_t) + params->ulSharedDataLen + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you fix indentation at line below? |
||
params->ulPublicDataLen; | ||
|
||
rv = serialize_32b(obj, obj->type); | ||
|
@@ -539,6 +555,9 @@ static CK_RV serialize_mecha_aes_cbc_encrypt_data(struct serializer *obj, | |
CK_RV rv = CKR_GENERAL_ERROR; | ||
uint32_t size = 0; | ||
|
||
if (!param || (param->length && !param->pData)) | ||
return CKR_MECHANISM_PARAM_INVALID; | ||
|
||
rv = serialize_32b(obj, obj->type); | ||
if (rv) | ||
return rv; | ||
|
@@ -566,6 +585,9 @@ static CK_RV serialize_mecha_rsa_pss_param(struct serializer *obj, | |
CK_RV rv = CKR_GENERAL_ERROR; | ||
uint32_t params_size = 3 * sizeof(uint32_t); | ||
|
||
if (!params) | ||
return CKR_MECHANISM_PARAM_INVALID; | ||
|
||
if (mecha->ulParameterLen != sizeof(*params)) | ||
return CKR_ARGUMENTS_BAD; | ||
|
||
|
@@ -593,7 +615,12 @@ static CK_RV serialize_mecha_rsa_oaep_param(struct serializer *obj, | |
{ | ||
CK_RSA_PKCS_OAEP_PARAMS *params = mecha->pParameter; | ||
CK_RV rv = CKR_GENERAL_ERROR; | ||
size_t params_size = 4 * sizeof(uint32_t) + params->ulSourceDataLen; | ||
size_t params_size = 0; | ||
|
||
if (!params || (params->ulSourceDataLen && !params->pSourceData)) | ||
return CKR_MECHANISM_PARAM_INVALID; | ||
|
||
params_size = 4 * sizeof(uint32_t) + params->ulSourceDataLen; | ||
|
||
if (mecha->ulParameterLen != sizeof(*params)) | ||
return CKR_ARGUMENTS_BAD; | ||
|
@@ -630,9 +657,18 @@ static CK_RV serialize_mecha_rsa_aes_key_wrap(struct serializer *obj, | |
CK_MECHANISM_PTR mecha) | ||
{ | ||
CK_RSA_AES_KEY_WRAP_PARAMS *params = mecha->pParameter; | ||
CK_RSA_PKCS_OAEP_PARAMS *aes_params = params->pOAEPParams; | ||
CK_RSA_PKCS_OAEP_PARAMS *aes_params = NULL; | ||
CK_RV rv = CKR_GENERAL_ERROR; | ||
size_t params_size = 5 * sizeof(uint32_t) + aes_params->ulSourceDataLen; | ||
size_t params_size = 0; | ||
|
||
if (!params || !params->pOAEPParams) | ||
return CKR_MECHANISM_PARAM_INVALID; | ||
|
||
aes_params = params->pOAEPParams; | ||
params_size = 5 * sizeof(uint32_t) + aes_params->ulSourceDataLen; | ||
|
||
if (aes_params->ulSourceDataLen && !aes_params->pSourceData) | ||
return CKR_MECHANISM_PARAM_INVALID; | ||
|
||
if (mecha->ulParameterLen != sizeof(*params)) | ||
return CKR_ARGUMENTS_BAD; | ||
|
@@ -675,6 +711,9 @@ static CK_RV serialize_mecha_eddsa(struct serializer *obj, | |
CK_RV rv = CKR_GENERAL_ERROR; | ||
CK_EDDSA_PARAMS *params = mecha->pParameter; | ||
|
||
if (!params || (params->ulContextDataLen && !params->pContextData)) | ||
return CKR_MECHANISM_PARAM_INVALID; | ||
|
||
rv = serialize_32b(obj, obj->type); | ||
if (rv) | ||
return rv; | ||
|
@@ -700,6 +739,9 @@ static CK_RV serialize_mecha_mac_general_param(struct serializer *obj, | |
CK_RV rv = CKR_GENERAL_ERROR; | ||
CK_ULONG ck_data = 0; | ||
|
||
if (mecha->ulParameterLen && !mecha->pParameter) | ||
return CKR_MECHANISM_PARAM_INVALID; | ||
|
||
if (mecha->ulParameterLen != sizeof(ck_data)) | ||
return CKR_ARGUMENTS_BAD; | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think test on
!param->pIv
was not really useful, testing!param
should be enough. That said, for consistency, could you test!param || (param->ulIvLen && !param->pIv)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking again at PKCS#11 specifications, on one hand v2.40-errata01 says both AES-GCM IV can be NULL and must be between 1 and 256 byte. On the other hand v2.30 says AES-GCM IV must be between 1 and 2^32-1 bytes. In all one, I think the legacy implementation here in optee_client is enough, so OK for your proposal
if (!param || !param->pIv)
.