Skip to content

auth: fix CheckScrambledPassword() panic for invalid input#1197

Merged
kennytm merged 3 commits intopingcap:masterfrom
tiancaiamao:fix-panic
Mar 24, 2021
Merged

auth: fix CheckScrambledPassword() panic for invalid input#1197
kennytm merged 3 commits intopingcap:masterfrom
tiancaiamao:fix-panic

Conversation

@tiancaiamao
Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

image

What is changed and how it works?

The input data may be invalid, but calling CheckScrambledPassword() on malformed data should not make TiDB server panic.

Check List

Tests

  • Unit test

Related changes

  • Need to cherry-pick to the release branch
  • Need to update the documentation
  • Need to be included in the release note

@tiancaiamao
Copy link
Copy Markdown
Collaborator Author

The malformed data maybe related to pingcap/tidb#19603, maybe we are not resolving the protocol correctly, but I have no clue.

PTAL @djshow832 @morgo

@kennytm
Copy link
Copy Markdown
Contributor

kennytm commented Mar 24, 2021

/lgtm

@ti-srebot ti-srebot added the status/LGT1 LGT1 label Mar 24, 2021
Copy link
Copy Markdown
Contributor

@djshow832 djshow832 left a comment

Choose a reason for hiding this comment

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

Add some test cases?

@tiancaiamao
Copy link
Copy Markdown
Collaborator Author

terror.Log(errors.Trace(err))
hash := crypt.Sum(nil)
// token = scrambleHash XOR stage1Hash
if len(auth) != len(hash) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it possible that len(auth) > len(hash)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It doesn't matter, as long as len(auth) != len(hash) the input is invalid.

@djshow832
Copy link
Copy Markdown
Contributor

/lgtm

@ti-srebot ti-srebot removed the status/LGT1 LGT1 label Mar 24, 2021
@ti-srebot ti-srebot added the status/LGT2 LGT2 label Mar 24, 2021
@djshow832
Copy link
Copy Markdown
Contributor

/merge

@ti-srebot
Copy link
Copy Markdown
Contributor

/run-all-tests

@ti-srebot
Copy link
Copy Markdown
Contributor

@tiancaiamao merge failed.

@morgo
Copy link
Copy Markdown
Contributor

morgo commented Mar 24, 2021

The malformed data maybe related to pingcap/tidb#19603, maybe we are not resolving the protocol correctly, but I have no clue.

PTAL @djshow832 @morgo

I took a look. The authSwitchRequest is relatively self contained unless the resp.AuthPlugin is caching_sha2_password (it doesn't attempt to authSwitch for any other plugins, even though it could). Do you know if it is a client attempting to use MySQL 8.0 auth?

There are other authentication plugins besides caching_sha2_password OR mysql_native_password that clients could attempt to use too, and it's also entirely possible it is a connector that doesn't speak the protocol correctly.

@morgo
Copy link
Copy Markdown
Contributor

morgo commented Mar 24, 2021

/run-all-tests

@kennytm
Copy link
Copy Markdown
Contributor

kennytm commented Mar 24, 2021

I think we should just get rid of the integration test. The TiDB is always lagging behind making it almost always failing and impossible to use "/merge".

@kennytm kennytm merged commit ab6d0f2 into pingcap:master Mar 24, 2021
@ti-srebot
Copy link
Copy Markdown
Contributor

cherry pick to release-5.0 failed

@tiancaiamao tiancaiamao deleted the fix-panic branch March 25, 2021 03:45
@tiancaiamao
Copy link
Copy Markdown
Collaborator Author

I took a look. The authSwitchRequest is relatively self contained unless the resp.AuthPlugin is caching_sha2_password (it doesn't attempt to authSwitch for any other plugins, even though it could). Do you know if it is a client attempting to use MySQL 8.0 auth?

There are other authentication plugins besides caching_sha2_password OR mysql_native_password that clients could attempt to use too, and it's also entirely possible it is a connector that doesn't speak the protocol correctly.

Yup, I've said I have no clue. I'm not sure how that happen and what trigger the malformed input.
We need more feedback from the user.

tiancaiamao added a commit to tiancaiamao/parser that referenced this pull request Mar 25, 2021
)

* auth: fix CheckScrambledPassword() panic for invalid input

* fix CI

Co-authored-by: ti-srebot <[email protected]>
tiancaiamao added a commit to tiancaiamao/parser that referenced this pull request Mar 25, 2021
)

* auth: fix CheckScrambledPassword() panic for invalid input

* fix CI

Co-authored-by: ti-srebot <[email protected]>
kennytm pushed a commit that referenced this pull request Mar 25, 2021
…1199)

* auth: fix CheckScrambledPassword() panic for invalid input

* fix CI

Co-authored-by: ti-srebot <[email protected]>

Co-authored-by: ti-srebot <[email protected]>
kennytm pushed a commit that referenced this pull request Mar 25, 2021
…1200)

* auth: fix CheckScrambledPassword() panic for invalid input

* fix CI

Co-authored-by: ti-srebot <[email protected]>

Co-authored-by: ti-srebot <[email protected]>
tiancaiamao added a commit to tiancaiamao/parser that referenced this pull request Apr 27, 2021
)

* auth: fix CheckScrambledPassword() panic for invalid input

* fix CI

Co-authored-by: ti-srebot <[email protected]>
@tiancaiamao tiancaiamao mentioned this pull request Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants