Skip to content

Commit

Permalink
Merge pull request #239 from ibmruntimes/openj9-staging
Browse files Browse the repository at this point in the history
Merge jdk-17.0.8+7 into 0.40.0 release
  • Loading branch information
JasonFengJ9 authored Jul 19, 2023
2 parents 2f3d502 + bf3d2d7 commit b7e431f
Show file tree
Hide file tree
Showing 28 changed files with 676 additions and 111 deletions.
2 changes: 1 addition & 1 deletion closed/GensrcJ9JCL.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ $(J9JCL_SOURCES_DONEFILE) : \
@$(MKDIR) -p $(J9TOOLS_DIR)
$(MAKE) $(MAKE_ARGS) -C $(OPENJ9_TOPDIR)/sourcetools -f buildj9tools.mk \
BOOT_JDK=$(BOOT_JDK) \
DEST_DIR=$(call FixPath,$(J9TOOLS_DIR)) \
DEST_DIR=$(call MixedPath,$(J9TOOLS_DIR)) \
JAVA_HOME=$(BOOT_JDK) \
preprocessor
@$(ECHO) Generating J9JCL sources
Expand Down
25 changes: 7 additions & 18 deletions closed/JPP.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,17 @@ endif # OPENJ9_ENABLE_INLINE_TYPES
# $3 - destination subdirectory
# $4 - more options (optional)
define RunJPP
@$(ECHO) $(BOOT_JDK)/bin/java \
-cp "$(call FixPath,$(JPP_JAR))" \
$(call EchoAndRun, $(BOOT_JDK)/bin/java \
-cp "$(call MixedPath,$(JPP_JAR))" \
-Dfile.encoding=US-ASCII \
com.ibm.jpp.commandline.CommandlineBuilder \
-verdict \
-config $1 \
-baseDir "$(call FixPath,$(dir $2))" \
-baseDir "$(call MixedPath,$(dir $2))" \
-srcRoot $(notdir $2)/ \
-xml "$(call FixPath,$(OPENJ9_TOPDIR)/jcl/jpp_configuration.xml)" \
-dest "$(call FixPath,$(SUPPORT_OUTPUTDIR)$(strip $3))" \
-xml "$(call MixedPath,$(OPENJ9_TOPDIR)/jcl/jpp_configuration.xml)" \
-dest "$(call MixedPath,$(SUPPORT_OUTPUTDIR)$(strip $3))" \
-tag:define "$(subst $(SPACE),;,$(sort $(JPP_TAGS)))" \
$4
@$(BOOT_JDK)/bin/java \
-cp "$(call FixPath,$(JPP_JAR))" \
-Dfile.encoding=US-ASCII \
com.ibm.jpp.commandline.CommandlineBuilder \
-verdict \
-config $1 \
-baseDir "$(call FixPath,$(dir $2))" \
-srcRoot $(notdir $2)/ \
-xml "$(call FixPath,$(OPENJ9_TOPDIR)/jcl/jpp_configuration.xml)" \
-dest "$(call FixPath,$(SUPPORT_OUTPUTDIR)$(strip $3))" \
-tag:define "$(subst $(SPACE),;,$(sort $(JPP_TAGS)))" \
$4
$4 \
)
endef # RunJPP
7 changes: 3 additions & 4 deletions closed/OpenJ9.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ifeq (,$(wildcard $(SPEC)))
endif
include $(SPEC)
include $(TOPDIR)/make/common/MakeBase.gmk
include $(TOPDIR)/closed/JPP.gmk

ifeq (,$(BUILD_ID))
BUILD_ID := 000000
Expand Down Expand Up @@ -318,8 +319,6 @@ $(foreach file, \
$(notdir $(wildcard $(OPENJ9_TOPDIR)/buildspecs/*)), \
$(eval $(call openj9_stage_buildspec_file,$(file))))

J9TOOLS_DIR := $(SUPPORT_OUTPUTDIR)/j9tools

stage-j9 :
@$(ECHO) Staging OpenJ9 runtime in $(OUTPUTDIR)/vm
$(call openj9_copy_tree,$(OUTPUTDIR)/vm,$(OPENJ9_TOPDIR)/runtime)
Expand Down Expand Up @@ -484,13 +483,13 @@ run-preprocessors-j9 : stage-j9
+BOOT_JDK=$(BOOT_JDK) $(EXPORT_COMPILER_ENV_VARS) OPENJDK_VERSION_NUMBER_FOUR_POSITIONS=$(VERSION_NUMBER_FOUR_POSITIONS) \
$(MAKE) $(MAKE_ARGS) -C $(OUTPUTDIR)/vm -f $(OPENJ9_TOPDIR)/runtime/buildtools.mk \
BUILD_ID=$(BUILD_ID) \
DEST_DIR=$(call FixPath,$(J9TOOLS_DIR)) \
DEST_DIR=$(call MixedPath,$(J9TOOLS_DIR)) \
EXTRA_CONFIGURE_ARGS=$(OMR_EXTRA_CONFIGURE_ARGS) \
FREEMARKER_JAR="$(FREEMARKER_JAR)" \
J9VM_SHA=$(OPENJ9_SHA) \
JAVA_HOME=$(BOOT_JDK) \
OMR_DIR=$(OUTPUTDIR)/vm/omr \
SOURCETOOLS_DIR=$(call FixPath,$(OPENJ9_TOPDIR))/sourcetools \
SOURCETOOLS_DIR=$(call MixedPath,$(OPENJ9_TOPDIR))/sourcetools \
SPEC=$(OPENJ9_BUILDSPEC) \
UMA_OPTIONS_EXTRA="-buildDate $(shell date +'%Y%m%d')" \
VERSION_MAJOR=$(VERSION_FEATURE) \
Expand Down
1 change: 0 additions & 1 deletion closed/custom/Main.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ JVM_MAIN_TARGETS := j9vm-build
JVM_TOOLS_TARGETS :=
JVM_DOCS_TARGETS :=
JVM_TEST_IMAGE_TARGETS := test-image-openj9
DEFAULT_JMOD_DEPS := j9vm-build
PHASE_MAKEDIRS := $(TOPDIR)/closed/make $(PHASE_MAKEDIRS)

OPENJ9_MAKE := $(MAKE) $(MAKE_ARGS) -f $(TOPDIR)/closed/OpenJ9.gmk
Expand Down
34 changes: 34 additions & 0 deletions closed/custom/common/MakeBase.gmk
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ===========================================================================
# (c) Copyright IBM Corp. 2023, 2023 All Rights Reserved
# ===========================================================================
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# IBM designates this particular file as subject to the "Classpath" exception
# as provided by IBM in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, see <http://www.gnu.org/licenses/>.
# ===========================================================================

# Echo a command and then execute it.
# $1 - the command
define EchoAndRun
@ $(ECHO) $1
@ $1
endef

# On Windows, FixPath yields backslashes which can cause problems, so
# we use PATHTOOL instead for tools (like java) that support both.
ifeq ($(call isTargetOs, windows), true)
MixedPath = $(shell $(PATHTOOL) -m $1)
else
MixedPath = $1
endif
2 changes: 1 addition & 1 deletion closed/openjdk-tag.gmk
Original file line number Diff line number Diff line change
@@ -1 +1 @@
OPENJDK_TAG := jdk-17.0.8+6
OPENJDK_TAG := jdk-17.0.8+7
2 changes: 1 addition & 1 deletion make/conf/version-numbers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ DEFAULT_VERSION_CLASSFILE_MINOR=0
DEFAULT_VERSION_DOCS_API_SINCE=11
DEFAULT_ACCEPTABLE_BOOT_VERSIONS="16 17"
DEFAULT_JDK_SOURCE_TARGET_VERSION=17
DEFAULT_PROMOTED_VERSION_PRE=ea
DEFAULT_PROMOTED_VERSION_PRE=
12 changes: 7 additions & 5 deletions src/java.base/share/classes/java/util/jar/JarFile.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -29,6 +29,7 @@
import jdk.internal.access.JavaUtilZipFileAccess;
import sun.security.action.GetPropertyAction;
import sun.security.util.ManifestEntryVerifier;
import sun.security.util.SignatureFileVerifier;

import java.io.ByteArrayInputStream;
import java.io.EOFException;
Expand Down Expand Up @@ -151,8 +152,6 @@ public class JarFile extends ZipFile {
private static final boolean MULTI_RELEASE_ENABLED;
private static final boolean MULTI_RELEASE_FORCED;
private static final ThreadLocal<Boolean> isInitializing = new ThreadLocal<>();
// The maximum size of array to allocate. Some VMs reserve some header words in an array.
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;

private SoftReference<Manifest> manRef;
private JarEntry manEntry;
Expand Down Expand Up @@ -800,8 +799,11 @@ private void initializeVerifier() {
private byte[] getBytes(ZipEntry ze) throws IOException {
try (InputStream is = super.getInputStream(ze)) {
long uncompressedSize = ze.getSize();
if (uncompressedSize > MAX_ARRAY_SIZE) {
throw new IOException("Unsupported size: " + uncompressedSize);
if (uncompressedSize > SignatureFileVerifier.MAX_SIG_FILE_SIZE) {
throw new IOException("Unsupported size: " + uncompressedSize +
" for JarEntry " + ze.getName() +
". Allowed max size: " +
SignatureFileVerifier.MAX_SIG_FILE_SIZE + " bytes");
}
int len = (int)uncompressedSize;
int bytesRead;
Expand Down
130 changes: 130 additions & 0 deletions src/java.base/share/classes/java/util/zip/ZipFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import jdk.internal.ref.CleanerFactory;
import jdk.internal.vm.annotation.Stable;
import sun.nio.cs.UTF_8;
import sun.security.action.GetBooleanAction;
import sun.security.util.SignatureFileVerifier;

import static java.util.zip.ZipConstants64.*;
Expand Down Expand Up @@ -121,6 +122,12 @@ public class ZipFile implements ZipConstants, Closeable {
*/
public static final int OPEN_DELETE = 0x4;

/**
* Flag which specifies whether the validation of the Zip64 extra
* fields should be disabled
*/
private static final boolean disableZip64ExtraFieldValidation =
GetBooleanAction.privilegedGetProperty("jdk.util.zip.disableZip64ExtraFieldValidation");
/**
* Opens a zip file for reading.
*
Expand Down Expand Up @@ -1195,6 +1202,16 @@ private int checkAndAddEntry(int pos, int index)
if (entryPos + nlen > cen.length - ENDHDR) {
zerror("invalid CEN header (bad header size)");
}

int elen = CENEXT(cen, pos);
if (elen > 0 && !disableZip64ExtraFieldValidation) {
long extraStartingOffset = pos + CENHDR + nlen;
if ((int)extraStartingOffset != extraStartingOffset) {
zerror("invalid CEN header (bad extra offset)");
}
checkExtraFields(pos, (int)extraStartingOffset, elen);
}

try {
ZipCoder zcp = zipCoderForPos(pos);
int hash = zcp.checkedHash(cen, entryPos, nlen);
Expand All @@ -1211,6 +1228,119 @@ private int checkAndAddEntry(int pos, int index)
return nlen;
}

/**
* Validate the Zip64 Extra block fields
* @param startingOffset Extra Field starting offset within the CEN
* @param extraFieldLen Length of this Extra field
* @throws ZipException If an error occurs validating the Zip64 Extra
* block
*/
private void checkExtraFields(int cenPos, int startingOffset,
int extraFieldLen) throws ZipException {
// Extra field Length cannot exceed 65,535 bytes per the PKWare
// APP.note 4.4.11
if (extraFieldLen > 0xFFFF) {
zerror("invalid extra field length");
}
// CEN Offset where this Extra field ends
int extraEndOffset = startingOffset + extraFieldLen;
if (extraEndOffset > cen.length) {
zerror("Invalid CEN header (extra data field size too long)");
}
int currentOffset = startingOffset;
while (currentOffset < extraEndOffset) {
int tag = get16(cen, currentOffset);
currentOffset += Short.BYTES;

int tagBlockSize = get16(cen, currentOffset);
int tagBlockEndingOffset = currentOffset + tagBlockSize;

// The ending offset for this tag block should not go past the
// offset for the end of the extra field
if (tagBlockEndingOffset > extraEndOffset) {
zerror("Invalid CEN header (invalid zip64 extra data field size)");
}
currentOffset += Short.BYTES;

if (tag == ZIP64_EXTID) {
// Get the compressed size;
long csize = CENSIZ(cen, cenPos);
// Get the uncompressed size;
long size = CENLEN(cen, cenPos);
checkZip64ExtraFieldValues(currentOffset, tagBlockSize,
csize, size);
}
currentOffset += tagBlockSize;
}
}

/**
* Validate the Zip64 Extended Information Extra Field (0x0001) block
* size and that the uncompressed size and compressed size field
* values are not negative.
* Note: As we do not use the LOC offset or Starting disk number
* field value we will not validate them
* @param off the starting offset for the Zip64 field value
* @param blockSize the size of the Zip64 Extended Extra Field
* @param csize CEN header compressed size value
* @param size CEN header uncompressed size value
* @throws ZipException if an error occurs
*/
private void checkZip64ExtraFieldValues(int off, int blockSize, long csize,
long size)
throws ZipException {
byte[] cen = this.cen;
// Validate the Zip64 Extended Information Extra Field (0x0001)
// length.
if (!isZip64ExtBlockSizeValid(blockSize)) {
zerror("Invalid CEN header (invalid zip64 extra data field size)");
}
// Check the uncompressed size is not negative
// Note we do not need to check blockSize is >= 8 as
// we know its length is at least 8 from the call to
// isZip64ExtBlockSizeValid()
if ((size == ZIP64_MAGICVAL)) {
if(get64(cen, off) < 0) {
zerror("Invalid zip64 extra block size value");
}
}
// Check the compressed size is not negative
if ((csize == ZIP64_MAGICVAL) && (blockSize >= 16)) {
if (get64(cen, off + 8) < 0) {
zerror("Invalid zip64 extra block compressed size value");
}
}
}

/**
* Validate the size and contents of a Zip64 extended information field
* The order of the Zip64 fields is fixed, but the fields MUST
* only appear if the corresponding LOC or CEN field is set to 0xFFFF:
* or 0xFFFFFFFF:
* Uncompressed Size - 8 bytes
* Compressed Size - 8 bytes
* LOC Header offset - 8 bytes
* Disk Start Number - 4 bytes
* See PKWare APP.Note Section 4.5.3 for more details
*
* @param blockSize the Zip64 Extended Information Extra Field size
* @return true if the extra block size is valid; false otherwise
*/
private static boolean isZip64ExtBlockSizeValid(int blockSize) {
/*
* As the fields must appear in order, the block size indicates which
* fields to expect:
* 8 - uncompressed size
* 16 - uncompressed size, compressed size
* 24 - uncompressed size, compressed sise, LOC Header offset
* 28 - uncompressed size, compressed sise, LOC Header offset,
* and Disk start number
*/
return switch(blockSize) {
case 8, 16, 24, 28 -> true;
default -> false;
};
}
private int getEntryHash(int index) { return entries[index]; }
private int getEntryNext(int index) { return entries[index + 1]; }
private int getEntryPos(int index) { return entries[index + 2]; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -52,6 +52,7 @@
import java.util.jar.JarFile;
import java.util.jar.Manifest;

import sun.security.action.GetIntegerAction;
import sun.security.jca.Providers;
import sun.security.pkcs.PKCS7;
import sun.security.pkcs.SignerInfo;
Expand Down Expand Up @@ -97,6 +98,12 @@ public class SignatureFileVerifier {
/** ConstraintsParameters for checking disabled algorithms */
private JarConstraintsParameters params;

// the maximum allowed size in bytes for the signature-related files
public static final int MAX_SIG_FILE_SIZE = initializeMaxSigFileSize();

// The maximum size of array to allocate. Some VMs reserve some header words in an array.
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;

/**
* Create the named SignatureFileVerifier.
*
Expand Down Expand Up @@ -842,4 +849,24 @@ void updateSigners(CodeSigner[] newSigners,
signerCache.add(cachedSigners);
signers.put(name, cachedSigners);
}

private static int initializeMaxSigFileSize() {
/*
* System property "jdk.jar.maxSignatureFileSize" used to configure
* the maximum allowed number of bytes for the signature-related files
* in a JAR file.
*/
Integer tmp = GetIntegerAction.privilegedGetProperty(
"jdk.jar.maxSignatureFileSize", 8000000);
if (tmp < 0 || tmp > MAX_ARRAY_SIZE) {
if (debug != null) {
debug.println("Default signature file size 8000000 bytes " +
"is used as the specified size for the " +
"jdk.jar.maxSignatureFileSize system property " +
"is out of range: " + tmp);
}
tmp = 8000000;
}
return tmp;
}
}
3 changes: 2 additions & 1 deletion src/java.base/share/conf/security/java.security
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,8 @@ jdk.tls.legacyAlgorithms=NULL, anon, RC4, DES, 3DES_EDE_CBC
# Note: This property is currently used by OpenJDK's JSSE implementation. It
# is not guaranteed to be examined and used by other implementations.
#
jdk.tls.keyLimits=AES/GCM/NoPadding KeyUpdate 2^37
jdk.tls.keyLimits=AES/GCM/NoPadding KeyUpdate 2^37, \
ChaCha20-Poly1305 KeyUpdate 2^37

#
# Cryptographic Jurisdiction Policy defaults
Expand Down
Loading

0 comments on commit b7e431f

Please sign in to comment.