Issue Details (XML | Word | Printable)

Key: SFOS-236
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Julio Guijarro
Reporter: Julio Guijarro
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
SmartFrog

Adding a java.policy file when using no security in SF, causes an infinite loop in SF: org.smartfrog.sfcore.security.DummySecurityManager

Created: 02/Jul/07 04:35 PM (BST)   Updated: 09/Nov/07 03:58 PM (GMT)
Component/s: .sfCore
Affects Version/s: 3.10.043 dev, 3.11.000 beta
Fix Version/s: 3.12.008

Time Tracking:
Not Specified

Issue Links:
Depends

Compatibility: may break builds or test process


 Description  « Hide
We need to add one more permission in the java.policy
 file in order to beallowed to register to the JMX
 MBeanServer. (see last line in attached java.policy file)
This allow works for conecting to the MBeanServer, but at the same time it causes an infinite
loop in the SmartFrog
 org.smartfrog.sfcore.security.DummySecurityManager.
See stack trace
below:
//------------Stack Trace
 2007-06-27 16:48:01,386 ERROR [STDERR] Exception in thread "main"
 2007-06-27 16:48:01,386 ERROR [STDERR] java.lang.StackOverflowError
 2007-06-27 16:48:01,396 ERROR [STDERR] at java.security.AccessController.doPrivileged(Native Method)
 2007-06-27 16:48:01,396 ERROR [STDERR] at java.io.FilePermission.init(FilePermission.java:212)
 2007-06-27 16:48:01,396 ERROR [STDERR] at java.io.FilePermission.<init>(FilePermission.java:264)
 2007-06-27 16:48:01,396 ERROR [STDERR] at sun.net.www.protocol.file.FileURLConnection.getPermission(FileURLCon nect ion.java:198)
 2007-06-27 16:48:01,397 ERROR [STDERR] at sun.security.provider.PolicyFile.canonicalizeCodebase(PolicyFile.java:17 90)
 2007-06-27 16:48:01,397 ERROR [STDERR] at sun.security.provider.PolicyFile.access$600(PolicyFile.java:262)
 2007-06-27 16:48:01,397 ERROR [STDERR] at sun.security.provider.PolicyFile$4.run(PolicyFile.java:1267)
 2007-06-27 16:48:01,397 ERROR [STDERR] at java.security.AccessController.doPrivileged(Native Method)
 2007-06-27 16:48:01,397 ERROR [STDERR] at sun.security.provider.PolicyFile.getPermissions(PolicyFile.java:1263 )
 2007-06-27 16:48:01,397 ERROR [STDERR] at sun.security.provider.PolicyFile.getPermissions(PolicyFile.java:1211 )
 2007-06-27 16:48:01,397 ERROR [STDERR] at sun.security.provider.PolicyFile.implies(PolicyFile.java:1166)
 2007-06-27 16:48:01,397 ERROR [STDERR] at java.security.ProtectionDomain.implies(ProtectionDomain.java:195)
 2007-06-27 16:48:01,398 ERROR [STDERR] at java.security.AccessControlContext.checkPermission(AccessControlContext. java:249)
 2007-06-27 16:48:01,398 ERROR [STDERR] at java.security.AccessController.checkPermission(AccessController.java :427 )
 2007-06-27 16:48:01,398 ERROR [STDERR] at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
 2007-06-27 16:48:01,398 ERROR [STDERR] at org.smartfrog.sfcore.security.DummySecurityManager.checkPermission(D ummy SecurityManager.j ava:57)
 2007-06-27 16:48:01,398 ERROR [STDERR] at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
 2007-06-27 16:48:01,398 ERROR [STDERR] at java.io.File.isDirectory(File.java:721)
 2007-06-27 16:48:01,398 ERROR [STDERR] at sun.net.www.ParseUtil.fileToEncodedURL(ParseUtil.java:236)
 2007-06-27 16:48:01,399 ERROR [STDERR] at sun.security.provider.PolicyFile.canonicalizeCodebase(PolicyFile.jav a:18 28)
 2007-06-27 16:48:01,399 ERROR [STDERR] at sun.security.provider.PolicyFile.access$600(PolicyFile.java:262)
 2007-06-27 16:48:01,399 ERROR [STDERR] at sun.security.provider.PolicyFile$4.run(PolicyFile.java:1267)
 2007-06-27 16:48:01,399 ERROR [STDERR] at java.security.AccessController.doPrivileged(Native Method)
 2007-06-27 16:48:01,399 ERROR [STDERR] at sun.security.provider.PolicyFile.getPermissions(PolicyFile.java:1263 )
 2007-06-27 16:48:01,399 ERROR [STDERR] at sun.security.provider.PolicyFile.getPermissions(PolicyFile.java:1211 )
 2007-06-27 16:48:01,399 ERROR [STDERR] at sun.security.provider.PolicyFile.implies(PolicyFile.java:1166)
 2007-06-27 16:48:01,399 ERROR [STDERR] at java.security.ProtectionDomain.implies(ProtectionDomain.java:195)
 2007-06-27 16:48:01,400 ERROR [STDERR] at java.security.AccessControlContext.checkPermission(AccessControlContext. java:249)
 2007-06-27 16:48:01,400 ERROR [STDERR] at java.security.AccessController.checkPermission(AccessController.java :427 )
 2007-06-27 16:48:01,400 ERROR [STDERR] at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
 2007-06-27 16:48:01,400 ERROR [STDERR] at org.smartfrog.sfcore.security.DummySecurityManager.checkPermission(D ummy SecurityManager.java:57)
 2007-06-27 16:48:01,400 ERROR [STDERR] at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
 2007-06-27 16:48:01,400 ERROR [STDERR] at java.io.File.isDirectory(File.java:721)
 2007-06-27 16:48:01,400 ERROR [STDERR] at sun.net.www.ParseUtil.fileToEncodedURL(ParseUtil.java:236)
 2007-06-27 16:48:01,400 ERROR [STDERR] at sun.security.provider.PolicyFile.canonicalizeCodebase(PolicyFile.jav a:18 28)
 2007-06-27 16:48:01,401 ERROR [STDERR] at sun.security.provider.PolicyFile.access$600(PolicyFile.java:262)
 2007-06-27 16:48:01,401 ERROR [STDERR] at sun.security.provider.PolicyFile$4.run(PolicyFile.java:1267)
 2007-06-27 16:48:01,401 ERROR [STDERR] at java.security.AccessController.doPrivileged(Native Method)
 2007-06-27 16:48:01,401 ERROR [STDERR] at sun.security.provider.PolicyFile.getPermissions(PolicyFile.java:1263 )
 2007-06-27 16:48:01,401 ERROR [STDERR] at sun.security.provider.PolicyFile.getPermissions(PolicyFile.java:1211 )
 2007-06-27 16:48:01,401 ERROR [STDERR] at sun.security.provider.PolicyFile.implies(PolicyFile.java:1166)
 2007-06-27 16:48:01,401 ERROR [STDERR] at java.security.ProtectionDomain.implies(ProtectionDomain.java:195)
 2007-06-27 16:48:01,412 ERROR [STDERR] at java.security.AccessControlContext.checkPermission(AccessControlContext. java:249)
 2007-06-27 16:48:01,412 ERROR [STDERR] at java.security.AccessController.checkPermission(AccessController.java :427 )
 2007-06-27 16:48:01,413 ERROR [STDERR] at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
 2007-06-27 16:48:01,413 ERROR [STDERR] at org.smartfrog.sfcore.security.DummySecurityManager.checkPermission(Dummy securityManager.j ava:57)
 2007-06-27 16:48:01,416 ERROR [STDERR] at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
 2007-06-27 16:48:01,416 ERROR [STDERR] at java.io.File.isDirectory(File.java:721)
 2007-06-27 16:48:01,416 ERROR [STDERR] at sun.net.www.ParseUtil.fileToEncodedURL(ParseUtil.java:236)
 2007-06-27 16:48:01,418 ERROR [STDERR] at sun.security.provider.PolicyFile.canonicalizeCodebase(PolicyFile.jav a:18 28)
 2007-06-27 16:48:01,419 ERROR [STDERR] at sun.security.provider.PolicyFile.access$600(PolicyFile.java:262)
 2007-06-27 16:48:01,419 ERROR [STDERR] at sun.security.provider.PolicyFile$4.run(PolicyFile.java:1267)
 2007-06-27 16:48:01,422 ERROR [STDERR] at java.security.AccessController.doPrivileged(Native Method)
 2007-06-27 16:48:01,422 ERROR [STDERR] at sun.security.provider.PolicyFile.getPermissions(PolicyFile.java:1263 )
 2007-06-27 16:48:01,422 ERROR [STDERR] at sun.security.provider.PolicyFile.getPermissions(PolicyFile.java:1211 )
 2007-06-27 16:48:01,422 ERROR [STDERR] at sun.security.provider.PolicyFile.implies(PolicyFile.java:1166)
 2007-06-27 16:48:01,425 ERROR [STDERR] at java.security.ProtectionDomain.implies(ProtectionDomain.java:195)
 2007-06-27 16:48:01,425 ERROR [STDERR] at java.security.AccessControlContext.checkPermission(AccessControlContext. java:249)
 2007-06-27 16:48:01,429 ERROR [STDERR] at java.security.AccessController.checkPermission(AccessController.java :427 )
 2007-06-27 16:48:01,429 ERROR [STDERR] at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
 2007-06-27 16:48:01,429 ERROR [STDERR] at org.smartfrog.sfcore.security.DummySecurityManager.checkPermission(D
 ummy
 SecurityManager.j
 ava:57)

 .../... Same for pages and pages
//----- End stack trace


 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Julio Guijarro added a comment - 02/Jul/07 04:37 PM (BST)
"The dummy security manager is not going to process any policy, it is just there for dynamic class loading in RMI to work with security off, but it does not do any security checks."

"If you want to enforce your own policy, you should just register a real security manager, i.e.,:
System.setSecurityManager(new SecurityManager());"

Antonio

Julio Guijarro added a comment - 02/Jul/07 04:40 PM (BST)
"We have reviewed the stack overflow problem, but from the information we have we can't tell what is happening and at the moment we can't reproduce it. But we have found a few bug reports on the internet that suggest possible problems in the Java Security Manager and ways to get around them."


Paul.

Julio Guijarro added a comment - 02/Jul/07 04:45 PM (BST)
I know we are many versions on from Java 1.2, but you do wonder whether they fixed this bug...
 
http://www.infosys.tuwien.ac.at/Staff/pooh/Minstrel/Receiver/CSF/concept/bugs.html#securityManager

This mentions overiding checkRead, which we don't, but all that checkRead does is call checkPermission which does all the work and we have overridden this.

Patrick

----------
Copy of the linked content for future reference:

=========================================
Why the security manager hangs in an infinite loop
=========================================
  
The problem, we have posted in the comp.java.programmer newsgroup:
  We've experienced several problems creating our own SecurityManager in JDK 1.2 (Solaris). We simply subclass'd the SecurityManager class and it worked perfectly:

public class CSFSecurityManager extends SecurityManager {
    public CSFSecurityManager() {
        super();
    }
}

But after writing our own checkRead method a never-ending loop appeared.

public class CSFSecurityManager extends SecurityManager {
    public CSFSecurityManager() {
        super();
    }
    public void checkRead(String file) {
        super.checkRead(file);
    }
}

The reason for the loop:
We try to open a file for reading. The System asks our CSFSecurityManager (checkRead) whether this peration is allowed. We, ourselves, ask the java.security.SecurityManager (super.checkRead) who asks the AccessController (checkPermission). The AccessController must read the permissions-file in order to check the permissions (it's the first call to the AccessController). But the SecurityManager asks the SecurityManager (our CSFSecurityManager) whether he's allowed to read the .java.policy file. He asks checkRead. Boom.
The question that worries us is: why does the first version (without implementing our own checkRead with a single line!!) work fine and the second one not?

Any words of wisdom?

Clemens Kerer
Roman Kurmanowytsch
 

  
Roland Schemers answered:
  This is an unfortunate bug that crept in at the last minute. In order to decrease start up time, we delay loading the policy file until the
last minute. When you have your own SecurityManager, it also has its own domain and when you call super.checkRead, the access controller must check the domain of your security manager, which causes the policy file to get loaded. While loading the policy file, you have to read files, which causes another checkRead, etc.
One work around is to make checkRead synchronized, and add a boolean flag which is set to true the first time you enter checkRead, and reset the last time you leave it. If you enter checkRead and the flag is set, simply return:

    boolean inReadCheck;

    public synchronized void checkRead(String file) {
         if (inReadCheck)
            return;
         else {
              try {
                  inReadCheck=true;
                  super.checkRead(file);
              } finally {
                  inReadCheck=false;
              }
         }
   }

Another workaround is to cause the domain of your security manager to get initialized before any calls are made to it:

  public CSFSecurityManager() {
     super();
     CSFSecurityManager.class.getProtectionDomain().implies(new java.security.AllPermission());
  }

Calling implies on the domain will cause the policy file to get loaded.

Yet another workaround is to put your custom security manager on the "boot" class path instead of CLASSPATH (See "java -X"), where it won't have a protection domain.

Also note that after fixing the above problem, you need to make sure that your security manager is granted all the permissions it needs to do the checking. If you override checkRead, make sure your security manager is granted permission to read any file so the call to super.checkRead will work.

This bug will be fixed in a dot-dot release.

roland
 



Julio Guijarro added a comment - 05/Jul/07 07:26 PM (BST)
Solution: replaced DummySecurityManager by normal java security manager when the system property java.securiy.policy is defined.
Now for dynamic classloading we need to define: -java.security.policy with the right policies and -Djava.security.manager for the java security manager

Therefore:
For classloading and no security:
Windows:
-Djava.security.policy=="%SFHOME%\private\sf.no.security.policy" -Djava.security.manager -Dorg.smartfrog.codebase=%CODEBASE%
Unix:
"-Djava.security.policy==$SFHOME/private/sf.no.security.policy -Djava.security.manager -Dorg.smartfrog.codebase=$CODEBASE"

The policy file: sf.no.security.policy grant everything = no security.

 If the property "java.security.policy" is not defined no security manager is loaded.

See SVN changes for more detail.

Julio Guijarro added a comment - 06/Jul/07 11:31 AM (BST)
CHANGE:
 Replaced java.security.poliy by "org.smartfrog.codebase" as key used to load security manager when using dynamic classloading and not security.

Steve Loughran added a comment - 06/Jul/07 03:11 PM (BST)
changing the release this fix is associated with