diff mbox series

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

Message ID 20261127064659.2169695-9-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 OBJECT IDENTIFIER (OID) encoding and decoding
that can lead to CPU exhaustion (DoS). A specially
crafted OID with an excessively large arc value can
trigger expensive processing in Perl's pack "w*" or
unpack "w*", causing excessive CPU usage and potentially
impacting application availability.

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

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

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

Patch

diff --git a/meta/recipes-extended/perl/libconvert-asn1-perl/CVE-2026-131877.patch b/meta/recipes-extended/perl/libconvert-asn1-perl/CVE-2026-131877.patch
new file mode 100644
index 0000000000..6b8da07d23
--- /dev/null
+++ b/meta/recipes-extended/perl/libconvert-asn1-perl/CVE-2026-131877.patch
@@ -0,0 +1,216 @@ 
+From ed9b6afffccd7f24b0bb93fff983065eb9508f2a Mon Sep 17 00:00:00 2001
+From: Timothy Legge <timlegge@gmail.com>
+Date: Tue, 17 Nov 2026 22:31:03 -0400
+Subject: [PATCH 8/8] Fix CVE-2026-131877 Limit OBJECT IDENTIFIER arc size to
+ prevent quadratic
+
+_dec_object_id passed the content straight to unpack "w*", which
+converts each arc to a decimal string in time quadratic in the arc's
+length. A single 80KB arc took about 10 seconds to decode and a 1MB
+arc would take around half an hour. _enc_object_id had the same cost
+through pack "w*" for an arc given as a very long decimal string.
+
+Add a max_oid_arc_len option for decode and encode, in encoded bytes
+per arc, defaulting to 32 (224 bits; a 128-bit UUID arc needs 19).
+ASN.1 puts no upper bound on an arc, so 0 disables the limit and
+negative values are rejected. On encode the limit is applied as a
+digit count that always fits, so the encoder cannot produce an OID
+the decoder refuses at the same setting. RELATIVE-OID shares both
+functions and the option. Document it in the pod and add
+t/28oid_arc_limit.t.
+
+  $asn->configure(decode => { max_oid_arc_len => 64 });   # allow up to 448-bit arcs
+  $asn->configure(decode => { max_oid_arc_len => 0  });   # no limit (not recommended)
+
+CVE: CVE-2026-131877
+Upstream-Status: Backport [https://github.com/cpan-authors/perl-Convert-ASN1/commit/805a7ee7d6c01a7dd6e0479fabcaadd7f9116e70]
+Signed-off-by: Omkar Patil <OmkarAbaji.Patil@windriver.com>
+---
+ lib/Convert/ASN1.pod        | 25 ++++++++++++
+ lib/Convert/ASN1/_decode.pm | 14 +++++++
+ lib/Convert/ASN1/_encode.pm | 12 ++++++
+ t/28oid_arc_limit.t         | 81 +++++++++++++++++++++++++++++++++++++
+ 4 files changed, 132 insertions(+)
+ create mode 100644 t/28oid_arc_limit.t
+
+diff --git a/lib/Convert/ASN1.pod b/lib/Convert/ASN1.pod
+index e52d8b9..87e18cc 100644
+--- a/lib/Convert/ASN1.pod
++++ b/lib/Convert/ASN1.pod
+@@ -137,6 +137,19 @@ limit.
+   $asn->configure(encode => { max_int_len => 4096 });   # allow up to 32767-bit
+   $asn->configure(encode => { max_int_len => 0    });   # no limit (not recommended)
+ 
++=item max_oid_arc_len
++
++Maximum size, in encoded bytes, of a single OBJECT IDENTIFIER or RELATIVE-OID
++arc before encoding is aborted with an error. ASN.1 places no upper bound on
++an arc, but the time to encode one grows with the square of its length.
++Defaults to C<32> (224 bits; a 128-bit UUID arc needs 19 bytes). The check is
++made on the number of decimal digits, so an arc within a few bits of the limit
++may be rejected. Set to C<0> to disable the limit; negative values are
++rejected as invalid.
++
++  $asn->configure(encode => { max_oid_arc_len => 64 });   # allow up to 448-bit arcs
++  $asn->configure(encode => { max_oid_arc_len => 0  });   # no limit (not recommended)
++
+ =back
+ 
+ Decode options
+@@ -198,6 +211,18 @@ 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 max_oid_arc_len
++
++Maximum size, in encoded bytes, of a single OBJECT IDENTIFIER or RELATIVE-OID
++arc before decoding is aborted with an error. ASN.1 places no upper bound on
++an arc, but the time to decode one grows with the square of its length, so a
++remote peer could otherwise consume unbounded CPU with a single large arc.
++Defaults to C<32> (224 bits; a 128-bit UUID arc needs 19 bytes). Set to C<0>
++to disable the limit; negative values are rejected as invalid.
++
++  $asn->configure(decode => { max_oid_arc_len => 64 });   # allow up to 448-bit arcs
++  $asn->configure(decode => { max_oid_arc_len => 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 0450471..9cdf1fd 100644
+--- a/lib/Convert/ASN1/_decode.pm
++++ b/lib/Convert/ASN1/_decode.pm
+@@ -351,6 +351,20 @@ sub _dec_object_id {
+ # 0      1    2       3     4     5     6
+ # $optn, $op, $stash, $var, $buf, $pos, $len
+ 
++  # unpack "w" is quadratic in arc length, so bound each arc first
++  my $max = exists $_[0]->{decode_max_oid_arc_len}
++              ? $_[0]->{decode_max_oid_arc_len}
++              : 32;
++  die "decode: max_oid_arc_len must not be negative\n" if $max < 0;
++  if ($max) {
++    my $oid = substr($_[4],$_[5],$_[6]);
++    # every byte of an arc except its last has the high bit set
++    while ($oid =~ /[\x80-\xff]+/g) {
++      die "OBJECT IDENTIFIER decode error (arc too large)\n"
++          if $+[0] - $-[0] >= $max;
++    }
++  }
++
+   my @data = unpack("w*",substr($_[4],$_[5],$_[6]));
+   if ($_[1]->[cTYPE] == opOBJID and @data > 1) {
+     if ($data[0] < 40) {
+diff --git a/lib/Convert/ASN1/_encode.pm b/lib/Convert/ASN1/_encode.pm
+index b1c0adb..335f3ec 100644
+--- a/lib/Convert/ASN1/_encode.pm
++++ b/lib/Convert/ASN1/_encode.pm
+@@ -190,6 +190,18 @@ sub _enc_object_id {
+ 
+   my @data = ($_[3] =~ /(\d+)/g);
+ 
++  # pack "w" is quadratic in arc length, so bound each arc first
++  my $max = exists $_[0]->{encode_max_oid_arc_len}
++              ? $_[0]->{encode_max_oid_arc_len}
++              : 32;
++  die "encode: max_oid_arc_len must not be negative\n" if $max < 0;
++  if ($max) {
++    # any arc of this many digits fits in $max bytes: 2.107 < 7 * log10(2)
++    my $digits = int($max * 2.107);
++    die "OBJECT IDENTIFIER arc too large\n"
++        if grep { length > $digits } @data;
++  }
++
+   if ($_[1]->[cTYPE] == opOBJID) {
+     if(@data < 2) {
+       @data = (0);
+diff --git a/t/28oid_arc_limit.t b/t/28oid_arc_limit.t
+new file mode 100644
+index 0000000..4de1b30
+--- /dev/null
++++ b/t/28oid_arc_limit.t
+@@ -0,0 +1,81 @@
++#!/usr/bin/perl
++# OBJECT IDENTIFIER and RELATIVE-OID arcs are limited in size, because
++# pack/unpack "w" take quadratic time on a very large arc.
++
++use strict;
++use warnings;
++use lib 'lib';
++use Convert::ASN1 qw(asn_encode_length);
++BEGIN { require './t/funcs.pl' }
++
++print "1..28\n";
++
++sub tlv { pack("C", $_[0]) . asn_encode_length(length $_[1]) . $_[1] }
++
++my ($asn, $rel, $ret, $enc, $t);
++btest 1, $asn = Convert::ASN1->new;
++btest 2, $asn->prepare('o OBJECT IDENTIFIER') or warn $asn->error;
++btest 3, $rel = Convert::ASN1->new;
++btest 4, $rel->prepare('o RELATIVE-OID') or warn $rel->error;
++
++# --- 5-6: ordinary and UUID-arc OIDs still round-trip ---
++for my $case ([5, '1.2.840.113549.1.1.11'],
++              [6, '2.25.329800735698586629295641978511506172918']) {
++    $enc = $asn->encode(o => $case->[1]);
++    $ret = defined $enc ? $asn->decode($enc) : undef;
++    btest $case->[0], $ret && $ret->{o} eq $case->[1] or warn $asn->error;
++}
++
++# --- 7-9: a huge arc is rejected on decode, quickly ---
++$t = time;
++btest 7, !defined($asn->decode(tlv(0x06, "\x2a" . ("\xff" x 60_000) . "\x7f")));
++btest 8, ($asn->error || '') =~ /arc too large/;
++btest 9, time - $t < 2;
++
++# --- 10-11: a 32-byte arc decodes, a 33-byte arc does not ---
++btest 10, defined($asn->decode(tlv(0x06, "\x2a" . ("\x81" x 31) . "\x01"))) or warn $asn->error;
++btest 11, !defined($asn->decode(tlv(0x06, "\x2a" . ("\x81" x 32) . "\x01")));
++
++# --- 12-13: RELATIVE-OID uses the same limit ---
++btest 12, !defined($rel->decode(tlv(0x0d, ("\xff" x 60_000) . "\x7f")));
++btest 13, ($rel->error || '') =~ /arc too large/;
++
++# --- 14-16: a huge arc is rejected on encode, quickly ---
++$t = time;
++btest 14, !defined($asn->encode(o => '1.2.' . ('9' x 80_000)));
++btest 15, ($asn->error || '') =~ /arc too large/;
++btest 16, time - $t < 2;
++
++# --- 17-18: a 67-digit arc encodes and decodes back, a 68-digit arc does not ---
++my $oid67 = '1.2.' . ('9' x 67);
++$enc = $asn->encode(o => $oid67);
++$ret = defined $enc ? $asn->decode($enc) : undef;
++btest 17, $ret && $ret->{o} eq $oid67 or warn $asn->error;
++btest 18, !defined($asn->encode(o => '1.2.' . ('9' x 68)));
++
++# --- 19: RELATIVE-OID encode uses the same limit ---
++btest 19, !defined($rel->encode(o => '5.' . ('9' x 80_000)));
++
++# --- 20-28: the limit is configurable through max_oid_arc_len ---
++my $arc33 = tlv(0x06, "\x2a" . ("\x81" x 32) . "\x01");     # one 33-byte arc
++my $oid68 = '1.2.' . ('9' x 68);
++
++my $cfg = Convert::ASN1->new;
++$cfg->prepare('o OBJECT IDENTIFIER') or warn $cfg->error;
++
++$cfg->configure(decode => { max_oid_arc_len => 64 }, encode => { max_oid_arc_len => 64 });
++btest 20, defined($cfg->decode($arc33)) or warn $cfg->error;
++btest 21, defined($cfg->encode(o => $oid68)) or warn $cfg->error;
++btest 22, !defined($cfg->decode(tlv(0x06, "\x2a" . ("\x81" x 64) . "\x01")));
++
++$cfg->configure(decode => { max_oid_arc_len => 0 }, encode => { max_oid_arc_len => 0 });
++btest 23, defined($cfg->decode(tlv(0x06, "\x2a" . ("\x81" x 500) . "\x01"))) or warn $cfg->error;
++btest 24, defined($cfg->encode(o => '1.2.' . ('9' x 1000))) or warn $cfg->error;
++
++$cfg->configure(decode => { max_oid_arc_len => 8 }, encode => { max_oid_arc_len => 8 });
++btest 25, !defined($cfg->decode(tlv(0x06, "\x2a" . ("\x81" x 8) . "\x01")));
++btest 26, !defined($cfg->encode(o => '1.2.' . ('9' x 17)));
++
++$cfg->configure(decode => { max_oid_arc_len => -1 }, encode => { max_oid_arc_len => -1 });
++btest 27, !defined($cfg->decode($arc33)) && ($cfg->error || '') =~ /max_oid_arc_len must not be negative/;
++btest 28, !defined($cfg->encode(o => '1.2.3')) && ($cfg->error || '') =~ /max_oid_arc_len must not be negative/;
+-- 
+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 c404b4f2b0..139c5d85fb 100644
--- a/meta/recipes-extended/perl/libconvert-asn1-perl_0.34.bb
+++ b/meta/recipes-extended/perl/libconvert-asn1-perl_0.34.bb
@@ -13,6 +13,7 @@  SRC_URI = "${CPAN_MIRROR}/authors/id/T/TI/TIMLEGGE/Convert-ASN1-${PV}.tar.gz \
 	   file://CVE-2026-126819.patch \
 	   file://CVE-2026-126956.patch \
 	   file://CVE-2026-131868.patch \
+	   file://CVE-2026-131877.patch \
 	   "
 
 SRC_URI[sha256sum] = "a628d7c9d390568fb76359975fa03f626ce57f10dc17980e8e3587d7713e4ee7"