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

Return on other errors at pkcs11_get_session #579

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

rafajunio
Copy link

The C_OpenSession function can return several error codes, as seen in the open-source implementation of pkcs11_api in the OP-TEE client repository: OP-TEE optee_client - pkcs11_api.c#L278

Some of these errors include:

  • CKR_CRYPTOKI_NOT_INITIALIZED
  • CKR_DEVICE_ERROR
  • CKR_DEVICE_MEMORY
  • CKR_DEVICE_REMOVED
  • CKR_FUNCTION_FAILED
  • CKR_GENERAL_ERROR
  • CKR_HOST_MEMORY
  • CKR_SESSION_COUNT
  • CKR_SESSION_PARALLEL_NOT_SUPPORTED
  • CKR_SESSION_READ_WRITE_SO_EXISTS
  • CKR_SLOT_ID_INVALID
  • CKR_TOKEN_NOT_PRESENT
  • CKR_TOKEN_NOT_RECOGNIZED
  • CKR_TOKEN_WRITE_PROTECTED
  • CKR_ARGUMENTS_BAD

If any of these errors occur, the function currently does not return, causing it to be stuck at pthread_cond_wait, leading to a freeze in the caller process that uses the libp11 API.

This commit ensures that when these errors are encountered, the function properly returns, preventing potential deadlocks.

The `C_OpenSession` function can return several error codes, as seen in the open-source implementation of `pkcs11_api` in the OP-TEE client repository:
[OP-TEE optee_client - pkcs11_api.c#L278](https://github.com/OP-TEE/optee_client/blob/e79465eea85adc18a4075529ee20a16dfa263aea/libckteec/src/pkcs11_api.c#L278)

Some of these errors include:

- `CKR_CRYPTOKI_NOT_INITIALIZED`
- `CKR_DEVICE_ERROR`
- `CKR_DEVICE_MEMORY`
- `CKR_DEVICE_REMOVED`
- `CKR_FUNCTION_FAILED`
- `CKR_GENERAL_ERROR`
- `CKR_HOST_MEMORY`
- `CKR_SESSION_COUNT`
- `CKR_SESSION_PARALLEL_NOT_SUPPORTED`
- `CKR_SESSION_READ_WRITE_SO_EXISTS`
- `CKR_SLOT_ID_INVALID`
- `CKR_TOKEN_NOT_PRESENT`
- `CKR_TOKEN_NOT_RECOGNIZED`
- `CKR_TOKEN_WRITE_PROTECTED`
- `CKR_ARGUMENTS_BAD`

If any of these errors occur, the function currently does not return, causing it to be stuck at `pthread_cond_wait`, leading to a freeze in the caller process that uses the `libp11` API.

This commit ensures that when these errors are encountered, the function properly returns, preventing potential deadlocks.
@mtrojnar mtrojnar merged commit 967fb11 into OpenSC:master Feb 10, 2025
11 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