]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.24] 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:00:54 +0000 (11:00 -0700)
commit5c3d61c886f7ecfce9a6d6d3c97e6d5a8afb17d1
tree548ba54d0e3535809d74bd607139b65a65102ff5
parentc6b04dd33b0215f5deb83724661921842bf67607
[release-branch.go1.24] 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 #75704
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/+/2984
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/709841
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Michael Pratt <mpratt@google.com>
TryBot-Bypass: Michael Pratt <mpratt@google.com>
src/encoding/asn1/asn1.go
src/encoding/asn1/asn1_test.go
src/go/build/deps_test.go