|
| 1 | +From b23aa406f96b773fc2c8cc2cf63451f59a435350 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Werner Koch <wk@gnupg.org> |
| 3 | +Date: Mon, 26 Jan 2026 11:13:44 +0100 |
| 4 | +Subject: [PATCH] tpm: Fix possible buffer overflow in PKDECRYPT |
| 5 | + |
| 6 | +* tpm2d/tpm2.c (tpm2_ecc_decrypt): Bail out on too long CIPHERTEXT. |
| 7 | +(tpm2_rsa_decrypt): Ditto. |
| 8 | +-- |
| 9 | + |
| 10 | +GnuPG-bug-id: 8045 |
| 11 | +Co-authored-by: NIIBE Yutaka <gniibe@fsij.org> |
| 12 | +Reported-by: OpenAI Security Research |
| 13 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 14 | +Upstream-reference: https://github.com/gpg/gnupg/commit/93fa34d9a346.patch |
| 15 | +--- |
| 16 | + tpm2d/tpm2.c | 22 +++++++++++++++++++++- |
| 17 | + 1 file changed, 21 insertions(+), 1 deletion(-) |
| 18 | + |
| 19 | +diff --git a/tpm2d/tpm2.c b/tpm2d/tpm2.c |
| 20 | +index 3e908dd..cd0347c 100644 |
| 21 | +--- a/tpm2d/tpm2.c |
| 22 | ++++ b/tpm2d/tpm2.c |
| 23 | +@@ -917,10 +917,20 @@ tpm2_ecc_decrypt (ctrl_t ctrl, TSS_CONTEXT *tssc, TPM_HANDLE key, |
| 24 | + size_t len; |
| 25 | + int ret; |
| 26 | + |
| 27 | ++#if defined(TPM2_MAX_ECC_KEY_BYTES) /* Intel stack */ |
| 28 | ++ if (ciphertext_len > 2*TPM2_MAX_ECC_KEY_BYTES + 1) |
| 29 | ++ return GPG_ERR_TOO_LARGE; |
| 30 | ++#elif defined(MAX_ECC_KEY_BYTES) /* IBM stack */ |
| 31 | ++ if (ciphertext_len > 2*MAX_ECC_KEY_BYTES + 1) |
| 32 | ++ return GPG_ERR_TOO_LARGE; |
| 33 | ++#else |
| 34 | ++# error TMP2 header are not correctly installed |
| 35 | ++#endif |
| 36 | ++ |
| 37 | + /* This isn't really a decryption per se. The ciphertext actually |
| 38 | + * contains an EC Point which we must multiply by the private key number. |
| 39 | + * |
| 40 | +- * The reason is to generate a diffe helman agreement on a shared |
| 41 | ++ * The reason is to generate a diffie-hellman agreement on a shared |
| 42 | + * point. This shared point is then used to generate the per |
| 43 | + * session encryption key. |
| 44 | + */ |
| 45 | +@@ -976,6 +986,16 @@ tpm2_rsa_decrypt (ctrl_t ctrl, TSS_CONTEXT *tssc, TPM_HANDLE key, |
| 46 | + TPM_HANDLE ah; |
| 47 | + char *auth; |
| 48 | + |
| 49 | ++#if defined(TPM2_MAX_RSA_KEY_BYTES) /* Intel stack */ |
| 50 | ++ if (ciphertext_len > TPM2_MAX_RSA_KEY_BYTES) |
| 51 | ++ return GPG_ERR_TOO_LARGE; |
| 52 | ++#elif defined(MAX_RSA_KEY_BYTES) /* IBM stack */ |
| 53 | ++ if (ciphertext_len > MAX_RSA_KEY_BYTES) |
| 54 | ++ return GPG_ERR_TOO_LARGE; |
| 55 | ++#else |
| 56 | ++# error TMP2 header are not correctly installed |
| 57 | ++#endif |
| 58 | ++ |
| 59 | + inScheme.scheme = TPM_ALG_RSAES; |
| 60 | + /* |
| 61 | + * apparent gcrypt error: occasionally rsa ciphertext will |
| 62 | +-- |
| 63 | +2.45.4 |
| 64 | + |
0 commit comments