diff mbox series

[wrynose,5/8] libconvert-asn1-perl: fix CVE-2026-126819

Message ID 20261127064659.2169695-6-OmkarAbaji.Patil@windriver.com
State New
Headers show
Series libconvert-asn1-perl: fix 8 CVEs | expand

Commit Message

Omkar Patil Nov. 27, 2026, 6:46 a.m. UTC
Convert::ASN1 versions before 0.37 contain a flaw in BIT
STRING decoding that can lead to memory exhaustion (DoS).
A specially crafted zero-length BIT STRING can cause the
decoder to copy large portions of input repeatedly, resulting
in excessive memory consumption and potentially crashing the
application.

Reference:
[https://nvd.nist.gov/vuln/detail/cve-2026-126819]

Upstream patch:
[https://github.com/cpan-authors/perl-Convert-ASN1/commit/a369bb1c39061d67454216a6a1d0eae11932806e]

Signed-off-by: Omkar Patil <OmkarAbaji.Patil@windriver.com>
---
 .../CVE-2026-126819.patch                     | 90 +++++++++++++++++++
 .../perl/libconvert-asn1-perl_0.34.bb         |  1 +
 2 files changed, 91 insertions(+)
 create mode 100644 meta/recipes-extended/perl/libconvert-asn1-perl/CVE-2026-126819.patch
diff mbox series

Patch

diff --git a/meta/recipes-extended/perl/libconvert-asn1-perl/CVE-2026-126819.patch b/meta/recipes-extended/perl/libconvert-asn1-perl/CVE-2026-126819.patch
new file mode 100644
index 0000000000..58d2f2c324
--- /dev/null
+++ b/meta/recipes-extended/perl/libconvert-asn1-perl/CVE-2026-126819.patch
@@ -0,0 +1,90 @@ 
+From 51c154f2922c268bae7498016607776c8b5333bf Mon Sep 17 00:00:00 2001
+From: Timothy Legge <timlegge@gmail.com>
+Date: Wed, 11 Nov 2026 20:42:29 +0000
+Subject: [PATCH 5/8] Fix CVE-2026-126819: zero-length BIT STRING decodes to
+ rest of input buffer
+
+A zero-length content field caused _dec_bitstring to compute a negative
+substr length, returning the remainder of the input buffer as the bit
+string value. Add an early return of ["", 0] for zero-length content, and
+reject unused-bits values greater than 7 (invalid per DER/BER). Add tests
+covering both cases including a 500-fragment constructed BIT STRING PoC.
+
+CVE: CVE-2026-126819
+Upstream-Status: Backport [https://github.com/cpan-authors/perl-Convert-ASN1/commit/a369bb1c39061d67454216a6a1d0eae11932806e]
+Signed-off-by: Omkar Patil <OmkarAbaji.Patil@windriver.com>
+---
+ lib/Convert/ASN1/_decode.pm  |  5 ++++
+ t/25dec_bitstring_zero_len.t | 44 ++++++++++++++++++++++++++++++++++++
+ 2 files changed, 49 insertions(+)
+ create mode 100644 t/25dec_bitstring_zero_len.t
+
+diff --git a/lib/Convert/ASN1/_decode.pm b/lib/Convert/ASN1/_decode.pm
+index 72db28e..3e1978d 100644
+--- a/lib/Convert/ASN1/_decode.pm
++++ b/lib/Convert/ASN1/_decode.pm
+@@ -300,6 +300,11 @@ sub _dec_bitstring {
+ # 0      1    2       3     4     5     6
+ # $optn, $op, $stash, $var, $buf, $pos, $len
+ 
++  if ($_[6] < 1) {
++    $_[3] = ["", 0];
++    return 1;
++  }
++  die "BIT STRING decode error\n" if unpack("C", substr($_[4],$_[5],1)) > 7;
+   $_[3] = [ substr($_[4],$_[5]+1,$_[6]-1), ($_[6]-1)*8-unpack("C",substr($_[4],$_[5],1)) ];
+   1;
+ }
+diff --git a/t/25dec_bitstring_zero_len.t b/t/25dec_bitstring_zero_len.t
+new file mode 100644
+index 0000000..c8ae4d1
+--- /dev/null
++++ b/t/25dec_bitstring_zero_len.t
+@@ -0,0 +1,44 @@
++#!/usr/bin/perl
++# Tests for _dec_bitstring zero-length content guard (F6).
++
++use strict;
++use warnings;
++use lib 'lib';
++use Convert::ASN1 qw(asn_encode_length);
++BEGIN { require './t/funcs.pl' }
++
++print "1..10\n";
++
++sub make_bitstring {
++    my $content = shift;
++    return pack("C", 0x03) . asn_encode_length(length $content) . $content;
++}
++
++my ($asn, $ret);
++btest 1, $asn = Convert::ASN1->new;
++btest 2, $asn->prepare('b BIT STRING') or warn $asn->error;
++
++# --- 3-4: zero-length BIT STRING decodes to empty string with 0 bits ---
++my $zero = make_bitstring('');
++btest 3, $ret = $asn->decode($zero) or warn $asn->error;
++btest 4, defined($ret) && $ret->{b}[0] eq '' && $ret->{b}[1] == 0;
++
++# --- 5-6: a valid non-empty BIT STRING still decodes correctly ---
++# content: 0x00 (0 unused bits) + 0xA0 (data byte)
++my $valid = make_bitstring("\x00\xA0");
++btest 5, $ret = $asn->decode($valid) or warn $asn->error;
++btest 6, defined($ret) && $ret->{b}[0] eq "\xA0" && $ret->{b}[1] == 8;
++
++# --- 7-8: constructed BIT STRING (tag 0x23) with 500 zero-length fragments
++# doesn't cause quadratic memory (mini-PoC scenario) ---
++btest 7, $asn->prepare('x BIT STRING') or warn $asn->error;
++my $frags = make_bitstring('') x 500;
++my $cbs = pack("C", 0x23) . asn_encode_length(length $frags) . $frags;
++my $t = time;
++$ret = $asn->decode($cbs);
++btest 8, time - $t < 5;
++
++# --- 9-10: unused-bits byte > 7 is rejected ---
++my $bad_unused = make_bitstring("\x08\xFF");   # 8 unused bits = invalid
++btest 9, !defined($asn->decode($bad_unused));
++btest 10, ($asn->error || '') =~ /BIT STRING decode error/;
+-- 
+2.40.0
+
diff --git a/meta/recipes-extended/perl/libconvert-asn1-perl_0.34.bb b/meta/recipes-extended/perl/libconvert-asn1-perl_0.34.bb
index 40bb779c03..4615a1a90e 100644
--- a/meta/recipes-extended/perl/libconvert-asn1-perl_0.34.bb
+++ b/meta/recipes-extended/perl/libconvert-asn1-perl_0.34.bb
@@ -10,6 +10,7 @@  SRC_URI = "${CPAN_MIRROR}/authors/id/T/TI/TIMLEGGE/Convert-ASN1-${PV}.tar.gz \
 	   file://CVE-2026-126568.patch \
 	   file://CVE-2026-126576.patch \
 	   file://CVE-2026-126682.patch \
+	   file://CVE-2026-126819.patch \
 	   "
 
 SRC_URI[sha256sum] = "a628d7c9d390568fb76359975fa03f626ce57f10dc17980e8e3587d7713e4ee7"