-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Error cases in syscall_asymm_operate() not trapped #6143
Comments
An obvious patch to fix the reported issue is the following: --- a/core/tee/tee_svc_cryp.c
+++ b/core/tee/tee_svc_cryp.c
@@ -4245,25 +4245,25 @@
/*
* If the optional TEE_ATTR_RSA_OAEP_MGF_HASH is
* provided for algorithm
* TEE_ALG_RSAES_PKCS1_OAEP_MGF1_x it must match
* the internal hash x since we don't support using
* a different hash for MGF1 yet.
*/
if (cs->algo != TEE_ALG_RSAES_PKCS1_V1_5 &&
params[n].attributeID ==
TEE_ATTR_RSA_OAEP_MGF_HASH) {
uint32_t hash = 0;
if (params[n].content.ref.length !=
sizeof(hash)) {
res = TEE_ERROR_BAD_PARAMETERS;
- break;
+ goto out;
}
memcpy(&hash, params[n].content.ref.buffer,
sizeof(hash));
if (hash !=
TEE_INTERNAL_HASH_TO_ALGO(cs->algo)) {
res = TEE_ERROR_NOT_SUPPORTED;
- break;
+ goto out;
}
} However, as reported by @seonghp such change leads to if (tv->algo == TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA1) {
algo_params[0].attributeID =
TEE_ATTR_RSA_OAEP_MGF_HASH;
algo_params[0].content.ref.length =
sizeof(uint32_t);
algo_params[0].content.ref.buffer =
&(uint32_t){TEE_ALG_SHA1}; <----- HERE
num_algo_params = 1;
} Note that the issue disappears when referred byffer is accessed before the TA is invoked, e.g.: if (tv->algo == TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA1) {
algo_params[0].attributeID =
TEE_ATTR_RSA_OAEP_MGF_HASH;
algo_params[0].content.ref.length =
sizeof(uint32_t);
algo_params[0].content.ref.buffer =
&(uint32_t){TEE_ALG_SHA1};
num_algo_params = 1;
+ fprintf(stderr, "TEE_ATTR_RSA_OAEP_MGF_HASH: hash 0x%x\n",
+ *(uint32_t *)algo_params[0].content.ref.buffer);
} That said, changing regression_4000.c to explicitly use the stack as buffer reference fixes the issue: (...)
+ uint32_t sha1_algo_id = TEE_ALG_SHA1;
(...)
if (tv->algo == TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA1) {
algo_params[0].attributeID =
TEE_ATTR_RSA_OAEP_MGF_HASH;
algo_params[0].content.ref.length =
- sizeof(uint32_t);
+ sizeof(sha1_algo_id);
algo_params[0].content.ref.buffer =
- &(uint32_t){TEE_ALG_SHA1};
+ &sha1_algo_id;
num_algo_params = 1;
} I'll propose this fix in optee_test. |
Explicit uses the stack to refer to attribute TEE_ATTR_RSA_OAEP_MGF_HASH passed to the crypt TA in tests regression 4006.37 and 4006.38 as the current implementation makes to TA to see an uninitialized buffer reference. Fixes: OP-TEE/optee_os#6143 Signed-off-by: Etienne Carriere <etienne.carriere@foss.st.com>
Fixes syscall_asymm_operate() to report inconsistent hash algorithm specified as attribute for TEE_ALG_RSAES_PKCS1_OAEP_MGF1_* operations as OP-TEE only supports the hash predefined for the request algorithm TEE_ALG_RSAES_PKCS1_OAEP_MGF1_xxx. Fixes: OP-TEE#6143 Signed-off-by: Etienne Carriere <etienne.carriere@foss.st.com>
Fixes syscall_asymm_operate() to report inconsistent hash algorithm specified as attribute for TEE_ALG_RSAES_PKCS1_OAEP_MGF1_* operations as OP-TEE only supports the hash predefined for the request algorithm TEE_ALG_RSAES_PKCS1_OAEP_MGF1_xxx. Link: OP-TEE#6143 Signed-off-by: Etienne Carriere <etienne.carriere@foss.st.com>
Explicit uses the stack to refer to attribute TEE_ATTR_RSA_OAEP_MGF_HASH passed to the crypt TA in tests regression 4006.37 and 4006.38 as the current implementation makes to TA to see an uninitialized buffer reference. Link: OP-TEE/optee_os#6143 Signed-off-by: Etienne Carriere <etienne.carriere@foss.st.com>
Created #6144 and OP-TEE/optee_test#678 to address the issue. |
Fixes syscall_asymm_operate() to report inconsistent hash algorithm specified as attribute for TEE_ALG_RSAES_PKCS1_OAEP_MGF1_* operations as OP-TEE only supports the hash predefined for the request algorithm TEE_ALG_RSAES_PKCS1_OAEP_MGF1_xxx. Link: OP-TEE#6143 Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Etienne Carriere <etienne.carriere@foss.st.com>
Explicit uses the stack to refer to attribute TEE_ATTR_RSA_OAEP_MGF_HASH passed to the crypt TA in tests regression 4006.37 and 4006.38 as the current implementation makes to TA to see an uninitialized buffer reference. Link: OP-TEE/optee_os#6143 Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Etienne Carriere <etienne.carriere@foss.st.com>
Explicit uses the stack to refer to attribute TEE_ATTR_RSA_OAEP_MGF_HASH passed to the crypt TA in tests regression 4006.37 and 4006.38 as the current implementation makes to TA to see an uninitialized buffer reference. Link: OP-TEE/optee_os#6143 Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Etienne Carriere <etienne.carriere@foss.st.com>
Fixes syscall_asymm_operate() to report inconsistent hash algorithm specified as attribute for TEE_ALG_RSAES_PKCS1_OAEP_MGF1_* operations as OP-TEE only supports the hash predefined for the request algorithm TEE_ALG_RSAES_PKCS1_OAEP_MGF1_xxx. Link: #6143 Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Etienne Carriere <etienne.carriere@foss.st.com>
syscall_asymm_operate()
can detect error conditions that are not reported, see #6135 (comment) and #6135 (comment).First tests by @seonghp reports xtest failure when addressed (#6135 (comment)).
To be investigated.
The text was updated successfully, but these errors were encountered: