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

Update doPrivilegedWithCombinerHelper function #20430

Merged
merged 1 commit into from
Jan 31, 2025

Conversation

JinhangZhang
Copy link
Contributor

@JinhangZhang JinhangZhang commented Oct 29, 2024

When we try to invoke doPrivilegedWithCombiner function to
perform a privileged action under an existing context
environment, we are used to construct a new context but ignore
the parent context.

We should take consideration of a combination of the current
and parent context, rather than just choose either the current
or the parent.

This patch solves the failed case in issue #19499.

@JinhangZhang JinhangZhang changed the title Compat Fix #https://github.com/eclipse-openj9/openj9/issues/19499 Oct 29, 2024
@JinhangZhang JinhangZhang changed the title Fix #https://github.com/eclipse-openj9/openj9/issues/19499 Fix an openj9 failure https://github.com/eclipse-openj9/openj9/issues/19499 Oct 29, 2024
@JinhangZhang JinhangZhang changed the title Fix an openj9 failure https://github.com/eclipse-openj9/openj9/issues/19499 Fix an openj9 failure for AccessController Oct 29, 2024
@JinhangZhang JinhangZhang force-pushed the compat branch 4 times, most recently from 4f2a353 to 05d9970 Compare November 12, 2024 00:12
@JinhangZhang JinhangZhang marked this pull request as ready for review November 12, 2024 00:13
@JinhangZhang JinhangZhang force-pushed the compat branch 3 times, most recently from 04afd31 to 5c436bf Compare November 12, 2024 04:48
@JinhangZhang JinhangZhang changed the title Fix an openj9 failure for AccessController Update doPrivilegedWithCombinerHelper function Nov 12, 2024
@JinhangZhang
Copy link
Contributor Author

@keithc-ca please help to review

@pshipton pshipton requested a review from JasonFengJ9 November 14, 2024 18:55
@JasonFengJ9
Copy link
Member

This patch solves the race condition in issue #19499.

What's the race condition in #19499?

Are there any personal builds that pass test suites including internal compliance tests?

@JinhangZhang
Copy link
Contributor Author

JinhangZhang commented Nov 14, 2024

This patch solves the race condition in issue #19499.

What's the race condition in #19499?

Are there any personal builds that pass test suites including internal compliance tests?

Hello, the failed case in #19499 is https://github.com/ibmruntimes/openj9-openjdk-jdk23/blob/openj9/test/jdk/javax/security/auth/Subject/Compat.java#L101.

There is a personal build that pass

  • sanity.jck

  • special.jck

  • extended.jck

  • sanity.openjdk

  • extended.openjdk

  • extended.functional

  • sanity.functional

  • special.functional

  • extended.system

  • sanity.system

  • special.system

AccessControlContext parentContext = getContextHelper(context == null);
DomainCombiner domaincombiner = parentContext.getCombiner();

return new AccessControlContext(pdArray, domaincombiner, parentContext, context, getNewAuthorizedState(context, domain));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return new AccessControlContext(pdArray, domaincombiner, parentContext, context, getNewAuthorizedState(context, domain));
return new AccessControlContext(pdArray, parentContext, context, getNewAuthorizedState(context, domain));

domaincombiner = parentContext.getCombiner() can be invoked within the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Copy link
Member

Choose a reason for hiding this comment

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

It still passes both parentContext.getCombiner() and parentContext, only parentContext is needed.
In addition, pls use tabs instead of spaces to be consistent with the existing codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@@ -351,6 +350,36 @@ public AccessControlContext(ProtectionDomain[] fromContext) {
this.containPrivilegedContext = true;
}

AccessControlContext(ProtectionDomain[] pdArray, AccessControlContext parent, AccessControlContext acc, int authorizeState) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
AccessControlContext(ProtectionDomain[] pdArray, AccessControlContext parent, AccessControlContext acc, int authorizeState) {
AccessControlContext(ProtectionDomain[] pdArray, AccessControlContext parentAcc, AccessControlContext context, int authorizeState) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

case STATE_AUTHORIZED:
if (null != acc) {
// when parent combiner is not null, use parent combiner to combine the current context
if (parent.getCombiner() != null) {
Copy link
Member

Choose a reason for hiding this comment

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

parent could be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

}
this.doPrivilegedAcc = acc;
this.authorizeState = authorizeState;
this.containPrivilegedContext = true;
Copy link
Member

Choose a reason for hiding this comment

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

Can AccessControlContext(AccessControlContext acc, ProtectionDomain[] context, int authorizeState) invoke this constructor to avoid code duplication?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be in a new constructor.

Copy link
Contributor

Choose a reason for hiding this comment

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

Jason makes a good suggstion: the two constructors above can use the new one:

AccessControlContext(ProtectionDomain[] context, int authorizeState) {
	this(context, null, null, authorizeState);
}

AccessControlContext(AccessControlContext acc, ProtectionDomain[] context, int authorizeState) {
	this(context, null, acc, authorizeState);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

/*[IF JAVA_SPEC_VERSION >= 24]*/
/*[MSG "K002e", "checking permissions is not supported"]*/
throw new AccessControlException(Msg.getString("K002e")); //$NON-NLS-1$
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
Copy link
Member

Choose a reason for hiding this comment

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

Please not remove this and other recent merged changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@JinhangZhang JinhangZhang force-pushed the compat branch 3 times, most recently from 29e2976 to 6d202c9 Compare November 25, 2024 03:29
} else {
this.domainCombiner = parentAcc.domainCombiner;
this.context = pdArray;
this.nextStackAcc = parentAcc;
Copy link
Member

Choose a reason for hiding this comment

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

This changed the AccessControlContext(AccessControlContext acc, ProtectionDomain[] context, int authorizeState) behaviour.
To avoid the uncertainty of existing AccessControlContext() constructors which is being disabled permanently for JDK24+, I revert the previous suggestion. Pls separate this new constructor from others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@JinhangZhang JinhangZhang force-pushed the compat branch 2 times, most recently from 0b44640 to 520741c Compare December 11, 2024 19:32
@JasonFengJ9
Copy link
Member

Please verify that the updated change still passes #19499 and the compliance tests.

}
this.doPrivilegedAcc = acc;
this.authorizeState = authorizeState;
this.containPrivilegedContext = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Jason makes a good suggstion: the two constructors above can use the new one:

AccessControlContext(ProtectionDomain[] context, int authorizeState) {
	this(context, null, null, authorizeState);
}

AccessControlContext(AccessControlContext acc, ProtectionDomain[] context, int authorizeState) {
	this(context, null, acc, authorizeState);
}

@JinhangZhang JinhangZhang force-pushed the compat branch 3 times, most recently from ad23095 to d51c66b Compare January 7, 2025 15:12
@JinhangZhang JinhangZhang force-pushed the compat branch 2 times, most recently from a992864 to 9dd994d Compare January 12, 2025 08:20
@JinhangZhang JinhangZhang force-pushed the compat branch 2 times, most recently from ba0a69c to 041311e Compare January 20, 2025 18:08
@keithc-ca
Copy link
Contributor

Please squash in preparation for testing.

@keithc-ca
Copy link
Contributor

Please squash in preparation for testing.

@pshipton pshipton removed their request for review January 30, 2025 17:28
When we try to invoke doPrivilegedWithCombiner function to
perform a privileged action under an existing context
environment, we are used to construct a new context but ignore
the parent context.

We should take consideration of a combination of the current
and parent context, rather than just choose either the current
or the parent.

This patch solves a failed case in issue eclipse-openj9#19499.

Issue: eclipse-openj9#19499

Signed-off-by: Jinhang Zhang <[email protected]>
@JinhangZhang
Copy link
Contributor Author

Please squash in preparation for testing.

done

@keithc-ca
Copy link
Contributor

Jenkins test sanity amac jdk23

@keithc-ca keithc-ca merged commit 24960fd into eclipse-openj9:master Jan 31, 2025
6 checks passed
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.

4 participants