Skip to content
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

libckteec: Fix CK_ULONG conversions in C_GetTokenInfo() #367

Merged
merged 2 commits into from
Jan 12, 2024

Conversation

vesajaaskelainen
Copy link
Contributor

When running in 64 bit CPU things like ulMaxSessionCount would get value of 4294967295 instead of ~0.

This fixes problem with https://github.com/latchset/pkcs11-provider usage.

Related issue in pkcs11-provider project:
latchset/pkcs11-provider#312

Test case for this:
OP-TEE/optee_test#718

info->ulTotalPublicMemory = TO_CK_ULONG(ta_info->total_public_memory);
info->ulFreePublicMemory = TO_CK_ULONG(ta_info->free_public_memory);
info->ulTotalPrivateMemory = TO_CK_ULONG(ta_info->total_private_memory);
info->ulFreePrivateMemory = TO_CK_ULONG(ta_info->free_private_memory);
Copy link
Contributor

@etienne-lms etienne-lms Dec 7, 2023

Choose a reason for hiding this comment

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

I'm not found of using singed signed/unsigned conversion to treat 32b/64b special case CK_UNAVAILABLE_INFORMATION.
I would prefer an explicit conversion here:

 static CK_ULONG maybe_unavail(uint32_t ta_value)
 {
 	if (ta_value == PKCS11_CK_UNAVAILABLE_INFORMATION)
 		return CK_UNAVAILABLE_INFORMATION;
 	else
		return ta_value;
 }

(edited: fix typo + i think the cast is useless)

Also, as per the spec, this specific value does not apply to ulMaxPinLen and ulMinPinLen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. Moved helper also to pkcs11_token.c.

Thanks for spotting the "small print" about CK_UNAVAILABLE_INFORMATION in CK_TOKEN_INFO.

Also fixed the pin fields.

@vesajaaskelainen
Copy link
Contributor Author

My laptop got broken and is in service and my dev environment is in there. I try to do the changes as soon as possible.

@vesajaaskelainen vesajaaskelainen force-pushed the pkcs11-fix-get-token-info branch from 9b76a10 to 01c69d8 Compare December 22, 2023 07:52
@vesajaaskelainen
Copy link
Contributor Author

Addressed review comments and rebased the PR.

@etienne-lms
Copy link
Contributor

Reviewed-by: Etienne Carriere <etienne.carriere@foss.st.com>

On 64 bit systems uint32_t cannot handle CK_ULONG defined
CK_UNAVAILABLE_INFORMATION.

This adds helper maybe_unavail() to assist in conversion.

Signed-off-by: Vesa Jääskeläinen <vesa.jaaskelainen@vaisala.com>
Reviewed-by: Etienne Carriere <etienne.carriere@foss.st.com>
When running in 64 bit CPU things like ulMaxSessionCount would get value
of 4294967295 instead of ~0.

Adjust all other CK_ULONG fields supporting CK_UNAVAILABLE_INFORMATION.

Signed-off-by: Vesa Jääskeläinen <vesa.jaaskelainen@vaisala.com>
Reviewed-by: Etienne Carriere <etienne.carriere@foss.st.com>
@vesajaaskelainen vesajaaskelainen force-pushed the pkcs11-fix-get-token-info branch from 01c69d8 to 3ea8ba2 Compare January 12, 2024 12:47
@vesajaaskelainen
Copy link
Contributor Author

Reviewed-by: Etienne Carriere <etienne.carriere@foss.st.com>

Thanks for the review!

Applied tags and rebased on top of master and tested it.

@jforissier jforissier merged commit 333e512 into OP-TEE:master Jan 12, 2024
3 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.

3 participants