LOW 3.8

CVE-2026-40528: OpenSC Buffer Overflow in pkcs15-init Profile Parser

OpenSC, a widely-used open-source library for working with smart cards and cryptographic tokens, contains a buffer overflow vulnerability in its profile configuration parser. When OpenSC's pkcs15-init tool processes a maliciously crafted configuration file, it can be tricked into copying more data than a buffer can hold, corrupting memory. An attacker would need local access to supply the malicious file and convince a user to run the initialization tool, but successful exploitation could allow memory corruption and potential code execution.

Source data · NVD / CISA · public domain

CVSS
3.1 · 3.8 LOW · CVSS:3.1/AV:P/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:L
Weaknesses (CWE)
CWE-121, CWE-122
Affected products
1 configuration(s)
Published / Modified
2026-05-29 / 2026-06-17

NVD description (verbatim)

OpenSC before 0.27.0, fixed in commit 0358817, contains a stack and heap buffer overrun vulnerability in the do_key_value() function in src/pkcs15init/profile.c that allows attackers to corrupt memory by supplying a crafted profile configuration file. During pkcs15-init invocation, a key value entry beginning with '=' followed by more than sizeof(keybuf) characters is copied into keybuf via memcpy without a length check, causing both stack and heap buffer overruns.

2 reference(s) · View on NVD →

SEC.co analysis · AI-assisted, reviewed against source

Technical summary

CVE-2026-40528 is a stack and heap buffer overrun in the do_key_value() function within src/pkcs15init/profile.c. The vulnerability exists because the function uses memcpy to copy a key value entry into a fixed-size buffer (keybuf) without validating the length. Specifically, when a profile configuration entry begins with '=' and is followed by more than sizeof(keybuf) characters, the copy operation overflows both the stack-allocated buffer and adjacent heap memory. This occurs during pkcs15-init execution when processing profile files. The issue is resolved in commit 0358817, incorporated into OpenSC version 0.27.0.

Business impact

For organizations using OpenSC for smart card or certificate management, this vulnerability presents a local privilege escalation and code execution risk if an attacker can influence the profile configuration files used by administrative staff. The threat is moderate for environments where pkcs15-init is run as root or with elevated privileges, particularly in PKI or identity management workflows. However, the requirement for local file access and user interaction significantly reduces exposure in well-segmented networks. Organizations relying on OpenSC for hardware token provisioning should prioritize this for remediation.

Affected systems

OpenSC versions before 0.27.0 are affected. Any system running pkcs15-init from an earlier version is vulnerable. This includes Linux distributions packaging OpenSC, BSD variants, and macOS systems used for certificate or key initialization on smart cards and USB tokens. Windows systems using OpenSC for cryptographic operations are also potentially affected, depending on the build and deployment model.

Exploitability

Exploitation requires local access to the system and the ability to write or modify an OpenSC profile configuration file—typically in a location where pkcs15-init will read it. An attacker must also convince or trick a user into running pkcs15-init with the malicious profile. The CVSS score of 3.8 reflects this restricted attack surface: physical proximity or local access is required (AV:P), exploitation demands specific conditions (AC:H), and user interaction is necessary (UI:R). Public exploit code is not known to exist, reducing immediate threat severity.

Remediation

Upgrade OpenSC to version 0.27.0 or later. For organizations unable to patch immediately, restrict write access to OpenSC profile directories, limit who can run pkcs15-init, and audit profile files for unexpected modifications. In highly sensitive environments, consider disabling or isolating pkcs15-init execution to air-gapped or hardened systems.

Patch guidance

Verify your OpenSC version using `opensc-tool --version` or by checking your package manager. Upgrade through your Linux distribution's package repository (apt, yum, brew, etc.) or download the latest source from the OpenSC GitHub repository. Verify the patch by confirming commit 0358817 is present in your installation. Test the upgrade in a non-production environment first, particularly if you have active smart card or token initialization workflows.

Detection guidance

Monitor system logs for unexpected invocations of pkcs15-init or other OpenSC initialization tools, especially outside scheduled maintenance windows. Check for file integrity alerts on OpenSC profile directories. If feasible, enable audit logging on profile configuration files to detect tampering. Network monitoring is of limited value here since the attack is local; focus on host-based detection of unauthorized profile modifications.

Why prioritize this

Although rated LOW severity by CVSS, this vulnerability merits prompt attention for organizations actively using OpenSC for certificate or token management. The requirement for local access limits exploitability, but memory corruption in cryptographic software can have outsized consequences if successfully weaponized. Prioritize this for teams managing PKI infrastructure or issuing smart cards; deprioritize for endpoints where OpenSC is installed but not actively used.

Risk score, explained

The CVSS 3.1 score of 3.8 reflects a low overall risk due to multiple mitigating factors: the attack vector is physical or local (AV:P), the attack complexity is high (AC:H), and user interaction is required (UI:R). While the confidentiality, integrity, and availability impacts are all low (L), the vulnerability still allows memory corruption. The score correctly captures that casual or opportunistic exploitation is unlikely, but determined or insider attackers with local access pose a real threat.

Frequently asked questions

What is pkcs15-init and why would we be using it?

pkcs15-init is the OpenSC tool for initializing and provisioning smart cards and cryptographic tokens (USB keys, HSM cards, etc.). Organizations managing digital certificates, multi-factor authentication tokens, or public key infrastructure use this tool during token issuance and configuration. If your organization doesn't actively issue or manage smart cards, you may not be affected.

Can this vulnerability be exploited remotely?

No. The CVSS vector AV:P (Physical/local) and the requirement to supply a malicious profile file mean remote exploitation is not feasible. An attacker must have local system access or the ability to modify files on the system where pkcs15-init runs.

What happens if the memory corruption is successful?

In the worst case, an attacker could achieve arbitrary code execution with the privileges of the user running pkcs15-init. If run as root or with elevated privileges, this would grant full system compromise. However, the high complexity (AC:H) means triggering reliable code execution is non-trivial and may require specific system memory layouts or additional knowledge of the target environment.

Do we need to reissue certificates or tokens because of this vulnerability?

No. This vulnerability is in the initialization tool, not in the cryptographic material itself. Tokens issued before or after patching are unaffected. You only need to ensure pkcs15-init is updated before issuing new tokens or re-provisioning existing ones.

This analysis is based on the CVE record and public OpenSC advisory information current as of the publication date. Security landscapes evolve; refer to the official OpenSC GitHub repository and your vendor advisories for the most current patch and compatibility guidance. No attempt to confirm exploitability claims has been made in this analysis. Organizations should perform their own risk assessment based on their specific deployment and threat model. Source: NVD (public-domain), retrieved 2026-07-07. Analysis generated by SEC.co (claude-haiku-4-5).