Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

bpo-32981: Fix catastrophic backtracking vulns#5955

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@davisjam
Copy link
Contributor

@davisjamdavisjam commentedMar 1, 2018
edited by bedevere-bot
Loading

Fix catastrophic backtracking vulns disclosed by email.

https://bugs.python.org/issue32981

@davisjamdavisjam requested a review froma team as acode ownerMarch 1, 2018 21:50
@the-knights-who-say-ni

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed thePSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username onbugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please followthe steps outlined in the CPython devguide to rectify this issue.

Thanks again to your contribution and we look forward to looking at it!

@davisjam
Copy link
ContributorAuthor

I have now signed the CLA.

@davisjam
Copy link
ContributorAuthor

davisjam commentedMar 1, 2018
edited
Loading

Because this is a security issue no issue was previously created to track it. Perhaps someone might create one now?

[Update: I createdbpo-32981.]

@davisjam
Copy link
ContributorAuthor

Travis failure:

Fixing Python file whitespace ... 2 files:  Lib/test/test_difflib.py  Lib/test/test_poplib.py

Took a look, I can't see what's wrong. Is there a command (or flag toconfigure) I can run on my end to get a more verbose error message?

@gvanrossum
Copy link
Member

That error comes fromTools/scripts/patchcheck.py.

@davisjam
Copy link
ContributorAuthor

Thank you. Fixed.

@davisjamdavisjam changed the titleFix catastrophic backtracking vulnsbpo-32981: Fix catastrophic backtracking vulnsMar 2, 2018
@davisjam
Copy link
ContributorAuthor

davisjam commentedMar 2, 2018
edited
Loading

I createdbpo-32981 for this problem.

I skimmed through the git log. Commit messages for security seem to follow the 'XXX (CVE-...)' format rather than the 'bpo-XXX: ...' format. Let me know if I should change the commit messages though.

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Please add a news entry and add your name into Misc/ACKS.

Choose a reason for hiding this comment

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

Use non-capturing group:(?:#\s*).

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Fixed.

Choose a reason for hiding this comment

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

Why notassertTrue()?

Copy link
ContributorAuthor

@davisjamdavisjamMar 2, 2018
edited
Loading

Choose a reason for hiding this comment

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

Fixed this and others, thanks.

Choose a reason for hiding this comment

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

Timing test is very fragile. It can fail randomly when tests are paused for some reasons. I suggest to remove the timing test and increase the size of input so that it would take a hour with non-fixed code.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Then the test will pass if you wait long enough. Since the test suite already takes a long time to run and does so in parallel (so one hanging test might not be visible), this seems undesirable to me. Thoughts?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Same thing in Lib/test/test_poplib.py

Choose a reason for hiding this comment

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

If the test takes too long time for running it will be failed on buildbots due to total timeout.

@davisjamdavisjamforce-pushed theTestAndFixCatastrophicBacktracking branch 2 times, most recently from1a03bf9 to83bf67cCompareMarch 2, 2018 15:32
@davisjam
Copy link
ContributorAuthor

@serhiy-storchaka Thank you! I think I have addressed all of your comments so far.

@davisjamdavisjamforce-pushed theTestAndFixCatastrophicBacktracking branch from83bf67c to539f390CompareMarch 2, 2018 15:40
Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Thank you James. Here yet few comments.

Choose a reason for hiding this comment

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

Add "Patch byyour name."

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Done.

Choose a reason for hiding this comment

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

assertTrue()?

Choose a reason for hiding this comment

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

Why not just

self.assertTrue(difflib.IS_LINE_JUNK(line))

?

And you can add the second argument ofassertTrue() for getting more information if the test fails:

self.assertTrue(difflib.IS_LINE_JUNK(line), rept(line))

But don't do this in test_is_line_junk_REDOS.

Choose a reason for hiding this comment

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

You can use a special helperswap_attr() for temporary setting the attribute:

withtest.support.swap_attr(self.client,'welcome',evil_welcome):

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Ah, nice, thanks for the tip.

Choose a reason for hiding this comment

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

Why not useassertRaises()?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

The reason for the poor choices of asserts is that I didn't know what asserts are available and made do with what I could find. I really appreciate your help.

Choose a reason for hiding this comment

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

https://docs.python.org/3/library/unittest.html#test-cases

assertRaises() can be used as a function:

self.assertRaises(poplib.error_proto,self.client.apop,'foo','dummypassword')

or as a context manager:

withself.assertRaises(poplib.error_proto):self.client.apop('foo','dummypassword')

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yup I have at last found the documentation for unittest.

Choose a reason for hiding this comment

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

What is the advantage over justb'+OK' + b'<' * 500000?

Choose a reason for hiding this comment

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

No longer used.

Choose a reason for hiding this comment

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

No longer used.

@davisjamdavisjamforce-pushed theTestAndFixCatastrophicBacktracking branch from539f390 to71db0e4CompareMarch 2, 2018 17:29
davisjamand others added3 commitsMarch 2, 2018 12:41
The regex to test a mail server's timestamp is susceptible tocatastrophic backtracking on long evil responses from the server.Happily, the maximum length of malicious inputs is 2K thanksto a limit introduced in the fix for CVE-2013-1752.A 2KB evil response from the mail server would result in small slowdowns(milliseconds vs. microseconds) accumulated over many apop calls.This is a potential DOS vector via accumulated slowdowns.Replace it with a similar non-vulnerable regex.The new regex is RFC compliant.The old regex was non-compliant in edge cases.Co-authored-by: Tim Peters <tim.peters@gmail.com>Co-authored-by: Christian Heimes <christian@python.org>
The default regex for IS_LINE_JUNK is susceptible tocatastrophic backtracking.This is a potential DOS vector.Replace it with an equivalent non-vulnerable regex.Also introduce unit and REDOS tests for difflib.Co-authored-by: Tim Peters <tim.peters@gmail.com>Co-authored-by: Christian Heimes <christian@python.org>
@davisjamdavisjamforce-pushed theTestAndFixCatastrophicBacktracking branch from71db0e4 to7bf9559CompareMarch 2, 2018 17:42
@davisjam
Copy link
ContributorAuthor

The latest version uses 1-million character attack strings. These take at least 3 minutes to evaluate on the master branch. I didn't want to wait for the full timeout.


deftest_is_line_junk_false(self):
forlinein ['##',' ##','## ','abc ','abc #','abc # ','Mr. Moose is up!']:
self.assertFalse(difflib.IS_LINE_JUNK(line),'should not be junk: {}'.format(line))

Choose a reason for hiding this comment

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

The length of this line exceeds the 79 character limit allowed byPEP 8.

And since testing strings contain spaces it is hard to distinguish the following cases:

should not be junk: abc #

and

should not be junk: abc #

This is why I suggestedrepr().

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

The length of this line exceeds the 79 character limit allowed by PEP 8.

Didn't realize this was being enforced, there are other lines over this limit as well. Will do.

This is why I suggestedrepr().

Got it, I misread that as rept earlier and couldn't understand what you meant.

evil_welcome=b'+OK'+ (b'<'*1000000)
withtest_support.swap_attr(self.client,'welcome',evil_welcome):
# The evil welcome is invalid, so apop should throw.
self.assertRaises(poplib.error_proto,self.client.apop,'arthur','kingofbritons')

Choose a reason for hiding this comment

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

Since this line is too long, a context manager form of assertRaises() would be more preferable.

@serhiy-storchaka
Copy link
Member

And please make your changes as new commits rather of editing old commits. This would make reviewing easier.

@davisjam
Copy link
ContributorAuthor

@serhiy-storchaka Acknowledged. I believe I've addressed all of the concerns you've raised.

@davisjam
Copy link
ContributorAuthor

Should I rebase or will these be squashed during merge anyway?

@serhiy-storchaka
Copy link
Member

Will be squashed during merge.

@serhiy-storchakaserhiy-storchaka added type-bugAn unexpected behavior, bug, or error needs backport to 3.6 labelsMar 2, 2018
@benjaminpbenjaminp merged commit0e6c8ee intopython:masterMar 4, 2018
@miss-islington
Copy link
Contributor

Thanks@davisjam for the PR, and@benjaminp for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6, 3.7.
🐍🍒⛏🤖

@bedevere-bot
Copy link

@benjaminp: Please replace# withGH- in the commit message next time. Thanks!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMar 4, 2018
* Prevent low-grade poplib REDOS (CVE-2018-1060)The regex to test a mail server's timestamp is susceptible tocatastrophic backtracking on long evil responses from the server.Happily, the maximum length of malicious inputs is 2K thanksto a limit introduced in the fix for CVE-2013-1752.A 2KB evil response from the mail server would result in small slowdowns(milliseconds vs. microseconds) accumulated over many apop calls.This is a potential DOS vector via accumulated slowdowns.Replace it with a similar non-vulnerable regex.The new regex is RFC compliant.The old regex was non-compliant in edge cases.* Prevent difflib REDOS (CVE-2018-1061)The default regex for IS_LINE_JUNK is susceptible tocatastrophic backtracking.This is a potential DOS vector.Replace it with an equivalent non-vulnerable regex.Also introduce unit and REDOS tests for difflib.Co-authored-by: Tim Peters <tim.peters@gmail.com>Co-authored-by: Christian Heimes <christian@python.org>(cherry picked from commit0e6c8ee)Co-authored-by: Jamie Davis <davisjam@vt.edu>
@bedevere-bot
Copy link

GH-5969 is a backport of this pull request to the3.7 branch.

@miss-islington
Copy link
Contributor

Sorry,@davisjam and@benjaminp, I could not cleanly backport this to3.6 due to a conflict.
Please backport usingcherry_picker on command line.
cherry_picker 0e6c8ee2358a2e23117501826c008842acb835ac 3.6

@miss-islington
Copy link
Contributor

Sorry,@davisjam and@benjaminp, I could not cleanly backport this to2.7 due to a conflict.
Please backport usingcherry_picker on command line.
cherry_picker 0e6c8ee2358a2e23117501826c008842acb835ac 2.7

benjaminp pushed a commit that referenced this pull requestMar 4, 2018
* Prevent low-grade poplib REDOS (CVE-2018-1060)The regex to test a mail server's timestamp is susceptible tocatastrophic backtracking on long evil responses from the server.Happily, the maximum length of malicious inputs is 2K thanksto a limit introduced in the fix for CVE-2013-1752.A 2KB evil response from the mail server would result in small slowdowns(milliseconds vs. microseconds) accumulated over many apop calls.This is a potential DOS vector via accumulated slowdowns.Replace it with a similar non-vulnerable regex.The new regex is RFC compliant.The old regex was non-compliant in edge cases.* Prevent difflib REDOS (CVE-2018-1061)The default regex for IS_LINE_JUNK is susceptible tocatastrophic backtracking.This is a potential DOS vector.Replace it with an equivalent non-vulnerable regex.Also introduce unit and REDOS tests for difflib.Co-authored-by: Tim Peters <tim.peters@gmail.com>Co-authored-by: Christian Heimes <christian@python.org>.(cherry picked from commit0e6c8ee)
@bedevere-bot
Copy link

GH-5970 is a backport of this pull request to the2.7 branch.

benjaminp pushed a commit that referenced this pull requestMar 4, 2018
* Prevent low-grade poplib REDOS (CVE-2018-1060)The regex to test a mail server's timestamp is susceptible tocatastrophic backtracking on long evil responses from the server.Happily, the maximum length of malicious inputs is 2K thanksto a limit introduced in the fix for CVE-2013-1752.A 2KB evil response from the mail server would result in small slowdowns(milliseconds vs. microseconds) accumulated over many apop calls.This is a potential DOS vector via accumulated slowdowns.Replace it with a similar non-vulnerable regex.The new regex is RFC compliant.The old regex was non-compliant in edge cases.* Prevent difflib REDOS (CVE-2018-1061)The default regex for IS_LINE_JUNK is susceptible tocatastrophic backtracking.This is a potential DOS vector.Replace it with an equivalent non-vulnerable regex.Also introduce unit and REDOS tests for difflib.Co-authored-by: Tim Peters <tim.peters@gmail.com>Co-authored-by: Christian Heimes <christian@python.org>.(cherry picked from commit0e6c8ee)
@bedevere-bot
Copy link

GH-5971 is a backport of this pull request to the3.6 branch.

benjaminp pushed a commit that referenced this pull requestMar 4, 2018
* Prevent low-grade poplib REDOS (CVE-2018-1060)The regex to test a mail server's timestamp is susceptible tocatastrophic backtracking on long evil responses from the server.Happily, the maximum length of malicious inputs is 2K thanksto a limit introduced in the fix for CVE-2013-1752.A 2KB evil response from the mail server would result in small slowdowns(milliseconds vs. microseconds) accumulated over many apop calls.This is a potential DOS vector via accumulated slowdowns.Replace it with a similar non-vulnerable regex.The new regex is RFC compliant.The old regex was non-compliant in edge cases.* Prevent difflib REDOS (CVE-2018-1061)The default regex for IS_LINE_JUNK is susceptible tocatastrophic backtracking.This is a potential DOS vector.Replace it with an equivalent non-vulnerable regex.Also introduce unit and REDOS tests for difflib.Co-authored-by: Tim Peters <tim.peters@gmail.com>Co-authored-by: Christian Heimes <christian@python.org>Co-authored-by: Jamie Davis <davisjam@vt.edu>(cherry picked from commit0e6c8ee)
benjaminp added a commit that referenced this pull requestMar 4, 2018
* Prevent low-grade poplib REDOS (CVE-2018-1060)The regex to test a mail server's timestamp is susceptible tocatastrophic backtracking on long evil responses from the server.Happily, the maximum length of malicious inputs is 2K thanksto a limit introduced in the fix for CVE-2013-1752.A 2KB evil response from the mail server would result in small slowdowns(milliseconds vs. microseconds) accumulated over many apop calls.This is a potential DOS vector via accumulated slowdowns.Replace it with a similar non-vulnerable regex.The new regex is RFC compliant.The old regex was non-compliant in edge cases.* Prevent difflib REDOS (CVE-2018-1061)The default regex for IS_LINE_JUNK is susceptible tocatastrophic backtracking.This is a potential DOS vector.Replace it with an equivalent non-vulnerable regex.Also introduce unit and REDOS tests for difflib.Co-authored-by: Tim Peters <tim.peters@gmail.com>Co-authored-by: Christian Heimes <christian@python.org>.(cherry picked from commit0e6c8ee)
benjaminp added a commit that referenced this pull requestMar 4, 2018
* Prevent low-grade poplib REDOS (CVE-2018-1060)The regex to test a mail server's timestamp is susceptible tocatastrophic backtracking on long evil responses from the server.Happily, the maximum length of malicious inputs is 2K thanksto a limit introduced in the fix for CVE-2013-1752.A 2KB evil response from the mail server would result in small slowdowns(milliseconds vs. microseconds) accumulated over many apop calls.This is a potential DOS vector via accumulated slowdowns.Replace it with a similar non-vulnerable regex.The new regex is RFC compliant.The old regex was non-compliant in edge cases.* Prevent difflib REDOS (CVE-2018-1061)The default regex for IS_LINE_JUNK is susceptible tocatastrophic backtracking.This is a potential DOS vector.Replace it with an equivalent non-vulnerable regex.Also introduce unit and REDOS tests for difflib.Co-authored-by: Tim Peters <tim.peters@gmail.com>Co-authored-by: Christian Heimes <christian@python.org>.(cherry picked from commit0e6c8ee)
ned-deily pushed a commit to ned-deily/cpython that referenced this pull requestMar 8, 2018
* Prevent low-grade poplib REDOS (CVE-2018-1060)The regex to test a mail server's timestamp is susceptible tocatastrophic backtracking on long evil responses from the server.Happily, the maximum length of malicious inputs is 2K thanksto a limit introduced in the fix for CVE-2013-1752.A 2KB evil response from the mail server would result in small slowdowns(milliseconds vs. microseconds) accumulated over many apop calls.This is a potential DOS vector via accumulated slowdowns.Replace it with a similar non-vulnerable regex.The new regex is RFC compliant.The old regex was non-compliant in edge cases.* Prevent difflib REDOS (CVE-2018-1061)The default regex for IS_LINE_JUNK is susceptible tocatastrophic backtracking.This is a potential DOS vector.Replace it with an equivalent non-vulnerable regex.Also introduce unit and REDOS tests for difflib.Co-authored-by: Tim Peters <tim.peters@gmail.com>Co-authored-by: Christian Heimes <christian@python.org>.(cherry picked from commit0e6c8ee)
ned-deily pushed a commit to ned-deily/cpython that referenced this pull requestMar 8, 2018
* Prevent low-grade poplib REDOS (CVE-2018-1060)The regex to test a mail server's timestamp is susceptible tocatastrophic backtracking on long evil responses from the server.Happily, the maximum length of malicious inputs is 2K thanksto a limit introduced in the fix for CVE-2013-1752.A 2KB evil response from the mail server would result in small slowdowns(milliseconds vs. microseconds) accumulated over many apop calls.This is a potential DOS vector via accumulated slowdowns.Replace it with a similar non-vulnerable regex.The new regex is RFC compliant.The old regex was non-compliant in edge cases.* Prevent difflib REDOS (CVE-2018-1061)The default regex for IS_LINE_JUNK is susceptible tocatastrophic backtracking.This is a potential DOS vector.Replace it with an equivalent non-vulnerable regex.Also introduce unit and REDOS tests for difflib.Co-authored-by: Tim Peters <tim.peters@gmail.com>Co-authored-by: Christian Heimes <christian@python.org>.
larryhastings pushed a commit that referenced this pull requestMar 11, 2018
* Prevent low-grade poplib REDOS (CVE-2018-1060)The regex to test a mail server's timestamp is susceptible tocatastrophic backtracking on long evil responses from the server.Happily, the maximum length of malicious inputs is 2K thanksto a limit introduced in the fix for CVE-2013-1752.A 2KB evil response from the mail server would result in small slowdowns(milliseconds vs. microseconds) accumulated over many apop calls.This is a potential DOS vector via accumulated slowdowns.Replace it with a similar non-vulnerable regex.The new regex is RFC compliant.The old regex was non-compliant in edge cases.* Prevent difflib REDOS (CVE-2018-1061)The default regex for IS_LINE_JUNK is susceptible tocatastrophic backtracking.This is a potential DOS vector.Replace it with an equivalent non-vulnerable regex.Also introduce unit and REDOS tests for difflib.Co-authored-by: Tim Peters <tim.peters@gmail.com>Co-authored-by: Christian Heimes <christian@python.org>.
larryhastings pushed a commit that referenced this pull requestMar 11, 2018
* Prevent low-grade poplib REDOS (CVE-2018-1060)The regex to test a mail server's timestamp is susceptible tocatastrophic backtracking on long evil responses from the server.Happily, the maximum length of malicious inputs is 2K thanksto a limit introduced in the fix for CVE-2013-1752.A 2KB evil response from the mail server would result in small slowdowns(milliseconds vs. microseconds) accumulated over many apop calls.This is a potential DOS vector via accumulated slowdowns.Replace it with a similar non-vulnerable regex.The new regex is RFC compliant.The old regex was non-compliant in edge cases.* Prevent difflib REDOS (CVE-2018-1061)The default regex for IS_LINE_JUNK is susceptible tocatastrophic backtracking.This is a potential DOS vector.Replace it with an equivalent non-vulnerable regex.Also introduce unit and REDOS tests for difflib.Co-authored-by: Tim Peters <tim.peters@gmail.com>Co-authored-by: Christian Heimes <christian@python.org>.(cherry picked from commit0e6c8ee)
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@serhiy-storchakaserhiy-storchakaserhiy-storchaka approved these changes

@tim-onetim-oneAwaiting requested review from tim-one

Assignees

No one assigned

Labels

type-bugAn unexpected behavior, bug, or error

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

7 participants

@davisjam@the-knights-who-say-ni@gvanrossum@serhiy-storchaka@miss-islington@bedevere-bot@benjaminp

[8]ページ先頭

©2009-2025 Movatter.jp