Skip to content

Hash collision security issue #57912

Closed
Closed

Description

@warsaw
BPO 13703
Nosy @malemburg, @gvanrossum, @tim-one, @loewis, @warsaw, @birkenfeld, @terryjreedy, @gpshead, @jcea, @mdickinson, @pitrou, @tiran, @benjaminp, @serwy, @merwok, @alex, @skrah, @davidmalcolm, @bz2, @markshannon, @ericsnowcurrently, @JimJJewett, @PaulMcMillan
Dependencies
  • bpo-13704: Random number generator in Python core
  • Files
  • hash-attack.patch
  • SafeDict.py: SafeDict implementation
  • bench_startup.py
  • random-8.patch
  • hash-collision-counting-dmalcolm-2012-01-20-001.patch
  • amortized-probe-counting-dmalcolm-2012-01-20-002.patch
  • amortized-probe-counting-dmalcolm-2012-01-21-003.patch
  • hash-attack-2.patch
  • hash-attack-3.patch
  • integercollision.py
  • backport-of-hash-randomization-to-2.7-dmalcolm-2012-01-23-001.patch: Backport of haypo's random-8.patch to 2.7
  • hybrid-approach-dmalcolm-2012-01-25-001.patch: Hybrid approach to solving dict DoS attack
  • hybrid-approach-dmalcolm-2012-01-25-002.patch
  • optin-hash-randomization-for-3.1-dmalcolm-2012-01-27-001.patch
  • optin-hash-randomization-for-3.1-dmalcolm-2012-01-28-001.patch
  • optin-hash-randomization-for-3.1-dmalcolm-2012-01-29-001.patch
  • unnamed
  • optin-hash-randomization-for-3.1-dmalcolm-2012-01-30-001.patch
  • optin-hash-randomization-for-3.1-dmalcolm-2012-01-30-002.patch
  • optin-hash-randomization-for-2.6-dmalcolm-2012-01-30-001.patch
  • results-16.txt
  • add-randomization-to-2.6-dmalcolm-2012-02-01-001.patch
  • fix-broken-tests-on-2.6-dmalcolm-2012-02-01-001.patch
  • add-randomization-to-3.1-dmalcolm-2012-02-01-001.patch
  • fix-broken-tests-on-3.1-dmalcolm-2012-02-01-001.patch
  • add-randomization-to-2.6-dmalcolm-2012-02-06-001.patch
  • fix-broken-tests-on-2.6-dmalcolm-2012-02-06-001.patch
  • add-randomization-to-3.1-dmalcolm-2012-02-06-001.patch
  • fix-broken-tests-on-3.1-dmalcolm-2012-02-06-001.patch
  • add-randomization-to-2.6-dmalcolm-2012-02-11-001.patch
  • add-randomization-to-3.1-dmalcolm-2012-02-11-001.patch
  • add-randomization-to-2.6-dmalcolm-2012-02-13-001.patch
  • add-randomization-to-3.1-dmalcolm-2012-02-13-001.patch
  • hash-patch-3.1-gb-03.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2012-03-13.22:25:45.919>
    created_at = <Date 2012-01-03.19:36:49.855>
    labels = ['type-security', 'interpreter-core', 'release-blocker', '3.11']
    title = 'Hash collision security issue'
    updated_at = <Date 2021-11-08.16:57:10.080>
    user = 'https://github.com/warsaw'

    bugs.python.org fields:

    activity = <Date 2021-11-08.16:57:10.080>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-03-13.22:25:45.919>
    closer = 'gregory.p.smith'
    components = ['Interpreter Core']
    creation = <Date 2012-01-03.19:36:49.855>
    creator = 'barry'
    dependencies = ['13704']
    files = ['24151', '24169', '24223', '24259', '24286', '24288', '24289', '24295', '24299', '24300', '24304', '24320', '24324', '24343', '24353', '24365', '24366', '24370', '24371', '24375', '24385', '24391', '24392', '24393', '24394', '24434', '24435', '24436', '24437', '24490', '24491', '24514', '24515', '24563']
    hgrepos = []
    issue_num = 13703
    keywords = ['patch']
    message_count = 328.0
    messages = ['150522', '150525', '150526', '150529', '150531', '150532', '150533', '150534', '150541', '150543', '150558', '150559', '150560', '150562', '150563', '150565', '150568', '150569', '150570', '150577', '150589', '150592', '150601', '150609', '150613', '150616', '150619', '150620', '150621', '150622', '150625', '150634', '150635', '150636', '150637', '150638', '150639', '150641', '150642', '150643', '150644', '150645', '150646', '150647', '150648', '150649', '150650', '150651', '150652', '150655', '150656', '150659', '150662', '150665', '150668', '150694', '150699', '150702', '150706', '150707', '150708', '150712', '150713', '150718', '150719', '150724', '150725', '150726', '150727', '150738', '150748', '150756', '150766', '150768', '150769', '150771', '150795', '150829', '150832', '150835', '150836', '150840', '150847', '150856', '150857', '150859', '150865', '150866', '150934', '151012', '151017', '151031', '151033', '151047', '151048', '151061', '151062', '151063', '151064', '151065', '151069', '151070', '151071', '151073', '151074', '151078', '151092', '151120', '151121', '151122', '151157', '151158', '151159', '151167', '151353', '151401', '151402', '151419', '151422', '151448', '151449', '151468', '151472', '151474', '151484', '151519', '151528', '151560', '151561', '151565', '151566', '151567', '151574', '151582', '151583', '151584', '151585', '151586', '151589', '151590', '151596', '151604', '151617', '151620', '151625', '151626', '151628', '151629', '151632', '151633', '151647', '151662', '151664', '151677', '151679', '151680', '151681', '151682', '151684', '151685', '151689', '151691', '151699', '151700', '151701', '151703', '151707', '151714', '151731', '151734', '151735', '151737', '151739', '151744', '151745', '151747', '151748', '151753', '151754', '151756', '151758', '151794', '151796', '151798', '151812', '151813', '151814', '151815', '151825', '151826', '151847', '151850', '151867', '151869', '151870', '151939', '151941', '151942', '151944', '151956', '151959', '151960', '151961', '151965', '151966', '151967', '151970', '151973', '151977', '151984', '152030', '152033', '152037', '152039', '152040', '152041', '152043', '152046', '152051', '152057', '152060', '152066', '152070', '152104', '152112', '152117', '152118', '152125', '152146', '152149', '152183', '152186', '152199', '152200', '152203', '152204', '152270', '152271', '152275', '152276', '152299', '152300', '152309', '152311', '152315', '152335', '152344', '152352', '152362', '152364', '152422', '152452', '152453', '152723', '152730', '152731', '152732', '152734', '152740', '152747', '152753', '152754', '152755', '152758', '152760', '152763', '152764', '152767', '152768', '152769', '152777', '152780', '152781', '152784', '152787', '152789', '152797', '152811', '152855', '153055', '153074', '153081', '153082', '153140', '153141', '153143', '153144', '153297', '153301', '153369', '153395', '153682', '153683', '153690', '153695', '153750', '153753', '153798', '153802', '153817', '153833', '153848', '153849', '153850', '153852', '153853', '153854', '153860', '153861', '153862', '153868', '153872', '153873', '153877', '153975', '153980', '154428', '154430', '154432', '154853', '155293', '155472', '155527', '155680', '155681', '155682', '405727', '405745']
    nosy_count = 36.0
    nosy_names = ['lemburg', 'gvanrossum', 'tim.peters', 'loewis', 'barry', 'georg.brandl', 'terry.reedy', 'gregory.p.smith', 'jcea', 'mark.dickinson', 'pitrou', 'christian.heimes', 'benjamin.peterson', 'roger.serwy', 'eric.araujo', 'grahamd', 'Arfrever', 'v+python', 'alex', 'cvrebert', 'zbysz', 'skrah', 'dmalcolm', 'gz', 'neologix', 'Arach', 'Mark.Shannon', 'python-dev', 'eric.snow', 'Zhiping.Deng', 'Huzaifa.Sidhpurwala', 'Jim.Jewett', 'PaulMcMillan', 'fx5', 'skorgu', 'jsvaughan']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'needs patch'
    status = 'closed'
    superseder = None
    type = 'security'
    url = 'https://bugs.python.org/issue13703'
    versions = ['Python 3.11']

    Activity

    1. warsaw commented on Jan 3, 2012

      @warsaw
      MemberAuthor

      This is already publicly known and in deep discussion on python-dev. The proper fix is still TBD. Essentially, hash collisions can be exploited to DoS a web framework that automatically parses input forms into dictionaries.

      Start here:

      http://mail.python.org/pipermail/python-dev/2011-December/115116.html

    2. added
      interpreter-core
      type-security
      on Jan 3, 2012
    3. tiran commented on Jan 3, 2012

      @tiran
      Member

      I had a short chat with Guido yesterday. I'll try to sum up the conversation. Guido, please correct me if I got something wrong or missed a point.

      Guido wants the fix as simple and less intrusive as possible as he wants to provide/apply a patch for Python 2.4 to 3.3. This means any new stuff is off the table unless it's really, really necessary. Say goodbye to my experimental MurmurHash3 patch.

      We haven't agreed whether the randomization should be enabled by default or disabled by default. IMHO it should be disabled for all releases except for the upcoming 3.3 release. The env var PYTHONRANDOMHASH=1 would enable the randomization. It's simple to set the env var in e.g. Apache for mod_python and mod_wsgi.

    4. pitrou commented on Jan 3, 2012

      @pitrou
      Member

      We haven't agreed whether the randomization should be enabled by
      default or disabled by default. IMHO it should be disabled for all
      releases except for the upcoming 3.3 release.

      I think on the contrary it must be enabled by default. Leaving security
      holes open is wrong.

    5. tiran commented on Jan 3, 2012

      @tiran
      Member

      I think on the contrary it must be enabled by default. Leaving security
      holes open is wrong.

      We can't foresee the implications of the randomization and only a small number of deployments is affected by the problem. But I won't start a fight on the matter. ;)

    6. gvanrossum commented on Jan 3, 2012

      @gvanrossum
      Member

      I'm with Antoine -- turn it on by default. Maybe there should be a release candidate to test the waters.

    7. warsaw commented on Jan 3, 2012

      @warsaw
      MemberAuthor

      On Jan 03, 2012, at 08:24 PM, Antoine Pitrou wrote:

      I think on the contrary it must be enabled by default. Leaving security
      holes open is wrong.

      Unless there's evidence of performance regressions or backward
      incompatibilities, I agree.

    8. vstinner commented on Jan 3, 2012

      @vstinner
      Member

      Unless there's evidence of performance regressions
      or backward incompatibilities, I agree.

      If hash() is modified, str(dict) and str(set) will change for example. It may break doctests. Can we consider that the application should not rely (indirectly) on hash and so fix (for example) their doctests? Or is it a backward incompatibility?

      hash() was already modified in major Python versions.

      For this specific issue, I consider that security is more important than str(dict).

    9. benjaminp commented on Jan 3, 2012

      @benjaminp
      Contributor

      Barry, when this gets fixed, shall we coordinate release times?

    10. warsaw commented on Jan 3, 2012

      @warsaw
      MemberAuthor

      On Jan 03, 2012, at 09:43 PM, Benjamin Peterson wrote:

      Barry, when this gets fixed, shall we coordinate release times?

      Yes!

    11. tiran commented on Jan 3, 2012

      @tiran
      Member

      Randomized hashing destabilizes the unit tests of Python, too. Here are the outputs of four test runs:

      11 tests failed:
      test_collections test_dbm test_dis test_gdb test_inspect
      test_packaging test_set test_symtable test_ttk_textonly
      test_urllib test_urlparse

      9 tests failed:
      test_dbm test_dis test_gdb test_json test_packaging test_set
      test_symtable test_urllib test_urlparse

      10 tests failed:
      test_dbm test_dis test_gdb test_inspect test_packaging test_set
      test_symtable test_ttk_textonly test_urllib test_urlparse

      9 tests failed:
      test_collections test_dbm test_dict test_dis test_gdb
      test_packaging test_symtable test_urllib test_urlparse

    12. PaulMcMillan commented on Jan 3, 2012

      PaulMcMillanmannequin
      Mannequin

      I agree that we should enable randomness by default, and provide an easy way for users to disable it if necessary (unit test suites that explicitly depend on order being an obvious candidate).

      I'll link my proposed algorithm change here, for the record:
      https://gist.github.com/0a91e52efa74f61858b5

      I've gotten confirmation from several other sources that the fix recommended by the presenters (just a random initialization seed) only prevents the most basic form of the attack.

    13. vstinner commented on Jan 4, 2012

      @vstinner
      Member

      Christian Heimes proposes the following change in its randomhash branch (see issue bpo-13704):

      -    x = (Py_uhash_t) *p << 7;
      +    x = Py_RndHashSeed + ((Py_uhash_t) *p << 7);
           for (i = 0; i < len; i++)
               x = (1000003U * x) ^ (Py_uhash_t) *p++;
           x ^= (Py_uhash_t) len;

      This change doesn't add any security if the attacker can inject any string and retreive the hash value. You can retreive directly Py_RndHashSeed using:

      Py_RndHashSeed = intmask((hash("a") ^ len("a") ^ ord("a")) * DIVIDE) - (ord("a") << 7)

      where intmask() truncates to a long (x mod 2^(long bits)) and DIVIDE = 1/1000003 mod 2^(long bits). For example, DIVIDE=2021759595 for 32 bits long.

    14. 306 remaining items

    15. serwy commented on Feb 27, 2012

      serwymannequin
      Mannequin

      It was a false alarm. I didn't recompile python before running it with the latest /Lib files. My apologies.

    16. cvrebert commented on Mar 3, 2012

      cvrebertmannequin
      Mannequin

      The Design and History FAQ (will) need a minor corresponding update:
      http://docs.python.org/dev/faq/design.html#how-are-dictionaries-implemented

    17. kseifriedredhatcom commented on Mar 10, 2012

      kseifriedredhatcommannequin
      Mannequin
    18. jsvaughan commented on Mar 12, 2012

      jsvaughanmannequin
      Mannequin

      FWIW I upgraded to ubuntu pangolin beta over the weekend, which includes 2.7.3rc1, and I'm also experiencing a problem with urandom.

      File "/usr/lib/python2.7/email/utils.py", line 27, in <module>
      import random
      File "/usr/lib/python2.7/random.py", line 47, in <module>
      from os import urandom as _urandom
      ImportError: cannot import name urandom

      Given Roger Serwy's comment it sounds like a beta ubuntu problem, but thought it worth mentioning.

    19. vstinner commented on Mar 12, 2012

      @vstinner
      Member

      FWIW I upgraded to ubuntu pangolin beta over the weekend,
      which includes 2.7.3rc1, ...

      File "/usr/lib/python2.7/random.py", line 47, in <module>
      from os import urandom as _urandom
      ImportError: cannot import name urandom

      It looks like you are using random.py of Python 2.7.3 with the Python program 2.7.2, because os.urandom() is now always available in Python 2.7.3.

    20. jsvaughan commented on Mar 13, 2012

      jsvaughanmannequin
      Mannequin

      Victor - yes that was it; a mixture of a 2.7.2 virtual env and 2.7.3. Apologies for any nuisance caused.

    21. vstinner commented on Mar 13, 2012

      @vstinner
      Member

      Can we close this issue?

    22. gpshead commented on Mar 13, 2012

      @gpshead
      Member

      I believe so. This is in all of the release candidates.

      The expat/xmlparse.c hash collision DoS issue is being handled on its own via http://bugs.python.org/issue14234.

    23. added
      3.11
      and removed
      interpreter-core
      on Nov 4, 2021
    24. added
      interpreter-core
      on Nov 4, 2021
    25. gvanrossum commented on Nov 4, 2021

      @gvanrossum
      Member

      Hey Erlend, why did you add so many people to the nosy list of this old
      issue?

      On Thu, Nov 4, 2021 at 07:33 Erlend E. Aasland <report@bugs.python.org>
      wrote:

      Change by Erlend E. Aasland <erlend.aasland@innova.no>:

      ----------
      components: +Interpreter Core -Argument Clinic
      nosy: +Arach, Arfrever, Huzaifa.Sidhpurwala, Jim.Jewett, Mark.Shannon,
      PaulMcMillan, Zhiping.Deng, alex, barry, benjamin.peterson,
      christian.heimes, cvrebert, dmalcolm, eric.araujo, eric.snow, fx5,
      georg.brandl, grahamd, gregory.p.smith, gvanrossum, gz, jcea, jsvaughan,
      lemburg, loewis, mark.dickinson, neologix, pitrou, python-dev, roger.serwy,
      skorgu, skrah, terry.reedy, tim.peters, v+python, vstinner, zbysz
      -ahmedsayeed1982, larry


      Python tracker <report@bugs.python.org>
      <https://bugs.python.org/issue13703\>


      --
      --Guido (mobile)

    26. terryjreedy commented on Nov 4, 2021

      @terryjreedy
      Member

      Because today's spammer, whose message was removed, deleted us all. Restoring the version to 3.3 is not possible.

    27. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.11interpreter-corerelease-blockertype-security

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions