JDK-5097939 : unnecessary rw opening of /dev/random while compiling
  • Type: Bug
  • Component: security-libs
  • Sub-Component: java.security
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2004-09-07
  • Updated: 2004-11-09
  • Resolved: 2004-11-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6
5.0u2Fixed 6 betaFixed
Description
Name: gm110360			Date: 09/07/2004


FULL PRODUCT VERSION :
java version "1.5.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-rc-b63)
Java HotSpot(TM) Client VM (build 1.5.0-rc-b63, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux georgm 2.6.8-gentoo-r3 #4 Tue Aug 31 13:00:14 CEST 2004 i686 Mobile Intel(R) Pentium(R) 4 - M CPU 1.80GHz GenuineIntel GNU/Linux


A DESCRIPTION OF THE PROBLEM :
When compiling, javac opens /dev/random in read-write mode. This is not necessary - read only should do it.
When running javac in a sandbox, this causes a sandbox violation.


strace javac Test.java gives the following information:

open("/dev/random", O_WRONLY|O_APPEND|O_CREAT|O_LARGEFILE, 0666) = -1 EACCES (Permission denied)

Could you please change the opening mode to read only?



REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
any java source file

---------- END SOURCE ----------
(Incident Review ID: 301942) 
======================================================================
###@###.### 10/7/04 18:02 GMT

Comments
WORK AROUND Change $JAVA_HOME/lib/security/java.security to say securerandom.source=file:/dev/random instead of /dev/random. Alternatively, invoke "java -Djava.security.egd=file:/dev/random ..." or for the compiler "javac -J-Djava.security.egd=file:/dev/urandom ..." ###@###.### 10/14/04 23:26 GMT
14-10-2004

EVALUATION SecureRandom tries to open /dev/random for writing so that we can pass entropy back to the OS if an application calls secureRandom.setSeed(). However, if /dev/random cannot be opened for writing, we ignore the error and proceed normally. Please explain how this causes a Java application to fail/misbehave. Marking as incomplete. ###@###.### 2004-09-07 Please excuse my ignorance wrt to Gentoo and sandboxes. Google pointed me to http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&chap=3&style=printable#doc_chap4 , if there is something else I should look at to better understand them, please post a comment with the URL in the JDC. Thanks. But unless I misunderstand the issue, the problem is the opening of /dev/random in write mode. Read-only is fine. If that is so, then we can change our code to delay opening in write mode until an application actually calls secureRandom.setSeed(). That should be sufficient to avoid this problem. I will try to get the fix into a Tiger update release, but please be aware that our QA processes take some time. In the meantime, please have a look at the workaround. BTW, I don't know why javac would need a SecureRandom. I could not find any direct reference to it in the javac source nor was it used when I compiled a few files. But that is only the secondary problem and not that important. ###@###.### 10/14/04 23:26 GMT
14-10-0004