2

I would like to disable them to block anyone from gaining access to passwords stored in memory. What I found so far is

-XX:+DisableAttachMechanism

This blocks connections via i.e. jconsole but I can force jmap to get a dump like:

jmap -dump:file=/tmp/x.bin -F $PID

I can't seem to find any option to completely disable them:

http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

Is there a way?

Thanks

kostas.kougios
  • 945
  • 10
  • 21
  • 2
    I don't think you can. I've worked with heap dumps in the past and never ran across a way to prevent jmap from taking the dump. Don't store passwords in plaintext in memory. – Kon Dec 02 '14 at 16:07
  • 1
    Why not send the dumps to `/dev/null`? That is, use `-XX:HeapDumpPath=/dev/null`. – RealSkeptic Dec 02 '14 at 16:15
  • a hacker can manually run jmap -dump:file=/tmp/x.bin -F $PID and get a dump – kostas.kougios Dec 03 '14 at 11:17

2 Answers2

2
  1. add jvm option -XX:+DisableAttachMechanism to disable jvm attach mechanism.
  2. disable os debug mechanism. When jmap find the jvm don't support attach mechanism, it try os debug mechanism to dump the memory. for linux, it is ptrace syscall. So you can disable the ptrace syscall. for ubuntu, set kernel.yama.ptrace_scope = 3 in file /etc/sysctl.d/10-ptrace.conf and reboot.
Sisyphus
  • 896
  • 11
  • 19
1

I don't think there is a way to do this. Instead, I'd suggest storing the password off-heap using sun.misc.Unsafe objects. See the discussion here:

https://stackoverflow.com/questions/5574241/using-sun-misc-unsafe-in-real-world/5607119

Community
  • 1
  • 1
Zeki
  • 5,107
  • 1
  • 20
  • 27