Skip to content

Commit

Permalink
tcp: add some entropy in __inet_hash_connect()
Browse files Browse the repository at this point in the history
Even when implementing RFC 6056 3.3.4 (Algorithm 4: Double-Hash
Port Selection Algorithm), a patient attacker could still be able
to collect enough state from an otherwise idle host.

Idea of this patch is to inject some noise, in the
cases __inet_hash_connect() found a candidate in the first
attempt.

This noise should not significantly reduce the collision
avoidance, and should be zero if connection table
is already well used.

Note that this is not implementing RFC 6056 3.3.5
because we think Algorithm 5 could hurt typical
workloads.

Signed-off-by: Eric Dumazet <[email protected]>
Cc: David Dworken <[email protected]>
Cc: Willem de Bruijn <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Eric Dumazet authored and davem330 committed Feb 11, 2021
1 parent 190cc82 commit c579bd1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions net/ipv4/inet_hashtables.c
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,11 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
return -EADDRNOTAVAIL;

ok:
/* If our first attempt found a candidate, skip next candidate
* in 1/16 of cases to add some noise.
*/
if (!i && !(prandom_u32() % 16))
i = 2;
WRITE_ONCE(table_perturb[index], READ_ONCE(table_perturb[index]) + i + 2);

/* Head lock still held and bh's disabled */
Expand Down

0 comments on commit c579bd1

Please sign in to comment.