Skip to content

Conversation

@vanzin
Copy link
Contributor

@vanzin vanzin commented Sep 26, 2018

The commons-crypto library does some questionable error handling internally,
which can lead to JVM crashes if some call into native code fails and cleans
up state it should not.

While the library is not fixed, this change adds some workarounds in Spark code
so that when an error is detected in the commons-crypto side, Spark avoids
calling into the library further.

Tested with existing and added unit tests.

Marcelo Vanzin added 2 commits September 26, 2018 10:27
The commons-crypto library does some questionable error handling internally,
which can lead to JVM crashes if some call into native code fails and cleans
up state it should not.

While the library is not fixed, this change adds some workarounds in Spark code
so that when an error is detected in the commons-crypto side, Spark avoids
calling into the library further.

Tested with existing and added unit tests.
@SparkQA
Copy link

SparkQA commented Sep 26, 2018

Test build #96637 has finished for PR 22557 at commit fe3f06b.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • trait BaseErrorHandler extends Closeable
  • class ErrorHandlingReadableChannel(

@SparkQA
Copy link

SparkQA commented Sep 26, 2018

Test build #96639 has finished for PR 22557 at commit 4606ed9.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@vanzin
Copy link
Contributor Author

vanzin commented Sep 27, 2018

@squito

Copy link
Contributor

@squito squito left a comment

Choose a reason for hiding this comment

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

unrelated, but shouldn't EncryptedMessage.transferTo() not keep looping if target.write() doesn't accept all the data?

}
intercept[IOException] {
errorHandler.read(out)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

since you're throwing a mock IOException above, this would be a little more clear if here you checked the message too

assert(intercept[IOException] {
  errorHandler.read(out)
}.getMessage() === ("Cipher stream is closed."))

(you can also use assertThrows if you're not looking at the exception at all, though doesn't really matter)

private var closed = false

protected def cipherStream: Closeable
protected def wrapped: Closeable
Copy link
Contributor

Choose a reason for hiding this comment

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

its a little confusing that there are two closeables. I'd add a comment here that wrapped is what the cipherStream is already wrapping, and we want to make sure it gets closed if the cipherStream has an internal error.

(when I see a variable named wrapped, I assumed it was what this was wrapping, not what the cipherStream was wrapping)

if (mode == Cipher.ENCRYPT_MODE) {
this.encryptor = null;
} else {
this.decryptor = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

any particular reason to set these to null, rather than having an isValid flag in here? you'd get an NPE if you ever tried to use the TranportCipher after this -- you are protecting against that in the wrapping code, but seems you could do it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add a check that the ciphers are not null, but no need to have a separate flag. These need to be set to null so that close knows not to try to mess with them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually the check is already there I'll just add a message to it.

@SparkQA
Copy link

SparkQA commented Sep 27, 2018

Test build #96714 has finished for PR 22557 at commit e6e5382.

  • This patch fails Java style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@vanzin
Copy link
Contributor Author

vanzin commented Sep 27, 2018

retest this please

@SparkQA
Copy link

SparkQA commented Sep 28, 2018

Test build #96720 has finished for PR 22557 at commit e6e5382.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@vanzin
Copy link
Contributor Author

vanzin commented Oct 1, 2018

unrelated, but shouldn't EncryptedMessage.transferTo() not keep looping if target.write() doesn't accept all the data?

Yes I noticed that too, but separate change. Hopefully I can fix other stuff in commons-crypto that would allow more of that code to be cleaned up...

@squito
Copy link
Contributor

squito commented Oct 2, 2018

lgtm

will leave for a day before mergning

@vanzin
Copy link
Contributor Author

vanzin commented Oct 8, 2018

Ping

@squito
Copy link
Contributor

squito commented Oct 9, 2018

merged to master

@asfgit asfgit closed this in 3eee9e0 Oct 9, 2018
@vanzin vanzin deleted the SPARK-25535 branch October 9, 2018 23:15
jackylee-ch pushed a commit to jackylee-ch/spark that referenced this pull request Feb 18, 2019
The commons-crypto library does some questionable error handling internally,
which can lead to JVM crashes if some call into native code fails and cleans
up state it should not.

While the library is not fixed, this change adds some workarounds in Spark code
so that when an error is detected in the commons-crypto side, Spark avoids
calling into the library further.

Tested with existing and added unit tests.

Closes apache#22557 from vanzin/SPARK-25535.

Authored-by: Marcelo Vanzin <[email protected]>
Signed-off-by: Imran Rashid <[email protected]>
@dongjoon-hyun
Copy link
Member

Hi, All.
Can we have this in branch-2.4 too since Spark 2.4.x is the last version of 2.x lines which we need to support for a long time?
cc @dbtsai

@dbtsai
Copy link
Member

dbtsai commented Apr 26, 2019

+1

@vanzin
Copy link
Contributor Author

vanzin commented Apr 26, 2019

Sure.

vanzin pushed a commit to vanzin/spark that referenced this pull request Apr 26, 2019
…mons-crypto.

The commons-crypto library does some questionable error handling internally,
which can lead to JVM crashes if some call into native code fails and cleans
up state it should not.

While the library is not fixed, this change adds some workarounds in Spark code
so that when an error is detected in the commons-crypto side, Spark avoids
calling into the library further.

Tested with existing and added unit tests.

Closes apache#22557 from vanzin/SPARK-25535.

Authored-by: Marcelo Vanzin <[email protected]>
Signed-off-by: Imran Rashid <[email protected]>
(cherry picked from commit 3eee9e0)
@vanzin
Copy link
Contributor Author

vanzin commented Apr 26, 2019

#24476

@dongjoon-hyun
Copy link
Member

Thank you so much, @vanzin and @dbtsai !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants