]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.25] encoding/asn1: prevent memory exhaustion when parsing using...
authorNicholas Husin <husin@google.com>
Wed, 3 Sep 2025 13:30:56 +0000 (09:30 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 7 Oct 2025 18:02:22 +0000 (11:02 -0700)
commite0f655bf3f96410f90756f49532bc6a1851855ca
tree4de8d220dc35a297eae5a6b46a2f5cbd656ba023
parent100c5a66802b5a895b1d0e5ed3b7918f899c4833
[release-branch.go1.25] encoding/asn1: prevent memory exhaustion when parsing using internal/saferio

Within parseSequenceOf, reflect.MakeSlice is being used to pre-allocate
a slice that is needed in order to fully validate the given DER payload.
The size of the slice allocated are also multiple times larger than the
input DER:

- When using asn1.Unmarshal directly, the allocated slice is ~28x
  larger.
- When passing in DER using x509.ParseCertificateRequest, the allocated
  slice is ~48x larger.
- When passing in DER using ocsp.ParseResponse, the allocated slice is
  ~137x larger.

As a result, a malicious actor can craft a big empty DER payload,
resulting in an unnecessary large allocation of memories. This can be a
way to cause memory exhaustion.

To prevent this, we now use SliceCapWithSize within internal/saferio to
enforce a memory allocation cap.

Thanks to Jakub Ciolek for reporting this issue.

For #75671
Fixes #75705
Fixes CVE-2025-58185

Change-Id: Id50e76187eda43f594be75e516b9ca1d2ae6f428
Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/2700
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/2966
Reviewed-by: Nicholas Husin <husin@google.com>
Commit-Queue: Roland Shoemaker <bracewell@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/709850
TryBot-Bypass: Michael Pratt <mpratt@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Michael Pratt <mpratt@google.com>
src/encoding/asn1/asn1.go
src/encoding/asn1/asn1_test.go
src/go/build/deps_test.go