<div><div><div><div>> Long term then it would be interesting to explore degrading and eventually dropping the security manager but that is beyond the scope of what I would like to discuss here.<br><br>That is a bold topic to immediately declare out of scope. I am looking for somewhere to reply, so I am forking this thread to a new subject to share my thoughts.<br><br>I am an engineer on the Elasticsearch team at Elastic. Elasticsearch is a popular server application implemented in Java that runs on the JVM. We run with the security manager enabled, and there is no option to disable it. We have two major motivations for using the security manger:<br> - as a server application, to reduce the scope of any exploits in the JDK, our code, or our third-party dependencies (e.g., prevent directory traversals, prevent RCE, etc.)<br> - we provide a plugin framework (e.g., to add scripting languages) and use the security manager to sandbox untrusted code<br><br>For additional background, please see the mail thread "SecurityManager environments" on jigsaw-dev[1].<br><br>>The bigger question is of course whether it is interesting to run with a security manager in 2017.<br><br>Of course it is. Java is often used to code servers[no citation needed]. The question should be: what can be done to make using the security manager easier for servers[2]? When looking at the major exploits in the Java ecosystem in the last few years (e.g., the commons collections CVE[3] that led to RCE in e.g., JBoss (among others), the Apache Struts CVE[4] that played a role in the Equifax breach), every time my mind turns to: this would not be as large a problem if the server was using the security manager. The JDK needs to be a platform that enables developing secure server applications. Seeing this question raised without any explicit or implicit mention of this need is surprising.<br><br>> We have seen a few cases where applications set a security manager in order to enforce some policy, like preventing plugins calling System.exit but these are cases that would be better served with other solutions.<br><br>We do this[5][6], although we had to wrap the security manager in our own implementation[7] because we still need to be able to exit on our own[8][9]. However: an API to serve this use-case solely is not enough to meet our current needs from the security manager.<br><br>> A big challenge is the System.setSecurityManager API as allows a security manager to be set in a running VM.<br><br>We use the System#setSecurityManager API[10][11]. I do not think our use-case is unreasonable: there are privileges that are required upfront, and then we drop them. I am okay with the run mode that you propose (as long as System#setSecurityManager in this run mode is not a no-op but a hard exception), I am not okay with dropping this API entirely (so do not deprecate the System#setSecurityManager API).<br><br>[1]: <a href="http://mail.openjdk.java.net/pipermail/jigsaw-dev/2017-April/012044.html" target="_blank">http://mail.openjdk.java.net/pipermail/jigsaw-dev/2017-April/012044.html</a><br>[2]: <a href="http://www.cs.cmu.edu/~clegoues/docs/coker15acsac.pdf" target="_blank">https://www.cs.cmu.edu/~clegoues/docs/coker15acsac.pdf</a><br>[3]: <a href="https://www.cvedetails.com/cve/CVE-2015-6420/" target="_blank">https://www.cvedetails.com/cve/CVE-2015-6420/</a><br>[4]: <a href="https://www.cvedetails.com/cve/CVE-2017-5638/" target="_blank">https://www.cvedetails.com/cve/CVE-2017-5638/</a><br>[5]: <a href="https://github.com/elastic/securesm/blob/v1.2/src/main/java/org/elasticsearch/SecureSM.java#L75-L83" target="_blank">https://github.com/elastic/securesm/blob/v1.2/src/main/java/org/elasticsearch/SecureSM.java#L75-L83</a><br>[6]: <a href="https://github.com/elastic/elasticsearch/blob/93a988c557fb4c4a052964d3192a5feb045039ae/core/src/main/java/org/elasticsearch/bootstrap/Security.java#L121-L123" target="_blank">https://github.com/elastic/elasticsearch/blob/93a988c557fb4c4a052964d3192a5feb045039ae/core/src/main/java/org/elasticsearch/bootstrap/Security.java#L121-L123</a><br>[7]: <a href="https://github.com/elastic/securesm" target="_blank">https://github.com/elastic/securesm</a><br>[8]: <a href="https://github.com/elastic/elasticsearch/blob/v6.0.0/core/src/main/java/org/elasticsearch/bootstrap/ElasticsearchUncaughtExceptionHandler.java" target="_blank">https://github.com/elastic/elasticsearch/blob/v6.0.0/core/src/main/java/org/elasticsearch/bootstrap/ElasticsearchUncaughtExceptionHandler.java</a><br>[9]: <a href="https://github.com/elastic/elasticsearch/blob/v6.0.0/core/src/main/java/org/elasticsearch/cli/Command.java#L150" target="_blank">https://github.com/elastic/elasticsearch/blob/v6.0.0/core/src/main/java/org/elasticsearch/cli/Command.java#L150</a><br>[10]: <a href="https://github.com/elastic/elasticsearch/blob/v6.0.0/core/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java#L75-L82" target="_blank">https://github.com/elastic/elasticsearch/blob/v6.0.0/core/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java#L75-L82</a><br>[11]: <a href="https://github.com/elastic/elasticsearch/blob/v6.0.0/core/src/main/java/org/elasticsearch/bootstrap/Security.java#L122-L123" target="_blank">https://github.com/elastic/elasticsearch/blob/v6.0.0/core/src/main/java/org/elasticsearch/bootstrap/Security.java#L122-L123</a><br><div><div><div><br><div class="gmail_quote"><div>On Mon, Nov 20, 2017 at 9:48 AM Alan Bateman <<a href="mailto:Alan.Bateman@oracle.com" target="_blank">Alan.Bateman@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
One of the long standing issues with the security manager support is<br>
that the overhead when there is no security manager is non-zero. Two<br>
specific examples are (i) the overhead of defineClass (assuming the<br>
defining loader is a SecureClassLoader) as it involves a callback to get<br>
the permissions for the protection domain and (ii) the overhead of<br>
AccessController.doPrivileged in order to execute an action on a<br>
privileged stack.<br>
<br>
The bigger question is of course whether it is interesting to run with a<br>
security manager in 2017. It's clearly still important for environments<br>
that download potentially malicious code to execute in a sandox but that<br>
isn't most applications these days. We have seen a few cases where<br>
applications set a security manager in order to enforce some policy,<br>
like preventing plugins calling System.exit but these are cases that<br>
would be better served with other solutions.<br>
<br>
I would like to explore changes to the API and implementation that would<br>
allow us to eliminate some of the overhead when not running with a<br>
security manager. Long term then it would be interesting to explore<br>
degrading and eventually dropping the security manager but that is<br>
beyond the scope of what I would like to discuss here. Sean Mullan and<br>
Jeff Nisewanger ran an interesting BOF at JavaOne 2017 on this topic and<br>
I believe are planning to do a survey at some point to understand the<br>
current usage of the security manager.<br>
<br>
For now I would like to explore what it would take to eliminate some of<br>
the overhead. A big challenge is the System.setSecurityManager API as<br>
allows a security manager to be set in a running VM. This means that<br>
classes loaded before a security manager is set may be involved in<br>
permission checks that happen after a security manager is set.<br>
Similarly, privileged actions may have started before the security<br>
manager is set. The complications around this go away if there was some<br>
way to know that a security manager can never be turned on in a running<br>
system.<br>
<br>
To get started, I've put a prototype of an initial proposal on the cr<br>
site [1]. The summary of the proposal is:<br>
<br>
1. A "disallow security manager" mode that is opt-in to disallow<br>
setSecurityManager being used to set a security manager in a running VM.<br>
Opt-in means it has not impact on existing code.<br>
<br>
2. Deprecates setSecurityManager to discourage further usage and allow<br>
for the possibility of making "disallow security manager" the default in<br>
the future. If that were to become the default then it would have no<br>
impact on deployments that set the security manager on the command line<br>
at startup.<br>
<br>
3. When running in "disallow security manager" mode,<br>
AccessController.doPrivileged invokes actions directly and<br>
SecureClassLoader.defineClass skips the callback to get permissions for<br>
the protection domain. This part helps startup and runtime performance.<br>
<br>
It's important not to get hung up on the details in the webrev, the<br>
important thing is understand if the security folks on this mailing list<br>
are open to a run mode that prevents a security manager being set in a<br>
running system.<br>
<br>
-Alan.<br>
<br>
[1] <a href="http://cr.openjdk.java.net/~alanb/8191053/webrev/" rel="noreferrer" target="_blank">http://cr.openjdk.java.net/~alanb/8191053/webrev/</a><br>
</blockquote></div></div></div></div></div></div></div></div>