From 0086e3b48155bfd7f71382f6e5122c6b6f283985948dfd9e6246ae88e0868944 Mon Sep 17 00:00:00 2001 From: Otto Hollmann Date: Thu, 1 Jun 2023 13:53:40 +0000 Subject: [PATCH] Accepting request 1090292 from home:ohollmann:branches:security:chipcard - Security Fix: [CVE-2023-2977, bsc#1211894] * opensc: out of bounds read in pkcs15 cardos_have_verifyrc_package() * Add opensc-CVE-2023-2977.patch OBS-URL: https://build.opensuse.org/request/show/1090292 OBS-URL: https://build.opensuse.org/package/show/security:chipcard/opensc?expand=0&rev=73 --- opensc-CVE-2023-2977.patch | 49 ++++++++++++++++++++++++++++++++++++++ opensc.changes | 7 ++++++ opensc.spec | 7 +++--- 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 opensc-CVE-2023-2977.patch diff --git a/opensc-CVE-2023-2977.patch b/opensc-CVE-2023-2977.patch new file mode 100644 index 0000000..c6a4966 --- /dev/null +++ b/opensc-CVE-2023-2977.patch @@ -0,0 +1,49 @@ +From 3bf3ab2f9091f984cda6dd910654ccbbe3f06a40 Mon Sep 17 00:00:00 2001 +From: fullwaywang +Date: Mon, 29 May 2023 10:38:48 +0800 +Subject: [PATCH] pkcs15init: correct left length calculation to fix buffer + overrun bug. Fixes #2785 + +--- + src/pkcs15init/pkcs15-cardos.c | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +diff --git a/src/pkcs15init/pkcs15-cardos.c b/src/pkcs15init/pkcs15-cardos.c +index 9715cf390f..f41f73c349 100644 +--- a/src/pkcs15init/pkcs15-cardos.c ++++ b/src/pkcs15init/pkcs15-cardos.c +@@ -872,7 +872,7 @@ static int cardos_have_verifyrc_package(sc_card_t *card) + sc_apdu_t apdu; + u8 rbuf[SC_MAX_APDU_BUFFER_SIZE]; + int r; +- const u8 *p = rbuf, *q; ++ const u8 *p = rbuf, *q, *pp; + size_t len, tlen = 0, ilen = 0; + + sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x88); +@@ -888,13 +888,13 @@ static int cardos_have_verifyrc_package(sc_card_t *card) + return 0; + + while (len != 0) { +- p = sc_asn1_find_tag(card->ctx, p, len, 0xe1, &tlen); +- if (p == NULL) ++ pp = sc_asn1_find_tag(card->ctx, p, len, 0xe1, &tlen); ++ if (pp == NULL) + return 0; + if (card->type == SC_CARD_TYPE_CARDOS_M4_3) { + /* the verifyRC package on CardOS 4.3B use Manufacturer ID 0x01 */ + /* and Package Number 0x07 */ +- q = sc_asn1_find_tag(card->ctx, p, tlen, 0x01, &ilen); ++ q = sc_asn1_find_tag(card->ctx, pp, tlen, 0x01, &ilen); + if (q == NULL || ilen != 4) + return 0; + if (q[0] == 0x07) +@@ -902,7 +902,7 @@ static int cardos_have_verifyrc_package(sc_card_t *card) + } else if (card->type == SC_CARD_TYPE_CARDOS_M4_4) { + /* the verifyRC package on CardOS 4.4 use Manufacturer ID 0x03 */ + /* and Package Number 0x02 */ +- q = sc_asn1_find_tag(card->ctx, p, tlen, 0x03, &ilen); ++ q = sc_asn1_find_tag(card->ctx, pp, tlen, 0x03, &ilen); + if (q == NULL || ilen != 4) + return 0; + if (q[0] == 0x02) diff --git a/opensc.changes b/opensc.changes index c567556..2764550 100644 --- a/opensc.changes +++ b/opensc.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Thu Jun 1 12:55:19 UTC 2023 - Otto Hollmann + +- Security Fix: [CVE-2023-2977, bsc#1211894] + * opensc: out of bounds read in pkcs15 cardos_have_verifyrc_package() + * Add opensc-CVE-2023-2977.patch + ------------------------------------------------------------------- Tue Nov 29 17:52:46 UTC 2022 - Michael Ströder diff --git a/opensc.spec b/opensc.spec index 5a11480..6eca5be 100644 --- a/opensc.spec +++ b/opensc.spec @@ -1,7 +1,7 @@ # # spec file for package opensc # -# Copyright (c) 2022 SUSE LLC +# Copyright (c) 2023 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -31,6 +31,8 @@ Source2: %{name}-rpmlintrc # https://web.archive.org/web/20111225073733/http://www.opensc-project.org/opensc/ticket/390 Source3: opensc.module Patch0: opensc-gcc11.patch +# PATCH-FIX-UPSTREAM: bsc#1211894, CVE-2023-2977 out of bounds read in pkcs15 cardos_have_verifyrc_package() +Patch1: opensc-CVE-2023-2977.patch BuildRequires: docbook-xsl-stylesheets BuildRequires: libxslt BuildRequires: pkgconfig @@ -59,8 +61,7 @@ possible operations may be supported for your card. Card initialization may require third party proprietary software. %prep -%setup -q -%patch0 -p1 +%autosetup -p1 %build %configure \