Skip to content

libckteec: prevent integer overflow in shared memory allocations#417

Open
karnakarreddi wants to merge 2 commits into
OP-TEE:masterfrom
karnakarreddi:fix/liccketeec-overflow
Open

libckteec: prevent integer overflow in shared memory allocations#417
karnakarreddi wants to merge 2 commits into
OP-TEE:masterfrom
karnakarreddi:fix/liccketeec-overflow

Conversation

@karnakarreddi

Copy link
Copy Markdown

Fixes integer overflow in several libckteec callers of ckteec_alloc_shm() and in the PKCS#11 serializer.

@etienne-lms etienne-lms 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.

For commit "libckteec: add {ADD|SUB|MUL}_OVERFLOW() helper macros":

  • Could break the message message into several lines, 80 char/line max IIR?
    (ditto for the 2nd commit)
  • Could you add a reference from where the macros implementation were fetched from, e.g. OP-TEE OS Github URLs? It would be easier for one to find the source.
  • With Co-developed-by, you need to also provide the co-developper Signed-off-by tag. Alternatively use Co-authored-by, that do not require an added S-o-b tag.

@karnakarreddi karnakarreddi force-pushed the fix/liccketeec-overflow branch from 336afb4 to 50b4e52 Compare May 19, 2026 04:36
@karnakarreddi

Copy link
Copy Markdown
Author

For commit "libckteec: add {ADD|SUB|MUL}_OVERFLOW() helper macros":

  • Could break the message message into several lines, 80 char/line max IIR?
    (ditto for the 2nd commit)
  • Could you add a reference from where the macros implementation were fetched from, e.g. OP-TEE OS Github URLs? It would be easier for one to find the source.
  • With Co-developed-by, you need to also provide the co-developper Signed-off-by tag. Alternatively use Co-authored-by, that do not require an added S-o-b tag.

Thanks for the review, @etienne-lms. I've addressed all three points and force-pushed the updated branch. Please take another look when you have a moment.

karnakarreddi and others added 2 commits May 19, 2026 10:48
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]

Co-authored-by: Etienne Carriere <etienne.carriere@st.com>
Signed-off-by: karnakarreddi <thoorpukarnakar@gmail.com>
Guard against overflow in buffer size before allocations and when
serializing data sent to the TA. The overflow guards return
CKR_ARGUMENTS_BAD via the function's existing bail/out cleanup
label so the serializer buffer allocated by
serialize_ck_attributes() and serialize_ck_mecha_params() is
released; the MUL_OVERFLOW() check in ck_find_objects() returns
directly as nothing is allocated above it.

Co-authored-by: Etienne Carriere <etienne.carriere@st.com>
Signed-off-by: karnakarreddi <thoorpukarnakar@gmail.com>
@karnakarreddi karnakarreddi force-pushed the fix/liccketeec-overflow branch from 50b4e52 to 5fd5c03 Compare May 19, 2026 06:55
@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 Jun 19, 2026
@jenswikl

Copy link
Copy Markdown
Contributor

@etienne-lms, are you OK with this PR?

@github-actions github-actions Bot removed the Stale label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants