diff mbox series

[wrynose,6/8] libconvert-asn1-perl: fix CVE-2026-126956

Message ID 20261127064659.2169695-7-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 constructed-form string decoding that can lead
to memory exhaustion (DoS). A specially crafted ASN.1
message with deeply nested constructed strings can
trigger unlimited recursion, causing excessive memory
consumption and potentially crashing the application.

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

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

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

Patch

diff --git a/meta/recipes-extended/perl/libconvert-asn1-perl/CVE-2026-126956.patch b/meta/recipes-extended/perl/libconvert-asn1-perl/CVE-2026-126956.patch
new file mode 100644
index 0000000000..99bdc249d4
--- /dev/null
+++ b/meta/recipes-extended/perl/libconvert-asn1-perl/CVE-2026-126956.patch
@@ -0,0 +1,182 @@ 
+From a2d8d2dab891fd5e7795eb34f14e903b0c8e8795 Mon Sep 17 00:00:00 2001
+From: Timothy Legge <timlegge@gmail.com>
+Date: Wed, 11 Nov 2026 22:25:08 +0000
+Subject: [PATCH 6/8] Fix CVE-2026-126956: constructed-form strings allow
+ unbounded recursion
+
+Add a configurable nesting depth limit at the top of _decode, covering
+all recursive call sites: constructed strings, SEQUENCE, SET, EXPLICIT
+tags, and CHOICE. Default is 99 (below Perl's built-in deep-recursion
+warning threshold); zero disables; negative values are rejected.
+
+Propagate depth counter into ANY DEFINED BY sub-decoders. The handler
+call at _decode.pm:148 invokes a separate ASN1 object whose $optn would
+otherwise reset the counter to zero; seeding _decode_depth and
+decode_max_depth with local before the call closes that bypass path.
+
+Rethrow the depth error from the eval around untagged CHOICE
+alternatives. Treating it as a non-match made each level retry every
+alternative, so nested CHOICEs could cost up to 2**max_depth work.
+
+  $asn->configure(decode => { max_depth => N });
+
+CVE: CVE-2026-126956
+Upstream-Status: Backport [https://github.com/cpan-authors/perl-Convert-ASN1/commit/99a96139a322ba0a5183c7e40a8857f3550daace]
+Signed-off-by: Omkar Patil <OmkarAbaji.Patil@windriver.com>
+---
+ lib/Convert/ASN1.pod        | 13 +++++++
+ lib/Convert/ASN1/_decode.pm | 25 ++++++++++++--
+ t/26dec_depth_limit.t       | 67 +++++++++++++++++++++++++++++++++++++
+ 3 files changed, 102 insertions(+), 3 deletions(-)
+ create mode 100644 t/26dec_depth_limit.t
+
+diff --git a/lib/Convert/ASN1.pod b/lib/Convert/ASN1.pod
+index 898f124..e52d8b9 100644
+--- a/lib/Convert/ASN1.pod
++++ b/lib/Convert/ASN1.pod
+@@ -185,6 +185,19 @@ rejected as invalid.
+   $asn->configure(decode => { max_int_len => 4096 });   # allow up to 32767-bit
+   $asn->configure(decode => { max_int_len => 0    });   # no limit (not recommended)
+ 
++=item max_depth
++
++Maximum number of nested C<_decode> calls permitted before decoding is aborted
++with an error. Each SEQUENCE, SET, EXPLICIT tag, constructed string, or CHOICE
++without a tag adds one level. Prevents a remote peer from causing unbounded
++stack growth by sending deeply nested structures. Defaults to C<99>, which is
++sufficient for any real-world X.509 certificate, LDAP message, or SNMP PDU,
++and stays below Perl's built-in deep-recursion warning threshold of 100.
++Set to C<0> to disable the limit; negative values are rejected as invalid.
++
++  $asn->configure(decode => { max_depth => 256 });   # allow deeper nesting
++  $asn->configure(decode => { max_depth => 0   });   # no limit (not recommended)
++
+ =item null
+ 
+ The value to decode ASN.1 NULL types into.
+diff --git a/lib/Convert/ASN1/_decode.pm b/lib/Convert/ASN1/_decode.pm
+index 3e1978d..0450471 100644
+--- a/lib/Convert/ASN1/_decode.pm
++++ b/lib/Convert/ASN1/_decode.pm
+@@ -44,6 +44,13 @@ my @ctr;
+ 
+ sub _decode {
+   my ($optn, $ops, $stash, $pos, $end, $seqof, $larr) = @_;
++
++  my $max_depth = exists $optn->{decode_max_depth} ? $optn->{decode_max_depth} : 99;
++  local $optn->{_decode_depth} = ($optn->{_decode_depth} || 0) + 1;
++  die "decode: max_depth must not be negative\n" if $max_depth < 0;
++  die "decode error (nesting depth limit exceeded)\n"
++      if $max_depth > 0 && $optn->{_decode_depth} > $max_depth;
++
+   my $idx = 0;
+ 
+   # we try not to copy the input buffer at any time
+@@ -137,8 +144,16 @@ sub _decode {
+               $handler ||= $optn->{handlers}{$op->[cVAR]}{$stash->{$op->[cDEFINE]}};
+             }
+ 
+-	    ($seqof ? $seqof->[$idx++] : ref($stash) eq 'SCALAR' ? $$stash : $stash->{$var})
+-	      = $handler ? $handler->decode(substr($buf,$pos,$len)) : substr($buf,$pos,$len);
++	    if ($handler) {
++	      local $handler->{options}{_decode_depth} = $optn->{_decode_depth};
++	      local $handler->{options}{decode_max_depth} = $max_depth
++	          unless exists $handler->{options}{decode_max_depth};
++	      ($seqof ? $seqof->[$idx++] : ref($stash) eq 'SCALAR' ? $$stash : $stash->{$var})
++	        = $handler->decode(substr($buf,$pos,$len));
++	    } else {
++	      ($seqof ? $seqof->[$idx++] : ref($stash) eq 'SCALAR' ? $$stash : $stash->{$var})
++	        = substr($buf,$pos,$len);
++	    }
+ 
+ 	    $pos += $len;
+ 
+@@ -206,7 +221,11 @@ sub _decode {
+ 
+ 		  @{$nstash}{keys %tmp_stash} = values %tmp_stash;
+ 
+-		} or next;
++		} or do {
++		  die $@ if $@ =~ /nesting depth limit exceeded/;
++		  next;
++		};
++
+ 
+ 		$pos = $npos+$len+$indef;
+ 
+diff --git a/t/26dec_depth_limit.t b/t/26dec_depth_limit.t
+new file mode 100644
+index 0000000..dba346e
+--- /dev/null
++++ b/t/26dec_depth_limit.t
+@@ -0,0 +1,67 @@
++#!/usr/bin/perl
++# Tests for _decode nesting depth limit (F7).
++
++use strict;
++use warnings;
++use lib 'lib';
++use Convert::ASN1 qw(asn_encode_length);
++BEGIN { require './t/funcs.pl' }
++
++print "1..12\n";
++
++# Build a schema with $depth levels of SEQUENCE nesting around an INTEGER.
++sub make_schema {
++    my $depth = shift;
++    my $s = 'n INTEGER';
++    $s = "x SEQUENCE { $s }" for 1 .. $depth;
++    return $s;
++}
++
++# Build matching BER input: $depth levels of SEQUENCE wrapping INTEGER value $v.
++sub make_input {
++    my ($depth, $v) = @_;
++    my $buf = "\x02\x01" . chr($v);
++    $buf = pack("C", 0x30) . asn_encode_length(length $buf) . $buf for 1 .. $depth;
++    return $buf;
++}
++
++my ($asn, $ret);
++btest 1, $asn = Convert::ASN1->new;
++
++# --- 2-3: 2 levels passes max_depth => 3 ---
++$asn->configure(decode => { max_depth => 3 });
++btest 2, $asn->prepare(make_schema(2)) or warn $asn->error;
++btest 3, defined($asn->decode(make_input(2, 7))) or warn $asn->error;
++
++# --- 4-6: 3 levels exceeds max_depth => 3 (depth reaches 4) ---
++btest 4, $asn->prepare(make_schema(3)) or warn $asn->error;
++btest 5, !defined($asn->decode(make_input(3, 7)));
++btest 6, ($asn->error || '') =~ /depth/;
++
++# --- 7: max_depth => 0 disables the limit ---
++$asn->configure(decode => { max_depth => 0 });
++btest 7, defined($asn->decode(make_input(3, 7))) or warn $asn->error;
++
++# --- 8: raising max_depth to 10 allows 3 levels ---
++$asn->configure(decode => { max_depth => 10 });
++btest 8, defined($asn->decode(make_input(3, 7))) or warn $asn->error;
++
++# --- 9: negative max_depth is a hard error ---
++$asn->configure(decode => { max_depth => -1 });
++btest 9, !defined($asn->decode(make_input(3, 7))) && ($asn->error || '') =~ /max_depth must not be negative/;
++
++# --- 10-12: depth error inside an untagged CHOICE alternative aborts the decode
++# rather than being treated as a non-match; otherwise each level retries every
++# alternative and the work grows as 2**max_depth ---
++{
++    my $levels = 30;
++    my $schema = "L0 ::= INTEGER\n";
++    $schema .= "L$_ ::= CHOICE { a L" . ($_ - 1) . ", b L" . ($_ - 1) . " }\n" for 1 .. $levels;
++    my $choice = Convert::ASN1->new;
++    $choice->configure(decode => { max_depth => 22 });
++    btest 10, $choice->prepare($schema) or warn $choice->error;
++    my $top = $choice->find("L$levels");
++    my $t = time;
++    btest 11, !defined($top->decode("\x04\x01\x41")) && ($top->error || '') =~ /depth/;
++    btest 12, 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 4615a1a90e..fc47ccf8d7 100644
--- a/meta/recipes-extended/perl/libconvert-asn1-perl_0.34.bb
+++ b/meta/recipes-extended/perl/libconvert-asn1-perl_0.34.bb
@@ -11,6 +11,7 @@  SRC_URI = "${CPAN_MIRROR}/authors/id/T/TI/TIMLEGGE/Convert-ASN1-${PV}.tar.gz \
 	   file://CVE-2026-126576.patch \
 	   file://CVE-2026-126682.patch \
 	   file://CVE-2026-126819.patch \
+	   file://CVE-2026-126956.patch \
 	   "
 
 SRC_URI[sha256sum] = "a628d7c9d390568fb76359975fa03f626ce57f10dc17980e8e3587d7713e4ee7"