Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prohibit Java VM from creating any dump upon crash / writing sensitive data to disk

I'm writing a Java program that stores sensitive data (password and private keys) in memory. It will be deployed freely to any OS. I know that a user can create a memory dump manually on almost any system, but I am worried about a dump being created by the OS or JVM implementation (including, but not limited to some segfault of the JVM itself) that would compromise the privacy of the sensitive data.

Are there any steps that could be taken to reduce these risks? This question is POSIX specific but gives me an answer for these platforms. I had one non-platform specific idea that included setting an UncaughtExceptionHandler (like this) to a class that would overwrite sensitive data. But what about if memory is swapped out? What if the JVM crashes (e.g. segmentation fault) due to a JVM/JNI bug? I know Linux can stop data from being swapped to disk but is there a Java code to do this cross-platform? Mostly I'm worried about the potential for recovery of data on magnetic storage devices so any help is appreciated.

like image 667
Hut8 Avatar asked May 20 '11 16:05

Hut8


People also ask

What happens when JVM crashes?

When the JRockit JVM crashes, it generates a binary crash file ( . core or . mdmp ). By default, the binary crash file contains a copy of the entire JVM process.

Why does the JVM crash with a core dump?

Common causes of JVM Crash Running out of native memory. This is caused when native memory is exhausted, read more about native memory allocation here. Segmentation faults. These are caused by a program trying to read or write an illegal memory location.


2 Answers

If you do not have control of the operating system, you basically cannot prohibit the user from accessing what you have in memory.

Hence, you need to keep the amount of sensitive data you hold onto to an absolute minimum. Just imagine that the knowledgeable user attaches a debugger, halts your program and snoops in your datastructures cherry-picking whatever they need to know.

So, when done using passwords, set all references to null. When done using keys, set their references to null. Note that this will not help for the determined knowledgeable user, but it will at least minimize the chance for accidental discovery.

like image 96
Thorbjørn Ravn Andersen Avatar answered Sep 21 '22 06:09

Thorbjørn Ravn Andersen


If you are trying to stop casual users, then you don't really need to do anything. if you are trying to stop knowledgeable/determined users, and you are running the code on their computer, then there is nothing you can do.

if the only thing you are worried about is the program writing stuff to disk "accidentally", then, again, there isn't much you can do. java programs don't generate heap dumps unless you specifically tell them to. any stack traces which get output from an uncaught exception are highly unlikely to include anything sensitive in them. the file which gets written when a jvm segfaults in a controlled manner also will not likely have anything sensitive in it. the only potentially problematic thing would be a core dump on some variant of a unix system. and, unfortunately, i don't believe you can control that at the program level, only at the system/user configuration level (which was mentioned in the first question you linked to).

like image 21
jtahlborn Avatar answered Sep 23 '22 06:09

jtahlborn