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

runtime: hash function should be randomized to prevent DOS attacks #2630

Closed
rmmh opened this issue Dec 29, 2011 · 14 comments
Closed

runtime: hash function should be randomized to prevent DOS attacks #2630

rmmh opened this issue Dec 29, 2011 · 14 comments
Milestone

Comments

@rmmh
Copy link
Contributor

rmmh commented Dec 29, 2011

Carefully crafted POST data can trigger a DOS by exploiting map's O(n) worst-case
performance by supplying keys that are known to collide.

The preferred fix for this is randomized hash functions.

oCERT advisory: http://www.ocert.org/advisories/ocert-2011-003.html
28C3 presentation: http://www.youtube.com/watch?v=R2Cq3CLI6H8
@rmmh
Copy link
Contributor Author

rmmh commented Dec 29, 2011

Comment 1:

Randomizing the hash function could be as simple as replacing the hash initialization
values (runtime/alg.c:20,22) with ones generated when the runtime starts.
Is there anything special about the magic numbers 2860486313 and 33054211828000289? They
have 19 and 27 set bits, respectively. I suspect any number with around half the bits
set and evenly distributed would have very similar performance.

@adg
Copy link
Contributor

adg commented Jan 4, 2012

Comment 2:

Labels changed: added priority-go1, removed priority-triage.

Owner changed to @rsc.

Status changed to Accepted.

@robpike
Copy link
Contributor

robpike commented Jan 13, 2012

Comment 3:

Owner changed to builder@golang.org.

@gopherbot
Copy link
Contributor

Comment 4 by thirsteh:

This may be of interest if the hash function is being altered anyway:
http://code.google.com/p/cityhash/source/browse/trunk/README

@dgryski
Copy link
Contributor

dgryski commented Jan 28, 2012

Comment 5:

Cityhash is overkill for a runtime hash function, and probably isn't sufficiently random
for the lengths of data we're likely to be using as map keys. Jenkins one-at-a-time has
much simpler code and would be good enough here. It's also what Perl uses for their
hashes. As a side note, there's already an implementation of Jenkins at
http://github.com/dgryski/dgohash .

@dgryski
Copy link
Contributor

dgryski commented Jan 28, 2012

Comment 6:

ENOCOFFEE:  Forgot the runtime is in C.  Anyways, the original Jenkins' C code is in the
public domain anyway: http://burtleburtle.net/bob/hash/doobs.html

@rsc
Copy link
Contributor

rsc commented Jan 29, 2012

Comment 7:

We won't be changing the hash function this close to Go 1,
to avoid introducing last-minute bugs.
However, after Go 1, I do think we should look into
whether it makes sense to use a different hash function.
If someone wants to do the work and the benchmarking,
great.

@rsc
Copy link
Contributor

rsc commented Jan 30, 2012

Comment 8:

Labels changed: added go1-must.

@rsc
Copy link
Contributor

rsc commented Feb 2, 2012

Comment 9:

This issue was closed by revision 8e765da.

Status changed to Fixed.

@gopherbot
Copy link
Contributor

Comment 10 by bboissin:

I might have misread the code, but I don't see a seed being used in alg.c (the "seed" is
mixed with the hash after the hash computation, so a collision will happen regardless of
the seed being changed.

@ianlancetaylor
Copy link
Member

Comment 11:

Since the seed is used in the hash computations, the set of keys that will collide is
different each time the program is run.  That avoids the stated problem.

@patrickmn
Copy link

Comment 12:

It helps, but the IV only adds so much randomness. A more long-term solution would be to
e.g. use https://131002.net/siphash/ down the road.

@ianlancetaylor
Copy link
Member

Comment 13:

I don't understand the benefit that would bring, but I do know this: if this is an
important issue that should be addressed, please open a new issue about it, rather than
adding a comment to an issue that is marked fixed.  Please don't simply reopen this
issue, as I believe the issue described in the original comment is indeed fixed.  Please
open a new issue describing the problem and the proposal.  Thanks.

@patrickmn
Copy link

Comment 14:

SipHash has similar speed to non-cryptographic hash functions, but it's about as hard to
find collisions as it is with cryptographically strong hash functions, rendering
pre-compute efforts futile even if the attacker guesses the IV/salt (or precomputes for
the set of all possible salts.)
I don't think it's terribly important, or that Go should adopt it yet--it's pretty
new--but point taken. I will, thanks. (FWIW, the Perl community was the first by far to
adopt IV randomization, and they've switched.)

@rmmh rmmh added fixed labels Jan 1, 2013
@rsc rsc added this to the Go1 milestone Apr 10, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants