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

Attempted bugfix for potential session reentrancy bug #273

Merged
merged 1 commit into from
Nov 30, 2021

Conversation

tony-iqlusion
Copy link
Member

Context: iqlusioninc/tmkms#37

To summarize, the yubihsm::Client type has internal locking for a Session with the YubiHSM. There is actually very little lock-related code associated with this scheme, but there appears to be a subtle reentrancy bug in pretty much the only function where it could possibly exist: the yubihsm::Client::send_command method.

Based on discussions on iqlusioninc/tmkms#37 the bug definitely seemed to be tied to rekeying the session after a preset number of messages had been sent. It appears there was a reentrancy bug where an RAII guard was still holding the Mutex for the session state, which prevented a subsequent attempt to resent the message from acquiring it.

The solution is to explicitly drop the stale session guard prior to trying to establish a new session.

Context: iqlusioninc/tmkms#37

To summarize, the `yubihsm::Client` type has internal locking for a
`Session` with the YubiHSM. There is actually very little lock-related
code associated with this scheme, but there appears to be a subtle
reentrancy bug in pretty much the only function where it could possibly
exist: the `yubihsm::Client::send_command` method.

Based on discussions on iqlusioninc/tmkms#37 the bug definitely seemed
to be tied to rekeying the session after a preset number of messages had
been sent. It appears there was a reentrancy bug where an RAII guard was
still holding the `Mutex` for the session state, which prevented a
subsequent attempt to resent the message from acquiring it.

The solution is to explicitly drop the stale session guard prior to
trying to establish a new session.
@tony-iqlusion tony-iqlusion requested a review from a team November 30, 2021 00:54
@tony-iqlusion tony-iqlusion merged commit 974b19b into main Nov 30, 2021
@tony-iqlusion tony-iqlusion deleted the session-reentrancy-bug branch November 30, 2021 01:34
@tony-iqlusion tony-iqlusion mentioned this pull request Dec 15, 2021
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