Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 772410 (CVE-2021-3505) - <dev-libs/libtpms-0.8.2: RSA keys weaker than expected (CVE-2021-3505)
Summary: <dev-libs/libtpms-0.8.2: RSA keys weaker than expected (CVE-2021-3505)
Status: RESOLVED FIXED
Alias: CVE-2021-3505
Product: Gentoo Security
Classification: Unclassified
Component: Vulnerabilities (show other bugs)
Hardware: All Linux
: Normal trivial (vote)
Assignee: Gentoo Security
URL: https://github.com/stefanberger/libtp...
Whiteboard: ~4 [noglsa]
Keywords: PullRequest
Depends on:
Blocks:
 
Reported: 2021-02-24 18:25 UTC by Christopher Byrne
Modified: 2021-04-22 19:45 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Byrne 2021-02-24 18:25:51 UTC
The newest version the dev-libs/libtpms discloses the following problem: 

Note: The TPM 2 implementation returns 2048 bit keys with ~1984 bit
strength due to a bug in the TPM 2 key creation algo that cannot
easily be fixed. The bug is in RsaAjustPrimeCandidate, which is
called before the prime number check.

It'll be be fixed in 0.8.0 (not released yet), but upgrading won't be sufficient. The only way to fix it is to unseal all data, delete the old TPM state file, generate a new one, then reseal the data.
Comment 1 John Helmert III archtester Gentoo Infrastructure gentoo-dev Security 2021-02-25 00:11:08 UTC
Thank you for the report! In, the PR, don't we need 0.8.0 to fix the vulnerability (https://github.com/stefanberger/libtpms/commit/c1f7bf55099fcd427715aa65e130475c6e836a6b)? Looks like there might be other things fixed that might be security-relevant too:

Fix output buffer parameter and size for RSA decryption that could cause
stack corruption under certain circumstances
Fixes to symmetric decryption related to input size check,
defer padding to the user [EVP_CIPHER_CTX_set_padding(ctx, 0)] and
to always use a temporary malloc'ed buffer for decryption
Comment 2 Christopher Byrne 2021-02-25 00:40:06 UTC
Upstream released 0.8.0 a few hours ago. I'm preparing an ebuild for it. Upgrading is necessary but not sufficient though. Any "seeds" generated prior to 0.8.0 will continue to use the flawed algorithm until changed, either through TPM commands or a new state file is created. Either way, any material sealed under the old seeds will be permanently inaccessible after that.
Comment 3 John Helmert III archtester Gentoo Infrastructure gentoo-dev Security 2021-02-25 00:46:52 UTC
(In reply to Salah Coronya from comment #2)
> Upstream released 0.8.0 a few hours ago. I'm preparing an ebuild for it.
> Upgrading is necessary but not sufficient though. Any "seeds" generated
> prior to 0.8.0 will continue to use the flawed algorithm until changed,
> either through TPM commands or a new state file is created. Either way, any
> material sealed under the old seeds will be permanently inaccessible after
> that.

I'm not at all familiar with this technology, is it at all possible to mitigate the issue on older seeds (maybe by using new seeds, somehow?)? Would it be possible to provide a short mitigation path via elog or similar (or link to somewhere that tells how to do it)?
Comment 4 Christopher Byrne 2021-02-25 03:52:48 UTC
There no really good generic way to migrate. Anyone using RSA keys and the virtual TPM 2 functionality (via swtpm) would need to decrypt (or have backups) of affected data, generate new seeds (most likely by deleting the state file and recreating it, then reeecrypt. There are TPM 2 commands to change the seeds, and the very least the Owner one would need to be changed vith a tpm2_clear - which has other side effects like clearing the NVRAM. The other seeds are more complicated).

I think the best that can be done is to inform the user (via elog?) that versions of libtpms before 0.8.0 generate weaker than expected TPM 2.0 RSA keys due to a flawed key creation algorithm. Because fixing this would render existing sealed data inaccessible, to use the corrected algorithm, the old TPM state file must be deleted and a new TPM state file created for that. Any data still sealed to the virtual TPM will be rendered permanently inaccessible after that.
Comment 5 John Helmert III archtester Gentoo Infrastructure gentoo-dev Security 2021-02-27 01:03:22 UTC
> I think the best that can be done is to inform the user (via elog?) that
> versions of libtpms before 0.8.0 generate weaker than expected TPM 2.0 RSA
> keys due to a flawed key creation algorithm. Because fixing this would
> render existing sealed data inaccessible, to use the corrected algorithm,
> the old TPM state file must be deleted and a new TPM state file created for
> that. Any data still sealed to the virtual TPM will be rendered permanently
> inaccessible after that.

Yes, a short elog message explaining the incompatibility and a link to the bug would be great.
Comment 6 Christopher Byrne 2021-03-02 18:05:05 UTC
Upstream has released 0.8.2:

CryptSym: fix AES output IV
A CVE has been filed for this bugfix. Unfortunately multi-step encrypted
data won't decrypt anymore but are now compatible with other TPM 2 devices.
Comment 7 Larry the Git Cow gentoo-dev 2021-03-06 15:13:01 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ac52bd092b79ddbbaa2be30822d27dc4eb563f0c

commit ac52bd092b79ddbbaa2be30822d27dc4eb563f0c
Author:     Salah Coronya <salah.coronya@gmail.com>
AuthorDate: 2021-02-27 02:36:28 +0000
Commit:     Joonas Niilola <juippis@gentoo.org>
CommitDate: 2021-03-06 15:12:52 +0000

    dev-libs/libtpms: Bump to 0.8.2
    
    Bug: https://bugs.gentoo.org/772410
    Package-Manager: Portage-3.0.13, Repoman-3.0.2
    Signed-off-by: Salah Coronya <salah.coronya@gmail.com>
    Signed-off-by: Joonas Niilola <juippis@gentoo.org>

 dev-libs/libtpms/Manifest                          |  1 +
 .../files/libtpms-0.8.0-Remove-WError.patch        | 13 ++++++
 dev-libs/libtpms/libtpms-0.8.2.ebuild              | 48 ++++++++++++++++++++++
 3 files changed, 62 insertions(+)
Comment 8 John Helmert III archtester Gentoo Infrastructure gentoo-dev Security 2021-03-06 15:16:25 UTC
Please cleanup. Given the incompatibility it should be fine to wait just a bit.
Comment 9 Mauro Matteo Cascella 2021-04-13 11:01:35 UTC
Hello Salah,

(In reply to Salah Coronya from comment #6)
> A CVE has been filed for this bugfix. Unfortunately multi-step encrypted
> data won't decrypt anymore but are now compatible with other TPM 2 devices.

Was the CVE assigned for this issue? If not, I can go ahead and request a new one if you wish.
Comment 10 Christopher Byrne 2021-04-13 14:49:21 UTC
Its CVE-2021-3446
Comment 11 Mauro Matteo Cascella 2021-04-13 16:27:57 UTC
(In reply to Salah Coronya from comment #10)
> Its CVE-2021-3446

Actually, I meant a new CVE for the original issue reported with this bug (RSA keys weaker than expected). That is different from CVE-2021-3446, isn't it?

Specifically, it looks like the issue discussed here was fixed in libtpms v0.8.0 (April 2020):

https://github.com/stefanberger/libtpms/commit/625171be0c8225824740b5d0fb7e8562f6a1c6a8
https://github.com/stefanberger/libtpms/commit/c1f7bf55099fcd427715aa65e130475c6e836a6b

While CVE-2021-3446 was fixed recently in v0.8.2 (March 2021):

https://github.com/stefanberger/libtpms/commit/32c159ab53db703749a8f90430cdc7b20b00975e

I'm wondering if we should get a CVE for the "weak RSA key" issue, even though it doesn't seem feasible to backport the fix to older versions (0.7.x).
Comment 12 Christopher Byrne 2021-04-13 17:12:54 UTC
Yeah, different issue. The RSA problem is described here: https://github.com/stefanberger/libtpms/issues/183 . Upstream never requested a CVE for this issue. If you feel one is needed, go ahead.
Comment 13 John Helmert III archtester Gentoo Infrastructure gentoo-dev Security 2021-04-22 19:45:19 UTC
Ah, I see this has been cleaned up. All done, thanks!