Skip to content

libckteec: add and use {ADD|SUB|MUL}_OVERFLOW() macros - #421

Closed
etienne-lms wants to merge 2 commits into
OP-TEE:masterfrom
etienne-lms:libckteec-overflow
Closed

libckteec: add and use {ADD|SUB|MUL}_OVERFLOW() macros#421
etienne-lms wants to merge 2 commits into
OP-TEE:masterfrom
etienne-lms:libckteec-overflow

Conversation

@etienne-lms

Copy link
Copy Markdown
Contributor

Add ADD_OVERFLOW(), SUB_OVERFLOW() and MUL_OVERFLOW() helper macros dumped from optee_os util.h [1] and compiler.h [2] and use them to guard against index/buffer overflows.

[1] https://github.com/OP-TEE/optee_os/blob/4.10.0/lib/libutils/ext/include/util.h
[2] https://github.com/OP-TEE/optee_os/blob/4.10.0/lib/libutils/ext/include/compiler.h

Add ADD_OVERFLOW(), SUB_OVERFLOW() and MUL_OVERFLOW() helper macros
dumped from optee_os util.h [1] and compiler.h [3] where released under
the same BSD-2-Clause license terms used in libckteec implementation.

Link: https://github.com/OP-TEE/optee_os/blob/4.10.0/lib/libutils/ext/include/util.h [1]
Link: https://github.com/OP-TEE/optee_os/blob/4.10.0/lib/libutils/ext/include/compiler.h [2]
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Guard against overflow in buffer size before they are allocated.
Guard against overflow in when serializing data send to the TA.
Use *_OVERFLOW() macros where applicable instead of less intuitive
implementation.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>

@jforissier jforissier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @etienne-lms,

Please see one comment below, and also:
s/Guard against overflow in when serializing/Guard against overflow when serializing/

With that fixed:

Reviewed-by: Jerome Forissier <jerome.forissier@arm.com>

Thanks!

* Copyright (c) 2017-2018, Linaro Limited
*/

#include <limits.h>

Copy link
Copy Markdown
Contributor

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 in local_utils.h instead

Copy link
Copy Markdown
Contributor Author

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.h is not needed here, can be removed.

* Copyright (c) 2017-2018, Linaro Limited
*/

#include <limits.h>

Copy link
Copy Markdown
Contributor Author

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.h is not needed here, can be removed.

/* 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;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake. serialize_ck_attributes() ( a few lines above) allocates memory that should be free before returning from this function. goto out would better apply here.

Note: I missed #417 that does the jobs nicely. I'll close my P-R.

@github-actions

Copy link
Copy Markdown

This pull request has been marked as a stale pull request because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment, otherwise this pull request will automatically be closed in 5 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions Bot added the Stale label Aug 27, 2026
@github-actions github-actions Bot closed this Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants