Skip to content

Conversation

@alexhoppus
Copy link
Contributor

@alexhoppus alexhoppus commented Nov 24, 2025

This change fixes an out-of-bounds read in the derive_ta_unique_key_test() oversized extra data test.

The test was calling derive_unique_key() with extra_data_len set to TA_DERIVED_EXTRA_DATA_MAX_SIZE + 1 while passing a much smaller extra_key_data buffer on the stack. In derive_unique_key(), map_tmp_param() used extra_data_len as the memcpy() size, which caused an out-of-bounds read from the source buffer.

The fix is to provide a dedicated extra_key_data_large buffer sized to TA_DERIVED_EXTRA_DATA_MAX_SIZE + 1 and use it for the oversized extra data test.

*/
res = derive_unique_key(session, key1, sizeof(key1), extra_key_data,
res = derive_unique_key(session, key1, sizeof(key1),
extra_key_data_large,
Copy link
Contributor

Choose a reason for hiding this comment

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

I see why the buffer must be large, but I don't see the point with this particular test or even why the PTA must enforce the limit TA_DERIVED_EXTRA_DATA_MAX_SIZE.
@jockebech do you remember?

@github-actions
Copy link

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 pull request at any time.

@github-actions github-actions bot added the Stale label Dec 26, 2025
Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

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

With my comment addressed, please apply:
Reviewed-by: Jens Wiklander <[email protected]>

TEE_MemFill(key2, 0, sizeof(key2));

/*
* Testing limits for extra data size (if this would success, then we
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update this comment. I think removing the "(...)" should be the best.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

derive_ta_unique_key_test() was calling derive_unique_key() with
extra_data_len set to TA_DERIVED_EXTRA_DATA_MAX_SIZE + 1 while passing
a much smaller extra_key_data buffer. map_tmp_param() used the length
as-is in memcpy(), which resulted in an out-of-bounds read from the
source buffer.

Signed-off-by: Aleksandr Iashchenko <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
@github-actions github-actions bot removed the Stale label Dec 31, 2025
@jenswi-linaro jenswi-linaro merged commit 6e479bd into OP-TEE:master Jan 2, 2026
2 checks passed
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.

2 participants