Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible memory leak in bc-fips related to Java finalizers #1776

Open
selliott512 opened this issue Aug 15, 2024 · 0 comments
Open

Possible memory leak in bc-fips related to Java finalizers #1776

selliott512 opened this issue Aug 15, 2024 · 0 comments

Comments

@selliott512
Copy link

selliott512 commented Aug 15, 2024

A memory analysis of a jmap memory dump revealed a significant number of java.lang.ref.Finalizer references. The referent is org.bouncycastle.crypto.fips.FipsPBKD$Parameters, created with call stack:

org.bouncycastle.jcajce.provider.ProvBCFKS$BCFIPSKeyStoreSpi.generateKey(Unknown Source)
at org.bouncycastle.jcajce.provider.ProvBCFKS$BCFIPSKeyStoreSpi.decryptData(Unknown Source)
at org.bouncycastle.jcajce.provider.ProvBCFKS$BCFIPSKeyStoreSpi.engineLoad(Unknown Source)
at java.security.KeyStore.load(java.base@11.0.23/KeyStore.java:1479)

We believe this is related to the use of finalizers (finalize methods) in bc-fips code. Finalizers are problematic, in part due to their two-pass nature.

Two possible solutions, in increasing order of difficulty:

  1. Simply remove all finalize methods.
  2. Replace the finalize methods with an alternative strategy, such as try-with-resources.

Regarding solution 1), since the finalize methods are primarily overwriting arrays with zeros, the security risk of removing them should be minimal, as most modern operating systems already ensure that freed memory isn't visible to other processes.

Additionally, issue #1536 refers to java.lang.ref.Finalizer, but it’s unclear if it's the same problem since that issue does not include the path.

The versions of the Bouncy Castle JARs used:

JAR Version
bc-fips 1.0.2.4
bctls-fips 1.0.18

The JRE is OpenJDK 11 on Red Hat Enterprise Linux 8.10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant