CVE-2022-45146: Bouncy Castle Garbage Collection Issue Vulnerability

MODERATE
Advisory Identifier: GHSA-68m8-v89j-7j2p
CVSS 5.5
CWE-416
Published
Advisory Summary

CVE-2022-45146 is a MODERATE (CVSS 5.5) garbage collection issue vulnerability (CWE-416: Use After Free) affecting Bouncy Castle libraries in the Maven ecosystem. The issue involves garbage collection issue in bc-fja in java 13 and later. Remediation is available by upgrading affected packages to version 1.0.2.4.

CVE-2022-45146 at a Glance

CVE Identifier CVE-2022-45146
GHSA Identifier GHSA-68m8-v89j-7j2p
Severity MODERATE
CVSS v3.1 Base Score 5.5
CWE Classification CWE-416: Use After Free
Affected Product Bouncy Castle
Package Ecosystem Maven
Published Date
Last Updated

Security Impact

CVSS: 5.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N).

Attack Vector Local (AV:L)
Attack Complexity Low (AC:L)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity None (I:N)
Availability None (A:N)

How to Fix CVE-2022-45146

To remediate this vulnerability, upgrade all affected Bouncy Castle dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

org.bouncycastle:bc-fips fixed: 1.0.2.4
<dependency>
    <groupId>org.bouncycastle</groupId>
    <artifactId>bc-fips</artifactId>
    <version>1.0.2.4</version>
</dependency>
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

mvn dependency:tree -Dincludes=org.bouncycastle

How to Check if You Are Affected

To determine whether your Java application is affected by CVE-2022-45146, inspect your build dependencies using the Maven Dependency Plugin:

mvn dependency:tree -Dincludes=org.bouncycastle

Analyze the terminal output to locate any version of Bouncy Castle in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.0.2.4), your application is affected.

Note: The mvn dependency:tree -Dincludes=org.bouncycastle command inspects the resolved dependency graph declared in your project's POM files; it does not perform automated security scanning or inspect runtime dynamic classpaths. Always verify runtime container classpaths and shaded JARs.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-416: Use After Free, where the product reuses or references memory after it has been freed. at some point afterward, the memory may be allocated again and saved in another pointer, while the original pointer references a location somewhere within the new allocation. any operations using the original pointer are no longer valid because the memory "belongs" to the code that operates on the new pointer. In Bouncy Castle, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

An issue was discovered in the FIPS Java API of Bouncy Castle BC-FJA before 1.0.2.4. Changes to the JVM garbage collector in Java 13 and later trigger an issue in the BC-FJA FIPS modules where it is possible for temporary keys used by the module to be zeroed out while still in use by the module, resulting in errors or potential information loss. NOTE: FIPS compliant users are unaffected because the FIPS certification is only for Java 7, 8, and 11.

CVE-2022-45146 Affected Bouncy Castle Versions

1 component(s)
Fixed Versions:
1.0.2.4
Product / Package Ecosystem Affected Versions Fixed Version
org.bouncycastle:bc-fips
Maven
< 1.0.2.4
1.0.2.4

References

Frequently Asked Questions

What is CVE-2022-45146?
CVE-2022-45146 is a security vulnerability in Bouncy Castle involving Garbage collection issue in BC-FJA in Java 13 and later under CWE-416: Use After Free.
Which Bouncy Castle versions are affected?
Affected versions include releases prior to 1.0.2.4 across affected packages: org.bouncycastle:bc-fips.
What version fixes CVE-2022-45146?
Upgrading to 1.0.2.4 (or the latest patched release for your respective branch) resolves the vulnerability.
Is bc-fips affected?
Yes, org.bouncycastle:bc-fips is affected in releases prior to 1.0.2.4. Upgrade your dependency to 1.0.2.4 or later.
What is the CVSS score of CVE-2022-45146?
CVE-2022-45146 has a CVSS v3.1 base score of 5.5 (MODERATE) with vector string CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N.
What CWE is associated with CVE-2022-45146?
CVE-2022-45146 is classified under CWE-416: Use After Free (The product reuses or references memory after it has been freed. At some point afterward, the memory may be allocated again and saved in another pointer, while the original pointer references a location somewhere within the new allocation. Any operations using the original pointer are no longer valid because the memory "belongs" to the code that operates on the new pointer.).
How can I check Maven dependencies for CVE-2022-45146?
Run the dependency tree command: 'mvn dependency:tree -Dincludes=org.bouncycastle'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-68m8-v89j-7j2p",
  "modified" : "2024-02-13T21:47:44Z",
  "published" : "2022-11-21T12:30:17Z",
  "aliases" : [ "CVE-2022-45146" ],
  "summary" : "Garbage collection issue in BC-FJA in Java 13 and later",
  "details" : "An issue was discovered in the FIPS Java API of Bouncy Castle BC-FJA before 1.0.2.4. Changes to the JVM garbage collector in Java 13 and later trigger an issue in the BC-FJA FIPS modules where it is possible for temporary keys used by the module to be zeroed out while still in use by the module, resulting in errors or potential information loss. \n\nNOTE: FIPS compliant users are unaffected because the FIPS certification is only for Java 7, 8, and 11.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Maven",
      "name" : "org.bouncycastle:bc-fips"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.0.2.4"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-45146"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/bcgit/bc-java/wiki/CVE-2022-45146"
  }, {
    "type" : "WEB",
    "url" : "https://mvnrepository.com/artifact/org.bouncycastle/bc-fips"
  }, {
    "type" : "WEB",
    "url" : "https://www.bouncycastle.org/latest_releases.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-416" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-11-22T00:01:39Z",
    "nvd_published_at" : "2022-11-21T10:15:00Z"
  }
}