diff options
author | Zhang Peng <peng.zhang1.cn@windriver.com> | 2025-01-15 15:24:24 +0800 |
---|---|---|
committer | Armin Kuster <akuster808@gmail.com> | 2025-01-22 19:28:43 -0500 |
commit | cd6d013e47774cf5b3ced01d7279de64af86c0e7 (patch) | |
tree | c2c4cc3936ad89dbedd17caf287d1f0b94ba40a9 | |
parent | ecdd64cf489a4892f105cb7ef56da6b4b859166b (diff) | |
download | meta-openembedded-cd6d013e47774cf5b3ced01d7279de64af86c0e7.tar.gz |
opensc: fix CVE-2024-45616
CVE-2024-45616:
A vulnerability was found in OpenSC, OpenSC tools, PKCS#11 module, minidriver, and CTK.
An attacker could use a crafted USB Device or Smart Card, which would present the system
with a specially crafted response to APDUs. The following problems were caused by
insufficient control of the response APDU buffer and its length when communicating
with the card.
Reference:
[https://nvd.nist.gov/vuln/detail/CVE-2024-45616]
Upstream patches:
[https://github.com/OpenSC/OpenSC/commit/1d3b410e06d33cfc4c70e8a25386e456cfbd7bd1]
[https://github.com/OpenSC/OpenSC/commit/265b28344d036a462f38002d957a0636fda57614]
[https://github.com/OpenSC/OpenSC/commit/e7177c7ca00200afea820d155dca67f38b232967]
[https://github.com/OpenSC/OpenSC/commit/ef7b10a18e6a4d4f03f0c47ea81aa8136f3eca60]
[https://github.com/OpenSC/OpenSC/commit/76115e34799906a64202df952a8a9915d30bc89d]
[https://github.com/OpenSC/OpenSC/commit/16ada9dc7cddf1cb99516aea67b6752c251c94a2]
[https://github.com/OpenSC/OpenSC/commit/3562969c90a71b0bcce979f0e6d627546073a7fc]
[https://github.com/OpenSC/OpenSC/commit/cccdfc46b10184d1eea62d07fe2b06240b7fafbc]
[https://github.com/OpenSC/OpenSC/commit/5fa758767e517779fc5398b6b4faedc4e36d3de5]
[https://github.com/OpenSC/OpenSC/commit/aa102cd9abe1b0eaf537d9dd926844a46060d8bc]
Signed-off-by: Zhang Peng <peng.zhang1.cn@windriver.com>
Signed-off-by: Armin Kuster <akuster808@gmail.com>
11 files changed, 510 insertions, 0 deletions
diff --git a/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0001.patch b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0001.patch new file mode 100644 index 0000000000..f4bebf039c --- /dev/null +++ b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0001.patch | |||
@@ -0,0 +1,52 @@ | |||
1 | From 1d3b410e06d33cfc4c70e8a25386e456cfbd7bd1 Mon Sep 17 00:00:00 2001 | ||
2 | From: =?UTF-8?q?Veronika=20Hanul=C3=ADkov=C3=A1?= <vhanulik@redhat.com> | ||
3 | Date: Thu, 11 Jul 2024 15:27:19 +0200 | ||
4 | Subject: [PATCH] cardos: Fix uninitialized values | ||
5 | |||
6 | Thanks Matteo Marini for report | ||
7 | https://github.com/OpenSC/OpenSC/security/advisories/GHSA-p3mx-7472-h3j8 | ||
8 | |||
9 | fuzz_card/2 | ||
10 | |||
11 | CVE: CVE-2024-45616 | ||
12 | Upstream-Status: Backport [https://github.com/OpenSC/OpenSC/commit/1d3b410e06d33cfc4c70e8a25386e456cfbd7bd1] | ||
13 | |||
14 | Signed-off-by: Zhang Peng <peng.zhang1.cn@windriver.com> | ||
15 | --- | ||
16 | src/libopensc/card-cardos.c | 8 ++++---- | ||
17 | 1 file changed, 4 insertions(+), 4 deletions(-) | ||
18 | |||
19 | diff --git a/src/libopensc/card-cardos.c b/src/libopensc/card-cardos.c | ||
20 | index 2e2d524333..a0e2322478 100644 | ||
21 | --- a/src/libopensc/card-cardos.c | ||
22 | +++ b/src/libopensc/card-cardos.c | ||
23 | @@ -94,14 +94,14 @@ static void fixup_transceive_length(const struct sc_card *card, | ||
24 | |||
25 | static int cardos_match_card(sc_card_t *card) | ||
26 | { | ||
27 | - unsigned char atr[SC_MAX_ATR_SIZE]; | ||
28 | + unsigned char atr[SC_MAX_ATR_SIZE] = { 0 }; | ||
29 | int i; | ||
30 | |||
31 | i = _sc_match_atr(card, cardos_atrs, &card->type); | ||
32 | if (i < 0) | ||
33 | return 0; | ||
34 | |||
35 | - memcpy(atr, card->atr.value, sizeof(atr)); | ||
36 | + memcpy(atr, card->atr.value, card->atr.len); | ||
37 | |||
38 | /* Do not change card type for CIE! */ | ||
39 | if (card->type == SC_CARD_TYPE_CARDOS_CIE_V1) | ||
40 | @@ -114,8 +114,8 @@ static int cardos_match_card(sc_card_t *card) | ||
41 | return 1; | ||
42 | if (card->type == SC_CARD_TYPE_CARDOS_M4_2) { | ||
43 | int rv; | ||
44 | - sc_apdu_t apdu; | ||
45 | - u8 rbuf[SC_MAX_APDU_BUFFER_SIZE]; | ||
46 | + sc_apdu_t apdu = { 0 }; | ||
47 | + u8 rbuf[SC_MAX_APDU_BUFFER_SIZE] = { 0 }; | ||
48 | /* first check some additional ATR bytes */ | ||
49 | if ((atr[4] != 0xff && atr[4] != 0x02) || | ||
50 | (atr[6] != 0x10 && atr[6] != 0x0a) || | ||
51 | -- | ||
52 | 2.34.1 | ||
diff --git a/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0002.patch b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0002.patch new file mode 100644 index 0000000000..012a9ecdbd --- /dev/null +++ b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0002.patch | |||
@@ -0,0 +1,48 @@ | |||
1 | From 265b28344d036a462f38002d957a0636fda57614 Mon Sep 17 00:00:00 2001 | ||
2 | From: =?UTF-8?q?Veronika=20Hanul=C3=ADkov=C3=A1?= <vhanulik@redhat.com> | ||
3 | Date: Thu, 1 Aug 2024 10:32:40 +0200 | ||
4 | Subject: [PATCH] card-cardos: Check length of APDU response | ||
5 | |||
6 | CVE: CVE-2024-45616 | ||
7 | Upstream-Status: Backport [https://github.com/OpenSC/OpenSC/commit/265b28344d036a462f38002d957a0636fda57614] | ||
8 | |||
9 | Signed-off-by: Zhang Peng <peng.zhang1.cn@windriver.com> | ||
10 | --- | ||
11 | src/libopensc/card-cardos.c | 8 ++++---- | ||
12 | 1 file changed, 4 insertions(+), 4 deletions(-) | ||
13 | |||
14 | diff --git a/src/libopensc/card-cardos.c b/src/libopensc/card-cardos.c | ||
15 | index 124752d78b..595ec099e3 100644 | ||
16 | --- a/src/libopensc/card-cardos.c | ||
17 | +++ b/src/libopensc/card-cardos.c | ||
18 | @@ -94,7 +94,7 @@ static void fixup_transceive_length(const struct sc_card *card, | ||
19 | |||
20 | static int cardos_match_card(sc_card_t *card) | ||
21 | { | ||
22 | - unsigned char atr[SC_MAX_ATR_SIZE] = { 0 }; | ||
23 | + unsigned char atr[SC_MAX_ATR_SIZE] = {0}; | ||
24 | int i; | ||
25 | |||
26 | i = _sc_match_atr(card, cardos_atrs, &card->type); | ||
27 | @@ -114,8 +114,8 @@ static int cardos_match_card(sc_card_t *card) | ||
28 | return 1; | ||
29 | if (card->type == SC_CARD_TYPE_CARDOS_M4_2) { | ||
30 | int rv; | ||
31 | - sc_apdu_t apdu = { 0 }; | ||
32 | - u8 rbuf[SC_MAX_APDU_BUFFER_SIZE] = { 0 }; | ||
33 | + sc_apdu_t apdu = {0}; | ||
34 | + u8 rbuf[SC_MAX_APDU_BUFFER_SIZE] = {0}; | ||
35 | /* first check some additional ATR bytes */ | ||
36 | if ((atr[4] != 0xff && atr[4] != 0x02) || | ||
37 | (atr[6] != 0x10 && atr[6] != 0x0a) || | ||
38 | @@ -131,7 +131,7 @@ static int cardos_match_card(sc_card_t *card) | ||
39 | apdu.lc = 0; | ||
40 | rv = sc_transmit_apdu(card, &apdu); | ||
41 | LOG_TEST_RET(card->ctx, rv, "APDU transmit failed"); | ||
42 | - if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00) | ||
43 | + if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00 || apdu.resplen < 2) | ||
44 | return 0; | ||
45 | if (apdu.resp[0] != atr[10] || | ||
46 | apdu.resp[1] != atr[11]) | ||
47 | -- | ||
48 | 2.34.1 | ||
diff --git a/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0003.patch b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0003.patch new file mode 100644 index 0000000000..4c0d1ec309 --- /dev/null +++ b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0003.patch | |||
@@ -0,0 +1,42 @@ | |||
1 | From e7177c7ca00200afea820d155dca67f38b232967 Mon Sep 17 00:00:00 2001 | ||
2 | From: Jakub Jelen <jjelen@redhat.com> | ||
3 | Date: Mon, 20 May 2024 22:14:48 +0200 | ||
4 | Subject: [PATCH] cac: Correctly calculate certificate length based on the | ||
5 | resplen | ||
6 | |||
7 | Thanks Matteo Marini for report | ||
8 | |||
9 | https://github.com/OpenSC/OpenSC/security/advisories/GHSA-h5f7-rjr5-vx54 | ||
10 | |||
11 | Signed-off-by: Jakub Jelen <jjelen@redhat.com> | ||
12 | |||
13 | CVE: CVE-2024-45616 | ||
14 | Upstream-Status: Backport [https://github.com/OpenSC/OpenSC/commit/e7177c7ca00200afea820d155dca67f38b232967] | ||
15 | |||
16 | Signed-off-by: Zhang Peng <peng.zhang1.cn@windriver.com> | ||
17 | --- | ||
18 | src/libopensc/card-cac1.c | 6 +++--- | ||
19 | 1 file changed, 3 insertions(+), 3 deletions(-) | ||
20 | |||
21 | diff --git a/src/libopensc/card-cac1.c b/src/libopensc/card-cac1.c | ||
22 | index 50c0928f5..bbdbc0a8d 100644 | ||
23 | --- a/src/libopensc/card-cac1.c | ||
24 | +++ b/src/libopensc/card-cac1.c | ||
25 | @@ -95,12 +95,12 @@ static int cac_cac1_get_certificate(sc_card_t *card, u8 **out_buf, size_t *out_l | ||
26 | if (apdu.sw1 != 0x63 || apdu.sw2 < 1) { | ||
27 | /* we've either finished reading, or hit an error, break */ | ||
28 | r = sc_check_sw(card, apdu.sw1, apdu.sw2); | ||
29 | - left -= len; | ||
30 | + left -= apdu.resplen; | ||
31 | break; | ||
32 | } | ||
33 | /* Adjust the lengths */ | ||
34 | - left -= len; | ||
35 | - out_ptr += len; | ||
36 | + left -= apdu.resplen; | ||
37 | + out_ptr += apdu.resplen; | ||
38 | len = MIN(left, apdu.sw2); | ||
39 | } | ||
40 | if (r < 0) { | ||
41 | -- | ||
42 | 2.34.1 | ||
diff --git a/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0004.patch b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0004.patch new file mode 100644 index 0000000000..603556388b --- /dev/null +++ b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0004.patch | |||
@@ -0,0 +1,43 @@ | |||
1 | From ef7b10a18e6a4d4f03f0c47ea81aa8136f3eca60 Mon Sep 17 00:00:00 2001 | ||
2 | From: =?UTF-8?q?Veronika=20Hanul=C3=ADkov=C3=A1?= <vhanulik@redhat.com> | ||
3 | Date: Thu, 18 Jul 2024 15:39:15 +0200 | ||
4 | Subject: [PATCH] card-oberthur: Check length of serial number | ||
5 | |||
6 | Thanks Matteo Marini for report | ||
7 | https://github.com/OpenSC/OpenSC/security/advisories/GHSA-p3mx-7472-h3j8 | ||
8 | |||
9 | fuzz_pkcs11/1, fuzz_pkcs15init/2 | ||
10 | |||
11 | CVE: CVE-2024-45616 | ||
12 | Upstream-Status: Backport [https://github.com/OpenSC/OpenSC/commit/ef7b10a18e6a4d4f03f0c47ea81aa8136f3eca60] | ||
13 | |||
14 | Signed-off-by: Zhang Peng <peng.zhang1.cn@windriver.com> | ||
15 | --- | ||
16 | src/libopensc/card-oberthur.c | 5 ++++- | ||
17 | 1 file changed, 4 insertions(+), 1 deletion(-) | ||
18 | |||
19 | diff --git a/src/libopensc/card-oberthur.c b/src/libopensc/card-oberthur.c | ||
20 | index 1fc40f7b3..bd45b6ff5 100644 | ||
21 | --- a/src/libopensc/card-oberthur.c | ||
22 | +++ b/src/libopensc/card-oberthur.c | ||
23 | @@ -148,7 +148,7 @@ auth_select_aid(struct sc_card *card) | ||
24 | { | ||
25 | struct sc_apdu apdu; | ||
26 | unsigned char apdu_resp[SC_MAX_APDU_BUFFER_SIZE]; | ||
27 | - struct auth_private_data *data = (struct auth_private_data *) card->drv_data; | ||
28 | + struct auth_private_data *data = (struct auth_private_data *)card->drv_data; | ||
29 | int rv, ii; | ||
30 | struct sc_path tmp_path; | ||
31 | |||
32 | @@ -165,6 +165,9 @@ auth_select_aid(struct sc_card *card) | ||
33 | |||
34 | rv = sc_transmit_apdu(card, &apdu); | ||
35 | LOG_TEST_RET(card->ctx, rv, "APDU transmit failed"); | ||
36 | + if (apdu.resplen < 20) { | ||
37 | + LOG_TEST_RET(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Serial number has incorrect length"); | ||
38 | + } | ||
39 | card->serialnr.len = 4; | ||
40 | memcpy(card->serialnr.value, apdu.resp+15, 4); | ||
41 | |||
42 | -- | ||
43 | 2.34.1 | ||
diff --git a/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0005.patch b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0005.patch new file mode 100644 index 0000000000..34e2a83d8a --- /dev/null +++ b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0005.patch | |||
@@ -0,0 +1,34 @@ | |||
1 | From 76115e34799906a64202df952a8a9915d30bc89d Mon Sep 17 00:00:00 2001 | ||
2 | From: Jakub Jelen <jjelen@redhat.com> | ||
3 | Date: Mon, 20 May 2024 21:19:15 +0200 | ||
4 | Subject: [PATCH] gids: Avoid using uninitialized memory | ||
5 | |||
6 | Thanks Matteo Marini for report | ||
7 | |||
8 | https://github.com/OpenSC/OpenSC/security/advisories/GHSA-h5f7-rjr5-vx54 | ||
9 | |||
10 | Signed-off-by: Jakub Jelen <jjelen@redhat.com> | ||
11 | |||
12 | CVE: CVE-2024-45616 | ||
13 | Upstream-Status: Backport [https://github.com/OpenSC/OpenSC/commit/76115e34799906a64202df952a8a9915d30bc89d] | ||
14 | |||
15 | Signed-off-by: Zhang Peng <peng.zhang1.cn@windriver.com> | ||
16 | --- | ||
17 | src/libopensc/card-gids.c | 2 +- | ||
18 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
19 | |||
20 | diff --git a/src/libopensc/card-gids.c b/src/libopensc/card-gids.c | ||
21 | index f25e37de4..10960875d 100644 | ||
22 | --- a/src/libopensc/card-gids.c | ||
23 | +++ b/src/libopensc/card-gids.c | ||
24 | @@ -251,7 +251,7 @@ static int gids_get_DO(sc_card_t* card, int fileIdentifier, int dataObjectIdenti | ||
25 | LOG_TEST_RET(card->ctx, r, "gids get data failed"); | ||
26 | LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return"); | ||
27 | |||
28 | - p = sc_asn1_find_tag(card->ctx, buffer, sizeof(buffer), dataObjectIdentifier, &datasize); | ||
29 | + p = sc_asn1_find_tag(card->ctx, buffer, apdu.resplen, dataObjectIdentifier, &datasize); | ||
30 | if (!p) { | ||
31 | LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND); | ||
32 | } | ||
33 | -- | ||
34 | 2.34.1 | ||
diff --git a/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0006.patch b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0006.patch new file mode 100644 index 0000000000..58b65b2917 --- /dev/null +++ b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0006.patch | |||
@@ -0,0 +1,50 @@ | |||
1 | From 16ada9dc7cddf1cb99516aea67b6752c251c94a2 Mon Sep 17 00:00:00 2001 | ||
2 | From: =?UTF-8?q?Veronika=20Hanul=C3=ADkov=C3=A1?= <vhanulik@redhat.com> | ||
3 | Date: Fri, 12 Jul 2024 15:04:19 +0200 | ||
4 | Subject: [PATCH] card-gids: Use actual length of reponse buffer | ||
5 | |||
6 | Thanks Matteo Marini for report | ||
7 | https://github.com/OpenSC/OpenSC/security/advisories/GHSA-p3mx-7472-h3j8 | ||
8 | |||
9 | fuzz_pkcs11/11 | ||
10 | |||
11 | CVE: CVE-2024-45616 | ||
12 | Upstream-Status: Backport [https://github.com/OpenSC/OpenSC/commit/16ada9dc7cddf1cb99516aea67b6752c251c94a2] | ||
13 | |||
14 | Signed-off-by: Zhang Peng <peng.zhang1.cn@windriver.com> | ||
15 | --- | ||
16 | src/libopensc/card-gids.c | 6 ++++-- | ||
17 | 1 file changed, 4 insertions(+), 2 deletions(-) | ||
18 | |||
19 | diff --git a/src/libopensc/card-gids.c b/src/libopensc/card-gids.c | ||
20 | index f25e37de4..91e1e0569 100644 | ||
21 | --- a/src/libopensc/card-gids.c | ||
22 | +++ b/src/libopensc/card-gids.c | ||
23 | @@ -231,6 +231,7 @@ static int gids_get_DO(sc_card_t* card, int fileIdentifier, int dataObjectIdenti | ||
24 | size_t datasize = 0; | ||
25 | const u8* p; | ||
26 | u8 buffer[MAX_GIDS_FILE_SIZE]; | ||
27 | + size_t buffer_len = sizeof(buffer); | ||
28 | |||
29 | SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE); | ||
30 | sc_log(card->ctx, | ||
31 | @@ -244,14 +245,15 @@ static int gids_get_DO(sc_card_t* card, int fileIdentifier, int dataObjectIdenti | ||
32 | apdu.data = data; | ||
33 | apdu.datalen = 04; | ||
34 | apdu.resp = buffer; | ||
35 | - apdu.resplen = sizeof(buffer); | ||
36 | + apdu.resplen = buffer_len; | ||
37 | apdu.le = 256; | ||
38 | |||
39 | r = sc_transmit_apdu(card, &apdu); | ||
40 | LOG_TEST_RET(card->ctx, r, "gids get data failed"); | ||
41 | LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return"); | ||
42 | + buffer_len = apdu.resplen; | ||
43 | |||
44 | - p = sc_asn1_find_tag(card->ctx, buffer, apdu.resplen, dataObjectIdentifier, &datasize); | ||
45 | + p = sc_asn1_find_tag(card->ctx, buffer, buffer_len, dataObjectIdentifier, &datasize); | ||
46 | if (!p) { | ||
47 | LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND); | ||
48 | } | ||
49 | -- | ||
50 | 2.34.1 | ||
diff --git a/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0007.patch b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0007.patch new file mode 100644 index 0000000000..d664e21332 --- /dev/null +++ b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0007.patch | |||
@@ -0,0 +1,56 @@ | |||
1 | From 3562969c90a71b0bcce979f0e6d627546073a7fc Mon Sep 17 00:00:00 2001 | ||
2 | From: =?UTF-8?q?Veronika=20Hanul=C3=ADkov=C3=A1?= <vhanulik@redhat.com> | ||
3 | Date: Fri, 12 Jul 2024 14:16:24 +0200 | ||
4 | Subject: [PATCH] card-mcrd: Check length of response buffer in select | ||
5 | |||
6 | Thanks Matteo Marini for report | ||
7 | https://github.com/OpenSC/OpenSC/security/advisories/GHSA-p3mx-7472-h3j8 | ||
8 | |||
9 | fuzz_pkcs11/5,12 fuzz_pkcs15_crypt/9 | ||
10 | |||
11 | CVE: CVE-2024-45616 | ||
12 | Upstream-Status: Backport [https://github.com/OpenSC/OpenSC/commit/3562969c90a71b0bcce979f0e6d627546073a7fc] | ||
13 | |||
14 | Signed-off-by: Zhang Peng <peng.zhang1.cn@windriver.com> | ||
15 | --- | ||
16 | src/libopensc/card-mcrd.c | 11 +++++++---- | ||
17 | 1 file changed, 7 insertions(+), 4 deletions(-) | ||
18 | |||
19 | diff --git a/src/libopensc/card-mcrd.c b/src/libopensc/card-mcrd.c | ||
20 | index fb5d02f89..30812e8a6 100644 | ||
21 | --- a/src/libopensc/card-mcrd.c | ||
22 | +++ b/src/libopensc/card-mcrd.c | ||
23 | @@ -634,11 +634,13 @@ do_select(sc_card_t * card, u8 kind, | ||
24 | } | ||
25 | } | ||
26 | |||
27 | - if (p2 == 0x04 && apdu.resp[0] == 0x62) { | ||
28 | + if (p2 == 0x04 && apdu.resplen > 2 && apdu.resp[0] == 0x62) { | ||
29 | *file = sc_file_new(); | ||
30 | if (!*file) | ||
31 | LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY); | ||
32 | /* EstEID v3.0 cards are buggy and sometimes return a double 0x62 tag */ | ||
33 | + if (apdu.resp[1] > apdu.resplen - 2) | ||
34 | + LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA); | ||
35 | if (card->type == SC_CARD_TYPE_MCRD_ESTEID_V30 && apdu.resp[2] == 0x62) | ||
36 | process_fcp(card, *file, apdu.resp + 4, apdu.resp[3]); | ||
37 | else | ||
38 | @@ -646,12 +648,13 @@ do_select(sc_card_t * card, u8 kind, | ||
39 | return SC_SUCCESS; | ||
40 | } | ||
41 | |||
42 | - if (p2 != 0x0C && apdu.resp[0] == 0x6F) { | ||
43 | + if (p2 != 0x0C && apdu.resplen > 2 && apdu.resp[0] == 0x6F) { | ||
44 | *file = sc_file_new(); | ||
45 | if (!*file) | ||
46 | LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY); | ||
47 | - if (apdu.resp[1] <= apdu.resplen) | ||
48 | - process_fcp(card, *file, apdu.resp + 2, apdu.resp[1]); | ||
49 | + if (apdu.resp[1] > apdu.resplen - 2) | ||
50 | + LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA); | ||
51 | + process_fcp(card, *file, apdu.resp + 2, apdu.resp[1]); | ||
52 | return SC_SUCCESS; | ||
53 | } | ||
54 | return SC_SUCCESS; | ||
55 | -- | ||
56 | 2.34.1 | ||
diff --git a/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0008.patch b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0008.patch new file mode 100644 index 0000000000..bdd56fb47a --- /dev/null +++ b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0008.patch | |||
@@ -0,0 +1,74 @@ | |||
1 | From cccdfc46b10184d1eea62d07fe2b06240b7fafbc Mon Sep 17 00:00:00 2001 | ||
2 | From: =?UTF-8?q?Veronika=20Hanul=C3=ADkov=C3=A1?= <vhanulik@redhat.com> | ||
3 | Date: Fri, 12 Jul 2024 13:16:56 +0200 | ||
4 | Subject: [PATCH] card-dnie: Check APDU response length and ASN1 lengths | ||
5 | |||
6 | Thanks Matteo Marini for report | ||
7 | https://github.com/OpenSC/OpenSC/security/advisories/GHSA-p3mx-7472-h3j8 | ||
8 | |||
9 | fuzz_pkcs15_decode/10, fuzz_pkcs15_encode/12 | ||
10 | |||
11 | CVE: CVE-2024-45616 | ||
12 | Upstream-Status: Backport [https://github.com/OpenSC/OpenSC/commit/cccdfc46b10184d1eea62d07fe2b06240b7fafbc] | ||
13 | |||
14 | Signed-off-by: Zhang Peng <peng.zhang1.cn@windriver.com> | ||
15 | --- | ||
16 | src/libopensc/asn1.c | 4 +++- | ||
17 | src/libopensc/card-dnie.c | 8 ++++++-- | ||
18 | 2 files changed, 9 insertions(+), 3 deletions(-) | ||
19 | |||
20 | diff --git a/src/libopensc/asn1.c b/src/libopensc/asn1.c | ||
21 | index 08ef56149c..548263a2da 100644 | ||
22 | --- a/src/libopensc/asn1.c | ||
23 | +++ b/src/libopensc/asn1.c | ||
24 | @@ -68,7 +68,7 @@ int sc_asn1_read_tag(const u8 ** buf, size_t buflen, unsigned int *cla_out, | ||
25 | |||
26 | *buf = NULL; | ||
27 | |||
28 | - if (left == 0 || !p) | ||
29 | + if (left == 0 || !p || buflen == 0) | ||
30 | return SC_ERROR_INVALID_ASN1_OBJECT; | ||
31 | if (*p == 0xff || *p == 0) { | ||
32 | /* end of data reached */ | ||
33 | @@ -83,6 +83,8 @@ int sc_asn1_read_tag(const u8 ** buf, size_t buflen, unsigned int *cla_out, | ||
34 | */ | ||
35 | cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED); | ||
36 | tag = *p & SC_ASN1_TAG_PRIMITIVE; | ||
37 | + if (left < 1) | ||
38 | + return SC_ERROR_INVALID_ASN1_OBJECT; | ||
39 | p++; | ||
40 | left--; | ||
41 | if (tag == SC_ASN1_TAG_PRIMITIVE) { | ||
42 | diff --git a/src/libopensc/card-dnie.c b/src/libopensc/card-dnie.c | ||
43 | index 2c36ddf5c..25c15b2b7 100644 | ||
44 | --- a/src/libopensc/card-dnie.c | ||
45 | +++ b/src/libopensc/card-dnie.c | ||
46 | @@ -1185,12 +1185,16 @@ static int dnie_compose_and_send_apdu(sc_card_t *card, const u8 *path, size_t pa | ||
47 | |||
48 | if (file_out) { | ||
49 | /* finally process FCI response */ | ||
50 | + size_t len = apdu.resp[1]; | ||
51 | sc_file_free(*file_out); | ||
52 | *file_out = sc_file_new(); | ||
53 | if (*file_out == NULL) { | ||
54 | LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY); | ||
55 | } | ||
56 | - res = card->ops->process_fci(card, *file_out, apdu.resp + 2, apdu.resp[1]); | ||
57 | + if (apdu.resplen - 2 < len || len < 1) { | ||
58 | + LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED); | ||
59 | + } | ||
60 | + res = card->ops->process_fci(card, *file_out, apdu.resp + 2, len); | ||
61 | } | ||
62 | LOG_FUNC_RETURN(ctx, res); | ||
63 | } | ||
64 | @@ -1948,7 +1952,7 @@ static int dnie_process_fci(struct sc_card *card, | ||
65 | int *op = df_acl; | ||
66 | int n = 0; | ||
67 | sc_context_t *ctx = NULL; | ||
68 | - if ((card == NULL) || (card->ctx == NULL) || (file == NULL)) | ||
69 | + if ((card == NULL) || (card->ctx == NULL) || (file == NULL) || buflen == 0) | ||
70 | return SC_ERROR_INVALID_ARGUMENTS; | ||
71 | ctx = card->ctx; | ||
72 | LOG_FUNC_CALLED(ctx); | ||
73 | -- | ||
74 | 2.34.1 | ||
diff --git a/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0009.patch b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0009.patch new file mode 100644 index 0000000000..f4c3e231e9 --- /dev/null +++ b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0009.patch | |||
@@ -0,0 +1,68 @@ | |||
1 | From 5fa758767e517779fc5398b6b4faedc4e36d3de5 Mon Sep 17 00:00:00 2001 | ||
2 | From: =?UTF-8?q?Veronika=20Hanul=C3=ADkov=C3=A1?= <vhanulik@redhat.com> | ||
3 | Date: Fri, 12 Jul 2024 14:03:59 +0200 | ||
4 | Subject: [PATCH] muscle: Report invalid SW when reading object | ||
5 | |||
6 | Thanks Matteo Marini for report | ||
7 | https://github.com/OpenSC/OpenSC/security/advisories/GHSA-p3mx-7472-h3j8 | ||
8 | |||
9 | fuzz_pkcs11/20, fuzz_pkcs15init/10 | ||
10 | |||
11 | CVE: CVE-2024-45616 | ||
12 | Upstream-Status: Backport [https://github.com/OpenSC/OpenSC/commit/5fa758767e517779fc5398b6b4faedc4e36d3de5] | ||
13 | |||
14 | Signed-off-by: Zhang Peng <peng.zhang1.cn@windriver.com> | ||
15 | --- | ||
16 | src/libopensc/muscle.c | 19 ++++++++++--------- | ||
17 | 1 file changed, 10 insertions(+), 9 deletions(-) | ||
18 | |||
19 | diff --git a/src/libopensc/muscle.c b/src/libopensc/muscle.c | ||
20 | index a749657df..b30173ec6 100644 | ||
21 | --- a/src/libopensc/muscle.c | ||
22 | +++ b/src/libopensc/muscle.c | ||
23 | @@ -92,33 +92,34 @@ int msc_partial_read_object(sc_card_t *card, msc_id objectId, int offset, u8 *da | ||
24 | apdu.resp = data; | ||
25 | r = sc_transmit_apdu(card, &apdu); | ||
26 | LOG_TEST_RET(card->ctx, r, "APDU transmit failed"); | ||
27 | - if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) | ||
28 | + if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00 && dataLength <= apdu.resplen) | ||
29 | return dataLength; | ||
30 | - if(apdu.sw1 == 0x9C) { | ||
31 | - if(apdu.sw2 == 0x07) { | ||
32 | + if (apdu.sw1 == 0x9C) { | ||
33 | + if (apdu.sw2 == 0x07) { | ||
34 | SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_FILE_NOT_FOUND); | ||
35 | - } else if(apdu.sw2 == 0x06) { | ||
36 | + } else if (apdu.sw2 == 0x06) { | ||
37 | SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_ALLOWED); | ||
38 | - } else if(apdu.sw2 == 0x0F) { | ||
39 | + } else if (apdu.sw2 == 0x0F) { | ||
40 | /* GUESSED */ | ||
41 | SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS); | ||
42 | } | ||
43 | } | ||
44 | sc_log(card->ctx, | ||
45 | "got strange SWs: 0x%02X 0x%02X\n", apdu.sw1, apdu.sw2); | ||
46 | - return dataLength; | ||
47 | - | ||
48 | + SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_UNKNOWN_DATA_RECEIVED); | ||
49 | } | ||
50 | |||
51 | int msc_read_object(sc_card_t *card, msc_id objectId, int offset, u8 *data, size_t dataLength) | ||
52 | { | ||
53 | - int r; | ||
54 | + int r = 0; | ||
55 | size_t i; | ||
56 | size_t max_read_unit = MSC_MAX_READ; | ||
57 | |||
58 | - for(i = 0; i < dataLength; i += max_read_unit) { | ||
59 | + for(i = 0; i < dataLength; i += r) { | ||
60 | r = msc_partial_read_object(card, objectId, offset + i, data + i, MIN(dataLength - i, max_read_unit)); | ||
61 | LOG_TEST_RET(card->ctx, r, "Error in partial object read"); | ||
62 | + if (r == 0) | ||
63 | + break; | ||
64 | } | ||
65 | return dataLength; | ||
66 | } | ||
67 | -- | ||
68 | 2.34.1 | ||
diff --git a/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0010.patch b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0010.patch new file mode 100644 index 0000000000..4a7752b28e --- /dev/null +++ b/meta-oe/recipes-support/opensc/files/CVE-2024-45616-0010.patch | |||
@@ -0,0 +1,33 @@ | |||
1 | From aa102cd9abe1b0eaf537d9dd926844a46060d8bc Mon Sep 17 00:00:00 2001 | ||
2 | From: =?UTF-8?q?Veronika=20Hanul=C3=ADkov=C3=A1?= <vhanulik@redhat.com> | ||
3 | Date: Tue, 23 Jul 2024 10:48:32 +0200 | ||
4 | Subject: [PATCH] card-entersafe: Check length of serial number | ||
5 | |||
6 | Thanks Matteo Marini for report | ||
7 | https://github.com/OpenSC/OpenSC/security/advisories/GHSA-p3mx-7472-h3j8 | ||
8 | |||
9 | fuzz_pkcs15_reader/5 | ||
10 | |||
11 | CVE: CVE-2024-45616 | ||
12 | Upstream-Status: Backport [https://github.com/OpenSC/OpenSC/commit/aa102cd9abe1b0eaf537d9dd926844a46060d8bc] | ||
13 | |||
14 | Signed-off-by: Zhang Peng <peng.zhang1.cn@windriver.com> | ||
15 | --- | ||
16 | src/libopensc/card-entersafe.c | 2 ++ | ||
17 | 1 file changed, 2 insertions(+) | ||
18 | |||
19 | diff --git a/src/libopensc/card-entersafe.c b/src/libopensc/card-entersafe.c | ||
20 | index 6372913d0..305323fd5 100644 | ||
21 | --- a/src/libopensc/card-entersafe.c | ||
22 | +++ b/src/libopensc/card-entersafe.c | ||
23 | @@ -1468,6 +1468,8 @@ static int entersafe_get_serialnr(sc_card_t *card, sc_serial_number_t *serial) | ||
24 | r=entersafe_transmit_apdu(card, &apdu,0,0,0,0); | ||
25 | LOG_TEST_RET(card->ctx, r, "APDU transmit failed"); | ||
26 | LOG_TEST_RET(card->ctx, sc_check_sw(card,apdu.sw1,apdu.sw2),"EnterSafe get SN failed"); | ||
27 | + if (apdu.resplen != 8) | ||
28 | + LOG_TEST_RET(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid length of SN"); | ||
29 | |||
30 | card->serialnr.len=serial->len=8; | ||
31 | memcpy(card->serialnr.value,rbuf,8); | ||
32 | -- | ||
33 | 2.34.1 | ||
diff --git a/meta-oe/recipes-support/opensc/opensc_0.22.0.bb b/meta-oe/recipes-support/opensc/opensc_0.22.0.bb index 9446237a09..ec01496709 100644 --- a/meta-oe/recipes-support/opensc/opensc_0.22.0.bb +++ b/meta-oe/recipes-support/opensc/opensc_0.22.0.bb | |||
@@ -31,6 +31,16 @@ SRC_URI = "git://github.com/OpenSC/OpenSC;branch=master;protocol=https \ | |||
31 | file://CVE-2024-45615-0003.patch \ | 31 | file://CVE-2024-45615-0003.patch \ |
32 | file://CVE-2024-45615-0004.patch \ | 32 | file://CVE-2024-45615-0004.patch \ |
33 | file://CVE-2024-45615-0005.patch \ | 33 | file://CVE-2024-45615-0005.patch \ |
34 | file://CVE-2024-45616-0001.patch \ | ||
35 | file://CVE-2024-45616-0002.patch \ | ||
36 | file://CVE-2024-45616-0003.patch \ | ||
37 | file://CVE-2024-45616-0004.patch \ | ||
38 | file://CVE-2024-45616-0005.patch \ | ||
39 | file://CVE-2024-45616-0006.patch \ | ||
40 | file://CVE-2024-45616-0007.patch \ | ||
41 | file://CVE-2024-45616-0008.patch \ | ||
42 | file://CVE-2024-45616-0009.patch \ | ||
43 | file://CVE-2024-45616-0010.patch \ | ||
34 | " | 44 | " |
35 | 45 | ||
36 | # CVE-2021-34193 is a duplicate CVE covering the 5 individual | 46 | # CVE-2021-34193 is a duplicate CVE covering the 5 individual |