-
Notifications
You must be signed in to change notification settings - Fork 257
libckteec: add and use {ADD|SUB|MUL}_OVERFLOW() macros #421
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| * Copyright (c) 2017-2018, Linaro Limited | ||
| */ | ||
|
|
||
| #include <limits.h> | ||
| #include <pkcs11.h> | ||
| #include <pkcs11_ta.h> | ||
| #include <stdio.h> | ||
|
|
@@ -12,6 +13,7 @@ | |
|
|
||
| #include "pkcs11_processing.h" | ||
| #include "invoke_ta.h" | ||
| #include "local_utils.h" | ||
| #include "serializer.h" | ||
| #include "serialize_ck.h" | ||
|
|
||
|
|
@@ -36,7 +38,9 @@ CK_RV ck_create_object(CK_SESSION_HANDLE session, CK_ATTRIBUTE_PTR attribs, | |
| goto out; | ||
|
|
||
| /* Shm io0: (i/o) [session-handle][serialized-attributes] / [status] */ | ||
| ctrl_size = sizeof(session_handle) + obj.size; | ||
| if (ADD_OVERFLOW(sizeof(session_handle), obj.size, &ctrl_size)) | ||
| return CKR_ARGUMENTS_BAD; | ||
|
Contributor
Author
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. My mistake. Note: I missed #417 that does the jobs nicely. I'll close my P-R. |
||
|
|
||
| ctrl = ckteec_alloc_shm(ctrl_size, CKTEEC_SHM_INOUT); | ||
| if (!ctrl) { | ||
| rv = CKR_HOST_MEMORY; | ||
|
|
@@ -132,7 +136,9 @@ CK_RV ck_encdecrypt_init(CK_SESSION_HANDLE session, | |
| * (in) [session-handle][key-handle][serialized-mechanism-blob] | ||
| * (out) [status] | ||
| */ | ||
| ctrl_size = sizeof(session_handle) + sizeof(key_handle) + obj.size; | ||
| ctrl_size = sizeof(session_handle) + sizeof(key_handle); | ||
| if (ADD_OVERFLOW(ctrl_size, obj.size, &ctrl_size)) | ||
| return CKR_ARGUMENTS_BAD; | ||
|
|
||
| ctrl = ckteec_alloc_shm(ctrl_size, CKTEEC_SHM_INOUT); | ||
| if (!ctrl) { | ||
|
|
@@ -388,7 +394,9 @@ CK_RV ck_digest_init(CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism) | |
| * (in) [session-handle][serialized-mechanism-blob] | ||
| * (out) [status] | ||
| */ | ||
| ctrl_size = sizeof(session_handle) + obj.size; | ||
| if (ADD_OVERFLOW(sizeof(session_handle), obj.size, &ctrl_size)) | ||
| return CKR_ARGUMENTS_BAD; | ||
|
|
||
| ctrl = ckteec_alloc_shm(ctrl_size, CKTEEC_SHM_INOUT); | ||
| if (!ctrl) { | ||
| rv = CKR_HOST_MEMORY; | ||
|
|
@@ -656,7 +664,10 @@ CK_RV ck_signverify_init(CK_SESSION_HANDLE session, | |
| * (in) [session-handle][key-handle][serialized-mechanism-blob] | ||
| * (out) [status] | ||
| */ | ||
| ctrl_size = sizeof(session_handle) + sizeof(key_handle) + obj.size; | ||
| ctrl_size = sizeof(session_handle) + sizeof(key_handle); | ||
| if (ADD_OVERFLOW(ctrl_size, obj.size, &ctrl_size)) | ||
| return CKR_ARGUMENTS_BAD; | ||
|
|
||
| ctrl = ckteec_alloc_shm(ctrl_size, CKTEEC_SHM_INOUT); | ||
| if (!ctrl) { | ||
| rv = CKR_HOST_MEMORY; | ||
|
|
@@ -902,7 +913,9 @@ CK_RV ck_generate_key(CK_SESSION_HANDLE session, | |
| * (in) [session-handle][serialized-mecha][serialized-attributes] | ||
| * (out) [status] | ||
| */ | ||
| ctrl_size = sizeof(session_handle) + smecha.size + sattr.size; | ||
| if (ADD_OVERFLOW(sizeof(session_handle), smecha.size, &ctrl_size) || | ||
| ADD_OVERFLOW(ctrl_size, sattr.size, &ctrl_size)) | ||
| return CKR_ARGUMENTS_BAD; | ||
|
|
||
| ctrl = ckteec_alloc_shm(ctrl_size, CKTEEC_SHM_INOUT); | ||
| if (!ctrl) { | ||
|
|
@@ -970,7 +983,9 @@ CK_RV ck_find_objects_init(CK_SESSION_HANDLE session, | |
| * (in) [session-handle][headed-serialized-attributes] | ||
| * (out) [status] | ||
| */ | ||
| ctrl_size = sizeof(session_handle) + obj.size; | ||
| if (ADD_OVERFLOW(sizeof(session_handle), obj.size, &ctrl_size)) | ||
| return CKR_ARGUMENTS_BAD; | ||
|
|
||
| ctrl = ckteec_alloc_shm(ctrl_size, CKTEEC_SHM_INOUT); | ||
| if (!ctrl) { | ||
| rv = CKR_HOST_MEMORY; | ||
|
|
@@ -1004,14 +1019,17 @@ CK_RV ck_find_objects(CK_SESSION_HANDLE session, | |
| TEEC_SharedMemory *out_shm = NULL; | ||
| uint32_t session_handle = session; | ||
| uint32_t *handles = NULL; | ||
| size_t handles_size = max_count * sizeof(uint32_t); | ||
| size_t handles_size = 0; | ||
| CK_ULONG n = 0; | ||
| CK_ULONG last = 0; | ||
| size_t out_size = 0; | ||
|
|
||
| if (!count || (max_count && !obj)) | ||
| return CKR_ARGUMENTS_BAD; | ||
|
|
||
| if (MUL_OVERFLOW(max_count, sizeof(uint32_t), &handles_size)) | ||
| return CKR_ARGUMENTS_BAD; | ||
|
|
||
| /* Shm io0: (in/out) ctrl = [session-handle] / [status] */ | ||
| ctrl = ckteec_alloc_shm(sizeof(session_handle), CKTEEC_SHM_INOUT); | ||
| if (!ctrl) { | ||
|
|
@@ -1154,7 +1172,9 @@ CK_RV ck_get_attribute_value(CK_SESSION_HANDLE session, | |
| goto bail; | ||
|
|
||
| /* Shm io0: (in/out) [session][obj-handle][attributes] / [status] */ | ||
| ctrl_size = sizeof(session_handle) + sizeof(obj_handle) + sattr.size; | ||
| ctrl_size = sizeof(session_handle) + sizeof(obj_handle); | ||
| if (ADD_OVERFLOW(ctrl_size, sattr.size, &ctrl_size)) | ||
| return CKR_ARGUMENTS_BAD; | ||
|
|
||
| ctrl = ckteec_alloc_shm(ctrl_size, CKTEEC_SHM_INOUT); | ||
| if (!ctrl) { | ||
|
|
@@ -1219,7 +1239,9 @@ CK_RV ck_set_attribute_value(CK_SESSION_HANDLE session, | |
| goto bail; | ||
|
|
||
| /* Shm io0: (in/out) [session][obj-handle][attributes] / [status] */ | ||
| ctrl_size = sizeof(session_handle) + sizeof(obj_handle) + sattr.size; | ||
| ctrl_size = sizeof(session_handle) + sizeof(obj_handle); | ||
| if (ADD_OVERFLOW(ctrl_size, sattr.size, &ctrl_size)) | ||
| return CKR_ARGUMENTS_BAD; | ||
|
|
||
| ctrl = ckteec_alloc_shm(ctrl_size, CKTEEC_SHM_INOUT); | ||
| if (!ctrl) { | ||
|
|
@@ -1271,7 +1293,9 @@ CK_RV ck_copy_object(CK_SESSION_HANDLE session, | |
| goto bail; | ||
|
|
||
| /* Shm io0: (in/out) [session][obj-handle][attributes] / [status] */ | ||
| ctrl_size = sizeof(session_handle) + sizeof(obj_handle) + sattr.size; | ||
| ctrl_size = sizeof(session_handle) + sizeof(obj_handle); | ||
| if (ADD_OVERFLOW(ctrl_size, sattr.size, &ctrl_size)) | ||
| return CKR_ARGUMENTS_BAD; | ||
|
|
||
| ctrl = ckteec_alloc_shm(ctrl_size, CKTEEC_SHM_INOUT); | ||
| if (!ctrl) { | ||
|
|
@@ -1350,8 +1374,10 @@ CK_RV ck_derive_key(CK_SESSION_HANDLE session, | |
| * (in) [session-handle][obj-handle][serialized-mecha][serialized-attributes] | ||
| * (out) [status] | ||
| */ | ||
| ctrl_size = sizeof(session_handle) + sizeof(obj_handle) + smecha.size + | ||
| sattr.size; | ||
| ctrl_size = sizeof(session_handle) + sizeof(obj_handle); | ||
| if (ADD_OVERFLOW(ctrl_size, smecha.size, &ctrl_size) || | ||
| ADD_OVERFLOW(ctrl_size, sattr.size, &ctrl_size)) | ||
| return CKR_ARGUMENTS_BAD; | ||
|
|
||
| ctrl = ckteec_alloc_shm(ctrl_size, CKTEEC_SHM_INOUT); | ||
| if (!ctrl) { | ||
|
|
@@ -1474,8 +1500,10 @@ CK_RV ck_generate_key_pair(CK_SESSION_HANDLE session, | |
| * [serialized-priv_attribs] | ||
| * (out) [status] | ||
| */ | ||
| ctrl_size = sizeof(session_handle) + smecha.size + pub_sattr.size + | ||
| priv_sattr.size; | ||
| if (ADD_OVERFLOW(sizeof(session_handle), smecha.size, &ctrl_size) || | ||
| ADD_OVERFLOW(ctrl_size, pub_sattr.size, &ctrl_size) || | ||
| ADD_OVERFLOW(ctrl_size, priv_sattr.size, &ctrl_size)) | ||
| return CKR_ARGUMENTS_BAD; | ||
|
|
||
| ctrl = ckteec_alloc_shm(ctrl_size, CKTEEC_SHM_INOUT); | ||
| if (!ctrl) { | ||
|
|
@@ -1557,7 +1585,9 @@ CK_RV ck_wrap_key(CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, | |
| * (out) [status] | ||
| */ | ||
| ctrl_size = sizeof(session_handle) + sizeof(wrp_key_handle) + | ||
| sizeof(key_handle) + smecha.size; | ||
| sizeof(key_handle); | ||
| if (ADD_OVERFLOW(ctrl_size, smecha.size, &ctrl_size)) | ||
| return CKR_ARGUMENTS_BAD; | ||
|
|
||
| ctrl = ckteec_alloc_shm(ctrl_size, CKTEEC_SHM_INOUT); | ||
| if (!ctrl) { | ||
|
|
@@ -1647,8 +1677,10 @@ CK_RV ck_unwrap_key(CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism, | |
| * [serialized-attributes] | ||
| * (out) [status] | ||
| */ | ||
| ctrl_size = sizeof(session_handle) + sizeof(unwrapping_key_handle) + | ||
| smecha.size + sattr.size; | ||
| ctrl_size = sizeof(session_handle) + sizeof(unwrapping_key_handle); | ||
| if (ADD_OVERFLOW(ctrl_size, smecha.size, &ctrl_size) || | ||
| ADD_OVERFLOW(ctrl_size, sattr.size, &ctrl_size)) | ||
| return CKR_ARGUMENTS_BAD; | ||
|
|
||
| ctrl = ckteec_alloc_shm(ctrl_size, CKTEEC_SHM_INOUT); | ||
| if (!ctrl) { | ||
|
|
||
Oops, something went wrong.
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 believe
<stdint.h>should be included inlocal_utils.hinsteadThere 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.
Would make sense.
That said,
limits.his not needed here, can be removed.