diff mbox series

[wrynose,3/8] libconvert-asn1-perl: fix CVE-2026-126576

Message ID 20261127064659.2169695-4-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 binary REAL decoding that can lead to
CPU exhaustion (DoS). A specially crafted ASN.1
value can cause the decoder to process large
portions of the input repeatedly due to improper
exponent length validation, resulting in excessive
CPU consumption.

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

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

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

Patch

diff --git a/meta/recipes-extended/perl/libconvert-asn1-perl/CVE-2026-126576.patch b/meta/recipes-extended/perl/libconvert-asn1-perl/CVE-2026-126576.patch
new file mode 100644
index 0000000000..147f8dfcad
--- /dev/null
+++ b/meta/recipes-extended/perl/libconvert-asn1-perl/CVE-2026-126576.patch
@@ -0,0 +1,125 @@ 
+From 6515eb600911c846c0e98651825d8583ff99e689 Mon Sep 17 00:00:00 2001
+From: Timothy Legge <timlegge@gmail.com>
+Date: Wed, 11 Nov 2026 03:43:20 +0000
+Subject: [PATCH 3/8] Fix CVE-2026-126576: _dec_real bounds-check expLen and
+ fix mantissa length
+
+Add a guard rejecting expLen values that exceed available content bytes,
+preventing buffer overread. Fix the mantissa length calculation to use
+the actual header overhead (1 for short-form, 2 for long-form exponent)
+instead of a hard-coded 1. Add tests covering both cases and correct an
+off-by-one in the max_int_len pod comment (4096 bytes = 32767 bits).
+
+Reject exponents longer than 4 bytes; they were decoded as a bigint
+and made pow() compute an unbounded exact power.
+
+CVE: CVE-2026-126576
+Upstream-Status: Backport [https://github.com/cpan-authors/perl-Convert-ASN1/commit/6158dbb33cc3d248a95b4ab4948a135e18141b51]
+Signed-off-by: Omkar Patil <OmkarAbaji.Patil@windriver.com>
+---
+ lib/Convert/ASN1.pod        |  2 +-
+ lib/Convert/ASN1/_decode.pm |  7 ++++-
+ t/23dec_real.t              | 57 +++++++++++++++++++++++++++++++++++++
+ 3 files changed, 64 insertions(+), 2 deletions(-)
+ create mode 100644 t/23dec_real.t
+
+diff --git a/lib/Convert/ASN1.pod b/lib/Convert/ASN1.pod
+index 3e9614b..dc98a8c 100644
+--- a/lib/Convert/ASN1.pod
++++ b/lib/Convert/ASN1.pod
+@@ -167,7 +167,7 @@ value. Defaults to C<1025> (enough for an RSA-8192 modulus, which requires a
+ leading sign byte). Set to C<0> to disable the limit; negative values are
+ rejected as invalid.
+ 
+-  $asn->configure(decode => { max_int_len => 4096 });   # allow up to 32768-bit
++  $asn->configure(decode => { max_int_len => 4096 });   # allow up to 32767-bit
+   $asn->configure(decode => { max_int_len => 0    });   # no limit (not recommended)
+ 
+ =item null
+diff --git a/lib/Convert/ASN1/_decode.pm b/lib/Convert/ASN1/_decode.pm
+index 3d10bb3..72db28e 100644
+--- a/lib/Convert/ASN1/_decode.pm
++++ b/lib/Convert/ASN1/_decode.pm
+@@ -369,10 +369,15 @@ sub _dec_real {
+     else {
+       $expLen++;
+     }
++
++    my $overhead = $estart - $_[5];   # 1 short-form, 2 long-form
++    # an exponent over 4 bytes would become a bigint and make pow() run unbounded
++    die "REAL decode error\n" if $expLen > 4 || $expLen > $_[6] - $overhead;
++
+     _dec_integer(undef, undef, undef, $exp, $_[4],$estart,$expLen);
+ 
+     my $mant = 0.0;
+-    for (reverse unpack("C*",substr($_[4],$estart+$expLen,$_[6]-1-$expLen))) {
++    for (reverse unpack("C*",substr($_[4],$estart+$expLen,$_[6]-$overhead-$expLen))) {
+       $exp +=8, $mant = (($mant+$_) / 256) ;
+     }
+ 
+diff --git a/t/23dec_real.t b/t/23dec_real.t
+new file mode 100644
+index 0000000..6d7d1ef
+--- /dev/null
++++ b/t/23dec_real.t
+@@ -0,0 +1,57 @@
++#!/usr/bin/perl
++# Tests for _dec_real exponent bounds fix (F4).
++
++use strict;
++use warnings;
++use lib 'lib';
++use Convert::ASN1;
++BEGIN { require './t/funcs.pl' }
++
++print "1..15\n";
++
++my ($asn, $ret);
++
++btest 1, $asn = Convert::ASN1->new;
++btest 2, $asn->prepare('r REAL') or warn $asn->error;
++
++# Helper: build a BER REAL from raw content bytes.
++sub make_real { "\x09" . chr(length $_[0]) . $_[0] }
++
++# --- 3: zero-length REAL decodes to 0.0 ---
++btest 3, $ret = $asn->decode(make_real('')) or warn $asn->error;
++btest 4, $ret->{r} == 0.0;
++
++# --- 5: valid binary REAL (1.0 base-2: first=0x80, exp=0, mant=1) ---
++# 09 03 80 00 01  -> binary, exp=0, mant=1 -> 1.0
++my $one = make_real("\x80\x00\x01");
++btest 5, $ret = $asn->decode($one) or warn $asn->error;
++btest 6, $ret->{r} == 1.0;
++
++# --- 7: expLen > content length is rejected (buffer overread / quadratic) ---
++# 09 01 80  -> binary, expLen=1, but content is only 1 byte (the first byte) -> invalid
++my $overread = make_real("\x80");
++btest 7, !defined($asn->decode($overread));
++btest 8, ($asn->error || '') =~ /REAL decode error/;
++
++# --- 9: long-form exponent off-by-one fix: valid encoding gives correct value ---
++# Binary REAL, long-form exponent (bits 0-1 = 11 = 3 -> long form):
++# first = 0x83 (binary, base-2, long-exp), expLen-byte = 0x01, exp = 0x00, mant = 0x01
++# -> 1.0
++my $longexp = make_real("\x83\x01\x00\x01");
++btest 9, $ret = $asn->decode($longexp) or warn $asn->error;
++btest 10, $ret->{r} == 1.0;
++
++# --- 11-12: a 4-byte long-form exponent still decodes ---
++# first = 0x83, expLen-byte = 0x04, exp = 0, mant = 0x01 -> 1.0
++btest 11, $ret = $asn->decode(make_real("\x83\x04\x00\x00\x00\x00\x01")) or warn $asn->error;
++btest 12, $ret && $ret->{r} == 1.0;
++
++# --- 13-15: an exponent longer than 4 bytes is rejected; decoding it as a
++# bigint would make pow() compute an enormous exact power ---
++my $t = time;
++local $SIG{ALRM} = sub { die "timeout\n" };
++eval { alarm 10 };    # fail rather than hang if the check is lost
++btest 13, !defined($asn->decode(make_real("\x83\x05\x01\x01\x01\x01\x01\xff")));
++eval { alarm 0 };
++btest 14, ($asn->error || '') =~ /REAL decode error/;
++btest 15, time - $t < 2;
+-- 
+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 f4460bf324..9de25f3f73 100644
--- a/meta/recipes-extended/perl/libconvert-asn1-perl_0.34.bb
+++ b/meta/recipes-extended/perl/libconvert-asn1-perl_0.34.bb
@@ -8,6 +8,7 @@  LIC_FILES_CHKSUM = "file://README.md;beginline=91;endline=97;md5=ceff7fd286eb6d8
 SRC_URI = "${CPAN_MIRROR}/authors/id/T/TI/TIMLEGGE/Convert-ASN1-${PV}.tar.gz \
 	   file://CVE-2026-126540.patch \
 	   file://CVE-2026-126568.patch \
+	   file://CVE-2026-126576.patch \
 	   "
 
 SRC_URI[sha256sum] = "a628d7c9d390568fb76359975fa03f626ce57f10dc17980e8e3587d7713e4ee7"