Fix buffer overrun vulnerability in pkcs15 cardos_have_verifyrc_package
This commit is contained in:
parent
3a62ecf5b5
commit
74fecdca0f
49
opensc-0.23.0-cardos-buffer-overrun.patch
Normal file
49
opensc-0.23.0-cardos-buffer-overrun.patch
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
From 3bf3ab2f9091f984cda6dd910654ccbbe3f06a40 Mon Sep 17 00:00:00 2001
|
||||||
|
From: fullwaywang <fullwaywang@tencent.com>
|
||||||
|
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)
|
@ -12,6 +12,8 @@ Patch1: opensc-0.19.0-pinpad.patch
|
|||||||
Patch8: %{name}-0.22.0-file-cache.patch
|
Patch8: %{name}-0.22.0-file-cache.patch
|
||||||
# https://github.com/OpenSC/OpenSC/pull/2656
|
# https://github.com/OpenSC/OpenSC/pull/2656
|
||||||
Patch9: %{name}-0.23.0-pkcs11-tool-import.patch
|
Patch9: %{name}-0.23.0-pkcs11-tool-import.patch
|
||||||
|
# https://github.com/OpenSC/OpenSC/pull/2787
|
||||||
|
Patch10: %{name}-0.23.0-cardos-buffer-overrun.patch
|
||||||
|
|
||||||
BuildRequires: make
|
BuildRequires: make
|
||||||
BuildRequires: pcsc-lite-devel
|
BuildRequires: pcsc-lite-devel
|
||||||
@ -52,6 +54,7 @@ every software/card that does so, too.
|
|||||||
%patch1 -p1 -b .pinpad
|
%patch1 -p1 -b .pinpad
|
||||||
%patch8 -p1 -b .file-cache
|
%patch8 -p1 -b .file-cache
|
||||||
%patch9 -p1 -b .pkcs11-tool-import
|
%patch9 -p1 -b .pkcs11-tool-import
|
||||||
|
%patch10 -p1 -b .cardos-buffer-overrun
|
||||||
|
|
||||||
# The test-pkcs11-tool-allowed-mechanisms already works in Fedora
|
# The test-pkcs11-tool-allowed-mechanisms already works in Fedora
|
||||||
sed -i -e '/XFAIL_TESTS/,$ {
|
sed -i -e '/XFAIL_TESTS/,$ {
|
||||||
|
Loading…
Reference in New Issue
Block a user