Skip to content

Commit d16fd6f

Browse files
authored
Tolerate creation of InnocuousThreads - to facilitate use of java.lang.ref.Cleaner backport(#77788) (#91852)
Update the ES security manager to tolerate the creation of the JDK's InnocuousThreads, to facilitate the use of java.lang.ref.Cleaner in ES and dependent code by default. Further details in issue ( #77788 ) resolves #77788 backport note - in 7.17 branch jdk8 is still supported. Therefore in order to recognize jdk.base domain it has to check for classloader == null (meaning it is a bootstrap classloader) instead of comparing modules backport(#77788)
1 parent dcc1b3a commit d16fd6f

File tree

1 file changed

+7
-1
lines changed
  • libs/secure-sm/src/main/java/org/elasticsearch/secure_sm

1 file changed

+7
-1
lines changed

libs/secure-sm/src/main/java/org/elasticsearch/secure_sm/SecureSM.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ private void debugThreadGroups(final ThreadGroup caller, final ThreadGroup targe
153153
private static final Permission MODIFY_THREAD_PERMISSION = new RuntimePermission("modifyThread");
154154
private static final Permission MODIFY_ARBITRARY_THREAD_PERMISSION = new ThreadPermission("modifyArbitraryThread");
155155

156+
// Returns true if the given thread is an instance of the JDK's InnocuousThread.
157+
private static boolean isInnocuousThread(Thread t) {
158+
final Class<?> c = t.getClass();
159+
return c.getClassLoader() == null && c.getName().equals("jdk.internal.misc.InnocuousThread");
160+
}
161+
156162
protected void checkThreadAccess(Thread t) {
157163
Objects.requireNonNull(t);
158164

@@ -165,7 +171,7 @@ protected void checkThreadAccess(Thread t) {
165171

166172
if (target == null) {
167173
return; // its a dead thread, do nothing.
168-
} else if (source.parentOf(target) == false) {
174+
} else if (source.parentOf(target) == false && isInnocuousThread(t) == false) {
169175
checkPermission(MODIFY_ARBITRARY_THREAD_PERMISSION);
170176
}
171177
}

0 commit comments

Comments
 (0)