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

8263779: SSLEngine reports NEED_WRAP continuously without producing any further output #3292

Closed
wants to merge 4 commits into from

Conversation

@XueleiFan
Copy link
Member

@XueleiFan XueleiFan commented Mar 31, 2021

As described in the bug, by connecting the SSLEngine with a misbehaving peer SSL implementation, it can get into a state where it calling wrap reports getStatus == OK, getHandshakeStatus === NEED_WRAP but still doesn't produce any further output. It happens when the output bound is not empty.

It is caused by a mismatching condition in the SSLEngineOutputRecord. The use hasAlert() method should be replaced with isEmpty(). Otherwise, there is conflicts of the closing status while checking with OutputRecord.isEmpty() in TransportContext.getHandshakeStatus() implementation. It is safe to remove hasAlert() method, as we don't allow creation of new output record if the closure is in progress, thus isEmpty() could be used instead.

The patch passed the test provided by the bug submitter.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8263779: SSLEngine reports NEED_WRAP continuously without producing any further output

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3292/head:pull/3292
$ git checkout pull/3292

Update a local copy of the PR:
$ git checkout pull/3292
$ git pull https://git.openjdk.java.net/jdk pull/3292/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3292

View PR using the GUI difftool:
$ git pr show -t 3292

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3292.diff

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Mar 31, 2021

👋 Welcome back xuelei! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot changed the title 8263779: SSLEngine reports NEED_WRAP continuously without producing a… 8263779: SSLEngine reports NEED_WRAP continuously without producing any further output Mar 31, 2021
@openjdk openjdk bot added the rfr label Mar 31, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Mar 31, 2021

@XueleiFan The following label will be automatically applied to this pull request:

  • security

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the security label Mar 31, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Mar 31, 2021

Webrevs

@XueleiFan
Copy link
Member Author

@XueleiFan XueleiFan commented Apr 5, 2021

ping ...

Copy link
Contributor

@djelinski djelinski left a comment

Would it be possible to add a test for that?

@@ -584,20 +584,34 @@ private void initiateOutboundClose() throws IOException {
closeNotify(useUserCanceled);
}

// Note; HandshakeStatus.FINISHED status is retrieved in other places.
// Note: HandshakeStatus.FINISHED status is retrieved in other places.
HandshakeStatus getHandshakeStatus() {
if (!outputRecord.isEmpty()) {
// If no handshaking, special case to wrap alters or

This comment has been minimized.

@djelinski

djelinski Apr 12, 2021
Contributor

Suggested change
// If no handshaking, special case to wrap alters or
// If not handshaking, special case to wrap alerts or

This comment has been minimized.

@XueleiFan

XueleiFan Apr 13, 2021
Author Member

Thank you for the correction.

HandshakeStatus getHandshakeStatus() {
if (!outputRecord.isEmpty()) {
// If no handshaking, special case to wrap alters or
// post-handshake messages.
return HandshakeStatus.NEED_WRAP;
if (!isOutboundClosed()) {

This comment has been minimized.

@djelinski

djelinski Apr 12, 2021
Contributor

If I'm reading the TransportContect#closeNotify and TransportContext#passiveInboundClose correctly, non-empty output record with both inbound and outbound closed happens when we reply with our close_notify to peer's. Now we will return NOT_HANDSHAKING which appears to be wrong.

This comment has been minimized.

@XueleiFan

XueleiFan Apr 13, 2021
Author Member

Good catch! I will have an update. Thank you for the code review.

Copy link
Contributor

@bradfordwetmore bradfordwetmore left a comment

SSLEngineOutputRecord.java:
Missing copyright date update.

SSLEngineOutputRecord:77
Unnecessary extra line added. Please remove.

@@ -1686,7 +1691,7 @@ private void handleException(Exception cause) throws IOException {

if (cause instanceof SocketException) {
try {
conContext.fatal(alert, cause);
throw conContext.fatal(alert, cause);

This comment has been minimized.

@bradfordwetmore

bradfordwetmore Apr 28, 2021
Contributor

Why did you change to a throw here? Isn't everything from fatal() going to be thrown anyway?

This comment has been minimized.

@XueleiFan

XueleiFan Apr 28, 2021
Author Member

The fatal() will always throw an exception. We could use the method without throw. In some places, IDE or compiler could complain because it cannot detect that the fatal() method will throw and the program ends here. In the past, we use fatal() method without throw, later we change the fatal() return value form "void" to an exception so that throw could be used to mitigate the IDE or compiler complaints.

It is not really necessary to make this code change here. I just want to make the coding style consistent for the fatal() calling.

This comment has been minimized.

@bradfordwetmore

bradfordwetmore Apr 30, 2021
Contributor

Interesting, ok. I don't recall seeing such situations with the IDE I often use. (Netbeans)

@@ -584,10 +584,10 @@ private void initiateOutboundClose() throws IOException {
closeNotify(useUserCanceled);
}

// Note; HandshakeStatus.FINISHED status is retrieved in other places.
// Note: HandshakeStatus.FINISHED status is retrieved in other places.

This comment has been minimized.

@bradfordwetmore

bradfordwetmore Apr 28, 2021
Contributor

I now see that v1 of this change had quite a few changes here, and what's left is now just compacting a line and making some old comment corrections.

This comment has been minimized.

@XueleiFan

XueleiFan Apr 28, 2021
Author Member

Yes.

@openjdk
Copy link

@openjdk openjdk bot commented Apr 28, 2021

@XueleiFan This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8263779: SSLEngine reports NEED_WRAP continuously without producing any further output

Reviewed-by: wetmore

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 105 new commits pushed to the master branch:

  • 30b1354: 8266153: mark hotspot compiler/onSpinWait tests which ignore VM flags
  • eeddb30: 8266150: mark hotspot compiler/arguments tests which ignore VM flags
  • feb18d2: 8266149: mark hotspot compiler/startup tests which ignore VM flags
  • eb72950: 8266154: mark hotspot compiler/oracle tests which ignore VM flags
  • 7f4a9f6: 8266088: compiler/arguments/TestPrintOptoAssemblyLineNumbers test should user driver mode
  • f560b89: 8264873: Dependencies: Split ClassHierarchyWalker
  • 0a88f0a: 8255915: jdk/incubator/vector/AddTest.java timed out
  • ab2aec2: 8265938: C2's conditional move optimization does not handle top Phi
  • 5634f20: 8265932: Move safepoint related fields from class Thread to JavaThread
  • b67b2b1: 8265690: Use the latest Ubuntu base image version in Docker testing
  • ... and 95 more: https://git.openjdk.java.net/jdk/compare/ca6b1b49ab791d505573fa6ef000faec3b19256c...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Apr 28, 2021
@XueleiFan
Copy link
Member Author

@XueleiFan XueleiFan commented Apr 28, 2021

SSLEngineOutputRecord.java:
Missing copyright date update.

Yes, I missed the copyright date.

SSLEngineOutputRecord:77
Unnecessary extra line added. Please remove.

Oops, I will correct it.

@XueleiFan
Copy link
Member Author

@XueleiFan XueleiFan commented Apr 28, 2021

/integrate

@openjdk openjdk bot closed this Apr 28, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Apr 28, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Apr 28, 2021

@XueleiFan Since your change was applied there have been 107 commits pushed to the master branch:

  • 889d246: 8265917: Different values computed by C2 and interpreter/C1 for Math.pow(x, 2.0) on x86_32
  • e144104: 8262908: JFR: Allow JFR to stream events from a known repository path
  • 30b1354: 8266153: mark hotspot compiler/onSpinWait tests which ignore VM flags
  • eeddb30: 8266150: mark hotspot compiler/arguments tests which ignore VM flags
  • feb18d2: 8266149: mark hotspot compiler/startup tests which ignore VM flags
  • eb72950: 8266154: mark hotspot compiler/oracle tests which ignore VM flags
  • 7f4a9f6: 8266088: compiler/arguments/TestPrintOptoAssemblyLineNumbers test should user driver mode
  • f560b89: 8264873: Dependencies: Split ClassHierarchyWalker
  • 0a88f0a: 8255915: jdk/incubator/vector/AddTest.java timed out
  • ab2aec2: 8265938: C2's conditional move optimization does not handle top Phi
  • ... and 97 more: https://git.openjdk.java.net/jdk/compare/ca6b1b49ab791d505573fa6ef000faec3b19256c...master

Your commit was automatically rebased without conflicts.

Pushed as commit 1a37bce.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@XueleiFan XueleiFan deleted the XueleiFan:JDK-8263779 branch Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants