8161121: VM::isSystemDomainLoader should consider platform class loader

Reviewed-by: alanb
This commit is contained in:
Mandy Chung 2017-07-28 13:22:33 -07:00
parent ec8ed521b7
commit 2cb9e39fc9
7 changed files with 13 additions and 18 deletions

View File

@ -364,9 +364,9 @@ public final class Class<T> implements java.io.Serializable,
// Reflective call to get caller class is only needed if a security manager
// is present. Avoid the overhead of making this call otherwise.
caller = Reflection.getCallerClass();
if (VM.isSystemDomainLoader(loader)) {
if (loader == null) {
ClassLoader ccl = ClassLoader.getClassLoader(caller);
if (!VM.isSystemDomainLoader(ccl)) {
if (ccl != null) {
sm.checkPermission(
SecurityConstants.GET_CLASSLOADER_PERMISSION);
}

View File

@ -2476,7 +2476,7 @@ return mh1;
return false;
}
ClassLoader loader = defc.getClassLoader();
if (!jdk.internal.misc.VM.isSystemDomainLoader(loader)) {
if (loader != null) {
ClassLoader sysl = ClassLoader.getSystemClassLoader();
boolean found = false;
while (sysl != null) {

View File

@ -453,7 +453,7 @@ public class Proxy implements java.io.Serializable {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
ClassLoader ccl = caller.getClassLoader();
if (VM.isSystemDomainLoader(loader) && !VM.isSystemDomainLoader(ccl)) {
if (loader == null && ccl != null) {
sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
}
ReflectUtil.checkProxyPackageAccess(ccl, interfaces);

View File

@ -25,6 +25,8 @@
package jdk.internal.logger;
import jdk.internal.misc.VM;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.HashMap;
@ -140,15 +142,9 @@ public class DefaultLoggerFinder extends LoggerFinder {
return AccessController.doPrivileged(new PrivilegedAction<>() {
@Override
public Boolean run() {
final ClassLoader moduleCL = m.getClassLoader();
if (moduleCL == null) return true;
ClassLoader cl = ClassLoader.getPlatformClassLoader();
while (cl != null && moduleCL != cl) {
cl = cl.getParent();
}
// returns true if moduleCL is the platform class loader
// or one of its ancestors.
return moduleCL == cl;
return VM.isSystemDomainLoader(m.getClassLoader());
}
});
}

View File

@ -124,11 +124,11 @@ public class VM {
}
/**
* Returns true if the given class loader is in the system domain
* in which all permissions are granted.
* Returns true if the given class loader is the bootstrap class loader
* or the platform class loader.
*/
public static boolean isSystemDomainLoader(ClassLoader loader) {
return loader == null;
return loader == null || loader == ClassLoader.getPlatformClassLoader();
}
/**

View File

@ -316,8 +316,7 @@ public class Reflection {
*/
public static boolean isCallerSensitive(Method m) {
final ClassLoader loader = m.getDeclaringClass().getClassLoader();
if (VM.isSystemDomainLoader(loader) ||
loader == ClassLoaders.platformClassLoader()) {
if (VM.isSystemDomainLoader(loader)) {
return m.isAnnotationPresent(CallerSensitive.class);
}
return false;

View File

@ -588,8 +588,8 @@ public class ManagementFactory {
Class<T> mxbeanInterface)
throws java.io.IOException {
// Only allow MXBean interfaces from rt.jar loaded by the
// bootstrap class loader
// Only allow MXBean interfaces from the platform modules loaded by the
// bootstrap or platform class loader
final Class<?> cls = mxbeanInterface;
ClassLoader loader =
AccessController.doPrivileged(