File opensc-CVE-2024-8443.patch of Package opensc.35664
commit b28a3cef416fcfb92fbb9ea7fd3c71df52c6c9fc
Author: Jakub Jelen <jjelen@redhat.com>
Date: Mon Aug 12 19:02:14 2024 +0200
openpgp: Do not accept non-matching key responses
When generating RSA key pair using PKCS#15 init, the driver could accept
responses relevant to ECC keys, which made further processing in the
pkcs15-init failing/accessing invalid parts of structures.
Thanks oss-fuzz!
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=71010
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Index: opensc-0.19.0/src/libopensc/card-openpgp.c
===================================================================
--- opensc-0.19.0.orig/src/libopensc/card-openpgp.c
+++ opensc-0.19.0/src/libopensc/card-openpgp.c
@@ -2296,16 +2296,26 @@ pgp_calculate_and_store_fingerprint(sc_c
/* update the blob containing fingerprints (00C5) */
sc_log(card->ctx, "Update the blob containing fingerprints (00C5)");
fpseq_blob = pgp_find_blob(card, 0x00C5);
- if (!fpseq_blob) {
- sc_log(card->ctx, "Not found 00C5");
+
+ if (fpseq_blob == NULL) {
+ r = SC_ERROR_OUT_OF_MEMORY;
+ sc_log(card->ctx, "Not found 00C5");
+ goto exit;
+ }
+ if (20 * key_info->keytype > fpseq_blob->len) {
+ r = SC_ERROR_OBJECT_NOT_VALID;
+ sc_log(card->ctx, "The 00C5 blob is not large enough");
goto exit;
- }
+ }
+
/* save the fingerprints sequence */
newdata = malloc(fpseq_blob->len);
- if (!newdata) {
+ if (newdata == NULL) {
+ r = SC_ERROR_OUT_OF_MEMORY;
sc_log(card->ctx, "Not enough memory to update fingerprints blob.");
goto exit;
}
+
memcpy(newdata, fpseq_blob->data, fpseq_blob->len);
/* move p to the portion holding the fingerprint of the current key */
p = newdata + 20*(key_info->keytype - 1);