CVE-2024-1394
Description
A memory leak flaw was found in Golang in the RSA encrypting/decrypting code, which might lead to a resource exhaustion vulnerability using attacker-controlled inputs. The memory leak happens in github.com/golang-fips/openssl/openssl/rsa.go#L113. The objects leaked are pkey and ctx. That function uses named return parameters to free pkey and ctx if there is an error initializing the context or setting the different properties. All return statements related to error cases follow the "return nil, nil, fail(...)" pattern, meaning that pkey and ctx will be nil inside the deferred function that should free them.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
github.com/golang-fips/goGo | <= 1.22.1 | — |
github.com/golang-fips/openssl/v2Go | < 2.0.1 | 2.0.1 |
github.com/microsoft/go-crypto-opensslGo | <= 0.2.8 | — |
github.com/microsoft/go-crypto-openssl/opensslGo | < 0.2.9 | 0.2.9 |
Patches
285d31d0d257cMerge pull request from GHSA-78hx-gp6g-7mj6
2 files changed · +11 −11
cipher.go+2 −2 modified@@ -533,12 +533,12 @@ func sliceForAppend(in []byte, n int) (head, tail []byte) { return } -func newCipherCtx(kind cipherKind, mode cipherMode, encrypt cipherOp, key, iv []byte) (ctx C.GO_EVP_CIPHER_CTX_PTR, err error) { +func newCipherCtx(kind cipherKind, mode cipherMode, encrypt cipherOp, key, iv []byte) (_ C.GO_EVP_CIPHER_CTX_PTR, err error) { cipher := loadCipher(kind, mode) if cipher == nil { panic("crypto/cipher: unsupported cipher: " + kind.String()) } - ctx = C.go_openssl_EVP_CIPHER_CTX_new() + ctx := C.go_openssl_EVP_CIPHER_CTX_new() if ctx == nil { return nil, fail("unable to create EVP cipher ctx") }
evp.go+9 −9 modified@@ -149,7 +149,15 @@ type verifyFunc func(C.GO_EVP_PKEY_CTX_PTR, *C.uchar, C.size_t, *C.uchar, C.size func setupEVP(withKey withKeyFunc, padding C.int, h, mgfHash hash.Hash, label []byte, saltLen C.int, ch crypto.Hash, - init initFunc) (ctx C.GO_EVP_PKEY_CTX_PTR, err error) { + init initFunc) (_ C.GO_EVP_PKEY_CTX_PTR, err error) { + var ctx C.GO_EVP_PKEY_CTX_PTR + withKey(func(pkey C.GO_EVP_PKEY_PTR) C.int { + ctx = C.go_openssl_EVP_PKEY_CTX_new(pkey, nil) + return 1 + }) + if ctx == nil { + return nil, newOpenSSLError("EVP_PKEY_CTX_new failed") + } defer func() { if err != nil { if ctx != nil { @@ -158,14 +166,6 @@ func setupEVP(withKey withKeyFunc, padding C.int, } } }() - - withKey(func(pkey C.GO_EVP_PKEY_PTR) C.int { - ctx = C.go_openssl_EVP_PKEY_CTX_new(pkey, nil) - return 1 - }) - if ctx == nil { - return nil, newOpenSSLError("EVP_PKEY_CTX_new failed") - } if err := init(ctx); err != nil { return nil, err }
104fe7f69127Fix memory leak in setupEVP
1 file changed · +9 −9
openssl/evpkey.go+9 −9 modified@@ -101,7 +101,15 @@ type verifyFunc func(C.GO_EVP_PKEY_CTX_PTR, *C.uchar, C.size_t, *C.uchar, C.size func setupEVP(withKey withKeyFunc, padding C.int, h, mgfHash hash.Hash, label []byte, saltLen C.int, ch crypto.Hash, - init initFunc) (ctx C.GO_EVP_PKEY_CTX_PTR, err error) { + init initFunc) (_ C.GO_EVP_PKEY_CTX_PTR, err error) { + var ctx C.GO_EVP_PKEY_CTX_PTR + withKey(func(pkey C.GO_EVP_PKEY_PTR) C.int { + ctx = C.go_openssl_EVP_PKEY_CTX_new(pkey, nil) + return 1 + }) + if ctx == nil { + return nil, newOpenSSLError("EVP_PKEY_CTX_new failed") + } defer func() { if err != nil { if ctx != nil { @@ -110,14 +118,6 @@ func setupEVP(withKey withKeyFunc, padding C.int, } } }() - - withKey(func(pkey C.GO_EVP_PKEY_PTR) C.int { - ctx = C.go_openssl_EVP_PKEY_CTX_new(pkey, nil) - return 1 - }) - if ctx == nil { - return nil, newOpenSSLError("EVP_PKEY_CTX_new failed") - } if err := init(ctx); err != nil { return nil, err }
Vulnerability mechanics
Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
50- github.com/advisories/GHSA-78hx-gp6g-7mj6ghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2024-1394ghsaADVISORY
- access.redhat.com/errata/RHSA-2024:1462nvdWEB
- access.redhat.com/errata/RHSA-2024:1468nvdWEB
- access.redhat.com/errata/RHSA-2024:1472nvdWEB
- access.redhat.com/errata/RHSA-2024:1501nvdWEB
- access.redhat.com/errata/RHSA-2024:1502nvdWEB
- access.redhat.com/errata/RHSA-2024:1561nvdWEB
- access.redhat.com/errata/RHSA-2024:1563nvdWEB
- access.redhat.com/errata/RHSA-2024:1566nvdWEB
- access.redhat.com/errata/RHSA-2024:1567nvdWEB
- access.redhat.com/errata/RHSA-2024:1574nvdWEB
- access.redhat.com/errata/RHSA-2024:1640nvdWEB
- access.redhat.com/errata/RHSA-2024:1644nvdWEB
- access.redhat.com/errata/RHSA-2024:1646nvdWEB
- access.redhat.com/errata/RHSA-2024:1763nvdWEB
- access.redhat.com/errata/RHSA-2024:1897nvdWEB
- access.redhat.com/errata/RHSA-2024:2562nvdWEB
- access.redhat.com/errata/RHSA-2024:2568nvdWEB
- access.redhat.com/errata/RHSA-2024:2569nvdWEB
- access.redhat.com/errata/RHSA-2024:2729nvdWEB
- access.redhat.com/errata/RHSA-2024:2730nvdWEB
- access.redhat.com/errata/RHSA-2024:2767nvdWEB
- access.redhat.com/errata/RHSA-2024:3265nvdWEB
- access.redhat.com/errata/RHSA-2024:3352nvdWEB
- access.redhat.com/errata/RHSA-2024:4146nvdWEB
- access.redhat.com/errata/RHSA-2024:4371nvdWEB
- access.redhat.com/errata/RHSA-2024:4378nvdWEB
- access.redhat.com/errata/RHSA-2024:4379nvdWEB
- access.redhat.com/errata/RHSA-2024:4502nvdWEB
- access.redhat.com/errata/RHSA-2024:4581nvdWEB
- access.redhat.com/errata/RHSA-2024:4591nvdWEB
- access.redhat.com/errata/RHSA-2024:4672nvdWEB
- access.redhat.com/errata/RHSA-2024:4699nvdWEB
- access.redhat.com/errata/RHSA-2024:4761nvdWEB
- access.redhat.com/errata/RHSA-2024:4762nvdWEB
- access.redhat.com/errata/RHSA-2024:4960nvdWEB
- access.redhat.com/errata/RHSA-2024:5258nvdWEB
- access.redhat.com/errata/RHSA-2024:5634nvdWEB
- access.redhat.com/errata/RHSA-2024:7262nvdWEB
- access.redhat.com/security/cve/CVE-2024-1394nvdWEB
- bugzilla.redhat.com/show_bug.cginvdWEB
- github.com/golang-fips/openssl/commit/85d31d0d257ce842c8a1e63c4d230ae850348136nvdWEB
- github.com/golang-fips/openssl/releases/tag/v2.0.1ghsaWEB
- github.com/golang-fips/openssl/security/advisories/GHSA-78hx-gp6g-7mj6nvdWEB
- github.com/microsoft/go-crypto-openssl/commit/104fe7f6912788d2ad44602f77a0a0a62f1f259fnvdWEB
- github.com/microsoft/go-crypto-openssl/releases/tag/v0.2.9ghsaWEB
- pkg.go.dev/vuln/GO-2024-2660nvdWEB
- vuln.go.dev/ID/GO-2024-2660.jsonnvdWEB
- access.redhat.com/errata/RHSA-2025:7118nvd
News mentions
0No linked articles in our index yet.