-
Notifications
You must be signed in to change notification settings - Fork 722
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
JDK24: Permanently Disable the Security Manager #20625
base: master
Are you sure you want to change the base?
Changes from all commits
5f46f88
3a5072d
d1238a7
7e5cffa
a2dfc42
7492ec2
3219249
c9cabc6
2df25f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1265,6 +1265,9 @@ static void checkTmpDir() { | |||||
|
||||||
/*[IF JAVA_SPEC_VERSION >= 9]*/ | ||||||
static void initSecurityManager(ClassLoader applicationClassLoader) { | ||||||
/*[IF JAVA_SPEC_VERSION >= 24]*/ | ||||||
boolean throwErrorOnInit = false; | ||||||
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */ | ||||||
String javaSecurityManager = internalGetProperties().getProperty("java.security.manager"); //$NON-NLS-1$ | ||||||
if (null == javaSecurityManager) { | ||||||
/*[IF JAVA_SPEC_VERSION >= 18]*/ | ||||||
|
@@ -1273,14 +1276,21 @@ static void initSecurityManager(ClassLoader applicationClassLoader) { | |||||
/* Do nothing. */ | ||||||
/*[ENDIF] JAVA_SPEC_VERSION >= 18 */ | ||||||
} else if ("allow".equals(javaSecurityManager)) { //$NON-NLS-1$ | ||||||
/*[IF JAVA_SPEC_VERSION >= 24]*/ | ||||||
throwErrorOnInit = true; | ||||||
/*[ELSE] JAVA_SPEC_VERSION >= 24 */ | ||||||
/* Do nothing. */ | ||||||
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */ | ||||||
} else if ("disallow".equals(javaSecurityManager)) { //$NON-NLS-1$ | ||||||
/*[IF JAVA_SPEC_VERSION > 11]*/ | ||||||
throwUOEFromSetSM = true; | ||||||
/*[ELSE] JAVA_SPEC_VERSION > 11 */ | ||||||
/* Do nothing. */ | ||||||
/*[ENDIF] JAVA_SPEC_VERSION > 11 */ | ||||||
} else { | ||||||
/*[IF JAVA_SPEC_VERSION >= 24]*/ | ||||||
throwErrorOnInit = true; | ||||||
/*[ELSE] JAVA_SPEC_VERSION >= 24 */ | ||||||
/*[IF JAVA_SPEC_VERSION >= 17]*/ | ||||||
initialErr.println("WARNING: A command line option has enabled the Security Manager"); //$NON-NLS-1$ | ||||||
initialErr.println("WARNING: The Security Manager is deprecated and will be removed in a future release"); //$NON-NLS-1$ | ||||||
theresa-m marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
@@ -1297,7 +1307,14 @@ static void initSecurityManager(ClassLoader applicationClassLoader) { | |||||
throw new Error(Msg.getString("K0631", e.toString()), e); //$NON-NLS-1$ | ||||||
} | ||||||
} | ||||||
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */ | ||||||
} | ||||||
/*[IF JAVA_SPEC_VERSION >= 24]*/ | ||||||
if (throwErrorOnInit) { | ||||||
/*[MSG "K0B04", "A command line option has attempted to allow or enable the Security Manager. Enabling a Security Manager is not supported."]*/ | ||||||
throw new Error(Msg.getString("K0B04")); //$NON-NLS-1$ | ||||||
} | ||||||
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I liked the variable since the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The message should be prefixed with "Error: "; see SecurityManagerWarnings.java. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is from
|
||||||
} | ||||||
/*[ENDIF] JAVA_SPEC_VERSION >= 9 */ | ||||||
|
||||||
|
@@ -1315,17 +1332,25 @@ static boolean allowSecurityManager() { | |||||
* | ||||||
* @param s the new security manager | ||||||
* | ||||||
/*[IF JAVA_SPEC_VERSION > 24] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* @throws UnsupportedOperationException always | ||||||
/*[ELSE] JAVA_SPEC_VERSION > 24 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* @throws SecurityException if the security manager has already been set and its checkPermission method doesn't allow it to be replaced. | ||||||
/*[IF JAVA_SPEC_VERSION > 11] | ||||||
* @throws UnsupportedOperationException if s is non-null and a special token "disallow" has been set for system property "java.security.manager" | ||||||
* which indicates that a security manager is not allowed to be set dynamically. | ||||||
/*[ENDIF] JAVA_SPEC_VERSION > 11 | ||||||
/*[ENDIF] JAVA_SPEC_VERSION > 24 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
/*[IF JAVA_SPEC_VERSION >= 17]*/ | ||||||
@Deprecated(since="17", forRemoval=true) | ||||||
@CallerSensitive | ||||||
/*[ENDIF] JAVA_SPEC_VERSION >= 17 */ | ||||||
public static void setSecurityManager(final SecurityManager s) { | ||||||
/*[IF JAVA_SPEC_VERSION >= 24]*/ | ||||||
/*[MSG "K0B03", "Setting a Security Manager is not supported"]*/ | ||||||
throw new UnsupportedOperationException(Msg.getString("K0B03")); //$NON-NLS-1$ | ||||||
/*[ELSE] JAVA_SPEC_VERSION >= 24*/ | ||||||
/*[IF CRIU_SUPPORT]*/ | ||||||
if (openj9.internal.criu.InternalCRIUSupport.isCRIUSupportEnabled()) { | ||||||
/*[MSG "K0B02", "Enabling a SecurityManager currently unsupported when -XX:+EnableCRIUSupport is specified"]*/ | ||||||
|
@@ -1403,6 +1428,7 @@ public Void run() { | |||||
currentSecurity.checkPermission(com.ibm.oti.util.RuntimePermissions.permissionSetSecurityManager); | ||||||
} | ||||||
security = s; | ||||||
/*[ENDIF] JAVA_SPEC_VERSION >= 24*/ | ||||||
} | ||||||
|
||||||
/** | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,9 @@ | |
package java.security; | ||
|
||
import com.ibm.oti.util.Msg; | ||
/*[IF JAVA_SPEC_VERSION < 24]*/ | ||
import sun.security.util.SecurityConstants; | ||
/*[ENDIF] JAVA_SPEC_VERSION < 24 */ | ||
|
||
/*[IF JAVA_SPEC_VERSION >= 9] | ||
import jdk.internal.reflect.CallerSensitive; | ||
|
@@ -44,30 +46,30 @@ | |
@SuppressWarnings("removal") | ||
/*[ENDIF] JAVA_SPEC_VERSION >= 17 */ | ||
public final class AccessController { | ||
/*[IF JAVA_SPEC_VERSION >= 24]*/ | ||
private static AccessControlContext ACC_NO_PERM = new AccessControlContext( | ||
new ProtectionDomain[] { new ProtectionDomain(null, null) }); | ||
/*[ELSE] JAVA_SPEC_VERSION >= 24 */ | ||
static { | ||
// Initialize vm-internal caches | ||
initializeInternal(); | ||
} | ||
|
||
/*[IF JAVA_SPEC_VERSION >= 24]*/ | ||
private static AccessControlContext ACC_NO_PERM = new AccessControlContext( | ||
new ProtectionDomain[] { new ProtectionDomain(null, null) }); | ||
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */ | ||
|
||
static final int OBJS_INDEX_ACC = 0; | ||
static final int OBJS_INDEX_PDS = 1; | ||
static final int OBJS_ARRAY_SIZE = 3; | ||
static final int OBJS_INDEX_PERMS_OR_CACHECHECKED = 2; | ||
|
||
private static native void initializeInternal(); | ||
private static native void initializeInternal(); | ||
|
||
/* [PR CMVC 188787] Enabling -Djava.security.debug option within WAS keeps JVM busy */ | ||
static final class DebugRecursionDetection { | ||
private static ThreadLocal<String> tlDebug = new ThreadLocal<>(); | ||
static ThreadLocal<String> getTlDebug() { | ||
return tlDebug; | ||
/* [PR CMVC 188787] Enabling -Djava.security.debug option within WAS keeps JVM busy */ | ||
static final class DebugRecursionDetection { | ||
private static ThreadLocal<String> tlDebug = new ThreadLocal<>(); | ||
static ThreadLocal<String> getTlDebug() { | ||
return tlDebug; | ||
} | ||
} | ||
} | ||
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */ | ||
|
||
/*[PR 1FDIC6B] J9JCL:WIN95 - AccessController missing private no-arg constructor */ | ||
/** | ||
|
@@ -77,6 +79,7 @@ private AccessController() { | |
super(); | ||
} | ||
|
||
/*[IF JAVA_SPEC_VERSION < 24]*/ | ||
/** | ||
* The object array returned has following format: | ||
* | ||
|
@@ -192,7 +195,6 @@ private static void throwACE(boolean debug, Permission perm, ProtectionDomain pD | |
} | ||
} | ||
|
||
/*[IF JAVA_SPEC_VERSION < 24]*/ | ||
/** | ||
* Helper method to check whether the running program is allowed to access the resource | ||
* being guarded by the given Permission argument | ||
|
@@ -275,7 +277,6 @@ private static boolean checkPermissionHelper(Permission perm, AccessControlConte | |
} | ||
return limitedPermImplied; | ||
} | ||
/*[ENDIF] JAVA_SPEC_VERSION < 24 */ | ||
|
||
/** | ||
* Helper to print debug stack information for checkPermission(). | ||
|
@@ -365,15 +366,23 @@ private static boolean debugHelperJEP140(Object[] objects, Permission perm) { | |
debugPrintStack(debug, perm); | ||
return debug; | ||
} | ||
/*[ENDIF] JAVA_SPEC_VERSION < 24 */ | ||
|
||
/** | ||
/*[IF JAVA_SPEC_VERSION >= 24] | ||
* Throws AccessControlException | ||
* | ||
* @param perm is ignored | ||
* @exception AccessControlException is always thrown | ||
/*[ELSE] JAVA_SPEC_VERSION >= 24 | ||
* Checks whether the running program is allowed to | ||
* access the resource being guarded by the given | ||
* Permission argument. | ||
* | ||
* @param perm the permission to check | ||
* @exception AccessControlException if access is not allowed. | ||
* NullPointerException if perm is null | ||
/*[ENDIF] JAVA_SPEC_VERSION >= 24 | ||
*/ | ||
public static void checkPermission(Permission perm) throws AccessControlException { | ||
/*[IF JAVA_SPEC_VERSION >= 24]*/ | ||
|
@@ -455,6 +464,9 @@ private static void keepalive(Permission... perms) { | |
} | ||
|
||
/** | ||
/*[IF JAVA_SPEC_VERSION >= 24] | ||
* @return an AccessControlContext with no permissions | ||
/*[ELSE] JAVA_SPEC_VERSION >= 24 | ||
* Answers the access controller context of the current thread, | ||
* including the inherited ones. It basically retrieves all the | ||
* protection domains from the calling stack and creates an | ||
|
@@ -463,6 +475,7 @@ private static void keepalive(Permission... perms) { | |
* @return an AccessControlContext which captures the current state | ||
* | ||
* @see AccessControlContext | ||
/*[ENDIF] JAVA_SPEC_VERSION >= 24 | ||
*/ | ||
public static AccessControlContext getContext() { | ||
/*[IF JAVA_SPEC_VERSION >= 24]*/ | ||
|
@@ -472,6 +485,7 @@ public static AccessControlContext getContext() { | |
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */ | ||
} | ||
|
||
/*[IF JAVA_SPEC_VERSION < 24]*/ | ||
/** | ||
* This is a helper method for getContext() and doPrivilegedWithCombiner methods. | ||
* Answers the access controller context of the current thread including the inherited ones. | ||
|
@@ -637,6 +651,7 @@ private static int getNewAuthorizedState(AccessControlContext acc, ProtectionDom | |
} | ||
return newAuthorizedState; | ||
} | ||
/*[ENDIF] JAVA_SPEC_VERSION < 24 */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be moved to L722 to include |
||
|
||
/** | ||
* Helper method to combine the ProtectionDomain objects | ||
|
@@ -849,7 +864,11 @@ public static <T> T doPrivileged (PrivilegedExceptionAction<T> action, AccessCon | |
*/ | ||
@CallerSensitive | ||
public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action) { | ||
/*[IF JAVA_SPEC_VERSION >= 24]*/ | ||
return doPrivileged(action, null); | ||
/*[ELSE] JAVA_SPEC_VERSION >= 24*/ | ||
return doPrivileged(action, doPrivilegedWithCombinerHelper(null)); | ||
/*[ENDIF] JAVA_SPEC_VERSION >= 24*/ | ||
} | ||
|
||
/** | ||
|
@@ -876,9 +895,14 @@ public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action) { | |
public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action) | ||
throws PrivilegedActionException | ||
{ | ||
/*[IF JAVA_SPEC_VERSION >= 24]*/ | ||
return doPrivileged(action, null); | ||
/*[ELSE] JAVA_SPEC_VERSION >= 24*/ | ||
return doPrivileged(action, doPrivilegedWithCombinerHelper(null)); | ||
/*[ENDIF] JAVA_SPEC_VERSION >= 24*/ | ||
} | ||
|
||
/*[IF JAVA_SPEC_VERSION < 24]*/ | ||
/** | ||
* Helper method to check if any permission is null | ||
* | ||
|
@@ -894,6 +918,7 @@ private static void checkPermsNPE(Permission... perms) { | |
} | ||
} | ||
} | ||
/*[ENDIF] JAVA_SPEC_VERSION < 24 */ | ||
|
||
/** | ||
* Performs the privileged action specified by <code>action</code>. | ||
|
@@ -922,7 +947,9 @@ private static void checkPermsNPE(Permission... perms) { | |
public static <T> T doPrivileged(PrivilegedAction<T> action, | ||
AccessControlContext context, Permission... perms) | ||
{ | ||
/*[IF JAVA_SPEC_VERSION < 24]*/ | ||
checkPermsNPE(perms); | ||
/*[ENDIF] JAVA_SPEC_VERSION < 24 */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
T result = action.run(); | ||
keepalive(context); | ||
keepalive(perms); | ||
|
@@ -954,8 +981,13 @@ public static <T> T doPrivileged(PrivilegedAction<T> action, | |
public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action, | ||
AccessControlContext context, Permission... perms) | ||
{ | ||
/*[IF JAVA_SPEC_VERSION >= 24]*/ | ||
return doPrivileged(action, context, perms); // 24 - perms? | ||
/*[ELSE] JAVA_SPEC_VERSION >= 24*/ | ||
checkPermsNPE(perms); | ||
return doPrivileged(action, doPrivilegedWithCombinerHelper(context), perms); | ||
/*[ENDIF] JAVA_SPEC_VERSION >= 24*/ | ||
|
||
} | ||
|
||
/** | ||
|
@@ -989,7 +1021,9 @@ public static <T> T doPrivileged(PrivilegedExceptionAction<T> action, | |
throws PrivilegedActionException | ||
{ | ||
try { | ||
/*[IF JAVA_SPEC_VERSION < 24]*/ | ||
checkPermsNPE(perms); | ||
/*[ENDIF] JAVA_SPEC_VERSION < 24 */ | ||
T result = action.run(); | ||
keepalive(context); | ||
keepalive(perms); | ||
|
@@ -1029,10 +1063,15 @@ public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action | |
AccessControlContext context, Permission... perms) | ||
throws PrivilegedActionException | ||
{ | ||
/*[IF JAVA_SPEC_VERSION >= 24]*/ | ||
return doPrivileged(action, context, perms); | ||
/*[ELSE] JAVA_SPEC_VERSION >= 24 */ | ||
checkPermsNPE(perms); | ||
return doPrivileged(action, doPrivilegedWithCombinerHelper(context), perms); | ||
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */ | ||
} | ||
|
||
/*[IF JAVA_SPEC_VERSION < 24]*/ | ||
/** | ||
* Helper method to construct an AccessControlContext for doPrivilegedWithCombiner methods. | ||
* | ||
|
@@ -1052,5 +1091,6 @@ private static AccessControlContext doPrivilegedWithCombinerHelper(AccessControl | |
} | ||
return fixedContext; | ||
} | ||
/*[ENDIF] JAVA_SPEC_VERSION < 24*/ | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
#include "j9.h" | ||
#include "j9port.h" | ||
|
||
#if JAVA_SPEC_VERSION < 24 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file can be removed for JDK24+. |
||
jboolean JNICALL Java_java_security_AccessController_initializeInternal(JNIEnv *env, jclass thisClz) | ||
{ | ||
J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM; | ||
|
@@ -63,3 +64,4 @@ jboolean JNICALL Java_java_security_AccessController_initializeInternal(JNIEnv * | |
fail: | ||
return JNI_FALSE; | ||
} | ||
#endif /* JAVA_SPEC_VERSION < 24 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initSecurityManager()
can be removed atopenj9/jcl/src/java.base/share/classes/java/lang/ClassLoader.java
Line 297 in 48709bf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still needed since
initSecurityManager
is used to detect settings of thejava.security.manager
property.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initSecurityManager()
reads the system propertyjava.security.manager
, and setsthrowUOEFromSetSM
which can be skipped withinsetSecurityManager()
.System.initSecurityManager(applicationClassLoader)
seems not needed for JDK24+.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will still be needed to throw an exception on startup for illegal java.security.manager manager settings triggered by
throwErrorOnInit
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.