main/libksba: backport cve fixes

This commit is contained in:
psykose 2022-12-23 07:58:09 +00:00
parent a64feecdb9
commit 417a1aaf71
3 changed files with 121 additions and 3 deletions

View File

@ -2,15 +2,22 @@
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=libksba
pkgver=1.5.1
pkgrel=0
pkgrel=1
pkgdesc="Libksba is a CMS and X.509 access library"
url="https://www.gnupg.org/software/libksba/index.html"
arch="all"
license="GPL-2.0-or-later or GPL-3.0-or-later"
makedepends="libgpg-error-dev"
subpackages="$pkgname-dev $pkgname-doc"
source="https://www.gnupg.org/ftp/gcrypt/libksba/libksba-$pkgver.tar.bz2"
source="https://www.gnupg.org/ftp/gcrypt/libksba/libksba-$pkgver.tar.bz2
CVE-2022-3515.patch
CVE-2022-47629.patch
"
# secfixes:
# 1.5.1-r1:
# - CVE-2022-3515
# - CVE-2022-47629
build() {
./configure \
@ -28,4 +35,8 @@ package() {
make DESTDIR="$pkgdir" install
}
sha512sums="156fe6a36daa7b11ce580366ab36a5fceda253413f0057ace791e4f028fd3158a70a3f6ba1d0c824fafee4420d1076864dbd0911606fb65e14c8b2332b6cc92b libksba-1.5.1.tar.bz2"
sha512sums="
156fe6a36daa7b11ce580366ab36a5fceda253413f0057ace791e4f028fd3158a70a3f6ba1d0c824fafee4420d1076864dbd0911606fb65e14c8b2332b6cc92b libksba-1.5.1.tar.bz2
87ebe25efa8f5e7c9375749cd38499084a622b09df585da565ef761dfd76de1de7898214f8f8bcbfa94865a96dccd5fd67da98073fb93c53b7926481d1adf874 CVE-2022-3515.patch
107755df2354ed738330e6f3a6be60c87afe8607f6d125863688e053255ef12b194c0303b818e51ea7b9acf1d967435b4bfcd4a37ff53358de0902c959488b82 CVE-2022-47629.patch
"

View File

@ -0,0 +1,41 @@
Patch-Source:https://git.gnupg.org/cgi-bin/gitweb.cgi?p=libksba.git;a=commitdiff;h=4b7d9cd4a018898d7714ce06f3faf2626c14582b;hp=e11e17620189e13b7347139ed5a1f1a76b1f89a7
From: Werner Koch <wk@gnupg.org>
Date: Wed, 5 Oct 2022 12:19:06 +0000 (+0200)
Subject: Detect a possible overflow directly in the TLV parser.
X-Git-Tag: libksba-1.6.2~1
X-Git-Url: http://git.gnupg.org/cgi-bin/gitweb.cgi?p=libksba.git;a=commitdiff_plain;h=4b7d9cd4a018898d7714ce06f3faf2626c14582b;hp=e11e17620189e13b7347139ed5a1f1a76b1f89a7
Detect a possible overflow directly in the TLV parser.
* src/ber-help.c (_ksba_ber_read_tl): Check for overflow of a commonly
used sum.
--
It is quite common to have checks like
if (ti.nhdr + ti.length >= DIM(tmpbuf))
return gpg_error (GPG_ERR_TOO_LARGE);
This patch detects possible integer overflows immmediately when
creating the TI object.
Reported-by: ZDI-CAN-18927, ZDI-CAN-18928, ZDI-CAN-18929
---
diff --git a/src/ber-help.c b/src/ber-help.c
index 81c31ed..56efb6a 100644
--- a/src/ber-help.c
+++ b/src/ber-help.c
@@ -182,6 +182,12 @@ _ksba_ber_read_tl (ksba_reader_t reader, struct tag_info *ti)
ti->length = len;
}
+ if (ti->length > ti->nhdr && (ti->nhdr + ti->length) < ti->length)
+ {
+ ti->err_string = "header+length would overflow";
+ return gpg_error (GPG_ERR_EOVERFLOW);
+ }
+
/* Without this kludge some example certs can't be parsed */
if (ti->class == CLASS_UNIVERSAL && !ti->tag)
ti->length = 0;

View File

@ -0,0 +1,66 @@
Patch-Source: https://git.gnupg.org/cgi-bin/gitweb.cgi?p=libksba.git;a=commitdiff;h=f61a5ea4e0f6a80fd4b28ef0174bee77793cf070;hp=ff8c0e857c2f3380a13be19c67b117337ed0ffb6
From: Werner Koch <wk@gnupg.org>
Date: Tue, 22 Nov 2022 15:36:46 +0000 (+0100)
Subject: Fix an integer overflow in the CRL signature parser.
X-Git-Tag: libksba-1.6.3~1
X-Git-Url: http://git.gnupg.org/cgi-bin/gitweb.cgi?p=libksba.git;a=commitdiff_plain;h=f61a5ea4e0f6a80fd4b28ef0174bee77793cf070;hp=ff8c0e857c2f3380a13be19c67b117337ed0ffb6
Fix an integer overflow in the CRL signature parser.
* src/crl.c (parse_signature): N+N2 now checked for overflow.
* src/ocsp.c (parse_response_extensions): Do not accept too large
values.
(parse_single_extensions): Ditto.
--
The second patch is an extra safegourd not related to the reported
bug.
GnuPG-bug-id: 6284
Reported-by: Joseph Surin, elttam
---
diff --git a/src/crl.c b/src/crl.c
index 9f71c85..2e6ca29 100644
--- a/src/crl.c
+++ b/src/crl.c
@@ -1349,7 +1349,7 @@ parse_signature (ksba_crl_t crl)
&& !ti.is_constructed) )
return gpg_error (GPG_ERR_INV_CRL_OBJ);
n2 = ti.nhdr + ti.length;
- if (n + n2 >= DIM(tmpbuf))
+ if (n + n2 >= DIM(tmpbuf) || (n + n2) < n)
return gpg_error (GPG_ERR_TOO_LARGE);
memcpy (tmpbuf+n, ti.buf, ti.nhdr);
err = read_buffer (crl->reader, tmpbuf+n+ti.nhdr, ti.length);
diff --git a/src/ocsp.c b/src/ocsp.c
index d4cba04..657d15f 100644
--- a/src/ocsp.c
+++ b/src/ocsp.c
@@ -721,6 +721,12 @@ parse_response_extensions (ksba_ocsp_t ocsp,
|| memcmp (ocsp->nonce, data, ti.length))
ocsp->bad_nonce = 1;
}
+ if (ti.length > (1<<24))
+ {
+ /* Bail out on much too large objects. */
+ err = gpg_error (GPG_ERR_BAD_BER);
+ goto leave;
+ }
ex = xtrymalloc (sizeof *ex + strlen (oid) + ti.length);
if (!ex)
{
@@ -788,6 +794,12 @@ parse_single_extensions (struct ocsp_reqitem_s *ri,
err = parse_octet_string (&data, &datalen, &ti);
if (err)
goto leave;
+ if (ti.length > (1<<24))
+ {
+ /* Bail out on much too large objects. */
+ err = gpg_error (GPG_ERR_BAD_BER);
+ goto leave;
+ }
ex = xtrymalloc (sizeof *ex + strlen (oid) + ti.length);
if (!ex)
{