Bug 2240913 (CVE-2023-40661)

Summary: CVE-2023-40661 OpenSC: multiple memory issues with pkcs15-init (enrollment tool)
Product: [Other] Security Response Reporter: TEJ RATHI <trathi>
Component: vulnerabilityAssignee: Product Security <prodsec-ir-bot>
Status: NEW --- QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedKeywords: Security
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: OpenSC 0.24.0-rc1 Doc Type: If docs needed, set a value
Doc Text:
Several memory vulnerabilities were identified within the OpenSC packages, particularly in the card enrollment process using pkcs15-init when a user or administrator enrolls cards. To take advantage of these flaws, an attacker must have physical access to the computer system and employ a custom-crafted USB device or smart card to manipulate responses to APDUs. This manipulation can potentially allow compromise key generation, certificate loading, and other card management operations during enrollment.
Story Points: ---
Clone Of: Environment:
Last Closed: Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 2248099    
Bug Blocks: 2240943    

Description TEJ RATHI 2023-09-27 08:41:15 UTC
Several memory issues that are security relevant that were reported since the release of OpenSC 0.23.0 and that are relevant to the handling the card enrollment process using pkcs15-init.

All of these require physical access to the computer at the time user or administrator would be enrolling the cards (generating keys and loading certificates, other card/token management) operations. The attack requires crafted USB device or smart card that would present the system with specially crafted responses to the APDUs so they are considered a high-complexity and low-severity. This issue is not exploitable just by using a PKCS#11 module as done in most of the end-user deployments.

https://github.com/OpenSC/OpenSC/issues/2792#issuecomment-1674806651
https://github.com/OpenSC/OpenSC/wiki/OpenSC-security-advisories
https://github.com/OpenSC/OpenSC/releases/tag/0.24.0-rc1

Comment 1 TEJ RATHI 2023-09-27 08:51:05 UTC
All memory issues reference bugs:

* Stack buffer overflow in sc_pkcs15_get_lastupdate in pkcs15init
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60769 
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60527

 * Heap buffer overflow in setcos_create_key in pkcs15init
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60672 

 * Heap buffer overflow in cosm_new_file in pkcs15init
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60650 

 * Heap double free in sc_pkcs15_free_object_content
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60616 

 * Stack buffer overflow in cflex_delete_file in pkcs15init
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58932 

 * Heap buffer overflow in sc_hsm_write_ef in pkcs15init
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=56213 

 * Stack buffer overflow while parsing pkcs15 profile files
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=55998 
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=55851

 * Stack buffer overflow in muscle driver in pkcs15init
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54312 

 * Stack buffer overflow in cardos driver in pkcs15init
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=53927

Comment 3 TEJ RATHI 2023-11-06 06:13:51 UTC
Created opensc tracking bugs for this issue:

Affects: fedora-all [bug 2248099]

Comment 4 errata-xmlrpc 2023-12-18 07:38:02 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8

Via RHSA-2023:7876 https://access.redhat.com/errata/RHSA-2023:7876

Comment 5 errata-xmlrpc 2023-12-18 11:01:48 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 9

Via RHSA-2023:7879 https://access.redhat.com/errata/RHSA-2023:7879