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

tpm2_linux open() file descriptor 0 should be allowed #365

Closed
radomik opened this issue Jul 31, 2024 · 2 comments · Fixed by #366
Closed

tpm2_linux open() file descriptor 0 should be allowed #365

radomik opened this issue Jul 31, 2024 · 2 comments · Fixed by #366
Assignees

Comments

@radomik
Copy link

radomik commented Jul 31, 2024

Hi,
I'm using older version of WolfTPM but see this part of code is same in newest version.

What my program does is intense usage of TPM2_GetRandom from few threads in parallel, for couple of minutes.

Observation is that in some cases /dev/tpm0 cannot be opened with errno=Success that caused then cascade of errno=Device or resource busy.

As from Linux man for open(0 can be seen that open() valid return value is nonnegative integer, thus 0 is valid value.

On success, open(), openat(), and creat() return the new file
       descriptor (a nonnegative integer).  On error, -1 is returned and
       [errno](https://man7.org/linux/man-pages/man3/errno.3.html) is set to indicate the error.

Suggest to change a condition fro > to >= to:

    fd = open(TPM2_LINUX_DEV, O_RDWR | O_NONBLOCK);
    if (fd >= 0) {
        /* Send the TPM command */

After fix, I see no more issues with my code using wolfTPM library.

@dgarske dgarske self-assigned this Jul 31, 2024
@dgarske
Copy link
Contributor

dgarske commented Jul 31, 2024

Hi @radomik , thank you so much for the detailed report! I'll put up a fix shortly and reference it here.
Thanks, David Garske, wolfSSL

dgarske added a commit to dgarske/wolfTPM that referenced this issue Jul 31, 2024
…cumentation for /dev/tpm0 permissions (fixes wolfSSL#358). Various spelling and documentation cleanups.
@dgarske
Copy link
Contributor

dgarske commented Jul 31, 2024

Hi @radomik , I posted the fix in PR #366.

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 a pull request may close this issue.

2 participants