Skip to content
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

Reject illegal entries in the bootstrap argument array #2700

Merged

Conversation

ChengJin01
Copy link

The changes are to validate the entries stored in
the bootstrap argument array to ensure they are
valid constant pool index required in the JVM Spec.

Signed-off-by: CHENGJin [email protected]

@ChengJin01
Copy link
Author

Code Reviewer: @DanHeidinga

runtime/bcutil/cfreader.c Outdated Show resolved Hide resolved
* CONSTANT_Double_info, CONSTANT_MethodHandle_info, or CONSTANT_MethodType_info structure.
*/
cpValueTag = cpBase[value].tag;
if ((CFR_CONSTANT_String != cpValueTag)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be clearer as a switch statement?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already updated against suggestion.

&& (CFR_CONSTANT_Float != cpValueTag)
&& (CFR_CONSTANT_Double != cpValueTag)
&& (CFR_CONSTANT_MethodHandle != cpValueTag)
&& (CFR_CONSTANT_MethodType != cpValueTag)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, for JDK11, what about Constant_Dynamic? It should be allowed as a BSM arg as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already double-checked the Spec at http://openjdk.java.net/jeps/309 and added Constant_Dynamic as valid structure.

@@ -1362,3 +1362,11 @@ J9NLS_CFR_ERR_CP_ENTRY_INVALID_BEFORE_V55.explanation=Please consult the Java Vi
J9NLS_CFR_ERR_CP_ENTRY_INVALID_BEFORE_V55.system_action=The JVM will throw a verification or classloading-related exception such as java.lang.ClassFormatError.
J9NLS_CFR_ERR_CP_ENTRY_INVALID_BEFORE_V55.user_response=Contact the provider of the classfile for a corrected version.
# END NON-TRANSLATABLE

J9NLS_CFR_ERR_BAD_BOOTSTRAP_ARGUMENT_ENTRY=The bootstrap argument array contains illegal indices to the constant pool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the message be updated to something like:
BootstrapMethod (%d) arguments contain invalid constantpool entry at index (%d) of type (%d)

So that it contains the BSM index, the cp entry and the cp entries type? It makes it much easier for users to understand what went wrong.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally introduced 2 parameters (bsmMethodIndex and bsmArgumentIndex) for this message but didn't move forward because the modification of the existing method buildError() incurs a bunch of unnecessary updating at all places.

From the user perspective, I am customizing a new method buildBootstrapMethodError() (still in coding) which only addresses this issue. Will see whether it works good in this case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got a crash with my new changes. Still investigating to see what happens to my code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed the bug in the new changes.

@ChengJin01 ChengJin01 force-pushed the bcv_classformat_boostrap_args branch 2 times, most recently from 898c8e4 to 8e5c77e Compare August 30, 2018 15:24
@ChengJin01
Copy link
Author

ChengJin01 commented Aug 30, 2018

Already finished the new changes and it works good as expected:

java.lang.ClassFormatError: JVMCFRE154 BootstrapMethod (0) arguments contain invalid constantpool entry at index (#20) of type (1); class=Foo, offset=492

@ChengJin01 ChengJin01 force-pushed the bcv_classformat_boostrap_args branch from 8e5c77e to 1bd2033 Compare August 30, 2018 16:33
/* J9NLS_CFR_ERR_BAD_BOOTSTRAP_ARGUMENT_ENTRY=BootstrapMethod (%1$d) arguments contain invalid constantpool entry at index (#%2$u) of type (%3$u); class=%5$.*4$s, offset=%6$u */
template = j9nls_lookup_message(J9NLS_ERROR | J9NLS_DO_NOT_APPEND_NEWLINE, J9NLS_CFR_ERR_BAD_BOOTSTRAP_ARGUMENT_ENTRY, "(%d)(#%u)(%u);%.*s,%u");

allocSize = strlen(template) + classNameLength + MAX_INT_SIZE * 4;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add brackets to the MAX_INT_SIZE * 4 so it's immediately obvious that you intended to multiple the max int size by 4, and not the entire amount

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed as suggested.

PORT_ACCESS_FROM_PORT(portLib);
UDATA allocSize = 0;
char *errorString = NULL;
const char *template;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either assign j9nls_lookup_message()'s return value to this variable directly or initialize it to null

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed as suggested.

@DanHeidinga DanHeidinga self-assigned this Sep 11, 2018
@ChengJin01 ChengJin01 force-pushed the bcv_classformat_boostrap_args branch from 1bd2033 to 7572bf4 Compare September 11, 2018 03:31
runtime/bcutil/cfreader.c Show resolved Hide resolved
@DanHeidinga
Copy link
Member

Jenkins test sanity xlinux jdk8,jdk11

@DanHeidinga
Copy link
Member

@ChengJin01 the build is failing - can you take a look?

13:49:25 cfrerr.c: In function ‘getJ9CfrErrorDetailMessageNoMethod’:
13:49:25 cfrerr.c:87:15: error: assignment discards ‘const’ qualifier from pointer target type [-Werror]
13:49:25    errorString = getJ9CfrErrorBsmMessage(portLib, error, className, classNameLength);
13:49:25                ^
13:49:25 cfrerr.c:90:15: error: assignment discards ‘const’ qualifier from pointer target type [-Werror]
13:49:25    errorString = getJ9CfrErrorNormalMessage(portLib, error, className, classNameLength);

@ChengJin01
Copy link
Author

Will investigate to see what happened in there.

The changes are to validate the entries stored in
the bootstrap argument array to ensure they are
valid constant pool index required in the JVM Spec.

Signed-off-by: CHENGJin <[email protected]>
@ChengJin01 ChengJin01 force-pushed the bcv_classformat_boostrap_args branch from 7572bf4 to 33096e2 Compare September 11, 2018 18:41
@ChengJin01
Copy link
Author

Jenkins test sanity xlinux jdk8,jdk11

1 similar comment
@DanHeidinga
Copy link
Member

Jenkins test sanity xlinux jdk8,jdk11

@DanHeidinga
Copy link
Member

I'm OK with merging this now but would like to see some tests added for this. In particular, to validate that the error cases print reasonable messages and don't crash :)

Opened #2856 for adding tests.

@DanHeidinga DanHeidinga merged commit ba68bbb into eclipse-openj9:master Sep 13, 2018
@ChengJin01 ChengJin01 deleted the bcv_classformat_boostrap_args branch June 23, 2020 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants