Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load plugins into classpath in bootstrap #11918

Merged
merged 3 commits into from Jun 29, 2015

Conversation

rmuir
Copy link
Contributor

@rmuir rmuir commented Jun 29, 2015

This can be done on startup, then we restore setAccessible(false) and engage security.

This also removes uber-dangerous global sun.misc permission (so only special jars have it).

Its not a true fix to #11917 but its progress and improves security.

Note: I had to remove some "integration-like" tests. In this simpler world all plugins are "classpath plugins" so testing is already more realistic (and we can followup by removing that confusing parameter) If we want some more integration tests around it I think those should be in a separate place? Anyway i feel bad about not being able to preserve all the tests, but I think its important to lock this down.

@rmuir
Copy link
Contributor Author

rmuir commented Jun 29, 2015

I discussed with @uschindler (he inspected source code), we don't need the try-finally block since the Method does not escape. I will simplify this one.

@uschindler
Copy link
Contributor

Hi,
you dont need to do setAccessible. The JVM allows setAccessible only per-instance (the Javadoc is a bit vague about this). The instances are never cached. Each call to Class.getMethod() returns a new instance (the internal cached one is cloned/copied). You can follow this in the JDK source code (grepcode.com). In fact the Method instances cannot really be cached for outside callers, because they are @CallerSensitive
Uwe

@rmuir
Copy link
Contributor Author

rmuir commented Jun 29, 2015

Thanks for the investigation! I cleaned this up

@uschindler
Copy link
Contributor

By the way here is the Method.copy() which is used by Java's cache. This one has the nice statement that confirms all of this: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/lang/reflect/Method.java#Method.copy%28%29

        // This routine enables sharing of MethodAccessor objects
        // among Method objects which refer to the same underlying
        // method in the VM. (All of this contortion is only necessary
        // because of the "accessibility" bit in AccessibleObject,
        // which implicitly requires that new java.lang.reflect
        // objects be fabricated for each reflective call on Class
        // objects.)

}
}

if (addURL == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can this be null except in the case the classloader is Object (impossible)? Won't each iteration of the loop have a non-null addURL (since setAccessible is called)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just moved this code from where it was. I didn't write it. Can we defer cleanup to another issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(the answer is that NoSuchMethodException can strike there)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disregard for now, I can see this code is just moved,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the event that the ClassLoader doesn't contain an addURL method this will be tripped. I think this is more of a WARNING level or and ERROR than a debug. Right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClassLoader itself doesn't have an addURL method, but SecureClassLoader does, and I suspect other subclasses will as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, i just moved this code from where it was. lets clean it up separately.

@rjernst
Copy link
Member

rjernst commented Jun 29, 2015

LGTM

@uschindler
Copy link
Contributor

We should really fix the addURL shit in later versions. It is horrible to add URLs to SystemClassLoader. The correct way to do this would be to make Bootstrap to create a new ClassLoader with all URLs and let the application classloader (which is != SystemClassloader, so this is also a security issue!!!) just be parent.

@rmuir
Copy link
Contributor Author

rmuir commented Jun 29, 2015

@uschindler yes, the long term fix is #11917

This issue is to improve security around this more, by doing this up-front in bootstrap. Its just a step. It removes access to sun.misc.Unsafe for example, except where explicitly granted.

If i go off on tangents and try to fix everything about some of this stuff, then we will make no progress. It remains the same stuff as it was before.

rmuir added a commit that referenced this pull request Jun 29, 2015
Load plugins into classpath in bootstrap
@rmuir rmuir merged commit 0ae638f into elastic:master Jun 29, 2015
@clintongormley clintongormley added >enhancement :Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts labels Jun 29, 2015
@uschindler
Copy link
Contributor

OK, thanks! I just wanted to point out that modifying the system classloader is a huge security issue. Nobody ever should do that! It would be OK if it s the application classloader, but this variant is a desaster! Really! That sucks horribly. I have to say that Apache Solr does a much better job here! :-)

@uschindler
Copy link
Contributor

Who wrote that code should be nailed against a wall and the Forbidden Policeman would probe his gun at him/her :-)

@uschindler
Copy link
Contributor

Was a joke, of course :-) Something for @UweSays :-)

@uschindler
Copy link
Contributor

I would also see this as huge security issue in any previous Elasticsearch version! You should patch earlier versions to not use System classloader and instead (if you dont fix it completely like in 2.0), change the code to use: Bootstrap.class.getClassLoader() instead of ClassLoader.getSystemClassLoader so it uses the application classloader and does not modify the JVM internals bypassing any security checks!

@rmuir
Copy link
Contributor Author

rmuir commented Jun 29, 2015

Hi Uwe, again the code was simply moved here, so securitymanager can blockaccess to sun.misc. That's all this issue is about. I did not write this code here.

If you want to improve the code, please spend efforts helping me with #11917, then its gone completely. We don't need to improve it. We need to remove it.

@uschindler
Copy link
Contributor

I was talking about 1.6 and earlier! I will open issue. This cannot stay like this!

@rmuir
Copy link
Contributor Author

rmuir commented Jun 29, 2015

1.6 isn't even on my radar. it doesn't even run with a security manager

@uschindler
Copy link
Contributor

It still breaks the whole JVM internals!

rmuir added a commit to rmuir/elasticsearch that referenced this pull request Jul 3, 2015
@mark-vieira mark-vieira added the Team:Delivery Meta label for Delivery team label Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts >enhancement Team:Delivery Meta label for Delivery team v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants