Bug 1885950 (CVE-2020-26571)

Summary: CVE-2020-26571 opensc: stack-based buffer overflow in sc_pkcs15emu_gemsafeGPK_init
Product: [Other] Security Response Reporter: Michael Kaplan <mkaplan>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED ERRATA QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedCC: crypto-team, gmazyland, jjelen
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: opensc 0.21.0-rc1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-05-18 20:36:35 UTC 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: 1885951, 1885952, 1887529    
Bug Blocks: 1885958    

Description Michael Kaplan 2020-10-07 10:54:36 UTC
The gemsafe GPK smart card software driver in OpenSC before 0.21.0-rc1 has a stack-based buffer overflow in sc_pkcs15emu_gemsafeGPK_init.

References:

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20612

Comment 1 Michael Kaplan 2020-10-07 10:55:23 UTC
Created opensc tracking bugs for this issue:

Affects: epel-6 [bug 1885951]
Affects: fedora-all [bug 1885952]

Comment 2 Todd Cullum 2020-10-08 19:54:08 UTC
Flaw summary:
In  `sc_pkcs15emu_gemsafeGPK_init()` routine in src/libopensc/pkcs15-gemsafeGPK.c, kinfo was defined as `keyinfo kinfo[8];` but an off-by-one error in loop `for (i = 7; i < 16; i++)` could access up to `kinfo[9]`, causing a stack buffer overflow and passing this to sc_read_record(), potentially causing an out-of-bounds write. The patch declares `keyinfo kinfo[9]` instead.

Upstream patch: https://github.com/OpenSC/OpenSC/commit/ed55fcd2996930bf58b9bb57e9ba7b1f3a753c43

Comment 4 Todd Cullum 2020-10-12 18:24:58 UTC
Mitigation:

This flaw can be mitigated in cases where you can use opensc without the gemsafeGPK driver enabled. In such cases, the vulnerable driver can be disabled by specifying them in /etc/opensc.conf card_drivers field in allowlist fashion.
One such example:

```
app default {
   card_drivers = cac, cac1, PIV-II;
}
```

This would only enable the cac, cac1, and PIV-II smart card drivers, and all others would be disabled, including the gemsafeGPK driver. With the gemsafeGPK driver disabled, this flaw is mitigated. It is important to list all drivers that you need in the card_drivers field so that they are not disabled too.

Comment 5 Jakub Jelen 2020-10-20 16:54:54 UTC
AFAIK, the fix for this issue is the following commit:

https://github.com/OpenSC/OpenSC/commit/ed55fcd2996930bf58b9bb57e9ba7b1f3a753c43

As mentioned in the issue, I was not able to reproduce the issue with the given vectors (and I am not able to reproduce it now either), but the following issue looks very similar:

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22319

Comment 7 errata-xmlrpc 2021-05-18 13:35:16 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8

Via RHSA-2021:1600 https://access.redhat.com/errata/RHSA-2021:1600

Comment 8 Product Security DevOps Team 2021-05-18 20:36:35 UTC
This bug is now closed. Further updates for individual products will be reflected on the CVE page(s):

https://access.redhat.com/security/cve/cve-2020-26571