CVE-2026-40510 Overview
CVE-2026-40510 is a stack buffer overflow vulnerability in OpenSC, an open source toolkit for working with smart cards and cryptographic tokens. The flaw resides in the piv_process_history() function within src/libopensc/card-piv.c. A physically present attacker can trigger memory corruption by presenting a crafted Personal Identity Verification (PIV) smart card or USB device that returns a URL field longer than 118 bytes in the Key History Object ASN.1 response. The issue is classified under [CWE-121: Stack-based Buffer Overflow] and affects OpenSC versions prior to 0.27.0-rc1. The vulnerability was fixed in commit 3f24f0b.
Critical Impact
Physical attackers presenting a malicious PIV smart card or USB token can corrupt stack memory in OpenSC, potentially leading to crashes or limited memory tampering on the host workstation.
Affected Products
- OpenSC versions before 0.27.0-rc1
- The vulnerable code path: piv_process_history() in src/libopensc/card-piv.c
- Systems consuming PIV smart cards or USB tokens via OpenSC libraries
Discovery Timeline
- 2026-05-29 - CVE-2026-40510 published to the National Vulnerability Database (NVD)
- 2026-06-03 - Last updated in NVD database
Technical Details for CVE-2026-40510
Vulnerability Analysis
The vulnerability exists in the PIV card handling logic of OpenSC. When OpenSC processes a Key History Object returned by a PIV-compatible smart card, the piv_process_history() function parses ASN.1-encoded fields, including a URL field that points to off-card certificate storage. The function copies this URL into a fixed-size stack buffer without enforcing length boundaries. When the URL field exceeds 118 bytes, the copy overruns the buffer, corrupting adjacent stack memory.
Exploitation requires physical access. The attacker must connect a crafted smart card or USB device that emulates a PIV applet returning the malicious ASN.1 response. User interaction is also required, as a victim must initiate card processing through an application that links against OpenSC. The impact is limited to memory corruption on the local host, with no network attack surface.
Root Cause
The root cause is missing bounds validation on attacker-controlled ASN.1 data. The piv_process_history() routine trusts the length of the URL field returned by the card and copies it into a stack-allocated buffer sized for typical PIV responses. The Key History Object specification does not enforce a hard URL length limit at the parser level, allowing oversized fields to overflow the destination buffer [CWE-121].
Attack Vector
The attack vector is physical. An attacker fabricates a smart card or USB device that returns an oversized URL in the Key History Object during PIV enumeration. When the victim inserts the device and an OpenSC-based application reads card metadata, piv_process_history() is invoked and the overflow triggers. The vulnerability is most relevant to environments where users routinely accept untrusted smart cards or removable cryptographic tokens. See the VulnCheck Security Advisory for additional technical context.
Detection Methods for CVE-2026-40510
Indicators of Compromise
- Unexpected crashes or stack corruption errors in processes linking libopensc (for example, pkcs11-tool, opensc-tool, browser PKCS#11 modules)
- Insertion of unknown PIV smart cards or USB cryptographic tokens on hosts running OpenSC
- Anomalous PC/SC service activity following insertion of a removable smart card device
Detection Strategies
- Inventory hosts running OpenSC and identify installed versions earlier than 0.27.0-rc1
- Monitor application crash telemetry for segmentation faults or stack-smashing protector aborts within OpenSC-linked binaries
- Audit USB and smart card insertion events through endpoint logging and correlate with subsequent process failures
Monitoring Recommendations
- Enable kernel and system audit logging for USB device attachment events
- Collect application crash dumps from workstations that interact with smart cards
- Track package versions for opensc across managed endpoints using configuration management tooling
How to Mitigate CVE-2026-40510
Immediate Actions Required
- Upgrade OpenSC to version 0.27.0-rc1 or later, which includes the fix in commit 3f24f0b
- Restrict the use of untrusted or unknown PIV smart cards and USB cryptographic tokens on managed endpoints
- Apply USB device control policies to limit smart card readers and tokens to approved hardware
Patch Information
The vulnerability is fixed in OpenSC commit 3f24f0b48a481a8cf2e46059d8238a283ddc1c13, merged via GitHub Pull Request #3558. The corresponding commit is available at the OpenSC GitHub repository. Administrators should update to 0.27.0-rc1 or any subsequent release that includes this commit.
Workarounds
- Disable PIV card support in OpenSC configuration where the feature is not required
- Enforce physical security controls limiting access to workstations with smart card readers
- Use endpoint device control policies to block unknown USB-class smart card devices
# Verify installed OpenSC version on Linux
opensc-tool --version
# Example: upgrade OpenSC on Debian/Ubuntu after distribution package update
sudo apt-get update && sudo apt-get install --only-upgrade opensc
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.


