netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* RFC: Established connections hash function
@ 2007-03-22 15:39 Nikolaos D. Bougalis
  2007-03-22 15:52 ` Evgeniy Polyakov
  2007-03-27 14:11 ` Andi Kleen
  0 siblings, 2 replies; 32+ messages in thread
From: Nikolaos D. Bougalis @ 2007-03-22 15:39 UTC (permalink / raw)
  To: netdev

    Hello,

    I have noticed that the hash function that the kernel uses for
established TCP/IP connections is rather simplistic, specifically:

    h = (local address ^ local_port) ^ (remote_address ^ remote_port);
    h ^= h >> 16;
    h ^= h >> 8;

    Now, simple is great, but this has a number of issues, not the least of
which is that an attacker can very easily cause collisions and force
extremely long chain lengths, a situation that becomes worse the more
distinct IP addresses and listening ports a box has.

    Consider, for example, a box that has 20 ports open and 4 consecutive IP
addresses. An attacker that has an entire class C available can create
24,576 connections that hash to the same value, resulting in a ridiculously
overlong chain. With servers that do virtual hosting and have dozens of IPs,
the situation can become much worse very fast.

    This particular hash seems to be the odd-man out, since most other
network related hashes in the kernel seem to be Jenkins-based, and some use
tagged hashing to defeat algorithmic complexity attacks. For example, the
route hash uses this:

static unsigned int rt_hash_rnd;

static unsigned int rt_hash_code(u32 daddr, u32 saddr)
{
        return (jhash_2words(daddr, saddr, rt_hash_rnd)
                & rt_hash_mask);
}

    With this in mind, I propose the following replacement for inet_ehashfn,
which defeats algorithmic complexity attacks and achieves excellent
distribution:

unsigned int inet_ehashfn(const __be32 laddr, const __u16 lport,
                          const __be32 faddr, const __be16 fport)
{
    return jhash_3words((__force __u32)faddr, (__force __u32)laddr,
                        (((__force __u32)fport) << 16) + lport,
                        inet_ehash_rnd);
}

    where inet_ehash_rnd is initialized once in tcp_init to a random 32-bit
value.

    I will be more than happy to provide a patch for this, but I figured I
would solicit some input first.

    Nik B.



^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2007-03-29  9:19 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-22 15:39 RFC: Established connections hash function Nikolaos D. Bougalis
2007-03-22 15:52 ` Evgeniy Polyakov
2007-03-22 17:32   ` Nikolaos D. Bougalis
2007-03-22 18:21     ` Evgeniy Polyakov
2007-03-22 19:44       ` Nikolaos D. Bougalis
2007-03-22 19:56         ` Evgeniy Polyakov
2007-03-22 20:53           ` Nikolaos D. Bougalis
2007-03-23  7:52             ` Evgeniy Polyakov
2007-03-22 20:58         ` David Miller
2007-03-22 22:03           ` Eric Dumazet
2007-03-23  7:11             ` David Miller
2007-03-23  8:00               ` Eric Dumazet
2007-03-23 18:46                 ` David Miller
2007-03-23  8:07           ` Evgeniy Polyakov
2007-03-23  8:17             ` Eric Dumazet
2007-03-23  8:33               ` Evgeniy Polyakov
2007-03-23  9:10                 ` Evgeniy Polyakov
2007-03-23 11:58             ` XOR hash beauty solved [Was: RFC: Established connections hash function] Evgeniy Polyakov
2007-03-23 12:51               ` Nikolaos D. Bougalis
2007-03-23 12:45             ` RFC: Established connections hash function Nikolaos D. Bougalis
2007-03-27 14:11 ` Andi Kleen
2007-03-28  5:01   ` Nikolaos D. Bougalis
2007-03-28  6:29     ` David Miller
2007-03-28  9:29     ` Andi Kleen
2007-03-28 10:45       ` Evgeniy Polyakov
2007-03-28 14:14         ` Andi Kleen
2007-03-28 13:50           ` Eric Dumazet
2007-03-28 14:52             ` Andi Kleen
2007-03-29  9:18               ` Evgeniy Polyakov
2007-03-28 14:17           ` RFC: Established connections hash function II Andi Kleen
2007-03-28 19:04           ` RFC: Established connections hash function David Miller
2007-03-28 20:12             ` Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).