Skip to content

Commit 8efeba7

Browse files
committed
Update
1 parent 24a05d4 commit 8efeba7

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

closed/src/java.base/share/classes/openj9/internal/security/RestrictedSecurity.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ private RestrictedSecurity() {
137137
super();
138138
}
139139

140+
private static boolean isJarVerifierInStackTrace() {
141+
java.util.function.Predicate<Class<?>> isJarVerifier =
142+
clazz -> "java.util.jar.JarVerifier".equals(clazz.getName())
143+
&& "java.base".equals(clazz.getModule().getName());
144+
145+
java.util.function.Function<Stream<StackWalker.StackFrame>, Boolean> matcher =
146+
stream -> stream.map(StackWalker.StackFrame::getDeclaringClass)
147+
.anyMatch(isJarVerifier);
148+
149+
return StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).walk(matcher);
150+
}
151+
140152
/**
141153
* Check loaded profiles' hash values.
142154
*
@@ -154,19 +166,19 @@ private static void checkHashValues(boolean fromProviders) {
154166
if (fromProviders) {
155167
enableCheckHashes = true;
156168
}
157-
if (enableCheckHashes && (hashPauseCount.get() == 0)) {
169+
if (enableCheckHashes && !isJarVerifierInStackTrace() && (hashPauseCount.get() == 0)) {
158170
profileParser = null;
159171
parser.checkHashValues();
160172
}
161173
}
162174
}
163175

164176
public static void pauseHashCheck() {
165-
hashPauseCount.incrementAndGet();
177+
hashPauseCount.incrementAndGet();
166178
}
167179

168180
public static void resumeHashCheck() {
169-
hashPauseCount.decrementAndGet();
181+
hashPauseCount.decrementAndGet();
170182
}
171183

172184
/**
@@ -252,6 +264,7 @@ public static boolean isServiceAllowed(Service service) {
252264
*/
253265
public static boolean canServiceBeRegistered(Service service) {
254266
if (securityEnabled) {
267+
checkHashValues(false);
255268
return restricts.isRestrictedServiceAllowed(service, false);
256269
}
257270
return true;

src/java.base/share/classes/java/util/jar/JarFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
package java.util.jar;
3333

3434
import jdk.internal.access.SharedSecrets;
35-
import openj9.internal.security.RestrictedSecurity;
3635
import jdk.internal.access.JavaUtilZipFileAccess;
3736
import jdk.internal.misc.ThreadTracker;
37+
import openj9.internal.security.RestrictedSecurity;
3838
import sun.security.util.ManifestEntryVerifier;
3939
import sun.security.util.SignatureFileVerifier;
4040

0 commit comments

Comments
 (0)