Skip to content

Commit ac289dd

Browse files
authored
Merge pull request ibmruntimes#477 from JasonFengJ9/mergestaging
Merge master jdk-17.0.16+1 into openj9-staging
2 parents dd9cdc9 + 26036ce commit ac289dd

File tree

1,318 files changed

+67268
-18379
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,318 files changed

+67268
-18379
lines changed

.jcheck/conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[general]
22
project=jdk-updates
33
jbs=JDK
4-
version=17.0.15
4+
version=17.0.16
55

66
[checks]
77
error=author,committer,reviewers,merge,issues,executable,symlink,message,hg-tag,whitespace,problemlists

closed/autoconf/custom-hook.m4

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,10 @@ AC_DEFUN([OPENJ9_CONFIGURE_CRAC_AND_CRIU_SUPPORT],
331331
332332
# Compute platform-specific defaults.
333333
case "$OPENJ9_PLATFORM_CODE" in
334-
xa64)
334+
xa64|xl64|xr64|xz64)
335335
default_crac=yes
336336
default_criu=yes
337337
;;
338-
xl64|xr64|xz64)
339-
default_crac=no
340-
default_criu=yes
341-
;;
342338
*)
343339
default_crac=no
344340
default_criu=no

closed/custom/modules/java.base/Copy.gmk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ ifneq ($(OPENSSL_BUNDLE_LIB_PATH), )
227227
$(error Cannot bundle OpenSSL - none of $(LIBCRYPTO_NAMES) are present in $(OPENSSL_BUNDLE_LIB_PATH))
228228
endif
229229

230-
LIBCRYPTO_TARGET_LIB := $(LIB_DST_DIR)/$(notdir $(LIBCRYPTO_PATH))
230+
LIBCRYPTO_TARGET_LIB := $(LIB_DST_DIR)/$(LIBRARY_PREFIX)crypto-semeru$(SHARED_LIBRARY_SUFFIX)
231231
TARGETS += $(LIBCRYPTO_TARGET_LIB)
232232
$(LIBCRYPTO_TARGET_LIB) : $(LIBCRYPTO_PATH)
233233
$(call install-file)
@@ -245,7 +245,7 @@ ifneq ($(OPENSSL_BUNDLE_LIB_PATH), )
245245
LIBSSL_PATH := $(firstword $(wildcard $(addprefix $(OPENSSL_BUNDLE_LIB_PATH)/, $(LIBSSL_NAMES))))
246246

247247
ifneq ($(LIBSSL_PATH), )
248-
LIBSSL_TARGET_LIB = $(LIB_DST_DIR)/$(notdir $(LIBSSL_PATH))
248+
LIBSSL_TARGET_LIB = $(LIB_DST_DIR)/$(LIBRARY_PREFIX)ssl-semeru$(SHARED_LIBRARY_SUFFIX)
249249
TARGETS += $(LIBSSL_TARGET_LIB)
250250
$(LIBSSL_TARGET_LIB) : $(LIBSSL_PATH)
251251
$(call install-file)

closed/openjdk-tag.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
OPENJDK_TAG := jdk-17.0.15+6
1+
OPENJDK_TAG := jdk-17.0.16+1

closed/src/java.base/share/classes/com/sun/crypto/provider/NativeCipherBlockChaining.java

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
/*
2626
* ===========================================================================
27-
* (c) Copyright IBM Corp. 2018, 2023 All Rights Reserved
27+
* (c) Copyright IBM Corp. 2018, 2025 All Rights Reserved
2828
* ===========================================================================
2929
*/
3030

@@ -33,6 +33,8 @@
3333
import java.security.InvalidKeyException;
3434
import java.security.ProviderException;
3535
import java.util.ArrayDeque;
36+
import java.util.Arrays;
37+
3638
import com.sun.crypto.provider.AESCrypt;
3739

3840
import jdk.crypto.jniprovider.NativeCrypto;
@@ -47,7 +49,6 @@
4749
* native implementation of CBC crypto.
4850
*
4951
*/
50-
5152
class NativeCipherBlockChaining extends FeedbackCipher {
5253

5354
protected final static int numContexts = 4096;
@@ -58,6 +59,12 @@ class NativeCipherBlockChaining extends FeedbackCipher {
5859
private static final Cleaner contextCleaner;
5960
private int previousKeyLength = -1;
6061

62+
/**
63+
* OpenSSL requires an additional block size for operations. This will be added
64+
* to all calculated output buffer sizes whenever native CBC operations are enabled.
65+
*/
66+
static final int OPENSSL_ENCRYPTION_RESIDUE = 16;
67+
6168
/*
6269
* Initialize the CBC context.
6370
*/
@@ -104,6 +111,29 @@ public void run() {
104111
}
105112
}
106113

114+
/**
115+
* This method checks if there is enough space in the provided output buffer
116+
* to accommodate encryption in OpenSSL. OpenSSL requires an extra full block size
117+
* for its operations according to the documentation associated with EVP_CipherUpdate
118+
* (EVP_EncryptUpdate).
119+
*
120+
* @param output the original output buffer
121+
* @param outputOffset the current offset in the output buffer
122+
* @param inputLen the length of the input data
123+
* @return a new byte array that can hold the combined output and residue (extra block),
124+
* or the original buffer if there is enough space in the output buffer {@code output}
125+
*/
126+
private static byte[] getOptionalLocalOpenSSLOutputBuffer(byte[] output, int outputOffset, int inputLen) {
127+
byte[] tmpOutputBuffer;
128+
int extraLen = Math.addExact(inputLen, OPENSSL_ENCRYPTION_RESIDUE);
129+
if (extraLen > (output.length - outputOffset)) {
130+
tmpOutputBuffer = new byte[extraLen];
131+
} else {
132+
tmpOutputBuffer = output;
133+
}
134+
return tmpOutputBuffer;
135+
}
136+
107137
/*
108138
* Get CBC context.
109139
*/
@@ -266,7 +296,7 @@ int encrypt(byte[] plain, int plainOffset, int plainLen,
266296
throw new ProviderException("Internal error in input buffering");
267297
}
268298

269-
/**
299+
/*
270300
* OpenSSL doesn't support overlapping buffers, make a copy of plain.
271301
*/
272302
if (plain == cipher) {
@@ -276,15 +306,34 @@ int encrypt(byte[] plain, int plainOffset, int plainLen,
276306
plainOffset = 0;
277307
}
278308

309+
/*
310+
* Determine if our output buffer is big enough for OpenSSL operations. Allocate a new
311+
* one if required.
312+
*/
313+
byte[] tmpOutputBuffer = getOptionalLocalOpenSSLOutputBuffer(cipher, cipherOffset, plainLen);
314+
279315
int ret;
280316
synchronized (this) {
281-
ret = nativeCrypto.CBCUpdate(nativeContext, plain, plainOffset,
282-
plainLen, cipher, cipherOffset);
317+
ret = nativeCrypto.CBCUpdate(nativeContext,
318+
plain,
319+
plainOffset,
320+
plainLen,
321+
tmpOutputBuffer,
322+
(cipher == tmpOutputBuffer) ? cipherOffset : 0);
283323
}
284324
if (ret == -1) {
285325
throw new ProviderException("Error in Native CipherBlockChaining");
286326
}
287327

328+
/*
329+
* If a larger output buffer was required for OpenSSL operations then copy back the results
330+
* into the callers output buffer.
331+
*/
332+
if (cipher != tmpOutputBuffer) {
333+
System.arraycopy(tmpOutputBuffer, 0, cipher, cipherOffset, ret);
334+
Arrays.fill(tmpOutputBuffer, (byte)0x00);
335+
}
336+
288337
// saving current running state
289338
System.arraycopy(cipher, cipherOffset+plainLen-blockSize, r, 0, blockSize);
290339
return ret;
@@ -339,16 +388,39 @@ int encryptFinal(byte[] plain, int plainOffset, int plainLen,
339388

340389
int ret;
341390

391+
/*
392+
* Determine if our output buffer is big enough for OpenSSL operations. Allocate a new
393+
* one if required.
394+
*/
395+
byte[] tmpOutputBuffer = getOptionalLocalOpenSSLOutputBuffer(cipher, cipherOffset, plainLen);
396+
342397
synchronized (this) {
343398
if (plain == cipher) {
344-
ret = nativeCrypto.CBCFinalEncrypt(nativeContext, plain.clone(),
345-
plainOffset, plainLen, cipher, cipherOffset);
399+
ret = nativeCrypto.CBCFinalEncrypt(nativeContext,
400+
plain.clone(),
401+
plainOffset,
402+
plainLen,
403+
tmpOutputBuffer,
404+
(cipher == tmpOutputBuffer) ? cipherOffset : 0);
346405
} else {
347-
ret = nativeCrypto.CBCFinalEncrypt(nativeContext, plain, plainOffset,
348-
plainLen, cipher, cipherOffset);
406+
ret = nativeCrypto.CBCFinalEncrypt(nativeContext,
407+
plain,
408+
plainOffset,
409+
plainLen,
410+
tmpOutputBuffer,
411+
(cipher == tmpOutputBuffer) ? cipherOffset : 0);
349412
}
350413
}
351414

415+
/*
416+
* If a larger output buffer was required for OpenSSL operations then copy back the results
417+
* into the callers output buffer.
418+
*/
419+
if (cipher != tmpOutputBuffer) {
420+
System.arraycopy(tmpOutputBuffer, 0, cipher, cipherOffset, ret);
421+
Arrays.fill(tmpOutputBuffer, (byte)0x00);
422+
}
423+
352424
if (ret == -1) {
353425
throw new ProviderException("Error in Native CipherBlockChaining");
354426
}

closed/src/java.base/share/classes/jdk/crypto/jniprovider/NativeCrypto.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,25 @@ private static long loadCryptoLibraries() {
9292
// Load jncrypto JNI library.
9393
System.loadLibrary("jncrypto");
9494

95+
// Get user-specified option to skip bundled OpenSSL library.
96+
boolean skipBundled = Boolean.parseBoolean(
97+
GetPropertyAction.privilegedGetProperty("jdk.native.openssl.skipBundled"));
98+
9599
// Get user-specified OpenSSL library to use, if available.
96100
String nativeLibName =
97-
GetPropertyAction.privilegedGetProperty("jdk.native.openssl.lib", "");
101+
GetPropertyAction.privilegedGetProperty("jdk.native.openssl.lib");
102+
103+
// Check that these mutually exclusive flags are not used at the same time.
104+
if (skipBundled && (nativeLibName != null)) {
105+
throw new RuntimeException("Conflicting properties " +
106+
"jdk.native.openssl.skipBundled and jdk.native.openssl.lib");
107+
}
98108

99109
// Get the JDK location.
100110
String javaHome = StaticProperty.javaHome();
101111

102112
// Load OpenSSL crypto library dynamically.
103-
osslVersion = loadCrypto(traceEnabled, nativeLibName, javaHome);
113+
osslVersion = loadCrypto(traceEnabled, skipBundled, nativeLibName, javaHome);
104114
if (osslVersion != -1) {
105115
if (traceEnabled) {
106116
System.err.println("Native crypto library load succeeded - using native crypto library.");
@@ -274,6 +284,7 @@ public void run() {
274284
/* OpenSSL utility interfaces */
275285

276286
private static final native long loadCrypto(boolean trace,
287+
boolean skipBundled,
277288
String libName,
278289
String javaHome);
279290

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public final class RestrictedSecurity {
7979

8080
private static ProfileParser profileParser;
8181

82+
private static boolean enableCheckHashes;
83+
8284
private static RestrictedSecurityProperties restricts;
8385

8486
private static final Set<String> unmodifiableProperties = new HashSet<>();
@@ -191,11 +193,29 @@ private static boolean isJarVerifierInStackTrace() {
191193
* extending profiles, instead of altering them, a digest of the profile
192194
* is calculated and compared to the expected value.
193195
*/
194-
private static void checkHashValues() {
196+
public static void checkHashValues() {
197+
checkHashValues(true);
198+
}
199+
200+
@SuppressWarnings("removal")
201+
private static void checkHashValues(boolean fromProviders) {
195202
ProfileParser parser = profileParser;
196-
if ((parser != null) && !isJarVerifierInStackTrace()) {
197-
profileParser = null;
198-
parser.checkHashValues();
203+
if (parser != null) {
204+
if (fromProviders) {
205+
enableCheckHashes = true;
206+
}
207+
if (enableCheckHashes) {
208+
boolean isVerifying;
209+
if (System.getSecurityManager() == null) {
210+
isVerifying = isJarVerifierInStackTrace();
211+
} else {
212+
isVerifying = AccessController.doPrivileged((PrivilegedAction<Boolean>)(() -> isJarVerifierInStackTrace()));
213+
}
214+
if (!isVerifying) {
215+
profileParser = null;
216+
parser.checkHashValues();
217+
}
218+
}
199219
}
200220
}
201221

@@ -268,7 +288,7 @@ public static boolean isFIPSEnabled() {
268288
*/
269289
public static boolean isServiceAllowed(Service service) {
270290
if (securityEnabled) {
271-
checkHashValues();
291+
checkHashValues(false);
272292
return restricts.isRestrictedServiceAllowed(service, true);
273293
}
274294
return true;
@@ -282,7 +302,7 @@ public static boolean isServiceAllowed(Service service) {
282302
*/
283303
public static boolean canServiceBeRegistered(Service service) {
284304
if (securityEnabled) {
285-
checkHashValues();
305+
checkHashValues(false);
286306
return restricts.isRestrictedServiceAllowed(service, false);
287307
}
288308
return true;
@@ -296,7 +316,7 @@ public static boolean canServiceBeRegistered(Service service) {
296316
*/
297317
public static boolean isProviderAllowed(String providerName) {
298318
if (securityEnabled) {
299-
checkHashValues();
319+
checkHashValues(false);
300320
// Remove argument, e.g. -NSS-FIPS, if present.
301321
int pos = providerName.indexOf('-');
302322
if (pos >= 0) {
@@ -316,7 +336,7 @@ public static boolean isProviderAllowed(String providerName) {
316336
*/
317337
public static boolean isProviderAllowed(Class<?> providerClazz) {
318338
if (securityEnabled) {
319-
checkHashValues();
339+
checkHashValues(false);
320340
String providerClassName = providerClazz.getName();
321341

322342
// Check if the specified class extends java.security.Provider.

0 commit comments

Comments
 (0)